mesonbuild / meson

The Meson Build System
http://mesonbuild.com
Apache License 2.0
5.49k stars 1.59k forks source link

clang++ doesn't like meson-generated .RSP files with mixed forward/back slashes #11304

Open vid512 opened 1 year ago

vid512 commented 1 year ago

Describe the bug Meson messes up paths when building catch2 with clang++ from MS Visual Studio 2019.

My attempt at analysis of the problem: When Meson generates .RSP file on Windows, it mixes forward slashes and backslashes in some paths. While such mixing seems to work fine in ninja.build files, it seems not to work correctly in .RSP files (at least with some tools).

To Reproduce meson.build:

project('testcatch2', 'cpp')
catch2_dep = dependency('catch2-with-main', version: '>=3')

repro.bat:

set CXX=clang++
meson wrap update-db
meson setup build
meson compile -C build

Install MS Visual Studio 2019 with clang support. Start the Visual studio developer console, or call vcvarsall.bat manually in console, to set up the development environment. Then run repro.bat. Wait for a while, until catch2 builds. You'll get all the expected output, plus few catch-related warnings, and then finally this:

<... snip ...>
[160/160] Linking target subprojects/Catch2-3.2.0/tests/SelfTest.exe
FAILED: subprojects/Catch2-3.2.0/tests/SelfTest.exe subprojects/Catch2-3.2.0/tests/SelfTest.pdb
"clang++" @subprojects/Catch2-3.2.0/tests/SelfTest.exe.rsp
clang++: error: no such file or directory: 'subprojectsCatch2-3.2.0src/catch2libCatch2Main.a'
clang++: error: no such file or directory: 'subprojectsCatch2-3.2.0src/catch2libCatch2.a'
ninja: build stopped: subcommand failed.

Notice missing path separators in reported errors. Looking into build/subprojects/Catch2-3.2.0/tests/SelfTest.exe.rsp, it contains "-Wl,/PDB:subprojects\Catch2-3.2.0\tests\SelfTest.pdb" "subprojects\Catch2-3.2.0\src/catch2\libCatch2Main.a" "subprojects\Catch2-3.2.0\src/catch2\libCatch2.a"

Notice mixed forward slashes and backslashes. If you manually escape all backslashes in SelfTest.exe.rsp, or replace them with forward slashes, then the command clang++" @subprojects/Catch2-3.2.0/tests/SelfTest.exe.rsp runs correctly.

Expected behavior Meson should fix backslashes in paths that go to .RSP files, so they work with MSVC clang++.

system parameters

Note When tested with regular Microsoft Visual C/C++ compiler (eg. by removing set CXX=clang++ from repro.bat), Meson seems to not generate this .RSP file for some reason. So, this problem might not be limited to clang, we just haven't forced .RSP generation in other cases.

aholster commented 1 year ago

Can confirm this issue. Am using similiar settings&Setup and seeing the same error and mixed slashes in the .RSP file.

JKot-Coder commented 3 months ago

Faced with same problem with clang and ninja. When compiling flecs ecs, got this:

[3/7] Linking target subprojects/flecs-4.0.0-beta/flecs.dll Creating library subprojectsflecs-4.0.0-betaflecs.lib and object subprojectsflecs-4.0.0-betaflecs.exp Dll is linked correctly, but lib and exp files are created with broken names, slash is ignored.

Replacing rule from c_LINKER_RSP to c_LINKER in build.ninja fixes the problem.