Closed star-hengxing closed 1 day ago
$ xmake l cli.bisect -g v2.9.3 -b dev --gitdir=A:/project/xmake/xmake -c "xmake test"
daaf89c5108e92db407532f3002493d071f9e88f is the first bad commit
commit daaf89c5108e92db407532f3002493d071f9e88f
Author: ruki <waruqi@gmail.com>
Date: Tue Jul 2 22:51:34 2024 +0800
fix load targets repeatly #5288
xmake/actions/test/main.lua | 3 ---
xmake/core/sandbox/modules/import/core/project/project.lua | 12 ++++++------
xmake/plugins/pack/main.lua | 3 ---
3 files changed, 6 insertions(+), 12 deletions(-)
这边没法复现,给个完整的复现工程
add_rules("mode.debug", "mode.release")
rule("test")
on_config(function (target)
target:add("deps", "foo")
end)
target("foo")
set_kind("static")
add_files("src/foo.cpp")
target("test")
set_kind("binary")
add_files("src/main.cpp")
add_tests("default")
add_rules("test")
ruki-2:test ruki$ xmake test -vD
checking for platform ... macosx
checking for architecture ... x86_64
checking for Xcode directory ... /Applications/Xcode.app
checking for Codesign Identity of Xcode ... Apple Development: waruqi@gmail.com (T3NA4MRVPU)
checking for SDK version of Xcode for macosx (x86_64) ... 14.0
checking for Minimal target version of Xcode for macosx (x86_64) ... 14.0
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
checking for nim ... /usr/local/bin/nim
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/b
in/clang ... ok
checking for the c++ compiler (cxx) ... clang
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/b
in/clang ... ok
checking for flags (-fPIC) ... ok
> clang "-fPIC" "-Qunused-arguments" "-target" "x86_64-apple-macos14.0" "-isysroot" "/Application
s/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk"
checking for flags (-fvisibility-inlines-hidden) ... ok
> clang "-fvisibility-inlines-hidden" "-Qunused-arguments" "-target" "x86_64-apple-macos14.0" "-i
sysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/Mac
OSX14.0.sdk"
checking for flags (-O3) ... ok
> clang "-O3" "-Qunused-arguments" "-target" "x86_64-apple-macos14.0" "-isysroot" "/Applications/
Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk"
checking for flags (-DNDEBUG) ... ok
> clang "-DNDEBUG" "-Qunused-arguments" "-target" "x86_64-apple-macos14.0" "-isysroot" "/Applicat
ions/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk"
[ 50%]: cache compiling.release src/foo.cpp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -c -
Qunused-arguments -target x86_64-apple-macos14.0 -isysroot /Applications/Xcode.app/Contents/Devel
oper/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -fvisibility=hidden -fvisibility-inl
ines-hidden -O3 -DNDEBUG -o build/.objs/foo/macosx/x86_64/release/src/foo.cpp.o src/foo.cpp
checking for flags (-MMD -MF) ... ok
> clang "-MMD" "-MF" "/dev/null" "-Qunused-arguments" "-target" "x86_64-apple-macos14.0" "-isysro
ot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14
.0.sdk"
checking for flags (-fdiagnostics-color=always) ... ok
> clang "-fdiagnostics-color=always" "-Qunused-arguments" "-target" "x86_64-apple-macos14.0" "-is
ysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacO
SX14.0.sdk"
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/b
in/ar ... ok
checking for the static library archiver (ar) ... ar
[ 62%]: archiving.release libfoo.a
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ar -cr bui
ld/macosx/x86_64/release/libfoo.a build/.objs/foo/macosx/x86_64/release/src/foo.cpp.o
checking for the c++ compiler (cxx) ... clang
[ 75%]: cache compiling.release src/main.cpp
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang -c -
Qunused-arguments -target x86_64-apple-macos14.0 -isysroot /Applications/Xcode.app/Contents/Devel
oper/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -fvisibility=hidden -fvisibility-inl
ines-hidden -O3 -DNDEBUG -o build/.objs/test/macosx/x86_64/release/src/main.cpp.o src/main.cpp
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/b
in/clang++ ... ok
checking for the linker (ld) ... clang++
checking for /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/b
in/clang++ ... ok
checking for flags (-fPIC) ... ok
> clang++ "-fPIC" "-target" "x86_64-apple-macos14.0" "-isysroot" "/Applications/Xcode.app/Content
s/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk" "-lz" "-target" "x86_64-appl
e-macos14.0" "-isysroot" "/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/De
veloper/SDKs/MacOSX14.0.sdk" "-lz"
[ 87%]: linking.release test
/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang++ -o
build/macosx/x86_64/release/test build/.objs/test/macosx/x86_64/release/src/main.cpp.o -target x
86_64-apple-macos14.0 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platf
orm/Developer/SDKs/MacOSX14.0.sdk -lz -Lbuild/macosx/x86_64/release -Wl,-x -Wl,-dead_strip -lfoo
build cache stats:
cache directory: /private/tmp/test/build/.build_cache
cache hit rate: 0%
cache hit: 0
cache hit total time: 0.000s
cache miss: 2
cache miss total time: 0.005s
new cached files: 2
remote cache hit: 0
remote new cached files: 0
preprocess failed: 0
compile fallback count: 0
compile total time: 0.555s
running tests ...
[100%]: running.test test/default
report of tests:
[100%]: test/default .................................... passed 0.012s
stdout: build/.gens/test/macosx/x86_64/release/tests/test/default.stdout.log
100% tests passed, 0 tests failed out of 1, spent 0.012s
大概是因为 target 在 on_config 才添加源文件,导致没有自动添加 c/c++ rule 。
加上 add_rules("c")
后,链接参数有 -lxxx
,但没有 syslinks 。
target("test")
set_kind("static")
-- add_files("src/lib.c")
add_rules("c")
on_config(function (target)
target:add("files", "src/lib.c")
target:add("syslinks", "user32")
end)
target("main")
set_kind("binary")
add_files("src/main.c")
add_deps("test")
[ 37%]: compiling.release src\lib.c
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.41.34120\\bin\\HostX64\\x64\\cl.exe" -c -nologo -O2 -DNDEBUG -Fobuild\.objs\test\windows\x64\release\src\lib.c.obj src\lib.c
[ 50%]: compiling.release src\main.c
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.41.34120\\bin\\HostX64\\x64\\cl.exe" -c -nologo -O2 -DNDEBUG -Fobuild\.objs\main\windows\x64\release\src\main.c.obj src\main.c
[ 62%]: archiving.release test.lib
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.41.34120\\bin\\HostX64\\x64\\link.exe" -lib -nologo -machine:x64 /opt:ref /opt:icf -out:build\windows\x64\release\test.lib build\.objs\test\windows\x64\release\src\lib.c.obj
[ 87%]: linking.release main.exe
"C:\\Program Files\\Microsoft Visual Studio\\2022\\Community\\VC\\Tools\\MSVC\\14.41.34120\\bin\\HostX64\\x64\\link.exe" -nologo -dynamicbase -nxcompat -machine:x64 -libpath:build\windows\x64\release /opt:ref /opt:icf test.lib -out:build\windows\x64\release\main.exe build\.objs\main\windows\x64\release\src\main.c.obj
error: test.lib(lib.c.obj) : error LNK2019: unresolved external symbol __imp_MessageBoxA referenced in function my_fn
build\windows\x64\release\main.exe : fatal error LNK1120: 1 unresolved externals
跟 c rule 没啥,关系,是 inherit links 那个 rule 用的也是 on_config,它的执行顺序 跟 用户 rule 的 on_config 平级,谁先执行未定义,这里先执行了内置的 inherit links ,所以这个时候 on_config 里面的 syslinks 还没被添加进去。
这种顺序问题,要想完全解决,只能等 3.0 对 rule 的执行顺序重构,做更灵活的配置支持
Bot detected the issue body's language is not English, translate it automatically.
It has nothing to do with the c rule. It is related to inherit links. That rule also uses on_config. Its execution order is the same as the on_config of the user rule. Whoever executes undefined first, here the built-in inherit links are executed first, so at this time in on_config The syslinks have not been added yet.
目前只能通过添加 before/after_config 来 workaround 提升配置 config 顺序的灵活性,先这么试试吧 https://github.com/xmake-io/xmake/pull/5813
回头 3.0 可能会重构改进这块,目前也没太多时间大改
Xmake Version
dev
Operating System Version and Architecture
Windows
Describe Bug
version.h
Expected Behavior
Work.
Project Configuration
test target -> add_rule(test) ->
target:add("deps", dep)
Additional Information and Error Logs