xmake-io / xmake

πŸ”₯ A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
10.14k stars 783 forks source link

C++20 modules does not seem to work #1906

Closed TmLev closed 2 years ago

TmLev commented 2 years ago

Describe the bug

Attempt to compile any C++20 modules example results in error.

Expected behavior

No errors.

Error output

```logs hybrids/xmake/modules on ξ‚  main [!?] via πŸŒ™ v5.3.5 Ξ» xmake -v -D generating.moduledeps src/hello.mpp [ 20%]: ccache compiling.release src/hello.mpp /usr/local/bin/ccache /usr/bin/gcc -c -Qunused-arguments -m64 -std=c++20 -fmodules -fimplicit-modules -fimplicit-module-maps -fprebuilt-module-path=build/.gens/main/macosx/x86_64/release/rules/modules/cache --precompile -x c++-module -fmodules-cache-path=build/.gens/main/macosx/x86_64/release/rules/modules/cache -o build/.gens/main/macosx/x86_64/release/rules/modules/cache/hello.pcm src/hello.mpp error: @programdir/modules/private/async/runjobs.lua:232: @programdir/modules/private/action/build/object.lua:78: @programdir/modules/core/tools/gcc.lua:501: src/hello.mpp:2:10: fatal error: module 'std' is needed but has not been provided, and implicit use of module files is disabled #include ^ 1 error generated. stack traceback: [C]: in function 'error' [@programdir/core/base/os.lua:829]: [@programdir/modules/core/tools/gcc.lua:501]: in function 'catch' [@programdir/core/sandbox/modules/try.lua:127]: in function 'try' [@programdir/modules/core/tools/gcc.lua:445]: [C]: in function 'xpcall' [@programdir/core/base/utils.lua:280]: [@programdir/modules/private/action/build/object.lua:78]: in function 'script' [@programdir/modules/private/action/build/object.lua:91]: in function 'build_object' [@programdir/rules/c++/modules/build_modules/clang.lua:103]: in function 'jobfunc' [@programdir/modules/private/async/runjobs.lua:208]: [C]: in function 'xpcall' [@programdir/core/base/utils.lua:280]: in function 'trycall' [@programdir/core/sandbox/modules/try.lua:121]: in function 'try' [@programdir/modules/private/async/runjobs.lua:200]: in function 'cotask' [@programdir/core/base/scheduler.lua:371]: stack traceback: [C]: in function 'error' @programdir/core/base/os.lua:829: in function 'os.raiselevel' (...tail calls...) @programdir/modules/private/async/runjobs.lua:232: in field 'catch' @programdir/core/sandbox/modules/try.lua:127: in global 'try' @programdir/modules/private/async/runjobs.lua:200: in upvalue 'cotask' @programdir/core/base/scheduler.lua:371: in function <@programdir/core/base/scheduler.lua:368> ```

Related Environment

Additional context

Also, setting cxx to clang++ from LLVM leads to nil error:

`xmake.lua`: ```xmake set_languages("c++20") set_config("cxx", "/usr/local/Cellar/llvm/13.0.0_1/bin/clang++") target("main") set_kind("binary") add_files("src/*.cpp", "src/*.mpp") ``` Command and output: ```logs hybrids/xmake/modules on ξ‚  main [!?] via πŸŒ™ v5.3.5 Ξ» xmake f --cxx=/usr/local/Cellar/llvm/13.0.0_1/bin/clang++ -v -D checking for platform ... macosx checking for architecture ... x86_64 checking for Xcode directory ... /Applications/Xcode.app checking for Codesign Identity of Xcode ... no checking for SDK version of Xcode for macosx (x86_64) ... 11.3 checking for Minimal target version of Xcode for macosx (x86_64) ... 11.4 checkinfo: cannot runv(dmd --version), No such file or directory checking for dmd ... no checkinfo: cannot runv(ldc2 --version), No such file or directory checking for ldc2 ... no checking for gdc ... /usr/local/bin/gdc checkinfo: cannot runv(zig version), No such file or directory checking for zig ... no checkinfo: cannot runv(zig version), No such file or directory checking for zig ... no configure { plat = macosx xcode = /Applications/Xcode.app buildir = build mode = release arch = x86_64 host = macosx cxx = /usr/local/Cellar/llvm/13.0.0_1/bin/clang++ kind = static ndk_stdcxx = true ccache = true } hybrids/xmake/modules on ξ‚  main [!?] via πŸŒ™ v5.3.5 Ξ» xmake -v -D error: @programdir/core/main.lua:280: @programdir/actions/build/main.lua:146: @programdir/rules/c++/modules/xmake.lua:55: attempt to index a nil value (local 'toolname') stack traceback: [@programdir/rules/c++/modules/xmake.lua:55]: in function 'script' [@programdir/actions/build/kinds/object.lua:41]: in function '_add_batchjobs_for_rule' [@programdir/actions/build/kinds/object.lua:146]: [@programdir/actions/build/kinds/binary.lua:165]: [@programdir/actions/build/build.lua:67]: in function '_add_batchjobs_builtin' [@programdir/actions/build/build.lua:80]: in function '_add_batchjobs' [@programdir/actions/build/build.lua:148]: in function '_add_batchjobs_for_target' [@programdir/actions/build/build.lua:192]: in function '_add_batchjobs_for_target_and_deps' [@programdir/actions/build/build.lua:231]: in function 'get_batchjobs' [@programdir/actions/build/build.lua:240]: [@programdir/actions/build/main.lua:133]: stack traceback: [C]: in function 'error' @programdir/core/base/os.lua:829: in function 'base/os.raiselevel' (...tail calls...) @programdir/core/main.lua:280: in upvalue 'cotask' @programdir/core/base/scheduler.lua:371: in function <@programdir/core/base/scheduler.lua:368> ```
waruqi commented 2 years ago

