Skip to content

metal: set the simulator cfg in build.rs to keep the 1.70 MSRV - #711

Open
nivaldomcj wants to merge 1 commit into
not-fl3:masterfrom
nivaldomcj:msrv-apple-sim-cfg
Open

nivaldomcj wants to merge 1 commit into
not-fl3:masterfrom
nivaldomcj:msrv-apple-sim-cfg

Conversation

@nivaldomcj

Copy link
Copy Markdown

Fixes #709.

metal.rs picks the uniform buffer alignment with cfg(target_abi = "sim"), which needs Rust 1.78, so Apple targets stopped building on the declared MSRV. This is option 2 from the issue: build.rs sets miniquad_apple_sim when TARGET ends in -sim (aarch64-apple-ios-sim, aarch64-apple-tvos-sim), and metal.rs uses that instead. The x86_64 simulators were already matched by target_arch = "x86_64".

Cargo before 1.80 warns about rustc-check-cfg, so build.rs only prints it when rustc --version is 1.80 or newer, the same way serde's build script does.

The MSRV job now also runs on macos-latest, so Apple-only code gets built with 1.70.

To check that the alignment didn't change, I built each Apple target on Rust 1.100.0 with a temporary compile-time assert comparing UNIFORM_BUFFER_ALIGN against master's target_abi cfgs:

Target miniquad_apple_sim Alignment
aarch64-apple-darwin, x86_64-apple-darwin no 256 (same as master)
aarch64-apple-ios, aarch64-apple-tvos no 16 (same as master)
x86_64-apple-ios no 256 (same as master)
aarch64-apple-ios-sim, aarch64-apple-tvos-sim yes 256 (same as master)

cargo +1.70.0 build --all-targets passes for aarch64-apple-darwin and x86_64-apple-darwin, where master fails with E0658. On 1.98.0 and 1.100.0, the macOS builds and cargo check --all-targets for the five iOS/tvOS targets pass with no warnings.

I also ran examples/quad with Metal API validation on the iOS 26.5 and tvOS 26.5 simulators (Xcode 27.2). This branch and master both draw with no validation errors. As a control, a build forced to the 16-byte alignment on the simulator fails on the first frame with "must be a multiple of 256 but was set to 16". Getting the example running there needed local workarounds for a few unrelated issues, which I'll open separately.

Tested on macOS 27.2.1 (26B131), Apple M3 Max (arm64), Rust 1.70.0, 1.98.0 and 1.100.0. cc @benface

cfg(target_abi) is only stable since Rust 1.78, so the uniform buffer
alignment check from not-fl3#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 not-fl3#709

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@benface

benface commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Thanks for picking this up! I tested it on macOS 27.2.1 with Xcode 27.2, on an M2 Max:

  • In my game, with this branch merged into the miniquad I use: it builds and runs on the iOS 27.2 and tvOS 27.2 simulators with Metal API validation on. There are no validation errors, and everything draws the same as without it. It also builds for aarch64-apple-ios, aarch64-apple-tvos and aarch64-apple-darwin.
  • examples/quad with the metal argument, on the iOS 26.5 and tvOS 26.5 simulators with validation on: it draws, with no errors. Like you, I needed a few unrelated fixes to get there: metal: pass draw's offsets as 64-bit integers #673, MetalKit linked on tvOS (build.rs: link MetalKit for tvOS targets #712), objc-rs's Apple runtime on tvOS (Bump objc-rs to 0.3 so Apple's runtime is used off macOS/iOS #653), and a scene manifest in the test bundle's Info.plist.
  • Alignment: with a temporary const assert under cargo check, UNIFORM_BUFFER_ALIGN is 256 for aarch64-apple-darwin, aarch64-apple-ios-sim and aarch64-apple-tvos-sim, and 16 for aarch64-apple-ios and aarch64-apple-tvos.
  • MSRV: cargo +1.70.0 build --all-targets --target aarch64-apple-darwin passes on this branch and fails on master with E0658. cargo check --all-targets on 1.80.1, 1.100.0 and a 1.96 nightly gives no warnings, and the nightly's version string still gets the rustc-check-cfg line.

One optional suggestion: like master, build.rs prints no cargo:rerun-if-changed, so it reruns whenever any file in the crate changes. Adding println!("cargo:rerun-if-changed=build.rs"); would limit that to edits of build.rs itself. Cargo still reruns it when the compiler changes. Not a blocker either way.

LGTM 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Apple targets don't build on the declared MSRV (1.70) since #636

2 participants