Skip to content
Merged
Show file tree
Hide file tree
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
7 changes: 4 additions & 3 deletions crates/perry/src/commands/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,9 +101,10 @@ use resolve::{
};
use strip_dedup::{
dedup_native_lib_for_tier3, dedup_runtime_for_tier3, dedup_stdlib_for_tier3,
localize_stdlib_stub_symbols, localize_stdlib_stub_symbols_for_windows,
strip_bundled_runtime_from_well_known_lib, strip_bundled_shared_deps_from_well_known_lib,
strip_duplicate_objects_from_lib, strip_duplicate_objects_from_well_known_lib,
dedup_ui_lib_against_linked_libs, localize_stdlib_stub_symbols,
localize_stdlib_stub_symbols_for_windows, strip_bundled_runtime_from_well_known_lib,
strip_bundled_shared_deps_from_well_known_lib, strip_duplicate_objects_from_lib,
strip_duplicate_objects_from_well_known_lib,
};
use targets::{
apple_sdk_version, find_visionos_swift_runtime, find_watchos_swift_runtime,
Expand Down
27 changes: 26 additions & 1 deletion crates/perry/src/commands/compile/link/build_and_run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,12 +965,37 @@ pub(crate) fn build_and_run_link(
let ui_lib = if is_windows || is_android || is_visionos {
ui_lib
} else {
match strip_duplicate_objects_from_lib(&ui_lib) {
let trimmed = match strip_duplicate_objects_from_lib(&ui_lib) {
Ok(trimmed) => trimmed,
Err(e) => {
eprintln!("[strip-dedup] skipped for UI lib (non-fatal): {e}");
ui_lib
}
};
// #5920 follow-up: the prebuilt UI lib bundles dependency
// copies (perry-runtime, std, itoa, …) from a foreign crate
// graph, so the member-name trim above can never drop them
// against a locally rebuilt (auto-optimized) stdlib. On Mach-O
// both copies then load and ld64.lld fails with duplicate
// `_js_*` / std externs. Localize every bundled global that
// the actually-linked stdlib/runtime provide, so UI references
// rebind to the single linked copy. Linux tolerates the
// duplicates via --allow-multiple-definition, so restrict to
// the ld64 shapes.
if is_linux {
trimmed
} else {
let mut linked_refs: Vec<&Path> = vec![runtime_lib];
if let Some(ref s) = stdlib_lib {
linked_refs.push(s.as_path());
}
match dedup_ui_lib_against_linked_libs(&trimmed, &linked_refs) {
Comment on lines +988 to +992

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🎯 Functional Correctness | 🟠 Major | ⚡ Quick win

Only dedup against archives that are actually linked.

linked_refs includes runtime_lib unconditionally and stdlib_lib whenever it exists, but both can be absent from this link line: stdlib_lib is not linked when ctx.needs_stdlib == false, and watchOS can skip runtime_lib because the UI archive is the runtime provider. Localizing against those unlinked archives can remove the UI lib’s external definitions without any replacement provider, causing undefined symbols.

Proposed fix
-                    let mut linked_refs: Vec<&Path> = vec![runtime_lib];
-                    if let Some(ref s) = stdlib_lib {
+                    let mut linked_refs: Vec<&Path> = Vec::new();
+                    if !skip_runtime {
+                        linked_refs.push(runtime_lib);
+                    }
+                    if ctx.needs_stdlib {
+                        if let Some(ref s) = stdlib_lib {
+                            linked_refs.push(s.as_path());
+                        }
+                    }
+                    if linked_refs.is_empty() {
+                        trimmed
+                    } else {
+                        match dedup_ui_lib_against_linked_libs(&trimmed, &linked_refs) {
+                            Ok(deduped) => deduped,
+                            Err(e) => {
+                                eprintln!(
+                                    "[strip-dedup] UI linked-lib dedup skipped (non-fatal): {e}"
+                                );
+                                trimmed
+                            }
+                        }
+                    }
-                        linked_refs.push(s.as_path());
-                    }
-                    match dedup_ui_lib_against_linked_libs(&trimmed, &linked_refs) {
-                        Ok(deduped) => deduped,
-                        Err(e) => {
-                            eprintln!(
-                                "[strip-dedup] UI linked-lib dedup skipped (non-fatal): {e}"
-                            );
-                            trimmed
-                        }
-                    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
let mut linked_refs: Vec<&Path> = vec![runtime_lib];
if let Some(ref s) = stdlib_lib {
linked_refs.push(s.as_path());
}
match dedup_ui_lib_against_linked_libs(&trimmed, &linked_refs) {
let mut linked_refs: Vec<&Path> = Vec::new();
if !skip_runtime {
linked_refs.push(runtime_lib);
}
if ctx.needs_stdlib {
if let Some(ref s) = stdlib_lib {
linked_refs.push(s.as_path());
}
}
if linked_refs.is_empty() {
trimmed
} else {
match dedup_ui_lib_against_linked_libs(&trimmed, &linked_refs) {
Ok(deduped) => deduped,
Err(e) => {
eprintln!(
"[strip-dedup] UI linked-lib dedup skipped (non-fatal): {e}"
);
trimmed
}
}
}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@crates/perry/src/commands/compile/link/build_and_run.rs` around lines 986 -
990, Only dedup the UI archive against libraries that are actually present on
the current link line. In build_and_run.rs, update the linked_refs construction
around dedup_ui_lib_against_linked_libs so runtime_lib is added only when it is
truly linked, and stdlib_lib is added only when ctx.needs_stdlib is true and the
stdlib archive will be linked. Use the existing build/link conditions in
build_and_run and the linked_refs vector to gate these entries before calling
dedup_ui_lib_against_linked_libs.

Ok(deduped) => deduped,
Err(e) => {
eprintln!("[strip-dedup] UI linked-lib dedup skipped (non-fatal): {e}");
trimmed
}
}
}
};
if is_windows {
Expand Down
8 changes: 4 additions & 4 deletions crates/perry/src/commands/compile/link/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ use crate::OutputFormat;

use super::{
apple_sdk_version, build_geisterhand_libs, dedup_native_lib_for_tier3, dedup_runtime_for_tier3,
dedup_stdlib_for_tier3, find_geisterhand_library, find_geisterhand_runtime,
find_geisterhand_stdlib, find_geisterhand_ui, find_lld_link, find_llvm_tool,
find_msvc_lib_paths, find_msvc_link_exe, find_perry_windows_sdk, find_stdlib_library,
find_ui_library, find_visionos_swift_runtime, find_watchos_swift_runtime,
dedup_stdlib_for_tier3, dedup_ui_lib_against_linked_libs, find_geisterhand_library,
find_geisterhand_runtime, find_geisterhand_stdlib, find_geisterhand_ui, find_lld_link,
find_llvm_tool, find_msvc_lib_paths, find_msvc_link_exe, find_perry_windows_sdk,
find_stdlib_library, find_ui_library, find_visionos_swift_runtime, find_watchos_swift_runtime,
localize_stdlib_stub_symbols, localize_stdlib_stub_symbols_for_windows, rust_target_triple,
strip_bundled_runtime_from_well_known_lib, strip_bundled_shared_deps_from_well_known_lib,
strip_duplicate_objects_from_lib, strip_duplicate_objects_from_well_known_lib,
Expand Down
Loading
Loading