Skip to content

Commit

Permalink
Publish windows image separately
Browse files Browse the repository at this point in the history
  • Loading branch information
vedantmgoyal9 authored Nov 3, 2024
1 parent 1ebd38c commit 5708918
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 58 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -219,8 +219,8 @@ jobs:
uses: docker/metadata-action@v5
with:
images: |
${{ secrets.DOCKER_USERNAME }}/cargo-zigbuild
ghcr.io/${{ github.repository_owner }}/cargo-zigbuild
${{ secrets.DOCKER_USERNAME }}/cargo-zigbuild.windows
ghcr.io/${{ github.repository_owner }}/cargo-zigbuild.windows
tags: |
type=schedule
type=ref,event=branch
Expand Down
74 changes: 18 additions & 56 deletions Dockerfile.windows
Original file line number Diff line number Diff line change
@@ -1,60 +1,22 @@
FROM mcr.microsoft.com/windows/nanoserver:ltsc2022
ARG RUST_VERSION=1.82.0
ARG ZIG_VERSION=0.10.1

# --- Download Zig and macOS SDK --- #

FROM mcr.microsoft.com/windows/servercore:ltsc2022 as zig-and-macos-sdk
ARG ZIG_VERSION
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
RUN Invoke-WebRequest "https://ziglang.org/download/$env:ZIG_VERSION/zig-windows-x86_64-$env:ZIG_VERSION.zip" -OutFile zig.zip; \
Invoke-WebRequest 'https://github.com/phracker/MacOSX-SDKs/releases/download/11.3/MacOSX11.3.sdk.tar.xz' -OutFile sdk.tar.xz; \
Invoke-WebRequest https://www.7-zip.org/a/7z2408-x64.exe -OutFile 7z-setup.exe;
RUN .\7z-setup.exe /S /D="C:";
RUN .\7z.exe -y -oC: x zig.zip; Rename-Item .\zig-windows-x86_64-$env:ZIG_VERSION .\zig;
RUN .\7z.exe e .\sdk.tar.xz; & .\7z.exe -y -oC: x .\sdk.tar; Rename-Item .\MacOSX11.3.sdk .\sdk;

# --- Download and setup Rust --- #

FROM mcr.microsoft.com/windows/servercore:ltsc2022 as rust-windows
ARG RUST_VERSION
SHELL ["powershell", "-Command", "$ErrorActionPreference = 'Stop'; $ProgressPreference = 'SilentlyContinue';"]
# Default host is set to x86_64-pc-windows-gnu to avoid MSVC which requires VS Build Tools
## Also, cargo-zigbuild can compile for x86_64-pc-windows-gnu, so we don't need MSVC anyway
RUN Invoke-WebRequest https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-msvc/rustup-init.exe -OutFile rustup-init.exe; \
.\rustup-init.exe -y --default-toolchain $env:RUST_VERSION --default-host x86_64-pc-windows-gnu; \
Remove-Item -Path .\rustup-init.exe -Force;

# --- Build cargo-zigbuild --- #

FROM rust-windows as builder
ENV CARGO_NET_GIT_FETCH_WITH_CLI=true
# Compile dependencies only for build caching
ADD Cargo.toml /cargo-zigbuild/Cargo.toml
ADD Cargo.lock /cargo-zigbuild/Cargo.lock
RUN New-Item -Path .\cargo-zigbuild -Name src -ItemType Directory; \
New-Item -Path .\cargo-zigbuild\src -Name lib.rs -Value \"`n\" -ItemType File; \
cargo build --manifest-path .\cargo-zigbuild\Cargo.toml --release
# Build cargo-zigbuild
USER ContainerAdministrator
ADD https://github.com/hexops-graveyard/sdk-macos-13.3/archive/refs/heads/main.zip /sdk.zip
ADD https://ziglang.org/download/${ZIG_VERSION}/zig-windows-x86_64-${ZIG_VERSION}.zip /zig.zip
ADD https://static.rust-lang.org/rustup/dist/x86_64-pc-windows-gnu/rustup-init.exe /rustup-init.exe
ADD . /cargo-zigbuild
# Manually update the timestamps as ADD keeps the local timestamps and cargo would then believe the cache is fresh
RUN $file = Get-Item .\cargo-zigbuild\src\lib.rs; $file.LastWriteTime = (Get-Date)
RUN $file = Get-Item .\cargo-zigbuild\src\bin\cargo-zigbuild.rs; $file.LastWriteTime = (Get-Date)
RUN cargo build --manifest-path .\cargo-zigbuild\Cargo.toml --release

# --- Final image --- #

FROM rust-windows as final
ENV SDKROOT=C:\\sdk
COPY --from=zig-and-macos-sdk C:\\zig C:\\zig
COPY --from=zig-and-macos-sdk C:\\sdk C:\\sdk
RUN [System.Environment]::SetEnvironmentVariable('PATH', $env:Path + ';C:\\zig', 'Machine')
RUN rustup target add aarch64-pc-windows-gnullvm \
x86_64-unknown-linux-gnu \
x86_64-unknown-linux-musl \
aarch64-unknown-linux-gnu \
aarch64-unknown-linux-musl \
arm-unknown-linux-gnueabihf \
arm-unknown-linux-musleabihf \
x86_64-apple-darwin \
aarch64-apple-darwin
COPY --from=builder C:\\cargo-zigbuild\\target\\release\\cargo-zigbuild.exe C:\\Users\\ContainerAdministrator\\.cargo\\bin\\cargo-zigbuild.exe
# Default host is set to x86_64-pc-windows-gnu to avoid MSVC which requires VS Build Tools
RUN rustup-init.exe -y --no-modify-path --default-toolchain %RUST_VERSION% --default-host x86_64-pc-windows-gnu --target \
aarch64-pc-windows-gnullvm \
x86_64-unknown-linux-gnu x86_64-unknown-linux-musl \
aarch64-unknown-linux-gnu aarch64-unknown-linux-musl \
arm-unknown-linux-gnueabihf arm-unknown-linux-musleabihf \
x86_64-apple-darwin aarch64-apple-darwin \
&& tar xf zig.zip && tar xf sdk.zip \
&& ren zig-windows-x86_64-%ZIG_VERSION% zig && move sdk-macos-13.3-main/root sdk \
&& setx /m PATH "%USERPROFILE%\.cargo\bin;C:\zig;%PATH%" \
&& %USERPROFILE%\.cargo\bin\cargo build --manifest-path cargo-zigbuild\Cargo.toml --release \
&& move cargo-zigbuild\target\release\cargo-zigbuild.exe %USERPROFILE%\.cargo\bin\cargo-zigbuild.exe \
&& rmdir /q /s cargo-zigbuild sdk-macos-13.3-main && del /q rustup-init.exe zig.zip sdk.zip

0 comments on commit 5708918

Please sign in to comment.