Fix hotpatching when the bin target's crate name differs from the package name (#5719) (#5720)

(cherry picked from commit 4c51c12bc19d78983cb2992f319ebe996acb2893)

Signed-off-by: Nico Burns <nico@nicoburns.com>
This commit is contained in:
Nico Burns authored and GitHub committed 2026-07-29 16:55:16 -07:00
1 parent 3e43ffa6cf
commit fda083bb65
4 files changed
+18 -4

No files matched your search

+3 -1
View File
@@ -408,7 +408,9 @@ impl AppBuilder {
// patch (starting from changed_crates + cascade). That serves a different purpose — it only
// compiles what changed now, not everything ever modified. Both use workspace_dependents_of
// for the BFS, so they stay in sync automatically.
let tip_crate_name = self.build.main_target.replace('-', "_");
// Track the tip by *package* name — that's the identity used by the file→crate
// mapping and the workspace dependents graph (the bin target name can differ).
let tip_crate_name = self.build.tip_package_name();
self.modified_crates.insert(tip_crate_name.clone());
// Add changed crates and their transitive workspace dependents (cascade).
+3 -1
View File
@@ -614,7 +614,9 @@ impl BuildRequest {
modified_crates: &HashSet<String>,
) -> Result<Vec<String>> {
// Exclude the tip crate — it's compiled separately via cargo_build after replay.
let tip = self.tip_crate_name();
// Modified crates are tracked by *package* name, which can differ from the bin
// target name (`tip_crate_name()`), e.g. package `browser` with `[[bin]] name = "blitz"`.
let tip = self.tip_package_name();
let crates: HashSet<&String> = modified_crates
.iter()
.filter(|name| **name != tip)
+11 -1
View File
@@ -2581,6 +2581,16 @@ impl BuildRequest {
self.main_target.replace('-', "_")
}
/// The workspace package name of the tip crate (hyphens replaced with underscores).
///
/// This can differ from `tip_crate_name()` when the binary target is named differently
/// than its package (e.g. package `browser` with `[[bin]] name = "blitz"`). Use this for
/// workspace-graph lookups (which are keyed by package name) and `tip_crate_name()` for
/// rustc `--crate-name` keys like `{name}.bin`.
pub(crate) fn tip_package_name(&self) -> String {
self.package().name.replace('-', "_")
}
/// Stderr captured from the linker during the last build. Written by the linker
/// interception in `rustcwrapper` and read back to surface warnings/errors to the user.
fn link_err_file(&self) -> PathBuf {
@@ -3095,7 +3105,7 @@ impl BuildRequest {
})
.collect();
let tip = self.tip_crate_name();
let tip = self.tip_package_name();
let Some(tip_nid) = krates.workspace_members().find_map(|m| match m {
krates::Node::Krate { id, krate, .. } if krate.name.replace('-', "_") == tip => {
krates.nid_for_kid(id)
+1 -1
View File
@@ -1187,7 +1187,7 @@ impl AppServer {
/// Uses BFS from the tip crate through its workspace dependencies to find the path.
/// If the changed crate IS the tip crate, returns just `[tip]`.
pub(crate) fn workspace_dep_chain(&self, changed_crate: &str) -> Vec<String> {
let tip_name = self.client.build.main_target.replace('-', "_");
let tip_name = self.client.build.tip_package_name();
// If the changed crate is the tip, no chain needed
if changed_crate == tip_name {