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: bash
The 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.
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
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.
What seems to be the issue here? Is there a way to solve this, or work around the issue?
# Windows: Disable .d files
if (CMAKE_HOST_WIN32)
set(CMAKE_C_LINKER_DEPFILE_SUPPORTED FALSE)
set(CMAKE_CXX_LINKER_DEPFILE_SUPPORTED FALSE)
endif()
Disabling depfile support through the toolchain file solved my problem