xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
9.87k stars 776 forks source link

add staticlib2 test for modules #5240

Closed waruqi closed 2 months ago

waruqi commented 3 months ago

https://github.com/xmake-io/xmake/discussions/5229

waruqi commented 3 months ago

When clang compiles an external target module, if it is marked as reuse, then its xxx.mpp.o path is currently incorrect.

waruqi commented 3 months ago

_try_reuse_modules does not work for gcc/clang. _are_flags_compatible() always returns false for gcc. and xxx.mpp.o is not found for clang. @Arthapz

Arthapz commented 3 months ago

_try_reuse_modules does not work for gcc/clang. _are_flags_compatible() always returns false for gcc. and xxx.mpp.o is not found for clang. @Arthapz

Strange it work on my project for clang, module reusage is only for public compatible bmifile, not objectfiles

I'll Check tomorrow

Arthapz commented 2 months ago

_try_reuse_modules does not work for gcc/clang. _are_flags_compatible() always returns false for gcc. and xxx.mpp.o is not found for clang. @Arthapz

i tried with GCC

-- check if flags are compatible for module reuse
function _are_flags_compatible(target, other, cppfile)
    local compinst1 = target:compiler("cxx")
    local flags1 = compinst1:compflags({sourcefile = cppfile, target = target})

    local compinst2 = other:compiler("cxx")
    local flags2 = compinst2:compflags({sourcefile = cppfile, target = other})

    -- strip unrelevent flags
    flags1 = compiler_support.strip_flags(target, flags1)
    flags2 = compiler_support.strip_flags(target, flags2)

    if #flags1 ~= #flags2 then
        return false
    end

    table.sort(flags1)
    table.sort(flags2)

    for i = 1, #flags1 do
        if flags1[i] ~= flags2[i] then
            return false
        end
    end
    print("TRUE")
    return true
end

and _are_flags_compatible() return true on my side, what GCC version do u used ?

image

waruqi commented 2 months ago
bash-5.2$ gcc --version
gcc (GCC) 14.0.1 20240411 (Red Hat 14.0.1-0)
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
function _are_flags_compatible(target, other, cppfile)
    local compinst1 = target:compiler("cxx")
    local flags1 = compinst1:compflags({sourcefile = cppfile, target = target})

    local compinst2 = other:compiler("cxx")
    local flags2 = compinst2:compflags({sourcefile = cppfile, target = other})

    -- strip unrelevent flags
    flags1 = compiler_support.strip_flags(target, flags1)
    flags2 = compiler_support.strip_flags(target, flags2)

    if #flags1 ~= #flags2 then
        print("_are_flags_compatible #flags1 (%s) != #flags2 (%s)", #flags1, #flags2)
        print(flags1, flags2)
        return false
    end

    table.sort(flags1)
    table.sort(flags2)

    for i = 1, #flags1 do
        if flags1[i] ~= flags2[i] then
            print("_are_flags_compatible %s != %s", flags1[i], flags2[i])
            print(flags1, flags2)
            return false
        end
    end
    print("TRUE")
    return true
end
bash-5.2$ xmake -r
[  0%]: <hello> generating.module.deps src/main.cpp
[  0%]: <hello> generating.module.deps src/bar.mpp
[  0%]: <hello> generating.module.deps src/foo.mpp
[  0%]: <foo> generating.module.deps src/foo.mpp
[  0%]: <foo> generating.module.deps src/foo.cpp
[  0%]: <foo> generating.module.deps src/bar.mpp
[  0%]: <bar> generating.module.deps src/bar.mpp
[  0%]: <bar> generating.module.deps src/bar.cpp
[ 13%]: <bar> compiling.bmi.release bar
[ 22%]: compiling.release src/bar.cpp
[ 27%]: archiving.release libbar.a
_are_flags_compatible #flags1 (5) != #flags2 (6)
{ 
  "-m64",
  "-fvisibility=hidden",
  "-fvisibility-inlines-hidden",
  "-std=c++20",
  "-fmodules-ts" 
}
 { 
  "-m64",
  "-fvisibility=hidden",
  "-fvisibility-inlines-hidden",
  "-std=c++20",
  "-fmodules-ts",
  "-fmodule-mapper=/tmp/.xmake995/240722/bar/src/bar.mpp" 
}

TRUE
[ 45%]: <foo> compiling.bmi.release foo
[ 50%]: <foo> compiling.module.release bar
[ 59%]: compiling.release src/foo.cpp
[ 63%]: archiving.release libfoo.a
_are_flags_compatible #flags1 (5) != #flags2 (6)
{ 
  "-m64",
  "-fvisibility=hidden",
  "-fvisibility-inlines-hidden",
  "-std=c++20",
  "-fmodules-ts" 
}
 { 
  "-m64",
  "-fvisibility=hidden",
  "-fvisibility-inlines-hidden",
  "-std=c++20",
  "-fmodules-ts",
  "-fmodule-mapper=/tmp/.xmake995/240722/bar/src/bar.mpp" 
}

_are_flags_compatible #flags1 (5) != #flags2 (6)
{ 
  "-m64",
  "-fvisibility=hidden",
  "-fvisibility-inlines-hidden",
  "-std=c++20",
  "-fmodules-ts" 
}
 { 
  "-m64",
  "-fvisibility=hidden",
  "-fvisibility-inlines-hidden",
  "-std=c++20",
  "-fmodules-ts",
  "-fmodule-mapper=/tmp/.xmake995/240722/foo/src/bar.mpp" 
}

TRUE
_are_flags_compatible #flags1 (5) != #flags2 (6)
{ 
  "-m64",
  "-fvisibility=hidden",
  "-fvisibility-inlines-hidden",
  "-std=c++20",
  "-fmodules-ts" 
}
 { 
  "-m64",
  "-fvisibility=hidden",
  "-fvisibility-inlines-hidden",
  "-std=c++20",
  "-fmodules-ts",
  "-fmodule-mapper=/tmp/.xmake995/240722/foo/src/foo.mpp" 
}

[ 81%]: <hello> compiling.module.release foo
[ 90%]: compiling.release src/main.cpp
[ 95%]: linking.release hello
[100%]: build ok, spent 1.375s
waruqi commented 2 months ago

flags count is mismatch . "-fmodule-mapper=/tmp/.xmake995/240722/bar/src/bar.mpp"

Arthapz commented 2 months ago

ok i see, i need to strip the module-mapper flag