Skip to content

Simplify library dependencies on compiler-builtins #144683

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
merged 3 commits into from
Aug 1, 2025
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
10 changes: 3 additions & 7 deletions library/Cargo.lock
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,8 @@ name = "panic_abort"
version = "0.0.0"
dependencies = [
"alloc",
"compiler_builtins",
"core",
"libc",
"rustc-std-workspace-core",
]

[[package]]
Expand All @@ -194,9 +193,8 @@ version = "0.0.0"
dependencies = [
"alloc",
"cfg-if",
"compiler_builtins",
"core",
"libc",
"rustc-std-workspace-core",
"unwind",
]

Expand Down Expand Up @@ -313,7 +311,6 @@ dependencies = [
"addr2line",
"alloc",
"cfg-if",
"compiler_builtins",
"core",
"dlmalloc",
"fortanix-sgx-abi",
Expand Down Expand Up @@ -380,9 +377,8 @@ name = "unwind"
version = "0.0.0"
dependencies = [
"cfg-if",
"compiler_builtins",
"core",
"libc",
"rustc-std-workspace-core",
"unwinding",
]

Expand Down
3 changes: 1 addition & 2 deletions library/panic_abort/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ bench = false
doc = false

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

[target.'cfg(target_os = "android")'.dependencies]
libc = { version = "0.2", default-features = false }
Expand Down
5 changes: 2 additions & 3 deletions library/panic_unwind/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,9 @@ doc = false

[dependencies]
alloc = { path = "../alloc" }
core = { path = "../core" }
unwind = { path = "../unwind" }
compiler_builtins = { path = "../compiler-builtins/compiler-builtins" }
cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
core = { path = "../rustc-std-workspace-core", package = "rustc-std-workspace-core" }
unwind = { path = "../unwind" }

[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
libc = { version = "0.2", default-features = false }
Expand Down
6 changes: 6 additions & 0 deletions library/rustc-std-workspace-core/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ on crates.io will draw a dependency edge to `libcore`, the version defined in
this repository. That should draw all the dependency edges to ensure Cargo
builds crates successfully!

`rustc-std-workspace-core` also ensures `compiler-builtins` is in the crate
graph. This crate is used by other crates in `library/`, other than `std` and
`alloc`, so the `compiler-builtins` setup only needs to be configured in a
single place. (Otherwise these crates would just need to depend on `core` and
`compiler-builtins` separately.)

Note that crates on crates.io need to depend on this crate with the name `core`
for everything to work correctly. To do that they can use:

Expand Down
1 change: 0 additions & 1 deletion library/std/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ cfg-if = { version = "1.0", features = ['rustc-dep-of-std'] }
panic_unwind = { path = "../panic_unwind", optional = true }
panic_abort = { path = "../panic_abort" }
core = { path = "../core", public = true }
compiler_builtins = { path = "../compiler-builtins/compiler-builtins" }
unwind = { path = "../unwind" }
hashbrown = { version = "0.15", default-features = false, features = [
'rustc-dep-of-std',
Expand Down
22 changes: 11 additions & 11 deletions library/std/src/sys/pal/uefi/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -444,17 +444,17 @@ impl<'a> DevicePathNode<'a> {

impl<'a> PartialEq for DevicePathNode<'a> {
fn eq(&self, other: &Self) -> bool {
let self_len = self.length();
let other_len = other.length();

self_len == other_len
&& unsafe {
compiler_builtins::mem::memcmp(
self.protocol.as_ptr().cast(),
other.protocol.as_ptr().cast(),
usize::from(self_len),
) == 0
}
// Compare as a single buffer rather than by field since it optimizes better.
//
// SAFETY: `Protocol` is followed by a buffer of `length - sizeof::<Protocol>()`. `Protocol`
// has no padding so it is sound to interpret as a slice.
unsafe {
let s1 =
slice::from_raw_parts(self.protocol.as_ptr().cast::<u8>(), self.length().into());
let s2 =
slice::from_raw_parts(other.protocol.as_ptr().cast::<u8>(), other.length().into());
s1 == s2
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions library/unwind/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ bench = false
doc = false

[dependencies]
core = { path = "../core" }
compiler_builtins = { path = "../compiler-builtins/compiler-builtins" }
cfg-if = "1.0"
core = { path = "../rustc-std-workspace-core", package = "rustc-std-workspace-core" }

[target.'cfg(not(all(windows, target_env = "msvc")))'.dependencies]
libc = { version = "0.2.140", features = ['rustc-dep-of-std'], default-features = false }
Expand Down
22 changes: 11 additions & 11 deletions src/bootstrap/src/core/builder/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -999,7 +999,7 @@ mod snapshot {
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustdoc 0 <host>
[doc] std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,std,std_detect,sysroot,test,unwind]
[doc] std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
");
}

Expand Down Expand Up @@ -1048,7 +1048,7 @@ mod snapshot {
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustdoc 1 <host>
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,std,std_detect,sysroot,test,unwind]
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[build] rustc 2 <host> -> std 2 <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 0 <host> -> RustInstaller 1 <host>
Expand Down Expand Up @@ -1090,7 +1090,7 @@ mod snapshot {
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
[build] rustc 1 <host> -> LlvmBitcodeLinker 2 <host>
[build] rustdoc 1 <host>
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,std,std_detect,sysroot,test,unwind]
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[build] rustc 2 <host> -> std 2 <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 0 <host> -> RustInstaller 1 <host>
Expand Down Expand Up @@ -1126,8 +1126,8 @@ mod snapshot {
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustdoc 1 <host>
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,std,std_detect,sysroot,test,unwind]
[doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,std,std_detect,sysroot,test,unwind]
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[build] rustc 2 <host> -> std 2 <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 0 <host> -> RustInstaller 1 <host>
Expand Down Expand Up @@ -1163,7 +1163,7 @@ mod snapshot {
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustdoc 1 <host>
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,std,std_detect,sysroot,test,unwind]
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[build] rustc 2 <host> -> std 2 <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 1 <host> -> std 1 <target1>
Expand Down Expand Up @@ -1200,8 +1200,8 @@ mod snapshot {
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustdoc 1 <host>
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,std,std_detect,sysroot,test,unwind]
[doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,std,std_detect,sysroot,test,unwind]
[doc] std 2 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[build] rustc 2 <host> -> std 2 <host>
[build] rustc 0 <host> -> LintDocs 1 <host>
[build] rustc 1 <host> -> std 1 <target1>
Expand Down Expand Up @@ -1242,7 +1242,7 @@ mod snapshot {
[build] rustc 1 <host> -> std 1 <host>
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustdoc 1 <host>
[doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,std,std_detect,sysroot,test,unwind]
[doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[build] rustc 2 <host> -> std 2 <host>
[build] rustc 0 <host> -> RustInstaller 1 <host>
[dist] docs <target1>
Expand Down Expand Up @@ -1274,7 +1274,7 @@ mod snapshot {
[build] rustc 1 <host> -> rustc 2 <host>
[build] rustc 1 <host> -> WasmComponentLd 2 <host>
[build] rustdoc 1 <host>
[doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,std,std_detect,sysroot,test,unwind]
[doc] std 2 <target1> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
[build] rustc 2 <host> -> std 2 <host>
[build] rustc 1 <host> -> std 1 <target1>
[build] rustc 2 <host> -> std 2 <target1>
Expand Down Expand Up @@ -1620,7 +1620,7 @@ mod snapshot {
[build] llvm <host>
[build] rustc 0 <host> -> rustc 1 <host>
[build] rustdoc 0 <host>
[doc] std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,std,std_detect,sysroot,test,unwind]
[doc] std 1 <host> crates=[alloc,compiler_builtins,core,panic_abort,panic_unwind,proc_macro,rustc-std-workspace-core,std,std_detect,sysroot,test,unwind]
");
}

Expand Down
Loading