Skip to content

Commit

Permalink
Setup clangd-based native dev env via rake native_dev:setup
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexJF committed Nov 7, 2023
1 parent b84ca45 commit e0bc04f
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 2 deletions.
52 changes: 50 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -602,14 +602,62 @@ namespace :changelog do
end
end

Rake::ExtensionTask.new("ddtrace_profiling_native_extension.#{RUBY_VERSION}_#{RUBY_PLATFORM}") do |ext|
native_exts = []

native_exts << Rake::ExtensionTask.new("ddtrace_profiling_native_extension.#{RUBY_VERSION}_#{RUBY_PLATFORM}") do |ext|
ext.ext_dir = 'ext/ddtrace_profiling_native_extension'
end

Rake::ExtensionTask.new("ddtrace_profiling_loader.#{RUBY_VERSION}_#{RUBY_PLATFORM}") do |ext|
native_exts << Rake::ExtensionTask.new("ddtrace_profiling_loader.#{RUBY_VERSION}_#{RUBY_PLATFORM}") do |ext|
ext.ext_dir = 'ext/ddtrace_profiling_loader'
end

NATIVE_CLEAN = ::Rake::FileList['ext/**/*.o', 'ext/**/*.bundle']
namespace :native_dev do
def generate_ext_makefile(ext)
cmd = ext.make_makefile_cmd(Dir.pwd, ext.ext_dir, "#{ext.ext_dir}/#{ext.config_script}", nil)
puts cmd
chdir ext.ext_dir do
sh(*cmd)
end
end

def generate_ext_compile_commands(ext)
chdir ext.ext_dir do
sh('make clean; bear -- make; make clean')
end
end

compile_commands_tasks = native_exts.map do |ext|
makefile_task = file "#{ext.ext_dir}/Makefile" do
generate_ext_makefile(ext)
end

NATIVE_CLEAN << makefile_task.name
NATIVE_CLEAN << "#{ext.ext_dir}/extconf.h"
NATIVE_CLEAN << "#{ext.ext_dir}/mkmf.log"

compile_commands_task = file "#{ext.ext_dir}/compile_commands.json": [makefile_task] do
generate_ext_compile_commands(ext)
end

NATIVE_CLEAN << compile_commands_task.name
compile_commands_task
end

desc 'Setup dev environment for native extensions.'
task setup: compile_commands_tasks do
puts 'Setting up native dev env'
end

desc 'Remove files generated for dev setup.'
task :clean do
Rake::Cleaner.cleanup_files(NATIVE_CLEAN)
end

CLEAN.concat(NATIVE_CLEAN)
end

desc 'Runs rubocop + main test suite'
task default: ['rubocop', 'typecheck', 'spec:main']

Expand Down
4 changes: 4 additions & 0 deletions ext/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
*/Makefile
*/extconf.h
*/compile_commands.json
*/.cache
1 change: 1 addition & 0 deletions ext/ddtrace_profiling_loader/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DisableFormat: true
1 change: 1 addition & 0 deletions ext/ddtrace_profiling_native_extension/.clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DisableFormat: true

0 comments on commit e0bc04f

Please sign in to comment.