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

toolchain 判断 是否交叉编译错误 #5774

Closed
yecate opened this issue Oct 31, 2024 · 7 comments
Closed

toolchain 判断 是否交叉编译错误 #5774

yecate opened this issue Oct 31, 2024 · 7 comments
Labels
Milestone

Comments

@yecate
Copy link
Contributor

yecate commented Oct 31, 2024

Xmake 版本

2.9.6

操作系统版本和架构

Windows 11 专业版 23H2 22631.4317

描述问题

xmake f -cvD -a x64 --vs=2022 --toolchain=clang-cl --sdk=K:\IDE\llvm\llvm-19.1.2
xmake -rv

编译的时候调用的是 msvc clang-cl ,并非 config 设置的 K:\IDE\llvm\llvm-19.1.2\bin\clang-cl.exe

经过排查 没有通过 config.get("sdk") 获取sdk目录:
问题链接

function _instance:sdkdir()
    return self:config("sdkdir") or config.get("sdk") or self:info():get("sdkdir")
end

function _instance:is_cross()
    if self:kind() == "cross" then
        return true
    elseif self:kind() == "standalone" and (self:cross() or self:config("sdkdir") or self:info():get("sdkdir")) then
        return true
    end
end

以前的版本 是直接调用的 self:sdkdir() 获取的sdk 目录

function _instance:is_cross()
    if self:kind() == "cross" then
        return true
    elseif self:kind() == "standalone" and (self:cross() or self:sdkdir()) then
        return true
    end
end

期待的结果

正确识别 设置的sdk目录

工程配置

add_rules("mode.debug", "mode.release")

target("test_clang_cl")
    set_kind("binary")
    add_files("src/*.cpp")

附加信息和错误日志

(0) > xmake f -cvD -a x64 --vs=2022 --toolchain=clang-cl --sdk=K:\IDE\llvm\llvm-19.1.2
checking for platform ... windows
checking for clang-cl.exe ... K:\IDE\vs2022\VC\Tools\Llvm\x64\bin\clang-cl.exe
checking for Microsoft Visual Studio (x64) version ... 2022
checking for LLVM Clang C/C++ Compiler (x64) version ... 18.1.8
checking for link.exe ... K:\IDE\vs2022\VC\Tools\MSVC\14.42.34431\bin\HostX64\x64\link.exe
checking for the linker (ld) ... link.exe
(0) > xmake -rvD
[ 50%]: cache compiling.release src\main.cpp
K:\IDE\vs2022\VC\Tools\Llvm\x64\bin\clang-cl.exe -c -m64 -O2 /EHsc -DNDEBUG -Fobuild\.objs\test_clang_cl\windows\x64\release\src\main.cpp.obj src\main.cpp
[ 75%]: linking.release test_clang_cl.exe
K:\IDE\vs2022\VC\Tools\MSVC\14.42.34431\bin\HostX64\x64\link.exe -nologo -dynamicbase -nxcompat -machine:x64 /opt:ref /opt:icf -out:build\windows\x64\release\test_clang_cl.exe build\.objs\test_clang_cl\windows\x64\release\src\main.cpp.obj

build cache stats:
cache directory: build\.build_cache
cache hit rate: 0%
cache hit: 0
cache hit total time: 0.000s
cache miss: 0
cache miss total time: 0.000s
new cached files: 0
remote cache hit: 0
remote new cached files: 0
preprocess failed: 0
compile fallback count: 0
compile total time: 0.000s

[100%]: build ok, spent 0.828s
@yecate yecate added the bug label Oct 31, 2024
@Issues-translate-bot
Copy link

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


Title: toolchain determines whether there is a cross-compilation error

@waruqi
Copy link
Member

waruqi commented Nov 1, 2024

这不是错误,之前才是不对的,使用 clang-cl 编译不属于交叉编译,不应该根据全局的 --sdk= 配置,将它作为 cross 编译处理。

目前 clang-cl toolchain 仅支持 vs 内置 clang-cl 以及在 PATH 中的 clang-cl ,并不支持切到指定 sdk

@Issues-translate-bot
Copy link

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


This is not an error, it was wrong before. Compiling with clang-cl is not cross-compilation, and it should not be treated as cross compilation according to the global --sdk= configuration.

Currently, the clang-cl toolchain only supports VS built-in clang-cl and clang-cl in PATH, and does not support switching to the specified sdk.

@yecate
Copy link
Contributor Author

yecate commented Nov 1, 2024

将clang-cl 目录放到PATH, 能够检测到PATH里面的clang-cl, 编译调用的是vs 内置的, 这样 和 vs 内置 的优先级是怎么样的?

(0) > xmake f -cvD -a x86 --vs=2022 --toolchain=clang-cl
checking for platform ... windows
checking for clang-cl.exe ... K:\IDE\llvm\llvm-19.1.2\bin\clang-cl.exe
checking for Microsoft Visual Studio (x86) version ... 2022
checking for LLVM Clang C/C++ Compiler (x86) version ... 19.1.2
checking for clang-cl.exe ... K:\IDE\vs2022\VC\Tools\Llvm\x64\bin\clang-cl.exe
checking for the c++ compiler (cxx) ... clang-cl.exe
checking for clang-cl.exe ... K:\IDE\vs2022\VC\Tools\Llvm\x64\bin\clang-cl.exe
checking for the c compiler (cc) ... clang-cl.exe
checking for link.exe ... K:\IDE\vs2022\VC\Tools\MSVC\14.42.34431\bin\HostX64\x86\link.exe
checking for the shared library linker (sh) ... link.exe
checking for link.exe ... K:\IDE\vs2022\VC\Tools\MSVC\14.42.34431\bin\HostX64\x86\link.exe
checking for the linker (ld) ... link.exe

@yecate
Copy link
Contributor Author

yecate commented Nov 1, 2024

卸载了 msvc 的 正常了

@yecate yecate closed this as completed Nov 1, 2024
@Issues-translate-bot
Copy link

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


After uninstalling msvc, it became normal.

@waruqi
Copy link
Member

waruqi commented Nov 2, 2024

试下这个 patch 应该可以了. #5780

xmake update -s github:xmake-io/xmake#clang

@waruqi waruqi added this to the v2.9.7 milestone Nov 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants