xmake-io / xmake

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

交叉工具链中check报错 #5541

Closed MaxwellGengYF closed 2 months ago

MaxwellGengYF commented 2 months ago

Xmake Version

v2.9.4+dev.c64cb5aa8,

Operating System Version and Architecture

Windows

Describe Bug

内部使用 set_toolchains(llvm) 且该target没有使用包管理的情况下出现报错: error: we cannot get tool(cxx) in toolchain(llvm) with windows/x64, because it has been not checked yet!

Expected Behavior

允许内部使用不同工具链

Project Configuration

target("xx") set_toolchains("llvm")

xmake f --toolchain=msvc -c

Additional Information and Error Logs

error: error: we cannot get tool(cxx) in toolchain(llvm) with windows/x64, because it has been not checked yet!

waruqi commented 2 months ago

因为当前很多提早的 tool 获取,尽管使用上看上去没问题,但实际内部状态已经有些紊乱了,会导致各种隐藏问题。。

现在严格检测报错了。具体看下:https://github.com/xmake-io/xmake/pull/5466

如果是 target toolchain 设置,按理 config 阶段,会对所有绑定的 toolchain 进行检测,确保有效。

https://github.com/xmake-io/xmake/blob/87630c8cf33105cc8c000e73cb7b67a2decfe02d/xmake/actions/config/main.lua#L126

如果你在 check 之前就去用了 toolchain 里面的配置,就会导致一些状态不一致,即使不报错,也是有问题的,所以还不如直接提示出来。

先确认下 toolchain 的访问的时间点是否在 on_config 之前,如果靠前,自己显式 check 下。。

local llvm = target:toolchain("llvm")
if llvm:check() then
    检测后,再去访问 target:tool() 和 target:has_tool
end
waruqi commented 2 months ago

我改成 warning 了,不过我还是建议加上 check ,否则某些状态可能是不对的。

xmake update -s dev
Issues-translate-bot commented 2 months ago

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


Title: check error in cross tool chain

Issues-translate-bot commented 2 months ago

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


I changed it to warning, but I still recommend adding check, otherwise some status may be wrong.