Skip to content

Commit 3e21361

Browse files
authored
Rollup merge of rust-lang#144683 - tgross35:builtins-via-std-workspace, r=bjorn3,Noratrieb
Simplify library dependencies on `compiler-builtins` The three panic-related library crates need to have access to `core`, and `compiler-builtins` needs to be in the crate graph. Rather than specifying both dependencies, switch these crates to use `rustc-std-workspace-core` which already does this. This means there is now a single place that the `compiler-builtins` dependency needs to get configured, for everything other than `alloc` and `std`. The second commit removes `compiler-builtins` from `std` (more details in the message).
2 parents 158ca24 + fc7b60d commit 3e21361

File tree

7 files changed

+24
-26
lines changed

7 files changed

+24
-26
lines changed

Cargo.lock

Lines changed: 3 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

panic_abort/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@ bench = false
1212
doc = false
1313

1414
[dependencies]
15-
core = { path = "../core" }
16-
compiler_builtins = { path = "../compiler-builtins/compiler-builtins" }
15+
core = { path = "../rustc-std-workspace-core", package = "rustc-std-workspace-core" }
1716

1817
[target.'cfg(target_os = "android")'.dependencies]
1918
libc = { version = "0.2", default-features = false }

panic_unwind/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ doc = false
1313

1414
[dependencies]
1515
alloc = { path = "../alloc" }
16-
core = { path = "../core" }
17-
unwind = { path = "../unwind" }
18-
compiler_builtins = { path = "../compiler-builtins/compiler-builtins" }
1916
cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
17+
core = { path = "../rustc-std-workspace-core", package = "rustc-std-workspace-core" }
18+
unwind = { path = "../unwind" }
2019

2120
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
2221
libc = { version = "0.2", default-features = false }

rustc-std-workspace-core/README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,12 @@ on crates.io will draw a dependency edge to `libcore`, the version defined in
1111
this repository. That should draw all the dependency edges to ensure Cargo
1212
builds crates successfully!
1313

14+
`rustc-std-workspace-core` also ensures `compiler-builtins` is in the crate
15+
graph. This crate is used by other crates in `library/`, other than `std` and
16+
`alloc`, so the `compiler-builtins` setup only needs to be configured in a
17+
single place. (Otherwise these crates would just need to depend on `core` and
18+
`compiler-builtins` separately.)
19+
1420
Note that crates on crates.io need to depend on this crate with the name `core`
1521
for everything to work correctly. To do that they can use:
1622

std/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
1818
panic_unwind = { path = "../panic_unwind", optional = true }
1919
panic_abort = { path = "../panic_abort" }
2020
core = { path = "../core", public = true }
21-
compiler_builtins = { path = "../compiler-builtins/compiler-builtins" }
2221
unwind = { path = "../unwind" }
2322
hashbrown = { version = "0.15", default-features = false, features = [
2423
'rustc-dep-of-std',

std/src/sys/pal/uefi/helpers.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -444,17 +444,17 @@ impl<'a> DevicePathNode<'a> {
444444

445445
impl<'a> PartialEq for DevicePathNode<'a> {
446446
fn eq(&self, other: &Self) -> bool {
447-
let self_len = self.length();
448-
let other_len = other.length();
449-
450-
self_len == other_len
451-
&& unsafe {
452-
compiler_builtins::mem::memcmp(
453-
self.protocol.as_ptr().cast(),
454-
other.protocol.as_ptr().cast(),
455-
usize::from(self_len),
456-
) == 0
457-
}
447+
// Compare as a single buffer rather than by field since it optimizes better.
448+
//
449+
// SAFETY: `Protocol` is followed by a buffer of `length - sizeof::<Protocol>()`. `Protocol`
450+
// has no padding so it is sound to interpret as a slice.
451+
unsafe {
452+
let s1 =
453+
slice::from_raw_parts(self.protocol.as_ptr().cast::<u8>(), self.length().into());
454+
let s2 =
455+
slice::from_raw_parts(other.protocol.as_ptr().cast::<u8>(), other.length().into());
456+
s1 == s2
457+
}
458458
}
459459
}
460460

unwind/Cargo.toml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ bench = false
1414
doc = false
1515

1616
[dependencies]
17-
core = { path = "../core" }
18-
compiler_builtins = { path = "../compiler-builtins/compiler-builtins" }
1917
cfg-if = "1.0"
18+
core = { path = "../rustc-std-workspace-core", package = "rustc-std-workspace-core" }
2019

2120
[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
2221
libc = { version = "0.2.140", features = ['rustc-dep-of-std'], default-features = false }

0 commit comments

Comments
 (0)