Skip to content
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

rustbuild: Build jemalloc and libbacktrace only once (take 2) #39329

Merged
merged 4 commits into from
Feb 3, 2017
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
7 changes: 5 additions & 2 deletions src/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/bootstrap/check.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,7 @@ pub fn krate(build: &Build,
// helper crate, not tested. If it leaks through then it ends up
// messing with various mtime calculations and such.
if !name.contains("jemalloc") && name != "build_helper" {
cargo.arg("-p").arg(name);
cargo.arg("-p").arg(&format!("{}:0.0.0", name));
}
for dep in build.crates[name].deps.iter() {
if visited.insert(dep) {
Expand Down
4 changes: 2 additions & 2 deletions src/bootstrap/compile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ use std::fs::{self, File};
use std::path::{Path, PathBuf};
use std::process::Command;

use build_helper::output;
use build_helper::{output, mtime};
use filetime::FileTime;

use util::{exe, libdir, mtime, is_dylib, copy};
use util::{exe, libdir, is_dylib, copy};
use {Build, Compiler, Mode};

/// Build the standard library.
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/doc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ use std::io::prelude::*;
use std::process::Command;

use {Build, Compiler, Mode};
use util::{up_to_date, cp_r};
use util::cp_r;
use build_helper::up_to_date;

/// Invoke `rustbook` as compiled in `stage` for `target` for the doc book
/// `name` into the `out` path.
Expand Down
30 changes: 11 additions & 19 deletions src/bootstrap/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@

#![deny(warnings)]

#[macro_use]
extern crate build_helper;
extern crate cmake;
extern crate filetime;
Expand All @@ -83,24 +84,9 @@ use std::fs::{self, File};
use std::path::{Component, PathBuf, Path};
use std::process::Command;

use build_helper::{run_silent, output};
use build_helper::{run_silent, output, mtime};

use util::{exe, mtime, libdir, add_lib_path};

/// A helper macro to `unwrap` a result except also print out details like:
///
/// * The file/line of the panic
/// * The expression that failed
/// * The error itself
///
/// This is currently used judiciously throughout the build system rather than
/// using a `Result` with `try!`, but this may change one day...
macro_rules! t {
($e:expr) => (match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {}", stringify!($e), e),
})
}
use util::{exe, libdir, add_lib_path};

mod cc;
mod channel;
Expand Down Expand Up @@ -482,7 +468,8 @@ impl Build {
//
// These variables are primarily all read by
// src/bootstrap/bin/{rustc.rs,rustdoc.rs}
cargo.env("RUSTC", self.out.join("bootstrap/debug/rustc"))
cargo.env("RUSTBUILD_NATIVE_DIR", self.native_dir(target))
.env("RUSTC", self.out.join("bootstrap/debug/rustc"))
.env("RUSTC_REAL", self.compiler_path(compiler))
.env("RUSTC_STAGE", stage.to_string())
.env("RUSTC_DEBUGINFO", self.config.rust_debuginfo.to_string())
Expand Down Expand Up @@ -746,10 +733,15 @@ impl Build {
}
}

/// Directory for libraries built from C/C++ code and shared between stages.
fn native_dir(&self, target: &str) -> PathBuf {
self.out.join(target).join("native")
}

/// Root output directory for rust_test_helpers library compiled for
/// `target`
fn test_helpers_out(&self, target: &str) -> PathBuf {
self.out.join(target).join("rust-test-helpers")
self.native_dir(target).join("rust-test-helpers")
}

/// Adds the compiler's directory of dynamic libraries to `cmd`'s dynamic
Expand Down
3 changes: 2 additions & 1 deletion src/bootstrap/native.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ use cmake;
use gcc;

use Build;
use util::{self, up_to_date};
use util;
use build_helper::up_to_date;

/// Compile LLVM for `target`.
pub fn llvm(build: &Build, target: &str) {
Expand Down
37 changes: 0 additions & 37 deletions src/bootstrap/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ use std::path::{Path, PathBuf};
use std::process::Command;
use std::time::Instant;

use filetime::FileTime;

/// Returns the `name` as the filename of a static library for `target`.
pub fn staticlib(name: &str, target: &str) -> String {
if target.contains("windows") {
Expand All @@ -31,13 +29,6 @@ pub fn staticlib(name: &str, target: &str) -> String {
}
}

/// Returns the last-modified time for `path`, or zero if it doesn't exist.
pub fn mtime(path: &Path) -> FileTime {
fs::metadata(path).map(|f| {
FileTime::from_last_modification_time(&f)
}).unwrap_or(FileTime::zero())
}

/// Copies a file from `src` to `dst`, attempting to use hard links and then
/// falling back to an actually filesystem copy if necessary.
pub fn copy(src: &Path, dst: &Path) {
Expand Down Expand Up @@ -132,34 +123,6 @@ pub fn add_lib_path(path: Vec<PathBuf>, cmd: &mut Command) {
cmd.env(dylib_path_var(), t!(env::join_paths(list)));
}

/// Returns whether `dst` is up to date given that the file or files in `src`
/// are used to generate it.
///
/// Uses last-modified time checks to verify this.
pub fn up_to_date(src: &Path, dst: &Path) -> bool {
let threshold = mtime(dst);
let meta = match fs::metadata(src) {
Ok(meta) => meta,
Err(e) => panic!("source {:?} failed to get metadata: {}", src, e),
};
if meta.is_dir() {
dir_up_to_date(src, &threshold)
} else {
FileTime::from_last_modification_time(&meta) <= threshold
}
}

fn dir_up_to_date(src: &Path, threshold: &FileTime) -> bool {
t!(fs::read_dir(src)).map(|e| t!(e)).all(|e| {
let meta = t!(e.metadata());
if meta.is_dir() {
dir_up_to_date(&e.path(), threshold)
} else {
FileTime::from_last_modification_time(&meta) < *threshold
}
})
}

/// Returns the environment variable which the dynamic library lookup path
/// resides in for this platform.
pub fn dylib_path_var() -> &'static str {
Expand Down
3 changes: 3 additions & 0 deletions src/build_helper/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@ authors = ["The Rust Project Developers"]
[lib]
name = "build_helper"
path = "lib.rs"

[dependencies]
filetime = "0.1"
71 changes: 71 additions & 0 deletions src/build_helper/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,30 @@

#![deny(warnings)]

extern crate filetime;

use std::fs;
use std::process::{Command, Stdio};
use std::path::{Path, PathBuf};

use filetime::FileTime;

/// A helper macro to `unwrap` a result except also print out details like:
///
/// * The file/line of the panic
/// * The expression that failed
/// * The error itself
///
/// This is currently used judiciously throughout the build system rather than
/// using a `Result` with `try!`, but this may change one day...
#[macro_export]
macro_rules! t {
($e:expr) => (match $e {
Ok(e) => e,
Err(e) => panic!("{} failed with {}", stringify!($e), e),
})
}

pub fn run(cmd: &mut Command) {
println!("running: {:?}", cmd);
run_silent(cmd);
Expand Down Expand Up @@ -88,6 +109,56 @@ pub fn output(cmd: &mut Command) -> String {
String::from_utf8(output.stdout).unwrap()
}

pub fn rerun_if_changed_anything_in_dir(dir: &Path) {
let mut stack = dir.read_dir().unwrap()
.map(|e| e.unwrap())
.filter(|e| &*e.file_name() != ".git")
.collect::<Vec<_>>();
while let Some(entry) = stack.pop() {
let path = entry.path();
if entry.file_type().unwrap().is_dir() {
stack.extend(path.read_dir().unwrap().map(|e| e.unwrap()));
} else {
println!("cargo:rerun-if-changed={}", path.display());
}
}
}

/// Returns the last-modified time for `path`, or zero if it doesn't exist.
pub fn mtime(path: &Path) -> FileTime {
fs::metadata(path).map(|f| {
FileTime::from_last_modification_time(&f)
}).unwrap_or(FileTime::zero())
}

/// Returns whether `dst` is up to date given that the file or files in `src`
/// are used to generate it.
///
/// Uses last-modified time checks to verify this.
pub fn up_to_date(src: &Path, dst: &Path) -> bool {
let threshold = mtime(dst);
let meta = match fs::metadata(src) {
Ok(meta) => meta,
Err(e) => panic!("source {:?} failed to get metadata: {}", src, e),
};
if meta.is_dir() {
dir_up_to_date(src, &threshold)
} else {
FileTime::from_last_modification_time(&meta) <= threshold
}
}

fn dir_up_to_date(src: &Path, threshold: &FileTime) -> bool {
t!(fs::read_dir(src)).map(|e| t!(e)).all(|e| {
let meta = t!(e.metadata());
if meta.is_dir() {
dir_up_to_date(&e.path(), threshold)
} else {
FileTime::from_last_modification_time(&meta) < *threshold
}
})
}

fn fail(s: &str) -> ! {
println!("\n\n{}\n\n", s);
std::process::exit(1);
Expand Down
Loading