The WebAssembly toolchain currently supports only -stdlib=libc++
and implicitly assumes the c++ stdlib to be libc++. Change this to also
support libstdc++. The default is still libc++.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
I haven't reviewed this yet, but since we got one of these before and never merged it (https://reviews.llvm.org/D101464) we should probably land one of these.
clang/lib/Driver/ToolChains/WebAssembly.cpp | ||
---|---|---|
434 | Where does 11 come from here? Do other drivers hardcode this the same way? |
clang/lib/Driver/ToolChains/WebAssembly.cpp | ||
---|---|---|
434 | 11 is just the current version. lib/Driver/ToolChains/Gnu.cpp figures out the correct version here via GCCInstallationDetector. I thought hard-coding is find for wasm because the v1 for libc++ above is also hardcoded and Gnu.cpp figures that out dynamically as well (in addLibCxxIncludePaths). |
clang/lib/Driver/ToolChains/WebAssembly.cpp | ||
---|---|---|
434 | I'd rather not hardcode that current version, that seems rather fragile/wrong. I agree the v1 is probably also wrong (feel free to add a TODO or update that too). |
clang/lib/Driver/ToolChains/WebAssembly.cpp | ||
---|---|---|
434 | Updated both. They both currently fall back to the old v1/11. I'm not sure how the test would otherwise work. As far as I know, the wasm sysroot will basically never contain an actual gcc installation, so GCCInstallationDetector can't be properly used. |
clang/lib/Driver/ToolChains/WebAssembly.cpp | ||
---|---|---|
426–439 | Can't these 6 lines be removed now? (don't they happen as part of addLibStdCXXIncludePaths?) | |
484 | Looking at Gnu.cpp and Fuscia.cpp it seems like return (or return false) here should be fine. | |
535 | Just early return here if no headers can be found? Looking at Gnu.cpp it seems that addLibStdCxxIncludePaths can simply to nothing if no GCC install is found. |
clang/lib/Driver/ToolChains/WebAssembly.cpp | ||
---|---|---|
426–439 | Yep, just a leftover, sorry. | |
535 | I saw that, but I'm not sure if this is correct for wasm. The tests certainly break because they check for the /v1/ (and not /11/) include paths but also use -sysroot=/foo, so the new code doesn't add any flags. Is there a good way to update the tests so they stay functional and useful? |
clang/lib/Driver/ToolChains/WebAssembly.cpp | ||
---|---|---|
535 | I would take a look at how other platforms test this... perhaps they setup some kind of fake header tree? Or perhaps they don't test these paths at all. For sure they don't depend on the actual system where the tests run, right? Can you point me to the tests that fail if you simply return empty string like on other platforms? |
clang/lib/Driver/ToolChains/WebAssembly.cpp | ||
---|---|---|
535 | The test using /foo as sysroot was just clang/test/Driver/wasm-toolchain.cpp. The driver tests are shipping a file hierarchy to be used for this, so I switched the tests to use that as well. |
Great! Thanks for working on this. I'm curious what toolchain you are working that uses GNU libstdc++?
I'm looking at libstdc++ enablement in a wasm/emscripten toolchain, so nothing existing/public.
Thanks for the review!
This patch is not correct.
cqwrteur@Home-Server:~/fast_io_cleanup/fast_io/examples/0001.helloworld$ clang++ -o helloworld helloworld.cc -Ofast -std=c++2b -s -flto -fuse-ld=lld --target=wasm32-wasi --sysroot=$HOME/toolchains/sysroot/wasm32-wasi -fno-exceptions -fno-rtti -fno-unwind-tables -fno-asynchronous-unwind-tables -I../../include -stdlib=libstdc++
In file included from helloworld.cc:1:
In file included from ../../include/fast_io.h:9:
In file included from ../../include/fast_io_hosted.h:17:
In file included from ../../include/fast_io_freestanding.h:12:
In file included from ../../include/fast_io_core.h:11:
In file included from ../../include/fast_io_concept.h:20:
In file included from /home/cqwrteur/toolchains/sysroot/wasm32-wasi/include/c++/12.0.1/concepts:44:
/home/cqwrteur/toolchains/sysroot/wasm32-wasi/include/c++/12.0.1/type_traits:38:10: fatal error: 'bits/c++config.h' file not found
#include <bits/c++config.h>
^~~~~~~~~~~~~~~~~~
1 error generated.
It cannot find bits/c++config.h
wasm32-wasi\include\c++\12.0.1\wasm32-wasi\bits
I have started a revision.
https://reviews.llvm.org/D119056
Where does 11 come from here? Do other drivers hardcode this the same way?