From d0c53516c732b800b5c05cc14dc86ade58841737 Mon Sep 17 00:00:00 2001 From: Kilian Hu <90606809+kilian-hu@users.noreply.github.com> Date: Wed, 18 Mar 2026 20:50:23 +0100 Subject: [PATCH] fix: Remove spurious emulation warning when just locking --- crates/pixi_cli/src/run.rs | 4 + crates/pixi_core/src/environment/mod.rs | 3 + crates/pixi_core/src/workspace/environment.rs | 97 +++++++++++-------- 3 files changed, 64 insertions(+), 40 deletions(-) diff --git a/crates/pixi_cli/src/run.rs b/crates/pixi_cli/src/run.rs index 4e4bf45f55..6398483d96 100644 --- a/crates/pixi_cli/src/run.rs +++ b/crates/pixi_cli/src/run.rs @@ -163,6 +163,10 @@ pub async fn execute(args: Args) -> miette::Result<()> { .into()); } + if args.lock_and_install_config.allow_installs() { + environment.emit_emulation_warning(); + } + // Ensure that the lock-file is up-to-date. let lock_file = workspace .update_lock_file(UpdateLockFileOptions { diff --git a/crates/pixi_core/src/environment/mod.rs b/crates/pixi_core/src/environment/mod.rs index 7cb2f69c7d..45f328ce05 100644 --- a/crates/pixi_core/src/environment/mod.rs +++ b/crates/pixi_core/src/environment/mod.rs @@ -572,6 +572,9 @@ pub async fn get_update_lock_file_and_prefixes<'env>( } .into()); } + if !no_install { + env.emit_emulation_warning(); + } } // Make sure the project is in a sane state diff --git a/crates/pixi_core/src/workspace/environment.rs b/crates/pixi_core/src/workspace/environment.rs index 890b0695bc..17b2328b02 100644 --- a/crates/pixi_core/src/workspace/environment.rs +++ b/crates/pixi_core/src/workspace/environment.rs @@ -127,61 +127,21 @@ impl<'p> Environment<'p> { return current; } - static WARN_ONCE: Once = Once::new(); - // If the current platform is osx-arm64 and the environment supports osx-64, // return osx-64. if current.is_osx() && self.platforms().contains(&Platform::Osx64) { - WARN_ONCE.call_once(|| { - let warn_folder = self.workspace.pixi_dir().join(consts::ONE_TIME_MESSAGES_DIR); - let emulation_warn = warn_folder.join("macos-emulation-warn"); - if !emulation_warn.exists() { - tracing::warn!( - "osx-arm64 (Apple Silicon) is not supported by the pixi.toml, falling back to osx-64 (emulated with Rosetta)" - ); - // Create a file to prevent the warning from showing up multiple times. Also ignore the result. - fs_err::create_dir_all(warn_folder).and_then(|_| { - fs_err::File::create(emulation_warn) - }).ok(); - } - }); return Platform::Osx64; } // If the current platform is win-arm64 and the environment supports win-64, // return win-64. if current.is_windows() && self.platforms().contains(&Platform::Win64) { - WARN_ONCE.call_once(|| { - let warn_folder = self.workspace.pixi_dir().join(consts::ONE_TIME_MESSAGES_DIR); - let emulation_warn = warn_folder.join("windows-emulation-warn"); - if !emulation_warn.exists() { - tracing::warn!( - "win-arm64 is not supported by the pixi.toml, falling back to win-64 (emulation)" - ); - // Create a file to prevent the warning from showing up multiple times. Also ignore the result. - fs_err::create_dir_all(warn_folder).and_then(|_| { - fs_err::File::create(emulation_warn) - }).ok(); - } - }); return Platform::Win64; } // If the current platform is win-64 and the environment supports win-32, // return win-32. if current == Platform::Win64 && self.platforms().contains(&Platform::Win32) { - WARN_ONCE.call_once(|| { - let warn_folder = self.workspace.pixi_dir().join(consts::ONE_TIME_MESSAGES_DIR); - let emulation_warn = warn_folder.join("windows-32-emulation-warn"); - if !emulation_warn.exists() { - tracing::warn!( - "win-64 is not supported by the pixi.toml, falling back to win-32 (emulation)" - ); - fs_err::create_dir_all(warn_folder).and_then(|_| { - fs_err::File::create(emulation_warn) - }).ok(); - } - }); return Platform::Win32; } @@ -197,6 +157,63 @@ impl<'p> Environment<'p> { current } + /// Emits a one-time warning if this environment requires platform emulation + /// (e.g. Rosetta on Apple Silicon Macs). + /// + /// This should only be called when the environment is actually being + /// installed or activated — not during lock file solving, which is + /// cross-platform and does not use emulation. + pub fn emit_emulation_warning(&self) { + let current = Platform::current(); + let best = self.best_platform(); + if current == best { + return; + } + + static WARN_ONCE: Once = Once::new(); + + if current.is_osx() && best == Platform::Osx64 { + WARN_ONCE.call_once(|| { + let warn_folder = self.workspace.pixi_dir().join(consts::ONE_TIME_MESSAGES_DIR); + let emulation_warn = warn_folder.join("macos-emulation-warn"); + if !emulation_warn.exists() { + tracing::warn!( + "osx-arm64 (Apple Silicon) is not supported by the current environment, falling back to osx-64 (emulated with Rosetta)" + ); + fs_err::create_dir_all(warn_folder) + .and_then(|_| fs_err::File::create(emulation_warn)) + .ok(); + } + }); + } else if current.is_windows() && best == Platform::Win64 { + WARN_ONCE.call_once(|| { + let warn_folder = self.workspace.pixi_dir().join(consts::ONE_TIME_MESSAGES_DIR); + let emulation_warn = warn_folder.join("windows-emulation-warn"); + if !emulation_warn.exists() { + tracing::warn!( + "win-arm64 is not supported by the current environment, falling back to win-64 (emulation)" + ); + fs_err::create_dir_all(warn_folder) + .and_then(|_| fs_err::File::create(emulation_warn)) + .ok(); + } + }); + } else if current == Platform::Win64 && best == Platform::Win32 { + WARN_ONCE.call_once(|| { + let warn_folder = self.workspace.pixi_dir().join(consts::ONE_TIME_MESSAGES_DIR); + let emulation_warn = warn_folder.join("windows-32-emulation-warn"); + if !emulation_warn.exists() { + tracing::warn!( + "win-64 is not supported by the current environment, falling back to win-32 (emulation)" + ); + fs_err::create_dir_all(warn_folder) + .and_then(|_| fs_err::File::create(emulation_warn)) + .ok(); + } + }); + } + } + /// Returns the tasks defined for this environment. /// /// Tasks are defined on a per-target per-feature per-environment basis.