mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-28 09:44:08 +00:00
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).
This commit is contained in:
parent
043745cb96
commit
947e9483e9
@ -15,6 +15,8 @@
|
||||
//! switching compilers for the bootstrap and for build scripts will probably
|
||||
//! never get replaced.
|
||||
|
||||
include!("../dylib_util.rs");
|
||||
|
||||
use std::env;
|
||||
use std::path::PathBuf;
|
||||
use std::process::{Child, Command};
|
||||
@ -50,11 +52,11 @@ fn main() {
|
||||
|
||||
let rustc = env::var_os(rustc).unwrap_or_else(|| panic!("{:?} was not set", rustc));
|
||||
let libdir = env::var_os(libdir).unwrap_or_else(|| panic!("{:?} was not set", libdir));
|
||||
let mut dylib_path = bootstrap::util::dylib_path();
|
||||
let mut dylib_path = dylib_path();
|
||||
dylib_path.insert(0, PathBuf::from(&libdir));
|
||||
|
||||
let mut cmd = Command::new(rustc);
|
||||
cmd.args(&args).env(bootstrap::util::dylib_path_var(), env::join_paths(&dylib_path).unwrap());
|
||||
cmd.args(&args).env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
|
||||
|
||||
// Get the name of the crate we're compiling, if any.
|
||||
let crate_name =
|
||||
@ -161,7 +163,7 @@ fn main() {
|
||||
eprintln!(
|
||||
"{} command: {:?}={:?} {:?}",
|
||||
prefix,
|
||||
bootstrap::util::dylib_path_var(),
|
||||
dylib_path_var(),
|
||||
env::join_paths(&dylib_path).unwrap(),
|
||||
cmd,
|
||||
);
|
||||
|
@ -7,6 +7,8 @@ use std::ffi::OsString;
|
||||
use std::path::PathBuf;
|
||||
use std::process::Command;
|
||||
|
||||
include!("../dylib_util.rs");
|
||||
|
||||
fn main() {
|
||||
let args = env::args_os().skip(1).collect::<Vec<_>>();
|
||||
let rustdoc = env::var_os("RUSTDOC_REAL").expect("RUSTDOC_REAL was not set");
|
||||
@ -20,14 +22,14 @@ fn main() {
|
||||
Err(_) => 0,
|
||||
};
|
||||
|
||||
let mut dylib_path = bootstrap::util::dylib_path();
|
||||
let mut dylib_path = dylib_path();
|
||||
dylib_path.insert(0, PathBuf::from(libdir.clone()));
|
||||
|
||||
let mut cmd = Command::new(rustdoc);
|
||||
cmd.args(&args)
|
||||
.arg("--sysroot")
|
||||
.arg(&sysroot)
|
||||
.env(bootstrap::util::dylib_path_var(), env::join_paths(&dylib_path).unwrap());
|
||||
.env(dylib_path_var(), env::join_paths(&dylib_path).unwrap());
|
||||
|
||||
// Force all crates compiled by this compiler to (a) be unstable and (b)
|
||||
// allow the `rustc_private` feature to link to other unstable crates
|
||||
@ -59,7 +61,7 @@ fn main() {
|
||||
if verbose > 1 {
|
||||
eprintln!(
|
||||
"rustdoc command: {:?}={:?} {:?}",
|
||||
bootstrap::util::dylib_path_var(),
|
||||
dylib_path_var(),
|
||||
env::join_paths(&dylib_path).unwrap(),
|
||||
cmd,
|
||||
);
|
||||
|
28
src/bootstrap/dylib_util.rs
Normal file
28
src/bootstrap/dylib_util.rs
Normal file
@ -0,0 +1,28 @@
|
||||
// Various utilities for working with dylib paths.
|
||||
//
|
||||
// This file is meant to be included directly to avoid a dependency on the bootstrap library from
|
||||
// the rustc and rustdoc wrappers. This improves compilation time by reducing the linking time.
|
||||
|
||||
/// Returns the environment variable which the dynamic library lookup path
|
||||
/// resides in for this platform.
|
||||
pub fn dylib_path_var() -> &'static str {
|
||||
if cfg!(target_os = "windows") {
|
||||
"PATH"
|
||||
} else if cfg!(target_os = "macos") {
|
||||
"DYLD_LIBRARY_PATH"
|
||||
} else if cfg!(target_os = "haiku") {
|
||||
"LIBRARY_PATH"
|
||||
} else {
|
||||
"LD_LIBRARY_PATH"
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses the `dylib_path_var()` environment variable, returning a list of
|
||||
/// paths that are members of this lookup path.
|
||||
pub fn dylib_path() -> Vec<PathBuf> {
|
||||
let var = match env::var_os(dylib_path_var()) {
|
||||
Some(v) => v,
|
||||
None => return vec![],
|
||||
};
|
||||
env::split_paths(&var).collect()
|
||||
}
|
@ -54,29 +54,7 @@ pub fn add_dylib_path(path: Vec<PathBuf>, cmd: &mut Command) {
|
||||
cmd.env(dylib_path_var(), t!(env::join_paths(list)));
|
||||
}
|
||||
|
||||
/// Returns the environment variable which the dynamic library lookup path
|
||||
/// resides in for this platform.
|
||||
pub fn dylib_path_var() -> &'static str {
|
||||
if cfg!(target_os = "windows") {
|
||||
"PATH"
|
||||
} else if cfg!(target_os = "macos") {
|
||||
"DYLD_LIBRARY_PATH"
|
||||
} else if cfg!(target_os = "haiku") {
|
||||
"LIBRARY_PATH"
|
||||
} else {
|
||||
"LD_LIBRARY_PATH"
|
||||
}
|
||||
}
|
||||
|
||||
/// Parses the `dylib_path_var()` environment variable, returning a list of
|
||||
/// paths that are members of this lookup path.
|
||||
pub fn dylib_path() -> Vec<PathBuf> {
|
||||
let var = match env::var_os(dylib_path_var()) {
|
||||
Some(v) => v,
|
||||
None => return vec![],
|
||||
};
|
||||
env::split_paths(&var).collect()
|
||||
}
|
||||
include!("dylib_util.rs");
|
||||
|
||||
/// Adds a list of lookup paths to `cmd`'s link library lookup path.
|
||||
pub fn add_link_lib_path(path: Vec<PathBuf>, cmd: &mut Command) {
|
||||
|
Loading…
Reference in New Issue
Block a user