Skip to content

Fix layer test on macOS aarch64e #3297

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions changelog.d/3267.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix the issue running layer integration test on macos aarch64
when using pre-built layer lib fat binary.
47 changes: 44 additions & 3 deletions mirrord/layer/tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use std::{
path::{Path, PathBuf},
process::Stdio,
str::FromStr,
sync::Arc,
sync::{Arc, OnceLock},
time::Duration,
};

Expand Down Expand Up @@ -41,6 +41,9 @@ pub const RUST_OUTGOING_PEERS: &str = "1.1.1.1:1111,2.2.2.2:2222,3.3.3.3:3333";
/// Configuration for [`Application::RustOutgoingTcp`] and [`Application::RustOutgoingUdp`].
pub const RUST_OUTGOING_LOCAL: &str = "4.4.4.4:4444";

#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
static MIRRORD_MACOS_ARM64_LIBRARY: OnceLock<PathBuf> = OnceLock::new();

/// Initializes tracing for the current thread, allowing us to have multiple tracing subscribers
/// writin logs to different files.
///
Expand Down Expand Up @@ -1393,20 +1396,58 @@ pub fn get_env(
MIRRORD_LAYER_INTPROXY_ADDR.to_string(),
intproxy_addr.to_string(),
),
(
LayerConfig::RESOLVED_CONFIG_ENV.to_string(),
config.encode().unwrap(),
),
#[cfg(target_os = "macos")]
(
"DYLD_INSERT_LIBRARIES".to_string(),
dylib_path.to_str().unwrap().to_string(),
),
#[cfg(target_os = "linux")]
(
"LD_PRELOAD".to_string(),
dylib_path.to_str().unwrap().to_string(),
),
#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
(
LayerConfig::RESOLVED_CONFIG_ENV.to_string(),
config.encode().unwrap(),
// The universal layer library loads arm64 library from the path specified in this
// environment variable when the host runs arm64e.
// See `mirorrd/layer/shim.c` for more information.
"MIRRORD_MACOS_ARM64_LIBRARY".to_string(),
arm64_dylib_path().to_str().unwrap().to_string(),
),
]
.into_iter()
.chain(extra_vars_owned)
.collect()
}

#[cfg(all(target_os = "macos", target_arch = "aarch64"))]
fn arm64_dylib_path() -> &'static Path {
MIRRORD_MACOS_ARM64_LIBRARY
.get_or_init(|| {
if let Ok(path) = std::env::var("MIRRORD_MACOS_ARM64_LIBRARY") {
let dylib_path = PathBuf::from(path);
println!("Using existing macOS arm64 layer lib from: {dylib_path:?}");
assert!(dylib_path.exists());
return dylib_path;
}

if let Ok(path) = std::env::var("MIRRORD_TEST_USE_EXISTING_LIB") {
let derived_path = path.replace("universal-apple-darwin", "aarch64-apple-darwin");
let dylib_path = PathBuf::from(&derived_path);
if dylib_path.exists() {
return dylib_path;
} else {
println!("Derived arm64 layer lib path does not exist: {derived_path}");
}
}

let dylib_path = test_cdylib::build_current_project();
println!("Built macOS arm64 layer lib at {dylib_path:?}");
dylib_path
})
.as_path()
}