Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Start the window on OCLP Macs with SYSTEM_VERSION_COMPAT=1 (#3080) (#8930)

TaeHeon Kim6c9afc6f7e08
diff --git a/apps/solidcraft/src/main.rs b/apps/solidcraft/src/main.rs
index c492f980e0..d9c6fbc9f6 100644
--- a/apps/solidcraft/src/main.rs
+++ b/apps/solidcraft/src/main.rs
@@ -758,6 +758,16 @@ fn main() -> eframe::Result {
#[cfg(target_os = "macos")]
objc2_foundation::NSProcessInfo::processInfo().setProcessName(objc2_foundation::ns_string!("SolidCraft"));
mark("main");
+ // On OCLP-patched Macs, wgpu picks a Metal Shading Language standard that the system's
+ // compiler refuses (`invalid value 'metal3.2'`), because the patched OS reports a newer
+ // macOS version than the GPU's Metal compiler supports. Re-launching with
+ // SYSTEM_VERSION_COMPAT=1 makes the OS report the real (older) version so wgpu selects
+ // a standard the compiler accepts. The variable must be set before the process starts, so
+ // we detect OCLP here and re-exec immediately, before any macOS framework call (#3080, #4605).
+ #[cfg(target_os = "macos")]
+ if let Err(e) = startup::relaunch_with_version_compat() {
+ log::warn!("startup: OCLP check failed (continuing normally): {e}");
+ }
// Validate before legacy adoption, crash markers or any user preference read.
let settings = settings_dir().map_err(|error| eframe::Error::AppCreation(error.into()))?;
if std::env::var_os("SOLIDCRAFT_SETTINGS_DIR").is_none() {
diff --git a/apps/solidcraft/src/startup.rs b/apps/solidcraft/src/startup.rs
index a5fdbd4031..718b8388c4 100644
--- a/apps/solidcraft/src/startup.rs
+++ b/apps/solidcraft/src/startup.rs
@@ -292,6 +292,71 @@ pub fn window_instance_flags(flags: eframe::wgpu::InstanceFlags, intel_mac: bool
if intel_mac && env.map(str::trim).is_none_or(str::is_empty) { flags - eframe::wgpu::InstanceFlags::VALIDATION_INDIRECT_CALL } else { flags }
}
+/// The environment variable that makes the macOS compatibility shim report an older OS
+/// version to wgpu's Metal backend. On OCLP-patched machines the Metal compiler accepts
+/// only up to the MSL standard of the original GPU, not the one the patched OS reports,
+/// so wgpu picks a standard that the compiler refuses (`invalid value 'metal3.2'`).
+/// Setting this variable before the process starts causes the OS to report the older
+/// version and wgpu selects a supported MSL standard (#3080, #4605).
+#[cfg(target_os = "macos")]
+pub const SYSTEM_VERSION_COMPAT_ENV: &str = "SYSTEM_VERSION_COMPAT";
+
+/// The NVRAM variable that OpenCore Legacy Patcher writes on every OCLP-booted system.
+/// Its presence is the primary signal that `SYSTEM_VERSION_COMPAT=1` is needed.
+#[cfg(target_os = "macos")]
+pub const OCLP_NVRAM_KEY: &str = "4D1FDA02-38C7-4A6A-9CC6-4BCCA8B30102:OCLP-Version";
+
+/// `true` if the OCLP NVRAM key is present on this system.
+///
+/// Runs `nvram <key>` and treats exit 0 as present. Any error (missing binary,
+/// permission denied, key absent) returns `false` — this is a best-effort probe.
+#[cfg(target_os = "macos")]
+pub fn oclp_nvram_present() -> bool {
+ std::process::Command::new("nvram").arg(OCLP_NVRAM_KEY).output().map(|o| o.status.success()).unwrap_or(false)
+}
+
+/// Whether to re-launch with `SYSTEM_VERSION_COMPAT=1`: it is not set yet and OCLP shows through
+/// the NVRAM key. The probe runs only when it is needed, so a re-launched process (variable
+/// set) never starts `nvram`.
+#[cfg(target_os = "macos")]
+fn compat_wanted(compat_set: bool, nvram: impl FnOnce() -> bool) -> bool {
+ !compat_set && nvram()
+}
+
+/// If this process is running under OCLP and `SYSTEM_VERSION_COMPAT` has not been set,
+/// re-launch the current binary with `SYSTEM_VERSION_COMPAT=1` added to the environment,
+/// then exit with the child's status code.
+///
+/// `SYSTEM_VERSION_COMPAT=1` must be present **before** the process starts: setting it
+/// with `std::env::set_var` inside `main` is too late because the macOS frameworks have
+/// already queried the OS version by then. Re-launching is the only safe approach that
+/// works without `unsafe` (a true `execve` replacement would require it).
+///
+/// Returns `Ok(false)` immediately when:
+/// - `SYSTEM_VERSION_COMPAT` is already set (re-launched process, no loop), or
+/// - the OCLP NVRAM key is absent.
+///
+/// Returns `Err` only when `std::env::current_exe()` fails or the child process cannot
+/// be spawned; the caller should log the error and continue normally.
+///
+/// Never returns `Ok(true)`: a successful re-launch exits the current process.
+#[cfg(target_os = "macos")]
+pub fn relaunch_with_version_compat() -> Result<bool, String> {
+ // A set variable means this is the re-launched process: no loop.
+ if !compat_wanted(std::env::var_os(SYSTEM_VERSION_COMPAT_ENV).is_some(), oclp_nvram_present) {
+ return Ok(false);
+ }
+ log::info!("startup: OCLP detected; re-launching with {}=1", SYSTEM_VERSION_COMPAT_ENV);
+ eprintln!("SolidCraft: OCLP detected; re-launching with {}=1", SYSTEM_VERSION_COMPAT_ENV);
+ let exe = std::env::current_exe().map_err(|e| format!("could not find own executable: {e}"))?;
+ let status = std::process::Command::new(&exe)
+ .args(std::env::args_os().skip(1))
+ .env(SYSTEM_VERSION_COMPAT_ENV, "1")
+ .status()
+ .map_err(|e| format!("could not re-launch with {}: {e}", SYSTEM_VERSION_COMPAT_ENV))?;
+ std::process::exit(status.code().unwrap_or(1));
+}
+
/// Windows with OpenGL: the window keeps the system title bar (#2063). The window without OS
/// decorations keeps its caption style while having no frame, and some OpenGL drivers (older
/// Intel HD/UHD) then show the picture a caption's height lower than the window, so it no longer
@@ -414,6 +479,27 @@ mod tests {
assert_eq!(window_instance_flags(on, false, None), on);
}
+ #[cfg(target_os = "macos")]
+ #[test]
+ fn oclp_relaunch_needs_the_signal_and_no_compat_variable() {
+ use super::compat_wanted;
+ let probed = std::cell::Cell::new(false);
+ let probe = |found: bool| {
+ let probed = &probed;
+ move || {
+ probed.set(true);
+ found
+ }
+ };
+ // The re-launched process has the variable: no probe, no second re-launch.
+ assert!(!compat_wanted(true, probe(true)));
+ assert!(!probed.get());
+ // The OCLP NVRAM key is the signal.
+ assert!(compat_wanted(false, probe(true)));
+ // No signal: an ordinary Mac starts as it is.
+ assert!(!compat_wanted(false, probe(false)));
+ }
+
#[test]
fn switches_read_from_the_environment() {
assert!(env_on(Some("1")) && env_on(Some("yes")) && !env_on(Some("0")) && !env_on(Some(" ")) && !env_on(None) && !env_on(Some("false")));