Skip to content

Conversation

@DavidTruby
Copy link
Member

This fixes an issue where builds on Windows with LLVM_OPTIMIZED_TABLEGEN
will fail if CMAKE_MAKE_PROGRAM, CMAKE_C_COMPILER_LAUNCHER or
CMAKE_CXX_COMPILER_LAUNCHER are lists rather than paths to a binary;
this occurs when one of these programs is passed with arguments instead
of just as a path.

On non-Windows this works regardless as the sub-cmake command runs in a
proper shell, but on Windows it runs differently and so these strings
need to be expanded correctly by cmake.

This fixes an issue where builds on Windows with LLVM_OPTIMIZED_TABLEGEN
will fail if CMAKE_MAKE_PROGRAM, CMAKE_C_COMPILER_LAUNCHER or
CMAKE_CXX_COMPILER_LAUNCHER are lists rather than paths to a binary;
this occurs when one of these programs is passed with arguments instead
of just as a path.

On non-Windows this works regardless as the sub-cmake command runs in a
proper shell, but on Windows it runs differently and so these strings
need to be expanded correctly by cmake.
@llvmbot llvmbot added the cmake Build system in general and CMake in particular label May 7, 2025
@DavidTruby
Copy link
Member Author

This is necessary because CMake won't expand a list into string if the quoted string isn't surrounded by whitespace. If it is, it will correctly expand and add quotes around the resulting string, so moving the string to cover the whole "-D..." option will make cmake do the right thing here.

-DCMAKE_MAKE_PROGRAM="${CMAKE_MAKE_PROGRAM}"
-DCMAKE_C_COMPILER_LAUNCHER="${CMAKE_C_COMPILER_LAUNCHER}"
-DCMAKE_CXX_COMPILER_LAUNCHER="${CMAKE_CXX_COMPILER_LAUNCHER}"
"-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you have an example where you'd want to pass flags to the native build system?

Copy link
Member Author

@DavidTruby DavidTruby May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't have one specifically for the CMAKE_MAKE_PROGRAM, I just thought I'd fx it as well while I was here as the same reasoning would apply there.
We want this for CMAKE_C/CXX_COMPILER_LAUNCHER, where we want to add flags to ccache when using LLVM_CCACHE_BUILD to control certain behaviour especially when building flang. When we tried to make that change it worked on non-Windows but didn't work on Windows, this fixes at least that case. So that's the specific motivation for the change.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suppose I can imagine a case where you might want to enable some debug modes in ninja with -d ...

Copy link
Member

@petrhosek petrhosek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, we have other places in LLVM where we set these variables and ideally we would make the same change consistently everywhere.

-DCMAKE_CXX_COMPILER_LAUNCHER="${CMAKE_CXX_COMPILER_LAUNCHER}"
"-DCMAKE_MAKE_PROGRAM=${CMAKE_MAKE_PROGRAM}"
"-DCMAKE_C_COMPILER_LAUNCHER=${CMAKE_C_COMPILER_LAUNCHER}"
"-DCMAKE_CXX_COMPILER_LAUNCHER=${CMAKE_CXX_COMPILER_LAUNCHER}"
Copy link
Contributor

@s-barannikov s-barannikov May 7, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LLVM_TABLEGEN_FLAGS below should also be fixed (added recently, #138086).

Copy link
Member

@Meinersbur Meinersbur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the difference is that the surrounding quotes are handled by CMake itself, so they are never seen when passing them as a command line string.

CMake indeed does not use always use cmd.exe to launch programs, but usually it normalizes paths to absolute paths and using forward slashes instead of backslashes, at least for CMAKE_*_COMPILER. Might be different for others.

@DavidTruby
Copy link
Member Author

DavidTruby commented Jun 3, 2025

I completely forgot that I'd submitted this as I've been really busy with other things...
I don't have the time to update all the places where this needs doing and test it all right now; would people be ok with submitting this as-is for now so we can remove the special cases for ccache+Windows, and punting the issue of fixing it all into a future patch?

Copy link
Member

@Meinersbur Meinersbur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK to commit as-is. It's low impact. LLVM_TABLEGEN_FLAGS can be considered unrelated.

@DavidTruby DavidTruby merged commit 8f7e574 into llvm:main Jun 6, 2025
13 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Jun 6, 2025

LLVM Buildbot has detected a new failure on builder clangd-ubuntu-tsan running on clangd-ubuntu-clang while building llvm at step 6 "test-build-clangd-clangd-index-server-clangd-in...".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/134/builds/20164

Here is the relevant piece of the build log for the reference
Step 6 (test-build-clangd-clangd-index-server-clangd-in...) failure: test (failure)
******************** TEST 'Clangd :: remote-index/log-prefix.test' FAILED ********************
Exit Code: 1

Command Output (stderr):
--
rm -rf /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/remote-index/Output/log-prefix.test.tmp # RUN: at line 1
+ rm -rf /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/remote-index/Output/log-prefix.test.tmp
clangd-indexer /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang-tools-extra/clangd/test/remote-index/Inputs/Source.cpp > /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/remote-index/Output/log-prefix.test.tmp.idx # RUN: at line 2
+ clangd-indexer /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang-tools-extra/clangd/test/remote-index/Inputs/Source.cpp
Error while trying to load a compilation database:
Could not auto-detect compilation database for file "/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang-tools-extra/clangd/test/remote-index/Inputs/Source.cpp"
No compilation database found in /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang-tools-extra/clangd/test/remote-index/Inputs or any parent directory
fixed-compilation-database: Error while opening fixed database: No such file or directory
json-compilation-database: Error while opening JSON database: No such file or directory
Running without flags.
"/usr/bin/python3.8" /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang-tools-extra/clangd/test/remote-index/pipeline_helper.py --input-file-name=/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang-tools-extra/clangd/test/remote-index/log-prefix.test --server-arg=--log=verbose --server-arg=-log-prefix=test-prefix --server-log=/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/remote-index/Output/log-prefix.test.tmp.log --project-root=/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang-tools-extra/clangd/test/remote-index --index-file=/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/remote-index/Output/log-prefix.test.tmp.idx > /dev/null # RUN: at line 3
+ /usr/bin/python3.8 /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang-tools-extra/clangd/test/remote-index/pipeline_helper.py --input-file-name=/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang-tools-extra/clangd/test/remote-index/log-prefix.test --server-arg=--log=verbose --server-arg=-log-prefix=test-prefix --server-log=/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/remote-index/Output/log-prefix.test.tmp.log --project-root=/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang-tools-extra/clangd/test/remote-index --index-file=/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/remote-index/Output/log-prefix.test.tmp.idx
I[20:26:53.598] clangd version 21.0.0git (https://github.com/llvm/llvm-project.git 8f7e57485ee73205e108d74abb5565d5c63beaca)
I[20:26:53.599] Features: linux+debug+tsan+grpc
I[20:26:53.599] PID: 28883
I[20:26:53.599] Working directory: /vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/build/tools/clang/tools/extra/clangd/test/remote-index
I[20:26:53.599] argv[0]: clangd
I[20:26:53.599] argv[1]: --remote-index-address=localhost:50771
I[20:26:53.599] argv[2]: --project-root=/vol/worker/clangd-ubuntu-clang/clangd-ubuntu-tsan/llvm-project/clang-tools-extra/clangd/test/remote-index
I[20:26:53.599] argv[3]: --lit-test
I[20:26:53.599] argv[4]: --sync
I[20:26:53.599] Connecting to remote index at localhost:50771
I[20:26:53.599] Starting LSP over stdin/stdout
V[20:26:53.599] <<< {
  "id": 0,
  "jsonrpc": "2.0",
  "method": "initialize",
  "params": {
    "capabilities": {},
    "processId": 123,
    "rootPath": "clangd",
    "trace": "off"
  }
}

I[20:26:53.599] <-- initialize(0)
I[20:26:53.601] --> reply:initialize(0) 1 ms
V[20:26:53.601] >>> {
  "id": 0,
  "jsonrpc": "2.0",
  "result": {
    "capabilities": {
      "astProvider": true,
      "callHierarchyProvider": true,
      "clangdInlayHintsProvider": true,
...

tomtor pushed a commit to tomtor/llvm-project that referenced this pull request Jun 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cmake Build system in general and CMake in particular

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants