From: "kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core" Date: 2023-12-01T16:28:40+00:00 Subject: [ruby-core:115567] [Ruby master Feature#20034] [mkmf] Support creating a compilation database for C language tooling Issue #20034 has been updated by kjtsanaktsidis (KJ Tsanaktsidis). Oh, I wrote a gem for this a while ago! https://rubygems.org/gems/extconf_compile_commands_json Does this do what you want? (I haven���t used it in a year or so, so it could just be broken at the moment - if so let me know and I���ll try and fix it). ---------------------------------------- Feature #20034: [mkmf] Support creating a compilation database for C language tooling https://bugs.ruby-lang.org/issues/20034#change-105500 * Author: pounce (Calvin Lee) * Status: Open * Priority: Normal ---------------------------------------- # Abstract Ruby projects are often developed with C extensions. These can be easily compiled by ruby by using `create_makefile` in `mkmf.rb`. Unfortunately, most C tooling is unable to interpret the ruby build system for C files, and thus cannot provide useful diagnostics to users about their C extensions. This request entails generating a compilation database (as discussed below), which would allow C tooling to understand how the extensions are compiled. # Background A [compilation database](https://clang.llvm.org/docs/JSONCompilationDatabase.html) is a standard format used to describe how C and C++ translation units are compiled. This is primarily used for a build system to communicate to C language tooling (such as a language server). Language servers need this information in order to determine how symbols, definitions and declarations are related in different files; and allows them to show descriptive warnings that may occur during compilation. This also allows users to perform quick and efficient refactors in their text editor. It is supported by many build systems by default, such as CMake and Meson. These build systems often place a `compile_commands.json` in the `build/` directory, which is automatically detected by most language servers. It is also supported by language servers such as clangd and ccls. # Proposal When generating a makefile in `create_makefile`, a compilation database should also be created for all targets that are to be compiled. # Implementation The location of the compilation database should be configurable, both by library and environment variable, so that a user may redirect the compilation database to a specific location if they desire. # Evaluation This feature should be evaluated as successful if it is compatible with common language servers such as clangd and ccls. For example, if a user first compiles a project and then edits a C file that is compiled, then clangd should work with little to no configuration. # Discussion For more information about compilation databases, please see [clangd's informational site](https://clangd.llvm.org/design/compile-commands) as well as [the ccls wiki])(https://github.com/MaskRay/ccls/wiki/Project-Setup). There is also an [article](https://sarcasm.github.io/notes/dev/compilation-database.html) by [Guillaume Papin](https://github.com/sarcasm) which discusses compilation databases and software which supports them. As an alternative, users may use [Bear](https://github.com/rizsotto/Bear) to generate their compilation database. However, this is not optimal, as it only works on Linux. Furthermore, Bear is only able to capture flags for C files which are compiled during a single execution of the build system. Thus, is not able to record flags for C files which have been skipped. -- https://bugs.ruby-lang.org/ ______________________________________________ ruby-core mailing list -- ruby-core@ml.ruby-lang.org To unsubscribe send an email to ruby-core-leave@ml.ruby-lang.org ruby-core info -- https://ml.ruby-lang.org/mailman3/postorius/lists/ruby-core.ml.ruby-lang.org/