Skip to content

Commit

Permalink
Enable noprelude uncondtionally
Browse files Browse the repository at this point in the history
Summary:
We were conditionally adding `noprelude`, which was resulting in a difference in behavior as compared to cargo builds.

1. In cargo, all std library crates are attached using `noprelude` https://github.com/rust-lang/cargo/blob/12541d6e5ef095b03035bb316461890b40db10f4/src/cargo/core/compiler/unit_dependencies.rs#L185.
2. When actually compiling the crate, `rustc` will inject the correct prelude (depending on `no_std`, `no_core`, etc) https://github.com/rust-lang/rust/blob/243d2ca4db6f96d2d18aaf3a2381251d38eb6b0b/src/tools/rust-analyzer/crates/hir-def/src/nameres/collector.rs#L488

Given (2), it is more correct for us to follow the same pattern as `cargo` and unconditionally apply `"noprelude"`.

Reviewed By: dtolnay

Differential Revision: D67805532

fbshipit-source-id: 05bfc8d85e1f3d749e92420f8bd8fe160d2210a2
  • Loading branch information
capickett authored and facebook-github-bot committed Jan 6, 2025
1 parent 81cbf45 commit d57bd51
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions prelude/rust/link_info.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -269,20 +269,22 @@ def gather_explicit_sysroot_deps(dep_ctx: DepCollectionContext) -> list[RustOrNa
out.append(RustOrNativeDependency(
dep = explicit_sysroot_deps.core,
name = None,
flags = ["nounused"],
flags = ["noprelude", "nounused"],
))
if explicit_sysroot_deps.std:
out.append(RustOrNativeDependency(
dep = explicit_sysroot_deps.std,
name = None,
flags = ["nounused", "force"],
# "force" is used here in order to link std internals (like alloc hooks) even if the rest
# of std is otherwise unused (e.g. we are building a no_std crate that needs to link with
# other std-enabled crates as a standalone dylib).
flags = ["noprelude", "nounused", "force"],
))
if explicit_sysroot_deps.proc_macro:
flags = ["noprelude"] if not dep_ctx.is_proc_macro or dep_ctx.include_doc_deps else []
out.append(RustOrNativeDependency(
dep = explicit_sysroot_deps.proc_macro,
name = None,
flags = ["nounused"] + flags,
flags = ["noprelude", "nounused"],
))

# When advanced_unstable_linking is on, we only add the dep that matches the
Expand All @@ -293,19 +295,16 @@ def gather_explicit_sysroot_deps(dep_ctx: DepCollectionContext) -> list[RustOrNa
out.append(RustOrNativeDependency(
dep = explicit_sysroot_deps.panic_unwind,
name = None,
flags = ["nounused"],
flags = ["noprelude", "nounused"],
))
if explicit_sysroot_deps.panic_abort:
if not dep_ctx.advanced_unstable_linking or dep_ctx.panic_runtime == PanicRuntime("abort"):
out.append(RustOrNativeDependency(
dep = explicit_sysroot_deps.panic_abort,
name = None,
flags = ["nounused"],
flags = ["noprelude", "nounused"],
))
for d in explicit_sysroot_deps.others:
# FIXME(JakobDegen): Ideally we would not be using `noprelude` here but
# instead report these as regular transitive dependencies. However,
# that's a bit harder to get right, so leave it like this for now.
out.append(RustOrNativeDependency(
dep = d,
name = None,
Expand Down

0 comments on commit d57bd51

Please sign in to comment.