Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make it easy to use clangd (i.e. an IDE) with the engine (especially post-RBE) #148519

Open
matanlurey opened this issue May 16, 2024 · 2 comments
Labels
c: proposal A detailed proposal for a change to Flutter e: engine-tool Engine-specific tooling (i.e. `tools/engine_tool`). e: rbe Related to `RBE` or toolchains in the engine. P3 Issues that are less important to the Flutter project team-engine Owned by Engine team triaged-engine Triaged by Engine team

Comments

@matanlurey
Copy link
Contributor

It was and still is possible to use clangd (i.e. with the VSCode clangd plugin) while working in the engine.

For example, here is an excerpt of my workspace settings (JSON):

"clangd.path": "${workspaceFolder}/buildtools/mac-arm64/clang/bin/clangd",
"clangd.arguments": [
  "--compile-commands-dir=${workspaceFolder}/../out/host_debug_unopt_arm64"
],
"clang-format.executable": "${workspaceRoot}/buildtools/mac-arm64/clang/bin/clang-format",

Even before RBE, this required manual configuration, and requires re-configuration as you change platforms (for example, editing C++ code that uses Android-only dependencies requires the --compile-commands-dir to point to a ../out/android_* target).

Post RBE, the default --compile-commands-dir for Google employees uses flags (wrappers) unrecognized by clangd:

image

One workaround is to intentionally create and use a target output that opts out of RBE:

./tools/gn --unopt --mac-cpu=arm64 --target-dir=host_debug_unopt_arm64_ide --no-rbe

Problems to address (outside of having to do all this manually):

  1. By default, this produces many broken links as a result of (mostly Impeller?) generators that need to run. One such example:

    # There are about ~3 sets of targets that need to be built so that clangd finds all generated files.
    ninja -C ../out/host_debug_unopt_arm64_ide shader_fixtures
  2. Because this target is not actually used, it will frequently get out of date. That is, you will need to need to gclient sync -D
    and reset GN arguments for both the target you're actually working on (i.e. host_debug_unopt_arm64, using RBE), and this stub target (host_debug_unopt_arm64_ide).

I'm opening this issue to solicit ideas for addressing this. Incremental is good, automated is good, tested is better.

@matanlurey matanlurey added c: proposal A detailed proposal for a change to Flutter team-engine Owned by Engine team e: engine-tool Engine-specific tooling (i.e. `tools/engine_tool`). e: rbe Related to `RBE` or toolchains in the engine. labels May 16, 2024
@bc-lee
Copy link

bc-lee commented May 16, 2024

In my opinion, consuming raw compile_commands.json generated by gn isn't feasible for tools like clangd, since gn dumps raw commands with all the flags used to build the target. I don't work at Google and therefore don't use Goma or RBE, but I encountered the same issue a long time ago and developed a solution to parse compile_commands.json and filter out flags unnecessary for consuming tools.

You can find my script here: https://gist.github.com/bc-lee/8707d1e62d14f8bb6bd30ef6e67f1625

The script modifies the compile_commands.json file by removing flags that clangd doesn't need. It's not perfect, but it works for me. At least it's much easier than maintaining a separate output folder to avoid using unnecessary flags with clangd.

Example usage:
$ gn gen --export-compile-commands out/out_dir && parse-compile-commands out/out_dir

@matanlurey
Copy link
Contributor Author

matanlurey commented May 16, 2024

Thanks @bc-lee, that certainly is an option, maybe even the best one.

I'll let the rest of the engine team weigh in, but I appreciate the contribution!

@jonahwilliams jonahwilliams added P3 Issues that are less important to the Flutter project triaged-engine Triaged by Engine team labels May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c: proposal A detailed proposal for a change to Flutter e: engine-tool Engine-specific tooling (i.e. `tools/engine_tool`). e: rbe Related to `RBE` or toolchains in the engine. P3 Issues that are less important to the Flutter project team-engine Owned by Engine team triaged-engine Triaged by Engine team
Projects
None yet
Development

No branches or pull requests

3 participants