Skip to content

Commit 7e3653f

Browse files
authored
Fix layer test on macOS aarch64e (#3297)
* Fix layer test on macOS aarch64e * Derive arm64 lib location from universal dylib * Put arm64_dylib_path in OnceLock * Rename changelog and add contributing guide back * Fix clippy
1 parent e0c440a commit 7e3653f

File tree

3 files changed

+54
-2
lines changed

3 files changed

+54
-2
lines changed

CONTRIBUTING.md

+7
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,13 @@ And then in order to use that dylib in the tests, run the tests like this:
201201
MIRRORD_TEST_USE_EXISTING_LIB=../../target/universal-apple-darwin/debug/libmirrord_layer.dylib cargo test -p mirrord-layer
202202
```
203203
204+
On Apple Silicon, set `MIRRORD_MACOS_ARM64_LIBRARY` additionally to use the arm64 layer lib as well:
205+
```bash
206+
MIRRORD_TEST_USE_EXISTING_LIB=../../target/universal-apple-darwin/debug/libmirrord_layer.dylib \
207+
MIRRORD_MACOS_ARM64_LIBRARY=../../target/aarch64-apple-darwin/debug/libmirrord_layer.dylib \
208+
cargo test -p mirrord-layer
209+
```
210+
204211
### Integration Tests logs and you
205212
206213
These tests will try writing the `mirrord-intproxy` logs to a file in `/tmp/intproxy_logs`

changelog.d/3267.internal.md

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix the issue running layer integration test on macos aarch64
2+
when using pre-built layer lib fat binary.

mirrord/layer/tests/common/mod.rs

+45-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
2+
use std::sync::OnceLock;
13
use std::{
24
assert_matches::assert_matches,
35
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";
4143
/// Configuration for [`Application::RustOutgoingTcp`] and [`Application::RustOutgoingUdp`].
4244
pub const RUST_OUTGOING_LOCAL: &str = "4.4.4.4:4444";
4345

46+
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
47+
static MIRRORD_MACOS_ARM64_LIBRARY: OnceLock<PathBuf> = OnceLock::new();
48+
4449
/// Initializes tracing for the current thread, allowing us to have multiple tracing subscribers
4550
/// writin logs to different files.
4651
///
@@ -1393,20 +1398,58 @@ pub fn get_env(
13931398
MIRRORD_LAYER_INTPROXY_ADDR.to_string(),
13941399
intproxy_addr.to_string(),
13951400
),
1401+
(
1402+
LayerConfig::RESOLVED_CONFIG_ENV.to_string(),
1403+
config.encode().unwrap(),
1404+
),
1405+
#[cfg(target_os = "macos")]
13961406
(
13971407
"DYLD_INSERT_LIBRARIES".to_string(),
13981408
dylib_path.to_str().unwrap().to_string(),
13991409
),
1410+
#[cfg(target_os = "linux")]
14001411
(
14011412
"LD_PRELOAD".to_string(),
14021413
dylib_path.to_str().unwrap().to_string(),
14031414
),
1415+
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
14041416
(
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(),
14071422
),
14081423
]
14091424
.into_iter()
14101425
.chain(extra_vars_owned)
14111426
.collect()
14121427
}
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

Comments
 (0)