Project

General

Profile

Actions

Feature #20034

open

[mkmf] Support creating a compilation database for C language tooling

Added by pounce (Calvin Lee) 5 months ago. Updated 4 months ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:115565]

Description

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 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 as well as [the ccls wiki])(https://github.com/MaskRay/ccls/wiki/Project-Setup). There is also an article by Guillaume Papin which discusses compilation databases and software which supports them.

As an alternative, users may use 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.

Actions

Also available in: Atom PDF

Like1
Like0Like0Like0Like0Like0Like1