Skip to content

Support Clang LSP development on CRuby - #6352

Closed
tenderlove wants to merge 1 commit into
ruby:masterfrom
tenderlove:clangd-support
Closed

Support Clang LSP development on CRuby#6352
tenderlove wants to merge 1 commit into
ruby:masterfrom
tenderlove:clangd-support

Conversation

@tenderlove

@tenderlove tenderlove commented Sep 9, 2022

Copy link
Copy Markdown
Member

This commit adds a new configure flag --enable-compile-commands. The flag enables building a compilation
database
while building CRuby. This option is intended for people who are doing development work on CRuby using Clang, and is not meant for use when doing normal builds of CRuby.

Enabling this flag will add -MJ [email protected] to the compilation flags. The MJ
flag
takes a file argument, and writes a compilation database entry unit to that file. For example:

$ make gc.o
making gc.rbinc
generating id.h
id.h updated
/usr/bin/ruby --disable=gems ./tool/gen_dummy_probes.rb ./probes.d > probes.dmyh
translating probes probes.d
. ./vm_opts.h
compiling gc.c
$ cat gc.o.json
{ "directory": "/Users/aaron/git/ruby", "file": "gc.c", "output": "gc.o", "arguments": ["/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", "-xc", "gc.c", "-fdeclspec", "-O3", "-fno-fast-math", "-ggdb3", "-Wall", "-Wextra", "-Wextra-tokens", "-Wdeprecated-declarations", "-Wdivision-by-zero", "-Wdiv-by-zero", "-Wimplicit-function-declaration", "-Wimplicit-int", "-Wmisleading-indentation", "-Wpointer-arith", "-Wshorten-64-to-32", "-Wwrite-strings", "-Wold-style-definition", "-Wmissing-noreturn", "-Wno-cast-function-type", "-Wno-constant-logical-operand", "-Wno-long-long", "-Wno-missing-field-initializers", "-Wno-overlength-strings", "-Wno-parentheses-equality", "-Wno-self-assign", "-Wno-tautological-compare", "-Wno-unused-parameter", "-Wno-unused-value", "-Wunused-variable", "-Wundef", "-std=gnu99", "-pipe", "-D", "_FORTIFY_SOURCE=2", "-fstack-protector-strong", "-fno-strict-overflow", "-fvisibility=hidden", "-D", "RUBY_EXPORT", "-fPIE", "-I", ".", "-I", ".ext/include/arm64-darwin21", "-I", "./include", "-I", ".", "-I", "./enc/unicode/14.0.0", "-D", "_XOPEN_SOURCE", "-D", "_DARWIN_C_SOURCE", "-D", "_DARWIN_UNLIMITED_SELECT", "-D", "_REENTRANT", "-o", "gc.o", "-c", "-Wno-reorder-init-list", "-Wno-implicit-int-float-conversion", "-Wno-c99-designator", "-Wno-final-dtor-non-final-class", "-Wno-extra-semi-stmt", "-Wno-quoted-include-in-framework-header", "-Wno-implicit-fallthrough", "-Wno-enum-enum-conversion", "-Wno-enum-float-conversion", "-Wno-elaborated-enum-base", "-Wno-reserved-identifier", "-Wno-gnu-folding-constant", "-Wno-objc-load-method", "-Xclang", "-clang-vendor-feature=+messageToSelfInClassMethodIdReturnType", "-Xclang", "-clang-vendor-feature=+disableInferNewAvailabilityFromInit", "-Xclang", "-clang-vendor-feature=+disableNonDependentMemberExprInCurrentInstantiation", "-mllvm", "-disable-aligned-alloc-awareness=1", "-Xclang", "-fno-odr-hash-protocols", "-Xclang", "-clang-vendor-feature=+enableAggressiveVLAFolding", "-Xclang", "-clang-vendor-feature=+revert09abecef7bbf", "-Xclang", "-clang-vendor-feature=+thisNoAlignAttr", "-Xclang", "-clang-vendor-feature=+thisNoNullAttr", "-mlinker-version=763", "-isysroot", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk", "-mmacosx-version-min=12.0.0", "-stdlib=libc++", "--target=arm64-apple-macosx12.0.0"]},

clangd looks for a file called compile_commands.json, and doing make compile_commands.json will generate that file.

Summary

This PR adds:

$ ./autogen.sh
$ ./configure --enable-compile-commands
$ make -j compile_commands.json

@tenderlove
tenderlove requested a review from nobu September 9, 2022 23:37
@tenderlove
tenderlove force-pushed the clangd-support branch 2 times, most recently from 5cb4304 to d5475d4 Compare September 10, 2022 02:51
Comment thread common.mk Outdated
Comment thread configure.ac
Comment thread configure.ac Outdated
@ioquatix

Copy link
Copy Markdown
Member

I like this.

@tenderlove

Copy link
Copy Markdown
Member Author

@nobu thanks for the feedback. I don't know autotools / Make very well, so I just did my best to get this working. I think if developers enable --enable-compile-commands, then doing make should create compile_commands.json, but I don't know how to do that.

@nobu nobu added the Feature label Sep 11, 2022
Comment thread defs/gmake.mk Outdated
Comment thread defs/gmake.mk Outdated
Comment thread configure.ac Outdated
This commit adds a new configure flag `--enable-compile-commands`.  The
flag enables building a [compilation
database](https://clang.llvm.org/docs/JSONCompilationDatabase.html)
while building CRuby.  This option is intended for people who are doing
development work on CRuby using Clang, and is *not* meant for use when
doing normal builds of CRuby.

Enabling this flag will add `-MJ [email protected]` to the compilation flags.  The
[`MJ`
flag](https://clang.llvm.org/docs/ClangCommandLineReference.html#cmdoption-clang-mj-arg)
takes a file argument, and writes a compilation database entry unit to
that file.  For example:

```
$ make gc.o
making gc.rbinc
generating id.h
id.h updated
/usr/bin/ruby --disable=gems ./tool/gen_dummy_probes.rb ./probes.d > probes.dmyh
translating probes probes.d
. ./vm_opts.h
compiling gc.c
$ cat gc.o.json
{ "directory": "/Users/aaron/git/ruby", "file": "gc.c", "output": "gc.o", "arguments": ["/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang", "-xc", "gc.c", "-fdeclspec", "-O3", "-fno-fast-math", "-ggdb3", "-Wall", "-Wextra", "-Wextra-tokens", "-Wdeprecated-declarations", "-Wdivision-by-zero", "-Wdiv-by-zero", "-Wimplicit-function-declaration", "-Wimplicit-int", "-Wmisleading-indentation", "-Wpointer-arith", "-Wshorten-64-to-32", "-Wwrite-strings", "-Wold-style-definition", "-Wmissing-noreturn", "-Wno-cast-function-type", "-Wno-constant-logical-operand", "-Wno-long-long", "-Wno-missing-field-initializers", "-Wno-overlength-strings", "-Wno-parentheses-equality", "-Wno-self-assign", "-Wno-tautological-compare", "-Wno-unused-parameter", "-Wno-unused-value", "-Wunused-variable", "-Wundef", "-std=gnu99", "-pipe", "-D", "_FORTIFY_SOURCE=2", "-fstack-protector-strong", "-fno-strict-overflow", "-fvisibility=hidden", "-D", "RUBY_EXPORT", "-fPIE", "-I", ".", "-I", ".ext/include/arm64-darwin21", "-I", "./include", "-I", ".", "-I", "./enc/unicode/14.0.0", "-D", "_XOPEN_SOURCE", "-D", "_DARWIN_C_SOURCE", "-D", "_DARWIN_UNLIMITED_SELECT", "-D", "_REENTRANT", "-o", "gc.o", "-c", "-Wno-reorder-init-list", "-Wno-implicit-int-float-conversion", "-Wno-c99-designator", "-Wno-final-dtor-non-final-class", "-Wno-extra-semi-stmt", "-Wno-quoted-include-in-framework-header", "-Wno-implicit-fallthrough", "-Wno-enum-enum-conversion", "-Wno-enum-float-conversion", "-Wno-elaborated-enum-base", "-Wno-reserved-identifier", "-Wno-gnu-folding-constant", "-Wno-objc-load-method", "-Xclang", "-clang-vendor-feature=+messageToSelfInClassMethodIdReturnType", "-Xclang", "-clang-vendor-feature=+disableInferNewAvailabilityFromInit", "-Xclang", "-clang-vendor-feature=+disableNonDependentMemberExprInCurrentInstantiation", "-mllvm", "-disable-aligned-alloc-awareness=1", "-Xclang", "-fno-odr-hash-protocols", "-Xclang", "-clang-vendor-feature=+enableAggressiveVLAFolding", "-Xclang", "-clang-vendor-feature=+revert09abecef7bbf", "-Xclang", "-clang-vendor-feature=+thisNoAlignAttr", "-Xclang", "-clang-vendor-feature=+thisNoNullAttr", "-mlinker-version=763", "-isysroot", "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk", "-mmacosx-version-min=12.0.0", "-stdlib=libc++", "--target=arm64-apple-macosx12.0.0"]},
```

`clangd` [looks for a file called
`compile_commands.json`](https://clangd.llvm.org/installation.html#compile_commandsjson),
and doing `make compile_commands.json` will generate that file.
@ioquatix

Copy link
Copy Markdown
Member

@tenderlove what was the status of this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants