Skip to content
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

[C++ Modules] XMake references the very module being built within its own command #2233

Closed
remi6397 opened this issue Apr 1, 2022 · 2 comments

Comments

@remi6397
Copy link

remi6397 commented Apr 1, 2022

Xmake Version

v2.6.4+dev.0fcbe01

Operating System Version and Architecture

macOS 12.2.1

Describe Bug

The following pattern causes XMake to seize up by referencing a module in its own compilation command as -fmodule-file=:

  • Module b imports module importable
  • Module a imports both importable and b

Test case: https://gist.github.com/ab56fbaad6045fa5f1434253efe5e4bb.git

Expected Behavior

-fmodule-file=build/.gens/rules/modules/cache/a.pcm is not passed as a parameter.

Project Configuration

No response

Additional Information and Error Logs

Details
❯ git clone https://gist.github.com/ab56fbaad6045fa5f1434253efe5e4bb.git test
❯ cd !$
❯ xmake f -c --toolchain=llvm --sdk=/usr/local/llvm14 --ar=/usr/local/llvm14/bin/llvm-ar --mode=debug --cxxflags='-g -O0' -vD -y
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) ... 12.1
configure
{
    mode = debug
    network = public
    xcode = /Applications/Xcode.app
    theme = default
    plat = macosx
    cxxflags = -g -O0
    ar = /usr/local/llvm14/bin/llvm-ar
    arch = x86_64
    proxy_pac = pac.lua
    pkg_searchdirs = /Users/redacted/Downloads
    kind = static
    clean = true
    host = macosx
    sdk = /usr/local/llvm14
    ndk_stdcxx = true
    buildir = build
    toolchain = llvm
    ccache = true
}
warning: cannot match target(abc).add_files("*.cpp") at ./xmake.lua:5
❯ xmake -rv
checking for clang ... /usr/local/llvm14/bin/clang
checking for the c++ compiler (cxx) ... clang
checking for /usr/local/llvm14/bin/clang ... ok
checking for flags (-fPIC) ... ok
checking for flags (-fmodules) ... ok
generating.moduledeps b.mpp
generating.moduledeps a.mpp
generating.moduledeps importable.mpp
checking for flags (-std=c++20) ... ok
checking for ccache ... no
[ 16%]: compiling.debug importable.mpp
/usr/local/llvm14/bin/clang -c -Qunused-arguments -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -fPIC -g -O0 -std=c++20 -fmodules -fimplicit-modules -fimplicit-module-maps -fprebuilt-module-path=build/.gens/rules/modules/cache --precompile -x c++-module -fmodules-cache-path=build/.gens/rules/modules/cache -o build/.gens/rules/modules/cache/importable.pcm importable.mpp
checking for flags (-MMD -MF) ... ok
[ 16%]: compiling.debug importable.mpp
/usr/local/llvm14/bin/clang -c -Qunused-arguments -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -fPIC -g -O0 -std=c++20 -fmodules -fimplicit-modules -fimplicit-module-maps -fprebuilt-module-path=build/.gens/rules/modules/cache --precompile -x c++-module -fmodules-cache-path=build/.gens/rules/modules/cache -o build/.gens/rules/modules/cache/importable.pcm importable.mpp
checking for flags (-fdiagnostics-color=always) ... ok
/usr/local/llvm14/bin/clang -c -Qunused-arguments -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -fPIC -g -O0 -std=c++20 -fmodules -fmodules-cache-path=build/.gens/rules/modules/cache -fimplicit-modules -fimplicit-module-maps -fprebuilt-module-path=build/.gens/rules/modules/cache -o build/.objs/abc/macosx/x86_64/debug/importable.mpp.o build/.gens/rules/modules/cache/importable.pcm
/usr/local/llvm14/bin/clang -c -Qunused-arguments -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -fPIC -g -O0 -std=c++20 -fmodules -fmodules-cache-path=build/.gens/rules/modules/cache -fimplicit-modules -fimplicit-module-maps -fprebuilt-module-path=build/.gens/rules/modules/cache -o build/.objs/abc/macosx/x86_64/debug/importable.mpp.o build/.gens/rules/modules/cache/importable.pcm
[ 50%]: compiling.debug b.mpp
/usr/local/llvm14/bin/clang -c -Qunused-arguments -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -fPIC -g -O0 -std=c++20 -fmodules -fimplicit-modules -fimplicit-module-maps -fprebuilt-module-path=build/.gens/rules/modules/cache --precompile -x c++-module -fmodules-cache-path=build/.gens/rules/modules/cache -o build/.gens/rules/modules/cache/b.pcm b.mpp
[ 50%]: compiling.debug b.mpp
/usr/local/llvm14/bin/clang -c -Qunused-arguments -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -fPIC -g -O0 -std=c++20 -fmodules -fimplicit-modules -fimplicit-module-maps -fprebuilt-module-path=build/.gens/rules/modules/cache --precompile -x c++-module -fmodules-cache-path=build/.gens/rules/modules/cache -o build/.gens/rules/modules/cache/b.pcm b.mpp
/usr/local/llvm14/bin/clang -c -Qunused-arguments -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -fPIC -g -O0 -std=c++20 -fmodules -fmodules-cache-path=build/.gens/rules/modules/cache -fimplicit-modules -fimplicit-module-maps -fprebuilt-module-path=build/.gens/rules/modules/cache -o build/.objs/abc/macosx/x86_64/debug/b.mpp.o build/.gens/rules/modules/cache/b.pcm
/usr/local/llvm14/bin/clang -c -Qunused-arguments -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -fPIC -g -O0 -std=c++20 -fmodules -fmodules-cache-path=build/.gens/rules/modules/cache -fimplicit-modules -fimplicit-module-maps -fprebuilt-module-path=build/.gens/rules/modules/cache -o build/.objs/abc/macosx/x86_64/debug/b.mpp.o build/.gens/rules/modules/cache/b.pcm
[ 83%]: compiling.debug a.mpp
/usr/local/llvm14/bin/clang -c -Qunused-arguments -m64 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.1.sdk -fPIC -g -O0 -std=c++20 -fmodule-file=build/.gens/rules/modules/cache/b.pcm -fmodule-file=build/.gens/rules/modules/cache/a.pcm -fmodule-file=build/.gens/rules/modules/cache/importable.pcm -fmodules -fimplicit-modules -fimplicit-module-maps -fprebuilt-module-path=build/.gens/rules/modules/cache --precompile -x c++-module -fmodules-cache-path=build/.gens/rules/modules/cache -o build/.gens/rules/modules/cache/a.pcm a.mpp
error: fatal error: module file 'build/.gens/rules/modules/cache/a.pcm' not found: module file not found
1 error generated.
@remi6397 remi6397 added the bug label Apr 1, 2022
@waruqi
Copy link
Member

waruqi commented Apr 1, 2022

This is a more complex issue, caused by the current imperfect support for building dependency graphs, which causes problems when #parent > 1. At the moment I haven't had time to deal with it and perhaps the dependency graph needs to be improved, which will take some time to refactor it.

for _, parent in ipairs(moduledep.parents) do
batchjobs:add(moduledep.job, parent.job)
end

{ 
  importable = { 
    name = "importable",
    file = "importable.mpp",
    parents = { 
      { &1
        name = "a",
        deps = { 
          "importable",
          "b" 
        },
        file = "a.mpp" 
      },
      { &2
        parents = { 
          *1 
        },
        name = "b",
        deps = { 
          "importable" 
        },
        file = "b.mpp" 
      } 
    } 
  },
  a = *1,
  b = *2 
}

@waruqi
Copy link
Member

waruqi commented Apr 3, 2022

I have fixed it, you can try this patch. #2237

xmake update -s dev

@waruqi waruqi added this to the v2.6.5 milestone Apr 3, 2022
@waruqi waruqi closed this as completed Apr 3, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants