Skip to content

Respect RUSTC_LINK_STD_INTO_RUSTC_DRIVER=0 in link_std_into_rustc_driver#153409

Open
DeepeshWR wants to merge 1 commit intorust-lang:mainfrom
DeepeshWR:respect_rustc_link_std_env
Open

Respect RUSTC_LINK_STD_INTO_RUSTC_DRIVER=0 in link_std_into_rustc_driver#153409
DeepeshWR wants to merge 1 commit intorust-lang:mainfrom
DeepeshWR:respect_rustc_link_std_env

Conversation

@DeepeshWR
Copy link
Contributor

This patch allows users to opt out of statically linking std into rustc_driver by setting the existing environment variable RUSTC_LINK_STD_INTO_RUSTC_DRIVER=0.

  • If the variable is unset or set to any other value, the function falls back to the default behavior (linking std on all platforms except Windows).

  • Note: This does not introduce a new environment variable; it only respects an existing one.

  • Defaults remain unchanged, so normal builds are unaffected.

Example usage:

export RUSTC_LINK_STD_INTO_RUSTC_DRIVER=0
./x.py build

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap) labels Mar 4, 2026
@rustbot
Copy link
Collaborator

rustbot commented Mar 4, 2026

r? @jieyouxu

rustbot has assigned @jieyouxu.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: bootstrap
  • bootstrap expanded to 6 candidates
  • Random selection from Mark-Simulacrum, clubby789, jieyouxu

@rust-log-analyzer

This comment has been minimized.

@DeepeshWR DeepeshWR force-pushed the respect_rustc_link_std_env branch from 429e4bc to 0d326ff Compare March 4, 2026 15:57
@rust-log-analyzer

This comment has been minimized.

@DeepeshWR DeepeshWR force-pushed the respect_rustc_link_std_env branch from 0d326ff to 168c019 Compare March 4, 2026 16:07
@rust-log-analyzer

This comment has been minimized.

Allow users to opt out of statically linking std into rustc_driver by
setting RUSTC_LINK_STD_INTO_RUSTC_DRIVER=0. If unset or set to any
other value, the function falls back to the default, linking std into
rustc_driver on all platforms except Windows.

Signed-off-by: Deepesh Varatharajan <Deepesh.Varatharajan@windriver.com>
@DeepeshWR DeepeshWR force-pushed the respect_rustc_link_std_env branch from 168c019 to b8b260f Compare March 4, 2026 16:15
@bjorn3
Copy link
Member

bjorn3 commented Mar 4, 2026

This should probably be an option in bootstrap.toml rather than an env var.

Note: This does not introduce a new environment variable; it only respects an existing one.

The existing env var is just an implementation detail of how the main bootstrap executable and the rustc wrapper of bootstrap communicate.

@DeepeshWR
Copy link
Contributor Author

This should probably be an option in bootstrap.toml rather than an env var.

Note: This does not introduce a new environment variable; it only respects an existing one.

The existing env var is just an implementation detail of how the main bootstrap executable and the rustc wrapper of bootstrap communicate.

Hi @bjorn3,
Thanks for the suggestion.
I’ve updated the patch as follows:

diff --git a/src/bootstrap/src/core/builder/mod.rs b/src/bootstrap/src/core/builder/mod.rs
index ae91b204062..b444952d16d 100644
--- a/src/bootstrap/src/core/builder/mod.rs
+++ b/src/bootstrap/src/core/builder/mod.rs
@@ -1125,6 +1125,10 @@ fn run_step_descriptions(&self, v: &[StepDescription], paths: &[PathBuf]) {
     /// Returns if `std` should be statically linked into `rustc_driver`.
     /// It's currently not done on `windows-gnu` due to linker bugs.
     pub fn link_std_into_rustc_driver(&self, target: TargetSelection) -> bool {
+        // Respect bootstrap.toml override if provided
+        if let Some(value) = self.config.link_std_into_rustc_driver {
+            return value;
+        }
         !target.triple.ends_with("-windows-gnu")
     }

diff --git a/src/bootstrap/src/core/config/config.rs b/src/bootstrap/src/core/config/config.rs
index 17f256188e1..3bd01c0f7b2 100644
--- a/src/bootstrap/src/core/config/config.rs
+++ b/src/bootstrap/src/core/config/config.rs
@@ -282,6 +282,7 @@ pub struct Config {
     pub windows_rc: Option<PathBuf>,
     pub reuse: Option<PathBuf>,
     pub cargo_native_static: bool,
+    pub link_std_into_rustc_driver: Option<bool>,
     pub configure_args: Vec<String>,
     pub out: PathBuf,
     pub rust_info: channel::GitInfo,
@@ -485,6 +486,7 @@ pub(crate) fn parse_inner(
             sanitizers: build_sanitizers,
             profiler: build_profiler,
             cargo_native_static: build_cargo_native_static,
+            link_std_into_rustc_driver: build_link_std_into_rustc_driver,
             low_priority: build_low_priority,
             configure_args: build_configure_args,
             local_rebuild: build_local_rebuild,
@@ -1364,6 +1366,7 @@ pub(crate) fn parse_inner(
             libdir: install_libdir.map(PathBuf::from),
             libgccjit_libs_dir: gcc_libgccjit_libs_dir,
             library_docs_private_items: build_library_docs_private_items.unwrap_or(false),
+            link_std_into_rustc_driver: build_link_std_into_rustc_driver,
             lld_enabled,
             lldb: build_lldb.map(PathBuf::from),
             llvm_allow_old_toolchain: llvm_allow_old_toolchain.unwrap_or(false),
diff --git a/src/bootstrap/src/core/config/toml/build.rs b/src/bootstrap/src/core/config/toml/build.rs
index 27bf753f691..042f1216ac7 100644
--- a/src/bootstrap/src/core/config/toml/build.rs
+++ b/src/bootstrap/src/core/config/toml/build.rs
@@ -52,6 +52,7 @@ struct Build {
         sanitizers: Option<bool> = "sanitizers",
         profiler: Option<bool> = "profiler",
         cargo_native_static: Option<bool> = "cargo-native-static",
+        link_std_into_rustc_driver: Option<bool> = "link-std-into-rustc-driver",
         low_priority: Option<bool> = "low-priority",
         configure_args: Option<Vec<String>> = "configure-args",
         local_rebuild: Option<bool> = "local-rebuild",

Is this what you were suggesting ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-bootstrap Relevant to the bootstrap subteam: Rust's build system (x.py and src/bootstrap)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants