From: "rubyFeedback (robert heiler) via ruby-core" Date: 2023-12-02T07:17:45+00:00 Subject: [ruby-core:115573] [Ruby master Feature#20034] [mkmf] Support creating a compilation database for C language tooling Issue #20034 has been updated by rubyFeedback (robert heiler). kjtsanaktsidis wrote: > I wonder if a middle ground between "in cruby" and "in a gem that ~nobody knows about" would be to include this functionality in the rake-compiler gem. This may be useful in that the functionality could become part of rake or rake-addons. The total number of people searching, and finding, gems such as the one mentioned above (even more so if it is a rare gem or disjoint from other more common ruby gems/tools), is probably very small (or may never find it, considering how even Google search does not always yield the best results these days), so exposing or "bundling" this via rake (or any other popular tool/gem) would surely be helpful. ---------------------------------------- Feature #20034: [mkmf] Support creating a compilation database for C language tooling https://bugs.ruby-lang.org/issues/20034#change-105507 * 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/