rust-cross / cargo-zigbuild

Compile Cargo project with zig as linker
MIT License
1.35k stars 50 forks source link

How to compile on Windows #247

Closed renatoathaydes closed 2 months ago

renatoathaydes commented 2 months ago

Hi, this is just a question, I don't believe there's any bugs here, but hope you can help me set up my release pipeline for Windows.

I've setup a release GitHub Action that uses this project to cross-compile for all platforms I'm interested in. It worked flawless for:

However, on the last platform I wanted to support, x86_64-pc-windows-gnu, it didn't work.

I chose this platform for the Windows binaries because of the installer I am using.

Here's the error I got on Windows (os: windows-latest on GH Actions):

error: linking with `C:\Users\runneradmin\AppData\Local\cargo-zigbuild\0.18.4\zigcc-x86_64-pc-windows-gnu.bat` failed: exit code: 1
  |
  = note: "cmd" "/c" "C:\\Users\\runneradmin\\AppData\\Local\\cargo-zigbuild\\0.18.4\\zigcc-x86_64-pc-windows-gnu.bat" "-fno-use-linker-plugin" "-Wl,--dynamicbase" "-Wl,--disable-auto-image-base" "-m64" "-Wl,--high-entropy-va" "C:\\Users\\runneradmin\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib\\rsbegin.o" "C:\\Users\\RUNNER~1\\AppData\\Local\\Temp\\rustc18MrZe\\symbols.o" "D:\\a\\jgrab\\jgrab\\jgrab-client\\target\\x86_64-pc-windows-gnu\\release\\deps\\jgrab_client-2988dcee4d3db51e.jgrab_client.503424660270d7a0-cgu.0.rcgu.o" "-L" "D:\\a\\jgrab\\jgrab\\jgrab-client\\target\\x86_64-pc-windows-gnu\\release\\deps" "-L" "D:\\a\\jgrab\\jgrab\\jgrab-client\\target\\release\\deps" "-L" "C:\\Users\\runneradmin\\.cargo\\registry\\src\\index.crates.io-6f17d22bba15001f\\windows_x86_64_gnu-0.48.5\\lib" "-L" "C:\\Users\\runneradmin\\.rustup\\toolchains\\stable-x86_64-pc-windows-msvc\\lib\\rustlib\\x86_64-pc-windows-gnu\\lib" "-Wl,-Bstatic" "C:\\Users\\runneradmin\\.rustup\\
  = note: warning: ignoring deprecated linker optimization setting '1'
          error: unable to find dynamic system library 'msvcrt' using strategy 'paths_first'. searched paths:
            D:\a\jgrab\jgrab\jgrab-client\target\x86_64-pc-windows-gnu\release\deps\msvcrt.dll
            D:\a\jgrab\jgrab\jgrab-client\target\x86_64-pc-windows-gnu\release\deps\msvcrt.lib
            D:\a\jgrab\jgrab\jgrab-client\target\x86_64-pc-windows-gnu\release\deps\libmsvcrt.a
            D:\a\jgrab\jgrab\jgrab-client\target\release\deps\msvcrt.dll
            D:\a\jgrab\jgrab\jgrab-client\target\release\deps\msvcrt.lib
            D:\a\jgrab\jgrab\jgrab-client\target\release\deps\libmsvcrt.a
            C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows_x86_64_gnu-0.48.5\lib\msvcrt.dll
            C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows_x86_64_gnu-0.48.5\lib\msvcrt.lib
            C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows_x86_64_gnu-0.48.5\lib\libmsvcrt.a
            C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-gnu\lib\msvcrt.dll
            C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-gnu\lib\msvcrt.lib
            C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-gnu\lib\libmsvcrt.a
            C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-gnu\lib\msvcrt.dll
            C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-gnu\lib\msvcrt.lib
            C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-gnu\lib\libmsvcrt.a

          D:\a\jgrab\jgrab\jgrab-client>C:\Users\runneradmin\.cargo\bin\cargo-zigbuild.exe zig cc -- -target x86_64-windows-gnu -g -fno-use-linker-plugin -Wl,--dynamicbase -Wl,--disable-auto-image-base -m64 -Wl,--high-entropy-va C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-gnu\lib\rsbegin.o C:\Users\RUNNER~1\AppData\Local\Temp\rustc18MrZe\symbols.o D:\a\jgrab\jgrab\jgrab-client\target\x86_64-pc-windows-gnu\release\deps\jgrab_client-2988dcee4d3db51e.jgrab_client.503424660270d7a0-cgu.0.rcgu.o -L D:\a\jgrab\jgrab\jgrab-client\target\x86_64-pc-windows-gnu\release\deps -L D:\a\jgrab\jgrab\jgrab-client\target\release\deps -L C:\Users\runneradmin\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows_x86_64_gnu-0.48.5\lib -L C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-gnu\lib -Wl,-Bstatic C:\Users\runneradmin\.rustup\toolchains\stable-x86_64-pc-windows-msvc\lib\rustlib\x86_64-pc-windows-gnu\lib\libcom

error: could not compile `jgrab-client` (bin "jgrab-client") due to 1 previous error
Error: Process completed with exit code 101.

Is there something I need to change or this platform is not supported?

If I just wanted to support Windows for most Windows users, which platforms should I be targetting (sorry about asking you, but I have no clue which Windows targets are appropriate and I thought that perhaps you could help with that)?

messense commented 2 months ago

Try zig 0.10.1/0.11.0 if you want to build for windows gnu targets, 0.12.0 doesn't work yet.

If I just wanted to support Windows for most Windows users, which platforms should I be targetting

IMO you should target x86_64-pc-windows-msvc (and you don't need to use cargo-zigbuild when you are building on windows), windows gnu targets are usually for cross compiling from a non-windows environment or avoid using proprietary MSFT softwares.