From fab751d633755d21b0c21f12ac1de3279a17f97b Mon Sep 17 00:00:00 2001 From: Nivaldo Date: Wed, 25 Nov 2026 05:01:21 -0300 Subject: [PATCH] metal: set the simulator cfg in build.rs to keep the 1.70 MSRV cfg(target_abi) is only stable since Rust 1.78, so the uniform buffer alignment check from #636 broke Apple builds on the declared MSRV. build.rs now sets miniquad_apple_sim for the -sim targets instead, which also reads the same on compilers that renamed it to target_env = "sim". check-cfg is only declared from Rust 1.80 on, where cargo accepts it. The MSRV job now runs on macOS as well, since metal.rs and the macOS backend never compile on the Linux runner. Fixes #709 Co-Authored-By: Claude Opus 5.5 --- .github/workflows/rust.yml | 8 ++++++-- build.rs | 24 ++++++++++++++++++++++++ src/graphics/metal.rs | 6 +++--- 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 28e3d8c86..4fcdb0698 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -72,8 +72,12 @@ jobs: cargo quad-apk build msrv: - name: MSRV Check - runs-on: ubuntu-latest + name: MSRV Check (${{ matrix.os }}) + runs-on: ${{ matrix.os }} + strategy: + matrix: + # metal.rs and the macOS backend only compile on Apple targets. + os: [ubuntu-latest, macos-latest] steps: - uses: actions/checkout@v4 - uses: actions-rs/toolchain@v1 diff --git a/build.rs b/build.rs index 50ba1b615..9b718c695 100644 --- a/build.rs +++ b/build.rs @@ -1,4 +1,5 @@ use std::env; +use std::process::Command; fn main() { let target = env::var("TARGET").unwrap_or_else(|e| panic!("{}", e)); @@ -6,4 +7,27 @@ fn main() { if target.contains("darwin") || target.contains("ios") { println!("cargo:rustc-link-lib=framework=MetalKit"); } + + // The arm64 simulator targets (aarch64-apple-ios-sim, aarch64-apple-tvos-sim); + // metal.rs tells the x86_64 simulators apart by target_arch. + // `cfg(target_abi = "sim")` needs Rust 1.78 and newer compilers spell it + // `target_env = "sim"`, so the target name is checked here instead. + if rustc_minor_version().map_or(false, |minor| minor >= 80) { + // Older cargo warns about this line; check-cfg is stable since 1.80. + println!("cargo:rustc-check-cfg=cfg(miniquad_apple_sim)"); + } + if target.ends_with("-sim") { + println!("cargo:rustc-cfg=miniquad_apple_sim"); + } +} + +fn rustc_minor_version() -> Option { + let rustc = env::var_os("RUSTC")?; + let output = Command::new(rustc).arg("--version").output().ok()?; + let version = std::str::from_utf8(&output.stdout).ok()?; + let mut pieces = version.split('.'); + if pieces.next() != Some("rustc 1") { + return None; + } + pieces.next()?.parse().ok() } diff --git a/src/graphics/metal.rs b/src/graphics/metal.rs index e18ec9f75..84726c4cd 100644 --- a/src/graphics/metal.rs +++ b/src/graphics/metal.rs @@ -10,7 +10,7 @@ use super::*; // https://developer.apple.com/metal/Metal-Feature-Set-Tables.pdf const MAX_UNIFORM_BUFFER_SIZE: u64 = 4 * 1024 * 1024; const NUM_INFLIGHT_FRAMES: usize = 3; -// iOS simulator on Apple Silicon Macs (`target_abi = "sim"`) runs +// iOS simulator on Apple Silicon Macs (`miniquad_apple_sim`) runs // iOS arm64 code but issues Metal commands against the host Mac's // GPU — which validates with the 256-byte rule, not iOS arm64's // 16-byte. Without breaking the simulator out of the iOS-arm64 @@ -20,14 +20,14 @@ const NUM_INFLIGHT_FRAMES: usize = 3; target_os = "macos", all( any(target_os = "ios", target_os = "tvos"), - any(target_arch = "x86_64", target_abi = "sim"), + any(target_arch = "x86_64", miniquad_apple_sim), ), ))] const UNIFORM_BUFFER_ALIGN: u64 = 256; #[cfg(all( any(target_os = "ios", target_os = "tvos"), target_arch = "aarch64", - not(target_abi = "sim"), + not(miniquad_apple_sim), ))] const UNIFORM_BUFFER_ALIGN: u64 = 16;