diff --git a/Rakefile b/Rakefile index adee0023b..62a33b8c4 100644 --- a/Rakefile +++ b/Rakefile @@ -11,6 +11,14 @@ bin = File.join(__dir__, "bin") Rake::ExtensionTask.new("rbs_extension") +compile_task = Rake::Task[:compile] + +task :setup_extconf_compile_commands_json do + ENV["COMPILE_COMMANDS_JSON"] = "1" +end + +compile_task.prerequisites.unshift(:setup_extconf_compile_commands_json) + test_config = lambda do |t| t.libs << "test" t.libs << "lib" diff --git a/ext/rbs_extension/extconf.rb b/ext/rbs_extension/extconf.rb index ba42c3c6e..88e971c3e 100644 --- a/ext/rbs_extension/extconf.rb +++ b/ext/rbs_extension/extconf.rb @@ -26,6 +26,10 @@ create_makefile 'rbs_extension' -require 'extconf_compile_commands_json' -ExtconfCompileCommandsJson.generate! -ExtconfCompileCommandsJson.symlink! +# Only generate compile_commands.json when compiling through Rake tasks +# This is to avoid adding extconf_compile_commands_json as a runtime dependency +if ENV["COMPILE_COMMANDS_JSON"] + require 'extconf_compile_commands_json' + ExtconfCompileCommandsJson.generate! + ExtconfCompileCommandsJson.symlink! +end