|
| 1 | +#[cfg(all(target_os = "macos", target_arch = "aarch64"))] |
| 2 | +use std::sync::OnceLock; |
1 | 3 | use std::{
|
2 | 4 | assert_matches::assert_matches,
|
3 | 5 | collections::HashMap,
|
@@ -41,6 +43,9 @@ pub const RUST_OUTGOING_PEERS: &str = "1.1.1.1:1111,2.2.2.2:2222,3.3.3.3:3333";
|
41 | 43 | /// Configuration for [`Application::RustOutgoingTcp`] and [`Application::RustOutgoingUdp`].
|
42 | 44 | pub const RUST_OUTGOING_LOCAL: &str = "4.4.4.4:4444";
|
43 | 45 |
|
| 46 | +#[cfg(all(target_os = "macos", target_arch = "aarch64"))] |
| 47 | +static MIRRORD_MACOS_ARM64_LIBRARY: OnceLock<PathBuf> = OnceLock::new(); |
| 48 | + |
44 | 49 | /// Initializes tracing for the current thread, allowing us to have multiple tracing subscribers
|
45 | 50 | /// writin logs to different files.
|
46 | 51 | ///
|
@@ -1393,20 +1398,58 @@ pub fn get_env(
|
1393 | 1398 | MIRRORD_LAYER_INTPROXY_ADDR.to_string(),
|
1394 | 1399 | intproxy_addr.to_string(),
|
1395 | 1400 | ),
|
| 1401 | + ( |
| 1402 | + LayerConfig::RESOLVED_CONFIG_ENV.to_string(), |
| 1403 | + config.encode().unwrap(), |
| 1404 | + ), |
| 1405 | + #[cfg(target_os = "macos")] |
1396 | 1406 | (
|
1397 | 1407 | "DYLD_INSERT_LIBRARIES".to_string(),
|
1398 | 1408 | dylib_path.to_str().unwrap().to_string(),
|
1399 | 1409 | ),
|
| 1410 | + #[cfg(target_os = "linux")] |
1400 | 1411 | (
|
1401 | 1412 | "LD_PRELOAD".to_string(),
|
1402 | 1413 | dylib_path.to_str().unwrap().to_string(),
|
1403 | 1414 | ),
|
| 1415 | + #[cfg(all(target_os = "macos", target_arch = "aarch64"))] |
1404 | 1416 | (
|
1405 |
| - LayerConfig::RESOLVED_CONFIG_ENV.to_string(), |
1406 |
| - config.encode().unwrap(), |
| 1417 | + // The universal layer library loads arm64 library from the path specified in this |
| 1418 | + // environment variable when the host runs arm64e. |
| 1419 | + // See `mirorrd/layer/shim.c` for more information. |
| 1420 | + "MIRRORD_MACOS_ARM64_LIBRARY".to_string(), |
| 1421 | + arm64_dylib_path().to_str().unwrap().to_string(), |
1407 | 1422 | ),
|
1408 | 1423 | ]
|
1409 | 1424 | .into_iter()
|
1410 | 1425 | .chain(extra_vars_owned)
|
1411 | 1426 | .collect()
|
1412 | 1427 | }
|
| 1428 | + |
| 1429 | +#[cfg(all(target_os = "macos", target_arch = "aarch64"))] |
| 1430 | +fn arm64_dylib_path() -> &'static Path { |
| 1431 | + MIRRORD_MACOS_ARM64_LIBRARY |
| 1432 | + .get_or_init(|| { |
| 1433 | + if let Ok(path) = std::env::var("MIRRORD_MACOS_ARM64_LIBRARY") { |
| 1434 | + let dylib_path = PathBuf::from(path); |
| 1435 | + println!("Using existing macOS arm64 layer lib from: {dylib_path:?}"); |
| 1436 | + assert!(dylib_path.exists()); |
| 1437 | + return dylib_path; |
| 1438 | + } |
| 1439 | + |
| 1440 | + if let Ok(path) = std::env::var("MIRRORD_TEST_USE_EXISTING_LIB") { |
| 1441 | + let derived_path = path.replace("universal-apple-darwin", "aarch64-apple-darwin"); |
| 1442 | + let dylib_path = PathBuf::from(&derived_path); |
| 1443 | + if dylib_path.exists() { |
| 1444 | + return dylib_path; |
| 1445 | + } else { |
| 1446 | + println!("Derived arm64 layer lib path does not exist: {derived_path}"); |
| 1447 | + } |
| 1448 | + } |
| 1449 | + |
| 1450 | + let dylib_path = test_cdylib::build_current_project(); |
| 1451 | + println!("Built macOS arm64 layer lib at {dylib_path:?}"); |
| 1452 | + dylib_path |
| 1453 | + }) |
| 1454 | + .as_path() |
| 1455 | +} |
0 commit comments