Skip to content

Commit 4cc5291

Browse files
authored
Allow discovery of x86-64 managed Python builds on macOS (#13722)
Replacement for #13474 (clobbered by a changed base) Once these are explicitly installed, they should be discoverable and usable. Currently, they are not.
1 parent 0c5ae1f commit 4cc5291

2 files changed

Lines changed: 76 additions & 1 deletion

File tree

crates/uv-python/src/platform.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,12 @@ impl Arch {
143143
// TODO: Implement `variant` support checks
144144

145145
// Windows ARM64 runs emulated x86_64 binaries transparently
146-
if cfg!(windows) && matches!(self.family, target_lexicon::Architecture::Aarch64(_)) {
146+
// Similarly, macOS aarch64 runs emulated x86_64 binaries transparently if you have Rosetta
147+
// installed. We don't try to be clever and check if that's the case here, we just assume
148+
// that if x86_64 distributions are available, they're usable.
149+
if (cfg!(windows) || cfg!(target_os = "macos"))
150+
&& matches!(self.family, target_lexicon::Architecture::Aarch64(_))
151+
{
147152
return other.family == target_lexicon::Architecture::X86_64;
148153
}
149154

crates/uv/tests/it/python_install.rs

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1416,3 +1416,73 @@ fn python_install_cached() {
14161416
Caused by: An offline Python installation was requested, but cpython-3.12.10[DATE]-[PLATFORM].tar.gz) is missing in python-cache
14171417
");
14181418
}
1419+
1420+
#[cfg(target_os = "macos")]
1421+
#[test]
1422+
fn python_install_emulated_macos() {
1423+
let context: TestContext = TestContext::new_with_versions(&[])
1424+
.with_filtered_exe_suffix()
1425+
.with_managed_python_dirs();
1426+
1427+
// Before installation, `uv python list` should not show the x86_64 download
1428+
uv_snapshot!(context.filters(), context.python_list().arg("3.13"), @r"
1429+
success: true
1430+
exit_code: 0
1431+
----- stdout -----
1432+
cpython-3.13.3-macos-aarch64-none <download available>
1433+
1434+
----- stderr -----
1435+
");
1436+
1437+
// Install an x86_64 version (assuming an aarch64 host)
1438+
uv_snapshot!(context.filters(), context.python_install().arg("cpython-3.13-macos-x86_64"), @r"
1439+
success: true
1440+
exit_code: 0
1441+
----- stdout -----
1442+
1443+
----- stderr -----
1444+
Installed Python 3.13.3 in [TIME]
1445+
+ cpython-3.13.3-macos-x86_64-none
1446+
");
1447+
1448+
// It should be discoverable with `uv python find`
1449+
uv_snapshot!(context.filters(), context.python_find().arg("3.13"), @r"
1450+
success: true
1451+
exit_code: 0
1452+
----- stdout -----
1453+
[TEMP_DIR]/managed/cpython-3.13.3-macos-x86_64-none/bin/python3.13
1454+
1455+
----- stderr -----
1456+
");
1457+
1458+
// And included in `uv python list`
1459+
uv_snapshot!(context.filters(), context.python_list().arg("3.13"), @r"
1460+
success: true
1461+
exit_code: 0
1462+
----- stdout -----
1463+
cpython-3.13.3-macos-aarch64-none <download available>
1464+
cpython-3.13.3-macos-x86_64-none managed/cpython-3.13.3-macos-x86_64-none/bin/python3.13
1465+
1466+
----- stderr -----
1467+
");
1468+
1469+
uv_snapshot!(context.filters(), context.python_install().arg("cpython-3.13-macos-aarch64"), @r"
1470+
success: true
1471+
exit_code: 0
1472+
----- stdout -----
1473+
1474+
----- stderr -----
1475+
Installed Python 3.13.3 in [TIME]
1476+
+ cpython-3.13.3-macos-aarch64-none
1477+
");
1478+
1479+
// Once we've installed the native version, it should be preferred over x86_64
1480+
uv_snapshot!(context.filters(), context.python_find().arg("3.13"), @r"
1481+
success: true
1482+
exit_code: 0
1483+
----- stdout -----
1484+
[TEMP_DIR]/managed/cpython-3.13.3-macos-aarch64-none/bin/python3.13
1485+
1486+
----- stderr -----
1487+
");
1488+
}

0 commit comments

Comments
 (0)