set_config("cxx", "/usr/local/Cellar/llvm/13.0.0_1/bin/clang++")

cxx not found

please remove this line, and get me a verbose output.

xmake f -c -vD --toolchain=llvm --sdk=/usr/local/Cellar/llvm/13.0.0_1
xmake -rv
TmLev commented 2 years ago

That works!

```logs hybrids/xmake/modules on ξ‚  main [!?] via πŸŒ™ v5.3.5 Ξ» xmake f -c -vD --toolchain=llvm --sdk=/usr/local/Cellar/llvm/13.0.0_1 checking for platform ... macosx checking for architecture ... x86_64 checking for Xcode directory ... /Applications/Xcode.app checking for SDK version of Xcode for macosx (x86_64) ... 11.3 configure { buildir = build toolchain = llvm kind = static plat = macosx clean = true xcode = /Applications/Xcode.app ccache = true mode = release ndk_stdcxx = true arch = x86_64 sdk = /usr/local/Cellar/llvm/13.0.0_1 host = macosx } hybrids/xmake/modules on ξ‚  main [!?] via πŸŒ™ v5.3.5 Ξ» xmake -rv checking for clang ... /usr/local/Cellar/llvm/13.0.0_1/bin/clang checking for the c++ compiler (cxx) ... clang checking for /usr/local/Cellar/llvm/13.0.0_1/bin/clang ... ok checking for flags (-fPIC) ... ok checking for flags (-fmodules) ... ok generating.moduledeps src/hello.mpp checking for clang++ ... /usr/local/Cellar/llvm/13.0.0_1/bin/clang++ checking for the linker (ld) ... clang++ checking for /usr/local/Cellar/llvm/13.0.0_1/bin/clang++ ... ok checking for flags (-fPIC) ... ok checking for flags (-std=c++20) ... ok checking for ccache ... /usr/local/bin/ccache [ 20%]: ccache compiling.release src/hello.mpp /usr/local/bin/ccache /usr/local/Cellar/llvm/13.0.0_1/bin/clang -c -Qunused-arguments -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -std=c++20 -fmodules -fimplicit-modules -fimplicit-module-maps -fprebuilt-module-path=build/.gens/main/macosx/x86_64/release/rules/modules/cache --precompile -x c++-module -fmodules-cache-path=build/.gens/main/macosx/x86_64/release/rules/modules/cache -o build/.gens/main/macosx/x86_64/release/rules/modules/cache/hello.pcm src/hello.mpp checking for flags (-MMD -MF) ... ok checking for flags (-fdiagnostics-color=always) ... ok /usr/local/bin/ccache /usr/local/Cellar/llvm/13.0.0_1/bin/clang -c -Qunused-arguments -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -std=c++20 -fmodules -fmodules-cache-path=build/.gens/main/macosx/x86_64/release/rules/modules/cache -fimplicit-modules -fimplicit-module-maps -fprebuilt-module-path=build/.gens/main/macosx/x86_64/release/rules/modules/cache -o build/.objs/main/macosx/x86_64/release/src/hello.mpp.o build/.gens/main/macosx/x86_64/release/rules/modules/cache/hello.pcm [ 40%]: ccache compiling.release src/main.cpp /usr/local/bin/ccache /usr/local/Cellar/llvm/13.0.0_1/bin/clang -c -Qunused-arguments -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk -std=c++20 -fmodules -fmodules-cache-path=build/.gens/main/macosx/x86_64/release/rules/modules/cache -fmodule-file=build/.gens/main/macosx/x86_64/release/rules/modules/cache/hello.pcm -o build/.objs/main/macosx/x86_64/release/src/main.cpp.o src/main.cpp [ 60%]: linking.release main /usr/local/Cellar/llvm/13.0.0_1/bin/clang++ -o build/macosx/x86_64/release/main build/.objs/main/macosx/x86_64/release/src/main.cpp.o build/.objs/main/macosx/x86_64/release/src/hello.mpp.o -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.3.sdk [100%]: build ok! ```