From 48c6511732e310faaa6950a0b797d0a726a8f669 Mon Sep 17 00:00:00 2001 From: Erick Bourgeois Date: Wed, 24 Dec 2025 09:43:11 -0500 Subject: [PATCH] Add support for building windows Signed-off-by: Erick Bourgeois --- .github/workflows/pr.yml | 33 ++++- CLAUDE.md | 82 +++++++++++ rust/build-binary/README.md | 221 +++++++++++++++++++++++++----- rust/build-binary/action.yaml | 19 ++- rust/generate-sbom/action.yaml | 20 +-- rust/setup-rust-build/README.md | 83 ++++++++--- rust/setup-rust-build/action.yaml | 23 +++- 7 files changed, 402 insertions(+), 79 deletions(-) diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml index 8470790..5ff1f78 100644 --- a/.github/workflows/pr.yml +++ b/.github/workflows/pr.yml @@ -571,8 +571,11 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - target: - - x86_64-unknown-linux-gnu + include: + - target: x86_64-unknown-linux-gnu + binary: test-binary + - target: x86_64-pc-windows-gnu + binary: test-binary.exe steps: - uses: actions/checkout@v4 @@ -591,17 +594,33 @@ jobs: with: target: ${{ matrix.target }} - - name: Test build-binary action + - name: Install mingw-w64 for Windows GNU target + if: matrix.target == 'x86_64-pc-windows-gnu' + run: | + sudo apt-get update + sudo apt-get install -y mingw-w64 + + - name: Build binary working-directory: test-binary run: | - cargo build --release --target ${{ matrix.target }} --verbose + if [[ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" || "${{ matrix.target }}" == "aarch64-pc-windows-msvc" ]]; then + cross build --release --target ${{ matrix.target }} --verbose + else + cargo build --release --target ${{ matrix.target }} --verbose + fi - name: Verify binary was built run: | cd test-binary - test -f target/${{ matrix.target }}/release/test-binary - echo "✓ Binary built successfully" - ./target/${{ matrix.target }}/release/test-binary + test -f target/${{ matrix.target }}/release/${{ matrix.binary }} + echo "✓ Binary built successfully for ${{ matrix.target }}" + ls -lh target/${{ matrix.target }}/release/${{ matrix.binary }} + + - name: Execute binary (Linux only) + if: matrix.target == 'x86_64-unknown-linux-gnu' + run: | + cd test-binary + ./target/${{ matrix.target }}/release/${{ matrix.binary }} test-verify-toolchain: name: Test rust/verify-toolchain diff --git a/CLAUDE.md b/CLAUDE.md index 385b6e0..f7ac4d0 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -340,6 +340,88 @@ Before submitting a PR, ensure: 6. **Signed commits**: All commits must be GPG or SSH signed 7. **Security scanning**: All actions undergo security analysis +## Supported Build Targets + +The Rust actions support building binaries for multiple target architectures: + +### Linux Targets + +**Native Builds (using `cargo`):** +- `x86_64-unknown-linux-gnu` - x86_64 Linux with GNU libc +- `x86_64-unknown-linux-musl` - x86_64 Linux with musl libc + +**Cross-Compilation Builds (using `cross`):** +- `aarch64-unknown-linux-gnu` - ARM64 Linux with GNU libc +- `aarch64-unknown-linux-musl` - ARM64 Linux with musl libc + +### Windows Targets + +**Cross-Compilation from Linux (using `cargo`):** +- `x86_64-pc-windows-msvc` - x86_64 Windows with MSVC toolchain (recommended) +- `x86_64-pc-windows-gnu` - x86_64 Windows with GNU/MinGW-w64 toolchain + +**Cross-Compilation from Linux (using `cross`):** +- `aarch64-pc-windows-msvc` - ARM64 Windows with MSVC toolchain + +**Choosing Between Windows MSVC and GNU:** + +MSVC (`x86_64-pc-windows-msvc`): +- Uses Microsoft Visual C++ toolchain +- Better integration with Windows ecosystem +- Best compatibility with Windows APIs +- **Requires Windows runners** (`runs-on: windows-latest`) +- Cannot cross-compile from Linux without complex setup (xwin) +- Recommended for production Windows deployments + +GNU (`x86_64-pc-windows-gnu`) - **Recommended for CI/CD**: +- Uses MinGW-w64 toolchain +- **Works on Linux runners** with mingw-w64 installed +- Better for cross-platform CI pipelines on Linux runners +- Requires mingw-w64 installation: `sudo apt-get install mingw-w64` +- Good compatibility with most Windows applications +- Simpler and faster for Linux-based CI/CD + +**CI/CD Recommendation**: +- Use `x86_64-pc-windows-gnu` on Linux runners (ubuntu-latest) +- Use `x86_64-pc-windows-msvc` on Windows runners (windows-latest) +- Both produce fully functional Windows executables + +### macOS Targets + +- `x86_64-apple-darwin` - x86_64 macOS (Intel) +- `aarch64-apple-darwin` - ARM64 macOS (Apple Silicon) + +### Target-Specific Requirements + +**Windows GNU Target (`x86_64-pc-windows-gnu`):** +```yaml +- name: Install mingw-w64 + if: matrix.target == 'x86_64-pc-windows-gnu' + run: | + sudo apt-get update + sudo apt-get install -y mingw-w64 +``` + +**Cross-compilation targets (require Docker):** +- `aarch64-unknown-linux-gnu` - ARM64 Linux +- `aarch64-pc-windows-msvc` - ARM64 Windows + +These targets automatically use the `cross` tool which requires Docker to be available on the runner. + +### Binary Output Paths + +**Linux binaries:** +``` +target/{target}/release/{binary-name} +Example: target/x86_64-unknown-linux-gnu/release/my-app +``` + +**Windows binaries (include .exe extension):** +``` +target/{target}/release/{binary-name}.exe +Example: target/x86_64-pc-windows-msvc/release/my-app.exe +``` + ## Technologies and Tools ### Core Technologies diff --git a/rust/build-binary/README.md b/rust/build-binary/README.md index 687a892..6bea6b8 100644 --- a/rust/build-binary/README.md +++ b/rust/build-binary/README.md @@ -5,8 +5,10 @@ A composite GitHub Action that intelligently builds Rust binaries for specified ## Features - Automatic selection of build tool (`cargo` vs `cross`) -- Native builds for x86_64 using standard `cargo` -- Cross-compilation for ARM64 using `cross` +- Native builds for x86_64 Linux using standard `cargo` +- Native builds for Windows (MSVC and GNU) using standard `cargo` +- Cross-compilation for ARM64 Linux using `cross` +- Cross-compilation for ARM64 Windows using `cross` - Verbose output for debugging build issues - Release profile optimization - Seamless integration with `rust/setup-rust-build` @@ -27,7 +29,7 @@ A composite GitHub Action that intelligently builds Rust binaries for specified target: x86_64-unknown-linux-gnu ``` -### ARM64 Cross-Compilation +### ARM64 Linux Cross-Compilation ```yaml - name: Setup Rust environment @@ -41,6 +43,47 @@ A composite GitHub Action that intelligently builds Rust binaries for specified target: aarch64-unknown-linux-gnu ``` +### Windows x86_64 Build (MSVC - requires Windows runner) + +```yaml +# Note: MSVC target requires Windows runners +runs-on: windows-latest + +steps: + - name: Setup Rust environment + uses: firestoned/github-actions/rust/setup-rust-build@v1 + with: + target: x86_64-pc-windows-msvc + + - name: Build binary + uses: firestoned/github-actions/rust/build-binary@v1 + with: + target: x86_64-pc-windows-msvc +``` + +### Windows x86_64 Build (GNU - works on Linux) + +```yaml +# Works on Linux runners with mingw-w64 +runs-on: ubuntu-latest + +steps: + - name: Install mingw-w64 + run: | + sudo apt-get update + sudo apt-get install -y mingw-w64 + + - name: Setup Rust environment + uses: firestoned/github-actions/rust/setup-rust-build@v1 + with: + target: x86_64-pc-windows-gnu + + - name: Build binary + uses: firestoned/github-actions/rust/build-binary@v1 + with: + target: x86_64-pc-windows-gnu +``` + ### Multi-Architecture Matrix Build ```yaml @@ -48,10 +91,18 @@ jobs: build: strategy: matrix: - target: - - x86_64-unknown-linux-gnu - - aarch64-unknown-linux-gnu - runs-on: ubuntu-latest + include: + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + - target: aarch64-unknown-linux-gnu + os: ubuntu-latest + - target: x86_64-pc-windows-msvc + os: ubuntu-latest + - target: x86_64-pc-windows-gnu + os: ubuntu-latest + - target: aarch64-pc-windows-msvc + os: ubuntu-latest + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -69,14 +120,14 @@ jobs: uses: actions/upload-artifact@v4 with: name: binary-${{ matrix.target }} - path: target/${{ matrix.target }}/release/my-app + path: target/${{ matrix.target }}/release/my-app${{ contains(matrix.target, 'windows') && '.exe' || '' }} ``` ## Inputs | Name | Description | Required | Default | |------|-------------|----------|---------| -| `target` | Rust target triple (e.g., `x86_64-unknown-linux-gnu`, `aarch64-unknown-linux-gnu`) | Yes | N/A | +| `target` | Rust target triple (e.g., `x86_64-unknown-linux-gnu`, `x86_64-pc-windows-msvc`, `aarch64-unknown-linux-gnu`) | Yes | N/A | ## How It Works @@ -87,21 +138,39 @@ The action automatically chooses the appropriate build tool based on the target: | Target | Build Tool | Reason | |--------|------------|--------| | `x86_64-unknown-linux-gnu` | `cargo` | Native compilation on x86_64 runners | -| `aarch64-unknown-linux-gnu` | `cross` | Cross-compilation from x86_64 to ARM64 | +| `aarch64-unknown-linux-gnu` | `cross` | Cross-compilation from x86_64 to ARM64 Linux | +| `x86_64-pc-windows-msvc` | `cargo` | Cross-compilation to Windows with MSVC toolchain | +| `x86_64-pc-windows-gnu` | `cargo` | Cross-compilation to Windows with GNU toolchain | +| `aarch64-pc-windows-msvc` | `cross` | Cross-compilation to ARM64 Windows | ### Build Process -#### For x86_64 (Native Build) +#### For x86_64 Linux (Native Build) ```bash cargo build --release --target x86_64-unknown-linux-gnu --verbose ``` -#### For ARM64 (Cross-Compilation) +#### For ARM64 Linux (Cross-Compilation) ```bash cross build --release --target aarch64-unknown-linux-gnu --verbose ``` -Both commands: +#### For x86_64 Windows MSVC (Cross-Compilation) +```bash +cargo build --release --target x86_64-pc-windows-msvc --verbose +``` + +#### For x86_64 Windows GNU (Cross-Compilation) +```bash +cargo build --release --target x86_64-pc-windows-gnu --verbose +``` + +#### For ARM64 Windows (Cross-Compilation) +```bash +cross build --release --target aarch64-pc-windows-msvc --verbose +``` + +All commands: - Use `--release` for optimized production builds - Use `--target` for explicit target specification - Use `--verbose` for detailed build logs @@ -110,12 +179,16 @@ Both commands: Built binaries are located at: ``` -target/{target}/release/{binary-name} +target/{target}/release/{binary-name}[.exe] ``` For example: -- `target/x86_64-unknown-linux-gnu/release/my-app` -- `target/aarch64-unknown-linux-gnu/release/my-app` +- Linux: `target/x86_64-unknown-linux-gnu/release/my-app` +- Linux ARM64: `target/aarch64-unknown-linux-gnu/release/my-app` +- Windows: `target/x86_64-pc-windows-msvc/release/my-app.exe` +- Windows ARM64: `target/aarch64-pc-windows-msvc/release/my-app.exe` + +**Note**: Windows binaries have a `.exe` extension ## Best Practices @@ -155,14 +228,14 @@ steps: ### 3. Upload Artifacts with Correct Paths -Use the standard Rust target directory structure: +Use the standard Rust target directory structure, including `.exe` for Windows: ```yaml - name: Upload binary uses: actions/upload-artifact@v4 with: name: binary-${{ matrix.target }} - path: target/${{ matrix.target }}/release/my-app + path: target/${{ matrix.target }}/release/my-app${{ contains(matrix.target, 'windows') && '.exe' || '' }} ``` ## Troubleshooting @@ -204,11 +277,14 @@ path: target/${{ matrix.target }}/release/my-app **Problem**: Binary built for wrong architecture **Solution**: Verify the target matches your deployment environment: -- Linux servers: `x86_64-unknown-linux-gnu` or `x86_64-unknown-linux-musl` -- ARM servers: `aarch64-unknown-linux-gnu` -- macOS: `x86_64-apple-darwin` or `aarch64-apple-darwin` +- Linux x86_64 servers: `x86_64-unknown-linux-gnu` or `x86_64-unknown-linux-musl` +- Linux ARM64 servers: `aarch64-unknown-linux-gnu` +- Windows x86_64: `x86_64-pc-windows-msvc` or `x86_64-pc-windows-gnu` +- Windows ARM64: `aarch64-pc-windows-msvc` +- macOS x86_64: `x86_64-apple-darwin` +- macOS ARM64: `aarch64-apple-darwin` -### Cross-Compilation Fails for ARM64 +### Cross-Compilation Fails for ARM64 or Windows ARM64 **Problem**: `cross` build fails with Docker errors @@ -218,6 +294,40 @@ path: target/${{ matrix.target }}/release/my-app uses: docker/setup-buildx-action@v3 ``` +### Windows Build Fails with Missing Linker + +**Problem**: Windows cross-compilation fails with "linker not found" + +**Solution for GNU target**: Install mingw-w64: +```yaml +- name: Install Windows GNU dependencies + if: matrix.target == 'x86_64-pc-windows-gnu' + run: | + sudo apt-get update + sudo apt-get install -y mingw-w64 +``` + +**Solution for MSVC target**: The MSVC target (`x86_64-pc-windows-msvc`) requires the Microsoft linker (`link.exe`) which is not available on Linux runners. You have two options: + +1. **Use Windows runners** (recommended for MSVC): +```yaml +runs-on: windows-latest +``` + +2. **Use the GNU target instead** (works on Linux runners): +```yaml +target: x86_64-pc-windows-gnu +``` + +3. **Use xwin for MSVC on Linux** (advanced, requires additional setup): +```yaml +- name: Setup xwin for MSVC linker + run: | + cargo install xwin + xwin --accept-license splat --output /tmp/xwin + echo "XWIN_ARCH=x86_64" >> $GITHUB_ENV +``` + ## Performance Tips ### 1. Use Caching @@ -247,7 +357,11 @@ Use matrix builds to build multiple targets in parallel: ```yaml strategy: matrix: - target: [x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu] + target: + - x86_64-unknown-linux-gnu + - aarch64-unknown-linux-gnu + - x86_64-pc-windows-msvc + - x86_64-pc-windows-gnu ``` ## Advanced Usage @@ -312,8 +426,36 @@ MIT License - Copyright (c) 2025 Erick Bourgeois, firestoned ## Supported Targets ### Currently Implemented -- `x86_64-unknown-linux-gnu` - Native build with `cargo` -- `aarch64-unknown-linux-gnu` - Cross-build with `cross` + +**Linux Targets:** +- `x86_64-unknown-linux-gnu` - x86_64 Linux with GNU libc (native build with `cargo`) +- `aarch64-unknown-linux-gnu` - ARM64 Linux with GNU libc (cross-build with `cross`) + +**Windows Targets:** +- `x86_64-pc-windows-msvc` - x86_64 Windows with MSVC toolchain (cross-build with `cargo`) +- `x86_64-pc-windows-gnu` - x86_64 Windows with GNU toolchain (cross-build with `cargo`) +- `aarch64-pc-windows-msvc` - ARM64 Windows with MSVC toolchain (cross-build with `cross`) + +### Choosing Between Windows MSVC and GNU + +**MSVC (`x86_64-pc-windows-msvc`)**: +- Uses Microsoft Visual C++ toolchain +- Better integration with Windows ecosystem +- Recommended for most Windows deployments +- **Requires Windows runners** (`runs-on: windows-latest`) +- Cannot cross-compile from Linux without complex setup (xwin) + +**GNU (`x86_64-pc-windows-gnu`)** - Recommended for CI/CD: +- Uses MinGW-w64 toolchain +- **Works on Linux runners** with mingw-w64 installed +- Better for cross-platform CI pipelines +- Requires mingw-w64 installation: `sudo apt-get install mingw-w64` +- Good compatibility with most applications + +**Recommendation for CI/CD**: +- Use `x86_64-pc-windows-gnu` on Linux runners (simpler, faster) +- Use `x86_64-pc-windows-msvc` on Windows runners (better Windows integration) +- Both produce fully functional Windows executables ### Extensible for Additional Targets @@ -342,10 +484,20 @@ jobs: build: strategy: matrix: - target: - - x86_64-unknown-linux-gnu - - aarch64-unknown-linux-gnu - runs-on: ubuntu-latest + include: + - target: x86_64-unknown-linux-gnu + os: ubuntu-latest + archive: tar.gz + - target: aarch64-unknown-linux-gnu + os: ubuntu-latest + archive: tar.gz + - target: x86_64-pc-windows-msvc + os: ubuntu-latest + archive: zip + - target: aarch64-pc-windows-msvc + os: ubuntu-latest + archive: zip + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 @@ -359,15 +511,22 @@ jobs: with: target: ${{ matrix.target }} - - name: Package binary + - name: Package binary (Linux) + if: matrix.archive == 'tar.gz' run: | cd target/${{ matrix.target }}/release tar czf my-app-${{ matrix.target }}.tar.gz my-app + - name: Package binary (Windows) + if: matrix.archive == 'zip' + run: | + cd target/${{ matrix.target }}/release + zip my-app-${{ matrix.target }}.zip my-app.exe + - name: Upload to release uses: softprops/action-gh-release@v1 with: - files: target/${{ matrix.target }}/release/my-app-${{ matrix.target }}.tar.gz + files: target/${{ matrix.target }}/release/my-app-${{ matrix.target }}.${{ matrix.archive }} ``` ### Build with Tests diff --git a/rust/build-binary/action.yaml b/rust/build-binary/action.yaml index 155d5d7..bb61d2e 100644 --- a/rust/build-binary/action.yaml +++ b/rust/build-binary/action.yaml @@ -22,12 +22,27 @@ runs: with: require-cargo: true - - name: Build (release) - x86_64 + - name: Build (release) - x86_64 Linux if: inputs.target == 'x86_64-unknown-linux-gnu' shell: bash run: cargo build --release --target ${{ inputs.target }} --verbose - - name: Build (release) - ARM64 with cross + - name: Build (release) - ARM64 Linux with cross if: inputs.target == 'aarch64-unknown-linux-gnu' shell: bash run: cross build --release --target ${{ inputs.target }} --verbose + + - name: Build (release) - x86_64 Windows MSVC + if: inputs.target == 'x86_64-pc-windows-msvc' + shell: bash + run: cargo build --release --target ${{ inputs.target }} --verbose + + - name: Build (release) - x86_64 Windows GNU + if: inputs.target == 'x86_64-pc-windows-gnu' + shell: bash + run: cargo build --release --target ${{ inputs.target }} --verbose + + - name: Build (release) - ARM64 Windows with cross + if: inputs.target == 'aarch64-pc-windows-msvc' + shell: bash + run: cross build --release --target ${{ inputs.target }} --verbose diff --git a/rust/generate-sbom/action.yaml b/rust/generate-sbom/action.yaml index a8fc9df..0a443da 100644 --- a/rust/generate-sbom/action.yaml +++ b/rust/generate-sbom/action.yaml @@ -130,21 +130,13 @@ runs: done fi - # Also check target directories (for describe=binaries or all-cargo-targets) - if [ "${{ inputs.describe }}" = "binaries" ] || [ "${{ inputs.describe }}" = "all-cargo-targets" ]; then - echo "" - echo "Searching for SBOMs in target directories..." - find target -name "*.cdx.*" -type f 2>/dev/null | while read sbom_file; do - ls -lh "$sbom_file" - done - fi - # Summary count echo "" total_sboms=$(find . -name "*.cdx.*" -not -path "*/target/*" -not -path "*/.git/*" -type f 2>/dev/null | wc -l | tr -d ' ') - if [ -d "target" ]; then - target_sboms=$(find target -name "*.cdx.*" -type f 2>/dev/null | wc -l | tr -d ' ') - else - target_sboms=0 + echo "Total SBOMs generated: $total_sboms" + + # Verify at least one SBOM was generated + if [ "$total_sboms" -eq 0 ]; then + echo "Error: No SBOM files were generated" + exit 1 fi - echo "Total SBOMs found: $total_sboms in workspace, $target_sboms in target/" diff --git a/rust/setup-rust-build/README.md b/rust/setup-rust-build/README.md index 165f8e7..9dd01d6 100644 --- a/rust/setup-rust-build/README.md +++ b/rust/setup-rust-build/README.md @@ -6,9 +6,10 @@ A composite GitHub Action that sets up a complete Rust build environment with in - Installs Rust toolchain with specified target support - Intelligent caching of Rust dependencies using `rust-cache` -- Automatic setup of `cross` for ARM64 builds +- Automatic setup of `cross` for ARM64 Linux and Windows builds - Binary caching for `cross` to speed up workflow runs - Docker verification for cross-compilation +- Support for Linux, Windows (MSVC and GNU), and cross-compilation targets - Configurable cache keys for custom cache isolation ## Usage @@ -22,16 +23,35 @@ A composite GitHub Action that sets up a complete Rust build environment with in target: x86_64-unknown-linux-gnu ``` -### ARM64 Cross-Compilation +### ARM64 Linux Cross-Compilation ```yaml -- name: Setup Rust build environment for ARM64 +- name: Setup Rust build environment for ARM64 Linux uses: firestoned/github-actions/rust/setup-rust-build@v1 with: target: aarch64-unknown-linux-gnu cross-version: v0.2.5 ``` +### Windows x86_64 Build (MSVC) + +```yaml +- name: Setup Rust build environment for Windows + uses: firestoned/github-actions/rust/setup-rust-build@v1 + with: + target: x86_64-pc-windows-msvc +``` + +### Windows ARM64 Cross-Compilation + +```yaml +- name: Setup Rust build environment for Windows ARM64 + uses: firestoned/github-actions/rust/setup-rust-build@v1 + with: + target: aarch64-pc-windows-msvc + cross-version: v0.2.5 +``` + ### Custom Cache Key ```yaml @@ -70,6 +90,10 @@ jobs: target: - x86_64-unknown-linux-gnu - aarch64-unknown-linux-gnu + - x86_64-pc-windows-msvc + - x86_64-pc-windows-gnu + - aarch64-pc-windows-msvc + runs-on: ubuntu-latest steps: - uses: actions/checkout@v4 @@ -79,14 +103,19 @@ jobs: target: ${{ matrix.target }} - name: Build - run: cargo build --release --target ${{ matrix.target }} + run: | + if [[ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" || "${{ matrix.target }}" == "aarch64-pc-windows-msvc" ]]; then + cross build --release --target ${{ matrix.target }} + else + cargo build --release --target ${{ matrix.target }} + fi ``` ## Inputs | Name | Description | Required | Default | |------|-------------|----------|---------| -| `target` | Rust target triple (e.g., `x86_64-unknown-linux-gnu`, `aarch64-unknown-linux-gnu`) | Yes | N/A | +| `target` | Rust target triple (e.g., `x86_64-unknown-linux-gnu`, `x86_64-pc-windows-msvc`, `aarch64-unknown-linux-gnu`) | Yes | N/A | | `cache-key` | Additional cache key component for isolating caches by branch or feature | No | `''` | | `cross-version` | Version of `cross` to install for ARM64 builds (e.g., `v0.2.5`) | No | `v0.2.5` | | `components` | Comma-separated list of Rust components to install (e.g., `rustfmt, clippy`) | No | `rustfmt, clippy` | @@ -101,13 +130,16 @@ jobs: 4. Caches Rust dependencies using `Swatinem/rust-cache@v2` 5. Uses target and cache-key for cache isolation -### ARM64 Builds (aarch64) +### Cross-Compilation Builds (ARM64 and Windows ARM64) + +For targets that require cross-compilation (`aarch64-unknown-linux-gnu`, `aarch64-pc-windows-msvc`): 1. Performs all standard build steps -2. Checks for cached `cross` binary -3. Installs `cross` if not cached (pinned to specified version) -4. Verifies Docker is available for cross-compilation -5. Caches `cross` binary for future runs +2. Determines if `cross` is needed based on target +3. Checks for cached `cross` binary +4. Installs `cross` if not cached (pinned to specified version) +5. Verifies Docker is available for cross-compilation +6. Caches `cross` binary for future runs ### Cache Strategy @@ -123,18 +155,29 @@ This ensures: ## Supported Targets -### Tier 1 Targets (Native Builds) -- `x86_64-unknown-linux-gnu` - 64-bit Linux (GNU) -- `x86_64-unknown-linux-musl` - 64-bit Linux (musl) -- `x86_64-apple-darwin` - 64-bit macOS -- `x86_64-pc-windows-msvc` - 64-bit Windows (MSVC) +### Linux Targets (Native and Cross-Compilation) +- `x86_64-unknown-linux-gnu` - x86_64 Linux with GNU libc (native) +- `x86_64-unknown-linux-musl` - x86_64 Linux with musl libc (native) +- `aarch64-unknown-linux-gnu` - ARM64 Linux with GNU libc (cross-compilation with `cross`) +- `aarch64-unknown-linux-musl` - ARM64 Linux with musl libc (cross-compilation) +- `armv7-unknown-linux-gnueabihf` - 32-bit ARM Linux (cross-compilation) + +### Windows Targets +- `x86_64-pc-windows-msvc` - x86_64 Windows with MSVC toolchain (cross-compilation from Linux) +- `x86_64-pc-windows-gnu` - x86_64 Windows with GNU toolchain (cross-compilation from Linux) +- `aarch64-pc-windows-msvc` - ARM64 Windows with MSVC toolchain (cross-compilation with `cross`) + +### macOS Targets +- `x86_64-apple-darwin` - x86_64 macOS (native on x86_64 macOS runners) +- `aarch64-apple-darwin` - ARM64 macOS (native on ARM64 macOS runners) + +### Automatically Uses Cross -### Tier 2 Targets (Cross-Compilation) -- `aarch64-unknown-linux-gnu` - 64-bit ARM Linux (GNU) -- `aarch64-unknown-linux-musl` - 64-bit ARM Linux (musl) -- `armv7-unknown-linux-gnueabihf` - 32-bit ARM Linux +This action automatically installs and configures `cross` for these targets: +- `aarch64-unknown-linux-gnu` - ARM64 Linux +- `aarch64-pc-windows-msvc` - ARM64 Windows -For a complete list, see the [Rust Platform Support](https://doc.rust-lang.org/nightly/rustc/platform-support.html) documentation. +For a complete list of Rust targets, see the [Rust Platform Support](https://doc.rust-lang.org/nightly/rustc/platform-support.html) documentation. ## Best Practices diff --git a/rust/setup-rust-build/action.yaml b/rust/setup-rust-build/action.yaml index 5ff890e..2ec9caa 100644 --- a/rust/setup-rust-build/action.yaml +++ b/rust/setup-rust-build/action.yaml @@ -41,8 +41,21 @@ runs: key: ${{ inputs.target }}-${{ inputs.cache-key }} cache-on-failure: true + - name: Determine if cross is needed + id: needs-cross + shell: bash + run: | + case "${{ inputs.target }}" in + aarch64-unknown-linux-gnu|aarch64-pc-windows-msvc) + echo "needed=true" >> $GITHUB_OUTPUT + ;; + *) + echo "needed=false" >> $GITHUB_OUTPUT + ;; + esac + - name: Cache cross binary - if: inputs.target == 'aarch64-unknown-linux-gnu' + if: steps.needs-cross.outputs.needed == 'true' id: cache-cross uses: actions/cache@v4 with: @@ -51,15 +64,15 @@ runs: restore-keys: | ${{ runner.os }}-cross- - - name: Install cross for ARM64 builds - if: inputs.target == 'aarch64-unknown-linux-gnu' && steps.cache-cross.outputs.cache-hit != 'true' + - name: Install cross for cross-compilation builds + if: steps.needs-cross.outputs.needed == 'true' && steps.cache-cross.outputs.cache-hit != 'true' shell: bash run: | cargo install cross --git https://github.com/cross-rs/cross --tag ${{ inputs.cross-version }} cross --version - - name: Verify Docker for cross (ARM64) - if: inputs.target == 'aarch64-unknown-linux-gnu' + - name: Verify Docker for cross + if: steps.needs-cross.outputs.needed == 'true' shell: bash run: | docker --version