-
-
Notifications
You must be signed in to change notification settings - Fork 818
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
Two mutually exclusive clang flags for C++20 modules compilation are included #3009
Comments
you need download full source code (contains git submodules), see |
Even when I add these flags, it still doesn't seem to work. @Arthapz Any idea about this? /usr/bin/clang -c -x c++-module --precompile -Qunused-arguments -m64 -fPIC -O3 -std=c++20 -fmodules -fbuiltin-module-map -fimplicit-modules -fimplicit-module-maps -fmodule-map-file=/usr/lib/llvm-15/lib/clang/15.0.2/include/module.modulemap -DNDEBUG -fmodules-cache-path=build/.gens/trouble/linux/x86_64/release/rules/modules/cache -o build/.gens/trouble/linux/x86_64/release/rules/modules/cache/my_module.pcm src/my_module.mpp
/usr/bin/clang -c -Qunused-arguments -m64 -fPIC -O3 -std=c++20 -fmodules -fbuiltin-module-map -fimplicit-modules -fimplicit-module-maps -fmodule-map-file=/usr/lib/llvm-15/lib/clang/15.0.2/include/module.modulemap -DNDEBUG -fmodules-cache-path=build/.gens/trouble/linux/x86_64/release/rules/modules/cache -o build/.objs/trouble/linux/x86_64/release/src/my_module.mpp.o build/.gens/trouble/linux/x86_64/release/rules/modules/cache/my_module.pcm
checking for flags (-MMD -MF) ... ok
checking for flags (-fdiagnostics-color=always) ... ok
error: src/my_module.mpp:3:8: fatal error: module 'std' not found
import std;
~~~~~~~^~~
1 error generated. |
That was the smallest non-building modules project I was able to create to illustrate the issue. I modified the
Please note that I had to add link flags, link dirs, include dirs and compile flags for this to work. |
I have not linuxbrew and mold. I modified llvm path, but it does not work for me. /usr/bin/clang -c -x c++-module --precompile -Qunused-arguments -m64 -fPIC -O3 -std=c++20 -I/usr/local/include -I/usr/lib/llvm-15/include -I/usr/lib/llvm-15/lib/clang/15.0.2/include/c++/v1 -fmodules -fcxx-modules -fmodule-maps -fimplicit-module-maps -fbuiltin-module-map -fmodule-map-file=/usr/lib/llvm-15/lib/clang/15.0.2/include/module.modulemap -fvisibility=default -fimplicit-modules -fno-implicit-module-maps -DNDEBUG -fmodules-cache-path=build/.gens/trouble/linux/x86_64/release/rules/modules/cache -o build/.gens/trouble/linux/x86_64/release/rules/modules/cache/my_module.pcm src/my_module.mpp
/usr/bin/clang -c -Qunused-arguments -m64 -fPIC -O3 -std=c++20 -I/usr/local/include -I/usr/lib/llvm-15/include -I/usr/lib/llvm-15/lib/clang/15.0.2/include/c++/v1 -fmodules -fcxx-modules -fmodule-maps -fimplicit-module-maps -fbuiltin-module-map -fmodule-map-file=/usr/lib/llvm-15/lib/clang/15.0.2/include/module.modulemap -fvisibility=default -fimplicit-modules -fno-implicit-module-maps -DNDEBUG -fmodules-cache-path=build/.gens/trouble/linux/x86_64/release/rules/modules/cache -o build/.objs/trouble/linux/x86_64/release/src/my_module.mpp.o build/.gens/trouble/linux/x86_64/release/rules/modules/cache/my_module.pcm
error: src/my_module.mpp:3:8: fatal error: module 'std' not found
import std;
~~~~~~~^~~
1 error generated. |
By commenting out
|
I cannot run this script, because I have not brew on my ubuntu. |
@waruqi the problem is that your compiler flags include the undesired |
But now I can't use your example to test it, even if I delete -fno-implicit-module-maps, I still have the same problem. |
Use this build script
|
Is xmake able to get clang's installation dir? |
/usr/lib/llvm-15/lib |
/usr/bin/clang -c -x c++-module --precompile -Qunused-arguments -m64 -fPIC -O3 -std=c++20 -I/usr/local/include -I/usr/lib/llvm-15/lib/clang/15.0.2/include/c++/v1 -fvisibility=default -fmodules -fbuiltin-module-map -fimplicit-modules -fno-implicit-module-maps -DNDEBUG -fmodules-cache-path=build/.gens/trouble/linux/x86_64/release/rules/modules/cache -o build/.gens/trouble/linux/x86_64/release/rules/modules/cache/my_module.pcm src/my_module.mpp
/usr/bin/clang -c -Qunused-arguments -m64 -fPIC -O3 -std=c++20 -I/usr/local/include -I/usr/lib/llvm-15/lib/clang/15.0.2/include/c++/v1 -fvisibility=default -fmodules -fbuiltin-module-map -fimplicit-modules -fno-implicit-module-maps -DNDEBUG -fmodules-cache-path=build/.gens/trouble/linux/x86_64/release/rules/modules/cache -o build/.objs/trouble/linux/x86_64/release/src/my_module.mpp.o build/.gens/trouble/linux/x86_64/release/rules/modules/cache/my_module.pcm
checking for flags (-MMD -MF) ... ok
checking for flags (-fdiagnostics-color=always) ... ok
error: src/my_module.mpp:3:8: fatal error: module 'std' not found
import std;
~~~~~~~^~~
1 error generated. it does not work. |
If it works on your machine, you can open a pr first. |
PR created |
see #3016 But I still need to solve the compatibility problem between libc++ and libstdc++. |
try it again. |
we need use -stdlib=libc++ for clang if we use add_rules("mode.debug", "mode.release")
set_languages("c++20")
add_cxxflags("clang::-stdlib=libc++")
target("mod")
set_kind("shared")
add_files("src/*.cpp", "src/*.mpp")
target("test")
set_kind("binary")
add_files("test/*.cpp")
add_deps("mod") |
It should work now. |
Xmake Version
2.7.1
Operating System Version and Architecture
Fedora 36, clang 15
Describe Bug
Since some time I've had problems building C++20 projects with modules. I had to resort to adding some compile flags but got tired of it and noticed that the compiler flags generation is including two mutually exclusive flags. In
xmake/rules/c++/modules/modules_support/clang.lua
we havelocal implicitmodulesflag = get_implicitmodulesflag(target)
local noimplicitmodulemapsflag = get_noimplicitmodulemapsflag(target)
and then
target:add("cxxflags", implicitmodulesflag, {force = true})
target:add("cxxflags", noimplicitmodulemapsflag, {force = true})
Xmake should include only the implicit modules flag, allowing us to use clang's module maps transparently. Unfortunately xmake will not build in my environment due to an error something like
No rule to build the target 'lua/lapi.c'
(my system is in Brazilian Portuguese so I have to guess this is how it is phrased in English). I would change the modules flag generation myself and submit a pull request if I could build xmake.In the meantime I have to keep adding the following flags to xmake.lua:
"-fimplicit-module-maps",
"-fmodule-map-file=$(shell brew --prefix)/include/c++/v1/module.modulemap",
Expected Behavior
xmake should include only the
-fimplicit-modules
flag.Project Configuration
trouble.zip
Additional Information and Error Logs
[~/git/trouble]$ xmake -bv
[ 0%]: generating.cxx.module.deps src/my_module.cpp
[ 23%]: generating.cxx.module.bmi my_module
/home/linuxbrew/.linuxbrew/opt/llvm/bin/clang -Qunused-arguments -m64 -fPIC -O3 -std=c++20 -fmodules -fbuiltin-module-map -fimplicit-modules -fno-implicit-module-maps -DNDEBUG -fmodules-cache-path=build/.gens/trouble/linux/x86_64/release/rules/modules/cache -c -x c++-module --precompile src/my_module.mpp -o build/.gens/trouble/linux/x86_64/release/rules/modules/cache/my_module.pcm
src/my_module.mpp:3:8: fatal error: module 'std' not found
import std;
The text was updated successfully, but these errors were encountered: