-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Description
Zig Version
0.14.0-dev.2441+3670910f2
Steps to Reproduce and Observed Behavior
From: https://stackoverflow.com/questions/79276124/zig-cross-compiling-riscv64-linux-musl-fails-on-windows
I'm using a simple github actions to try to build some ELF binaries using windows-latest just to check if it works: https://github.com/libriscv/godot-sandbox-programs/blob/windows/.github/workflows/zig-windows.yml
build:
runs-on: windows-latest
env:
CC: zig cc -target riscv64-linux-musl
CXX: zig c++ -target riscv64-linux-musl
...
- name: Build all examples
working-directory: ${{github.workspace}}
run: |
export PATH=$PWD/zig-windows-x86_64-0.14.0-dev.2441+3670910f2:$PATH
cmake -G Ninja -B build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DSTRIPPED=ON -DCMAKE_TOOLCHAIN_FILE=cmake/zig-toolchain.cmake -DCMAKE_C_COMPILER="${{env.CC}}" -DCMAKE_CXX_COMPILER="${{env.CXX}}"
cmake --build build --parallel 8
shell: bashThe toolchain file is very short:
set(CMAKE_SYSTEM_NAME "Linux")
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR "riscv64")
set(CMAKE_CROSSCOMPILING TRUE)
set(CMAKE_TRY_COMPILE_TARGET_TYPE STATIC_LIBRARY)
set(CMAKE_C_COMPILER "zig" cc -target riscv64-linux-musl)
set(CMAKE_CXX_COMPILER "zig" c++ -target riscv64-linux-musl)... and it works on Linux and macOS both. So, good job with that. It works well!
On Windows I am using ninja to build, and it's correctly showing Clang 19.1 as the compiler (Zig 0.14 nightly):
Run export PATH=$PWD/zig-windows-x86_64-0.14.0-dev.2441+3670910f2:$PATH
-- The C compiler identification is Clang 19.1.0
-- The CXX compiler identification is Clang 19.1.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: D:/a/godot-sandbox-programs/godot-sandbox-programs/zig-windows-x86_64-0.14.0-dev.2441+3670910f2/zig.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: D:/a/godot-sandbox-programs/godot-sandbox-programs/zig-windows-x86_64-0.14.0-dev.2441+3670910f2/zig.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
It then proceeds to build everything until the first program needs to be linked:
[146/181] Linking CXX executable bin\asm
FAILED: bin/asm
C:\Windows\system32\cmd.exe /C "cd . && D:\a\godot-sandbox-programs\godot-sandbox-programs\zig-windows-x86_64-0.14.0-dev.2441+3670910f2\zig.exe c++ -target riscv64-linux-musl -O3 -DNDEBUG -s -Xlinker --dependency-file -Xlinker programs\asm\CMakeFiles\asm.dir\link.d programs/asm/CMakeFiles/asm.dir/main.cpp.o programs/asm/CMakeFiles/asm.dir/extra/obstack.c.o -o bin\asm -Wl,--whole-archive _deps/godot-sandbox-build/libsandbox_api.a -Wl,--no-whole-archive -static D:/a/godot-sandbox-programs/godot-sandbox-programs/programs/asm/zig-libRiscvAsmLib.a -Wl,--image-base=0x100000 _deps/zlib-build/libz.a && cd ."
error: unsupported linker arg: --dependency-file
Attached the full logs here: job-logs.txt
Is this argument passed by Zig? As far as I understand, --dependency-file is a legit option for ELF targets, and LLD should be accepting it here? So, what's the problem? Does it not think it's linking ELF?
Looking at Kitware I find this issue which looks related, but ultimately is the opposite of what I'm doing: https://gitlab.kitware.com/cmake/cmake/-/issues/26250 That is, I'm not trying to build Windows binaries. This is a 64-bit RISC-V toolchain that produces ELF binaries on two other platforms. Windows should not be any different here.
The CMake bug report links to this LLVM issue: llvm/llvm-project#118748 where CMAKE_EXECUTABLE_FORMAT is mentioned. The issue itself is not relevant as it's the opposite problem, but I found it interesting that it could perhaps be related to what CMake believes the executable format to be?
Expected Behavior
The linking should succeed.