-
-
Notifications
You must be signed in to change notification settings - Fork 816
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
需要改进对 zig 编译器的支持 #5915
Comments
Title: Need to improve zig compiler support Xmake versionv2.9.6+20241030 Operating system version and architectureManjaro Linux Describe the problemGenerally, there is a need to use zig to compile C/C++ projects. xmake already has preliminary support for this, but testing found that there are still some aspects that need improvement.
Expected results
local opt = {
system = false
}
add_requireconfs('**|cmake|pkg-config', opt)
Project configurationN/A Additional information and error logsN/A |
这个在语言层面是没法自动处理的,你只能自己配置 system = false 不走系统, 或者
没时间,可以来个 pr 过来。
这个可以参考 gcc/clang/msvc ,在 toolchain 中增加支持的 runtimes ,比如 glibc 等 xmake/xmake/toolchains/gcc/xmake.lua Line 31 in 71a5624
然后在 zig rules 中取 runtimes 处理下,可以来个 pr 过来 |
这个好像不好加,因为 glibc version 是这样用的 |
This seems difficult to add, because the glibc version is |
那啥也不用改,走 cross 平台就行了, $ xmake f -p cross --toolchain=zig -c --cross=x86_64-linux-gnu.2.29
$ xmake -rv
[ 50%]: cache compiling.release src/main.c
/tmp/.xmake999/250113/zigcc/cc -c -target x86_64-linux-gnu.2.29 -fvisibility=hidden -O3 -DNDEBUG -o build/.objs/test/cross/x86_64/release/src/main.c.o src/main.c
[ 75%]: linking.release test
/tmp/.xmake999/250113/zigcc/c++ -o build/cross/x86_64/release/test build/.objs/test/cross/x86_64/release/src/main.c.o -target x86_64-linux-gnu.2.29 -s
[100%]: build ok, spent 0.67s |
另外,我放开了 zig 下对 cross 设置,任何平台,只要设置了 cross 优先使用 |
看起来 zig rule 默认 runtimes 应该设置为 libc++。 可以试一下 sysroot 之类的行不行 |
In addition, I have released the cross settings under zig. Any platform, as long as cross is set, will be used first. |
msys2 + mingw64 + zig + libstdc++
[ 50%]: cache compiling.release src\main.cpp
C:\msys64\tmp\.xmake\250113\zigcc\c++.cmd -c -target x86_64-windows-gnu -IC:\msys64\mingw64\include -IC:\msys64\mingw64\include\c++\14.2.0 -IC:\msys64\mingw64\include\c++\14.2.0\x86_64-w64-mingw32 -IC:\Users\star\AppData\Local\.xmake\packages\a\ada\v2.9.2\1e516e9da60946fb8b0a5ee751eefead\include -nostdinc++ -nostdlib++ -o build\.objs\test\mingw\x86_64\release\src\main.cpp.obj src\main.cpp
[ 75%]: linking.release test.exe
C:\msys64\tmp\.xmake\250113\zigcc\c++.cmd -o build\mingw\x86_64\release\test.exe build\.objs\test\mingw\x86_64\release\src\main.cpp.obj -target x86_64-windows-gnu -LC:\msys64\mingw64\lib C:\Users\star\AppData\Local\.xmake\packages\a\ada\v2.9.2\1e516e9da60946fb8b0a5ee751eefead\lib\libada.dll.a C:/msys64/mingw64/lib/libstdc++.dll.a
[100%]: build ok, spent 1.375s
:/msys64/mingw64/lib/libstdc++.dll.a
error: unable to find dynamic system library 'ada' using strategy 'paths_first'. searched paths:
C:\msys64\mingw64\lib\ada.dll
C:\msys64\mingw64\lib\ada.lib
C:\msys64\mingw64\lib\libada.a
C:\Users\star\AppData\Local\.xmake\packages\a\ada\v2.9.2\1e516e9da60946fb8b0a5ee751eefead\lib\ada.dll
C:\Users\star\AppData\Local\.xmake\packages\a\ada\v2.9.2\1e516e9da60946fb8b0a5ee751eefead\lib\ada.lib
C:\Users\star\AppData\Local\.xmake\packages\a\ada\v2.9.2\1e516e9da60946fb8b0a5ee751eefead\lib\libada.a add_requires("ada[shared]")
add_packages("ada", {linkpath = true})
set_runtimes("stdc++_shared")
target("test")
set_kind("binary")
add_files("src/main.cpp")
set_toolchains("zig")
on_config(function (target)
if target:has_runtime("stdc++_shared", "stdc++_static") then
if is_subhost("msys") then
local mingw_prefix = os.getenv("MINGW_PREFIX")
if mingw_prefix and os.isdir(mingw_prefix) then
target:add("includedirs", path.join(mingw_prefix, "include"))
target:add("includedirs", path.join(mingw_prefix, "include/c++/14.2.0"))
target:add("includedirs", path.join(mingw_prefix, "include/c++/14.2.0/x86_64-w64-mingw32"))
target:add("cxflags", "-nostdinc++", "-nostdlib++")
target:add("linkdirs", path.join(mingw_prefix, "lib"))
target:add("syslinks", "C:/msys64/mingw64/lib/libstdc++.dll.a")
end
end
end
end) |
It looks like the zig rule default runtimes should be set to libc++. Can you try something like sysroot? |
Xmake 版本
v2.9.6+20241030
操作系统版本和架构
Manjaro Linux
描述问题
一般有需要使用 zig 编译 C/C++ 项目的需求,xmake 对此已经有了初步支持,但测试发现仍然有些方面需要改进。
对于系统包的处理
zig 默认不导入系统包,而 xmake 的默认行为恰好与之相反,这将导致头文件查找问题。
依赖库编译的工具链
zig 基于 llvm 工具链构建,与 linux 下常用的 gcc 工具链(以及对应包)兼容性往往存在问题。
glibc 版本选择
zig 支持在 target 中传入 glibc 版本(doc),xmake 尚不支持。
Compiling a cmake project with zig c++ doesn't resolve to and absolute path #5610
期待的结果
考虑在文档中写明兼容问题,或者添加警告?
添加一个
glibc_version
参数工程配置
N/A
附加信息和错误日志
N/A
The text was updated successfully, but these errors were encountered: