ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:115565] [Ruby master Feature#20034] [mkmf] Support creating a compilation database for C language tooling
@ 2023-12-01 14:00 pounce (Calvin Lee) via ruby-core
  2023-12-01 16:28 ` [ruby-core:115567] " kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: pounce (Calvin Lee) via ruby-core @ 2023-12-01 14:00 UTC (permalink / raw
  To: ruby-core; +Cc: pounce (Calvin Lee)

Issue #20034 has been reported by pounce (Calvin Lee).

----------------------------------------
Feature #20034: [mkmf] Support creating a compilation database for C language tooling
https://bugs.ruby-lang.org/issues/20034

* 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/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:115567] [Ruby master Feature#20034] [mkmf] Support creating a compilation database for C language tooling
  2023-12-01 14:00 [ruby-core:115565] [Ruby master Feature#20034] [mkmf] Support creating a compilation database for C language tooling pounce (Calvin Lee) via ruby-core
@ 2023-12-01 16:28 ` kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core
  2023-12-01 22:11 ` [ruby-core:115570] " pounce (Calvin Lee) via ruby-core
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core @ 2023-12-01 16:28 UTC (permalink / raw
  To: ruby-core; +Cc: kjtsanaktsidis (KJ Tsanaktsidis)

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/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:115570] [Ruby master Feature#20034] [mkmf] Support creating a compilation database for C language tooling
  2023-12-01 14:00 [ruby-core:115565] [Ruby master Feature#20034] [mkmf] Support creating a compilation database for C language tooling pounce (Calvin Lee) via ruby-core
  2023-12-01 16:28 ` [ruby-core:115567] " kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core
@ 2023-12-01 22:11 ` pounce (Calvin Lee) via ruby-core
  2023-12-02  0:13 ` [ruby-core:115572] " kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pounce (Calvin Lee) via ruby-core @ 2023-12-01 22:11 UTC (permalink / raw
  To: ruby-core; +Cc: pounce (Calvin Lee)

Issue #20034 has been updated by pounce (Calvin Lee).


kjtsanaktsidis (KJ Tsanaktsidis) wrote in #note-1:
> 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).

I found this during my search! I apologize for not linking to it. It did not work for me (insomuch that I could not find the generated compile-commands.json). I believe the `RUBYOPT` functionality is quite useful, and is what I needed since I am working on an open source project that I do not own.
I ended up using bear, as described in my request.

However, I still think it would be nice if this functionality were added to upstream ruby. This would make ruby C compilation feature-compatible to other common build systems, and it would make C tooling work automatically in Ruby projects.


----------------------------------------
Feature #20034: [mkmf] Support creating a compilation database for C language tooling
https://bugs.ruby-lang.org/issues/20034#change-105504

* 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/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:115572] [Ruby master Feature#20034] [mkmf] Support creating a compilation database for C language tooling
  2023-12-01 14:00 [ruby-core:115565] [Ruby master Feature#20034] [mkmf] Support creating a compilation database for C language tooling pounce (Calvin Lee) via ruby-core
  2023-12-01 16:28 ` [ruby-core:115567] " kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core
  2023-12-01 22:11 ` [ruby-core:115570] " pounce (Calvin Lee) via ruby-core
@ 2023-12-02  0:13 ` kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core
  2023-12-02  7:17 ` [ruby-core:115573] " rubyFeedback (robert heiler) via ruby-core
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core @ 2023-12-02  0:13 UTC (permalink / raw
  To: ruby-core; +Cc: kjtsanaktsidis (KJ Tsanaktsidis)

Issue #20034 has been updated by kjtsanaktsidis (KJ Tsanaktsidis).


> It did not work for me (insomuch that I could not find the generated compile-commands.json)

I just had another play around with it - It did work (spat out `./ext/nio4r/compile_commands.json` when I tried to compile nio4r, for example, and my clangd setup could go-to-definition). But I _did_ realise the snippet in the README about how to wrap `rake compile` with `RUBYOPT` was wrong (it was missing an `-r`). If you do give it another go and it still doesn't work for you, please do open an issue about it over there.

> However, I still think it would be nice if this functionality were added to upstream ruby

mkmf is the thing which has the information about how to generate such a file properly; everything else (like my gem) is just hacking at its implementation details from the outside. So, from a "where is the architecturally correct place for this functionality" perspective, I think I agree.

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. In my experience that's how the vast majority of people interact with building C extensions whilst developing them so perhaps that might be a good place to prove out the need for this feature & mature the implementation a bit.

----------------------------------------
Feature #20034: [mkmf] Support creating a compilation database for C language tooling
https://bugs.ruby-lang.org/issues/20034#change-105506

* 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/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:115573] [Ruby master Feature#20034] [mkmf] Support creating a compilation database for C language tooling
  2023-12-01 14:00 [ruby-core:115565] [Ruby master Feature#20034] [mkmf] Support creating a compilation database for C language tooling pounce (Calvin Lee) via ruby-core
                   ` (2 preceding siblings ...)
  2023-12-02  0:13 ` [ruby-core:115572] " kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core
@ 2023-12-02  7:17 ` rubyFeedback (robert heiler) via ruby-core
  2023-12-02 13:17 ` [ruby-core:115578] " pounce (Calvin Lee) via ruby-core
  2023-12-27  0:20 ` [ruby-core:115914] " kou (Kouhei Sutou) via ruby-core
  5 siblings, 0 replies; 7+ messages in thread
From: rubyFeedback (robert heiler) via ruby-core @ 2023-12-02  7:17 UTC (permalink / raw
  To: ruby-core; +Cc: rubyFeedback (robert heiler)

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/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:115578] [Ruby master Feature#20034] [mkmf] Support creating a compilation database for C language tooling
  2023-12-01 14:00 [ruby-core:115565] [Ruby master Feature#20034] [mkmf] Support creating a compilation database for C language tooling pounce (Calvin Lee) via ruby-core
                   ` (3 preceding siblings ...)
  2023-12-02  7:17 ` [ruby-core:115573] " rubyFeedback (robert heiler) via ruby-core
@ 2023-12-02 13:17 ` pounce (Calvin Lee) via ruby-core
  2023-12-27  0:20 ` [ruby-core:115914] " kou (Kouhei Sutou) via ruby-core
  5 siblings, 0 replies; 7+ messages in thread
From: pounce (Calvin Lee) via ruby-core @ 2023-12-02 13:17 UTC (permalink / raw
  To: ruby-core; +Cc: pounce (Calvin Lee)

Issue #20034 has been updated by pounce (Calvin Lee).


kjtsanaktsidis (KJ Tsanaktsidis) wrote in #note-3:
> 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 was my initial idea too. I [opened an issue](https://github.com/rake-compiler/rake-compiler/issues/230) in the rake-compiler repository before I opened this issue, and the rake-compiler maintainer directed me here.

----------------------------------------
Feature #20034: [mkmf] Support creating a compilation database for C language tooling
https://bugs.ruby-lang.org/issues/20034#change-105511

* 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/

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [ruby-core:115914] [Ruby master Feature#20034] [mkmf] Support creating a compilation database for C language tooling
  2023-12-01 14:00 [ruby-core:115565] [Ruby master Feature#20034] [mkmf] Support creating a compilation database for C language tooling pounce (Calvin Lee) via ruby-core
                   ` (4 preceding siblings ...)
  2023-12-02 13:17 ` [ruby-core:115578] " pounce (Calvin Lee) via ruby-core
@ 2023-12-27  0:20 ` kou (Kouhei Sutou) via ruby-core
  5 siblings, 0 replies; 7+ messages in thread
From: kou (Kouhei Sutou) via ruby-core @ 2023-12-27  0:20 UTC (permalink / raw
  To: ruby-core; +Cc: kou (Kouhei Sutou)

Issue #20034 has been updated by kou (Kouhei Sutou).


I'm the current rake-compiler maintainer.

rake-compiler just runs `extconf.rb` and uses generated `Makefile`. If we do this by rake-compiler, rake-compiler needs to parse `Makefile` or something to generate `compile_commands.json`. It's not straightforward and optimal.

I think that `mkmf.rb` not rake-compiler should generate `compile_commands.json`. Or we may want to develop a new modern `mkmf.rb` alternative.

----------------------------------------
Feature #20034: [mkmf] Support creating a compilation database for C language tooling
https://bugs.ruby-lang.org/issues/20034#change-105868

* 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/

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2023-12-27  0:20 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-12-01 14:00 [ruby-core:115565] [Ruby master Feature#20034] [mkmf] Support creating a compilation database for C language tooling pounce (Calvin Lee) via ruby-core
2023-12-01 16:28 ` [ruby-core:115567] " kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core
2023-12-01 22:11 ` [ruby-core:115570] " pounce (Calvin Lee) via ruby-core
2023-12-02  0:13 ` [ruby-core:115572] " kjtsanaktsidis (KJ Tsanaktsidis) via ruby-core
2023-12-02  7:17 ` [ruby-core:115573] " rubyFeedback (robert heiler) via ruby-core
2023-12-02 13:17 ` [ruby-core:115578] " pounce (Calvin Lee) via ruby-core
2023-12-27  0:20 ` [ruby-core:115914] " kou (Kouhei Sutou) via ruby-core

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).