xmake-io / xmake

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

Cross compile bug #5658

Closed MaxwellGengYF closed 3 days ago

MaxwellGengYF commented 4 days ago

Xmake 版本

v2.9.5+dev.21e4c2a3a

操作系统版本和架构

Windows

描述问题

同项目使用 cross compile 导致 can not find program ar

期待的结果

正常编译。

工程配置

target("llvm_target")
set_languages("cxx20")
set_toolchains("llvm")
on_load(function(target)
    target:set("kind", "static")
end)
add_files("dummy.cpp")
target_end()

target("clang_cl_target")
set_languages("cxx20")
on_load(function(target)
    target:set("kind", "static")
end)
add_files("dummy.cpp")
target_end()

xmake f -m debug --toolchain=clang_cl -c xmake xmake f -m release --toolchain=clang_cl -c xmake xmake f -m debug --toolchain=clang_cl -c xmake ...

附加信息和错误日志

error: cannot get program for ar

waruqi commented 3 days ago

试下,应该可以了,这个跟 cache 没啥关系,是 clang-cl toolchain 的问题。。

因为 msvc/clang-cl 都是用的 link.exe ,但是探测 find_link 需要调用 cl/clang-cl 去尝试编译+ link

切到 clang-cl toolchain 后,envs 被加载为 clang-cl的环境,cl.exe 不在 PATH 里,所以之前 find_link 固定用 cl.exe 去探测,就会出这个问题,导致 link.exe 没找到。

waruqi commented 3 days ago

https://github.com/xmake-io/xmake/pull/5661

Issues-translate-bot commented 3 days ago

Bot detected the issue body's language is not English, translate it automatically.


Try it, it should work. This has nothing to do with the cache, it is a problem with the clang-cl toolchain. .

Because msvc/clang-cl all use link.exe, but to detect find_link you need to call cl/clang-cl to try to compile + link

After switching to the clang-cl toolchain, envs is loaded as the clang-cl environment, and cl.exe is not in the PATH. Therefore, before find_link was fixed to use cl.exe to detect, this problem will occur, causing link.exe not to be found.