No release in over a year
The extconf_compile_commands_json gem allows you to easily generate compatible compile_commands.json files from your extconf.rb file. This makes it easy to use the clangd LSP when working on your gem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
 Dependencies

Development

~> 1.12
 Project Readme

extconf_compile_commands_json

This simple gem generates a clangd-compatible compile_commands.json file from the extconf.rb file of a native gem. It's purpose is to enable clangd/LSP to work better when developing native Ruby extension gems.

Method 1: modifying extconf.rb

Just add this to your extconf.rb file after your create_makefile invocation:

require 'extconf_compile_commands_json'
ExtconfCompileCommandsJson.generate!

That will write out a compile_commands.json file to the same directory that mkmf generated your Makefile in.

If you're using rake-compiler to compile your project, that will be in tmp/${arch}/${gem_name}/${ruby_version}/compile_commands.json; you will probably want to symlink that file into the root of your project so that clangd can find it. This can be done by calling symlink!; so:

require 'extconf_compile_commands_json'
ExtconfCompileCommandsJson.generate!
ExtconfCompileCommandsJson.symlink!

Method 2: without modifying extconf.rb

Modifying extconf.rb is fine if you own all the build config for your project, but if, for example, you're working on somebody else's project and don't want to modify their extconf.rb, you can still use extconf_compile_commands_json! Something like the following should work, if using rake-compiler:

RUBYOPT="$RUBYOPT -r$(gem which extconf_compile_commands_json/autoload)" bundle exec rake compile

That will load up extconf_compile_commands_json as a patch on mkmf and inject it into any Ruby process that your Rake invocation spawns.