Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions .github/workflows/rust.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 24 additions & 0 deletions build.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,33 @@
use std::env;
use std::process::Command;

fn main() {
let target = env::var("TARGET").unwrap_or_else(|e| panic!("{}", e));

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<u32> {
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()
}
6 changes: 3 additions & 3 deletions src/graphics/metal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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;

Expand Down
Loading