Skip to content

Commit 947e948

Browse files
committed
Make the rustc and rustdoc wrapper not depend on libbootstrap
This slightly improves compilation time by reducing linking time (saving about a 1/10 of the the total compilation time after changing rustbuild) and slightly reduces disk usage (from 16MB for the rustc wrapper to 4MB).
1 parent 043745c commit 947e948

File tree

4 files changed

+39
-29
lines changed

4 files changed

+39
-29
lines changed

src/bootstrap/bin/rustc.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
//! switching compilers for the bootstrap and for build scripts will probably
1616
//! never get replaced.
1717
18+
include!("../dylib_util.rs");
19+
1820
use std::env;
1921
use std::path::PathBuf;
2022
use std::process::{Child, Command};
@@ -50,11 +52,11 @@ fn main() {
5052

5153
let rustc = env::var_os(rustc).unwrap_or_else(|| panic!("{:?} was not set", rustc));
5254
let libdir = env::var_os(libdir).unwrap_or_else(|| panic!("{:?} was not set", libdir));
53-
let mut dylib_path = bootstrap::util::dylib_path();
55+
let mut dylib_path = dylib_path();
5456
dylib_path.insert(0, PathBuf::from(&libdir));
5557

5658
let mut cmd = Command::new(rustc);
57-
cmd.args(&args).env(bootstrap::util::dylib_path_var(), env::join_paths(&dylib_path).unwrap());
59+
cmd.args(&args).env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
5860

5961
// Get the name of the crate we're compiling, if any.
6062
let crate_name =
@@ -161,7 +163,7 @@ fn main() {
161163
eprintln!(
162164
"{} command: {:?}={:?} {:?}",
163165
prefix,
164-
bootstrap::util::dylib_path_var(),
166+
dylib_path_var(),
165167
env::join_paths(&dylib_path).unwrap(),
166168
cmd,
167169
);

src/bootstrap/bin/rustdoc.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ use std::ffi::OsString;
77
use std::path::PathBuf;
88
use std::process::Command;
99

10+
include!("../dylib_util.rs");
11+
1012
fn main() {
1113
let args = env::args_os().skip(1).collect::<Vec<_>>();
1214
let rustdoc = env::var_os("RUSTDOC_REAL").expect("RUSTDOC_REAL was not set");
@@ -20,14 +22,14 @@ fn main() {
2022
Err(_) => 0,
2123
};
2224

23-
let mut dylib_path = bootstrap::util::dylib_path();
25+
let mut dylib_path = dylib_path();
2426
dylib_path.insert(0, PathBuf::from(libdir.clone()));
2527

2628
let mut cmd = Command::new(rustdoc);
2729
cmd.args(&args)
2830
.arg("--sysroot")
2931
.arg(&sysroot)
30-
.env(bootstrap::util::dylib_path_var(), env::join_paths(&dylib_path).unwrap());
32+
.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
3133

3234
// Force all crates compiled by this compiler to (a) be unstable and (b)
3335
// allow the `rustc_private` feature to link to other unstable crates
@@ -59,7 +61,7 @@ fn main() {
5961
if verbose > 1 {
6062
eprintln!(
6163
"rustdoc command: {:?}={:?} {:?}",
62-
bootstrap::util::dylib_path_var(),
64+
dylib_path_var(),
6365
env::join_paths(&dylib_path).unwrap(),
6466
cmd,
6567
);

src/bootstrap/dylib_util.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Various utilities for working with dylib paths.
2+
//
3+
// This file is meant to be included directly to avoid a dependency on the bootstrap library from
4+
// the rustc and rustdoc wrappers. This improves compilation time by reducing the linking time.
5+
6+
/// Returns the environment variable which the dynamic library lookup path
7+
/// resides in for this platform.
8+
pub fn dylib_path_var() -> &'static str {
9+
if cfg!(target_os = "windows") {
10+
"PATH"
11+
} else if cfg!(target_os = "macos") {
12+
"DYLD_LIBRARY_PATH"
13+
} else if cfg!(target_os = "haiku") {
14+
"LIBRARY_PATH"
15+
} else {
16+
"LD_LIBRARY_PATH"
17+
}
18+
}
19+
20+
/// Parses the `dylib_path_var()` environment variable, returning a list of
21+
/// paths that are members of this lookup path.
22+
pub fn dylib_path() -> Vec<PathBuf> {
23+
let var = match env::var_os(dylib_path_var()) {
24+
Some(v) => v,
25+
None => return vec![],
26+
};
27+
env::split_paths(&var).collect()
28+
}

src/bootstrap/util.rs

+1-23
Original file line numberDiff line numberDiff line change
@@ -54,29 +54,7 @@ pub fn add_dylib_path(path: Vec<PathBuf>, cmd: &mut Command) {
5454
cmd.env(dylib_path_var(), t!(env::join_paths(list)));
5555
}
5656

57-
/// Returns the environment variable which the dynamic library lookup path
58-
/// resides in for this platform.
59-
pub fn dylib_path_var() -> &'static str {
60-
if cfg!(target_os = "windows") {
61-
"PATH"
62-
} else if cfg!(target_os = "macos") {
63-
"DYLD_LIBRARY_PATH"
64-
} else if cfg!(target_os = "haiku") {
65-
"LIBRARY_PATH"
66-
} else {
67-
"LD_LIBRARY_PATH"
68-
}
69-
}
70-
71-
/// Parses the `dylib_path_var()` environment variable, returning a list of
72-
/// paths that are members of this lookup path.
73-
pub fn dylib_path() -> Vec<PathBuf> {
74-
let var = match env::var_os(dylib_path_var()) {
75-
Some(v) => v,
76-
None => return vec![],
77-
};
78-
env::split_paths(&var).collect()
79-
}
57+
include!("dylib_util.rs");
8058

8159
/// Adds a list of lookup paths to `cmd`'s link library lookup path.
8260
pub fn add_link_lib_path(path: Vec<PathBuf>, cmd: &mut Command) {

0 commit comments

Comments
 (0)