Skip to content
Merged
Changes from all 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
58 changes: 58 additions & 0 deletions crates/perry/src/commands/compile/library_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1018,6 +1018,18 @@ pub(super) fn collect_library_candidates(name: &str, target: Option<&str>) -> Ve
candidates.push(PathBuf::from(format!("target/release/{}", name)));
candidates.push(PathBuf::from(format!("target/debug/{}", name)));
}
// #6716: `--target macos` on a macOS host is host-native, not a
// cross-compile — `cargo build --release -p perry-ui-macos` (the
// command the missing-UI-lib error suggests) writes to `target/release/`
// without the `aarch64-apple-darwin` triple subdir, so mirror the
// Windows/Linux branches above and probe the bare dirs too. Guarded on
// the host cfg so a genuine cross-compile to macOS (e.g. from Linux)
// still avoids picking up host-platform libs from `target/release/`.
#[cfg(target_os = "macos")]
if matches!(target, Some("macos")) {
candidates.push(PathBuf::from(format!("target/release/{}", name)));
candidates.push(PathBuf::from(format!("target/debug/{}", name)));
}
// Also check directories relative to the perry executable.
if let Ok(exe) = std::env::current_exe() {
if let Some(dir) = exe.parent() {
Expand Down Expand Up @@ -1916,6 +1928,52 @@ mod llvm_tool_discovery_tests {
}
}

// #6716: `--target macos` on a macOS host is host-native — the candidate list
// must probe the bare `target/{release,debug}/` dirs (where a plain
// `cargo build -p perry-ui-macos` lands), while a genuine cross target keeps the
// conservative triple-only search.
#[cfg(all(test, target_os = "macos"))]
mod macos_host_candidate_tests {
use super::collect_library_candidates;
use std::path::PathBuf;

#[test]
fn macos_target_probes_bare_target_dirs() {
let cands = collect_library_candidates("libperry_ui_macos.a", Some("macos"));
// Triple-qualified dir is still searched — derive the triple from the
// same mapping the production code uses rather than hardcoding it, so
// this stays in sync if the `macos` → triple mapping ever changes.
let triple = super::rust_target_triple(Some("macos"))
.expect("macos target should resolve to a triple");
assert!(
cands.contains(&PathBuf::from(format!(
"target/{triple}/release/libperry_ui_macos.a"
))),
"missing triple dir in {cands:?}"
);
// ...and so is the bare host-native dir the suggested build command writes to.
assert!(
cands.contains(&PathBuf::from("target/release/libperry_ui_macos.a")),
"missing bare target/release in {cands:?}"
);
assert!(
cands.contains(&PathBuf::from("target/debug/libperry_ui_macos.a")),
"missing bare target/debug in {cands:?}"
);
}

#[test]
fn cross_target_keeps_conservative_search() {
// A real cross-compile (iOS) must NOT fall back to the host's bare
// target/release — that would risk linking a macOS lib into an iOS app.
let cands = collect_library_candidates("libperry_ui_ios.a", Some("ios"));
assert!(
!cands.contains(&PathBuf::from("target/release/libperry_ui_ios.a")),
"cross target unexpectedly probed bare target/release in {cands:?}"
);
}
}

#[cfg(all(test, target_os = "windows"))]
mod windows_toolchain_tests {
use super::msvc_vswhere_installation_path_args;
Expand Down
Loading