Skip to content

Commit 7de99cd

Browse files
committed
Merge remote tracking branch 'upstream/master'
2 parents 3ccb87a + 57ecd7a commit 7de99cd

File tree

13 files changed

+142
-112
lines changed

13 files changed

+142
-112
lines changed

src/Cargo.lock

+5-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/bootstrap/check.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ pub fn krate(build: &Build,
383383
// helper crate, not tested. If it leaks through then it ends up
384384
// messing with various mtime calculations and such.
385385
if !name.contains("jemalloc") && name != "build_helper" {
386-
cargo.arg("-p").arg(name);
386+
cargo.arg("-p").arg(&format!("{}:0.0.0", name));
387387
}
388388
for dep in build.crates[name].deps.iter() {
389389
if visited.insert(dep) {

src/bootstrap/compile.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,10 @@ use std::fs::{self, File};
2121
use std::path::{Path, PathBuf};
2222
use std::process::Command;
2323

24-
use build_helper::output;
24+
use build_helper::{output, mtime};
2525
use filetime::FileTime;
2626

27-
use util::{exe, libdir, mtime, is_dylib, copy};
27+
use util::{exe, libdir, is_dylib, copy};
2828
use {Build, Compiler, Mode};
2929

3030
/// Build the standard library.

src/bootstrap/doc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ use std::io::prelude::*;
2222
use std::process::Command;
2323

2424
use {Build, Compiler, Mode};
25-
use util::{up_to_date, cp_r};
25+
use util::cp_r;
26+
use build_helper::up_to_date;
2627

2728
/// Invoke `rustbook` as compiled in `stage` for `target` for the doc book
2829
/// `name` into the `out` path.

src/bootstrap/lib.rs

+11-19
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
6767
#![deny(warnings)]
6868

69+
#[macro_use]
6970
extern crate build_helper;
7071
extern crate cmake;
7172
extern crate filetime;
@@ -83,24 +84,9 @@ use std::fs::{self, File};
8384
use std::path::{Component, PathBuf, Path};
8485
use std::process::Command;
8586

86-
use build_helper::{run_silent, output};
87+
use build_helper::{run_silent, output, mtime};
8788

88-
use util::{exe, mtime, libdir, add_lib_path};
89-
90-
/// A helper macro to `unwrap` a result except also print out details like:
91-
///
92-
/// * The file/line of the panic
93-
/// * The expression that failed
94-
/// * The error itself
95-
///
96-
/// This is currently used judiciously throughout the build system rather than
97-
/// using a `Result` with `try!`, but this may change one day...
98-
macro_rules! t {
99-
($e:expr) => (match $e {
100-
Ok(e) => e,
101-
Err(e) => panic!("{} failed with {}", stringify!($e), e),
102-
})
103-
}
89+
use util::{exe, libdir, add_lib_path};
10490

10591
mod cc;
10692
mod channel;
@@ -482,7 +468,8 @@ impl Build {
482468
//
483469
// These variables are primarily all read by
484470
// src/bootstrap/bin/{rustc.rs,rustdoc.rs}
485-
cargo.env("RUSTC", self.out.join("bootstrap/debug/rustc"))
471+
cargo.env("RUSTBUILD_NATIVE_DIR", self.native_dir(target))
472+
.env("RUSTC", self.out.join("bootstrap/debug/rustc"))
486473
.env("RUSTC_REAL", self.compiler_path(compiler))
487474
.env("RUSTC_STAGE", stage.to_string())
488475
.env("RUSTC_DEBUGINFO", self.config.rust_debuginfo.to_string())
@@ -746,10 +733,15 @@ impl Build {
746733
}
747734
}
748735

736+
/// Directory for libraries built from C/C++ code and shared between stages.
737+
fn native_dir(&self, target: &str) -> PathBuf {
738+
self.out.join(target).join("native")
739+
}
740+
749741
/// Root output directory for rust_test_helpers library compiled for
750742
/// `target`
751743
fn test_helpers_out(&self, target: &str) -> PathBuf {
752-
self.out.join(target).join("rust-test-helpers")
744+
self.native_dir(target).join("rust-test-helpers")
753745
}
754746

755747
/// Adds the compiler's directory of dynamic libraries to `cmd`'s dynamic

src/bootstrap/native.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ use cmake;
2828
use gcc;
2929

3030
use Build;
31-
use util::{self, up_to_date};
31+
use util;
32+
use build_helper::up_to_date;
3233

3334
/// Compile LLVM for `target`.
3435
pub fn llvm(build: &Build, target: &str) {

src/bootstrap/util.rs

-37
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ use std::path::{Path, PathBuf};
2020
use std::process::Command;
2121
use std::time::Instant;
2222

23-
use filetime::FileTime;
24-
2523
/// Returns the `name` as the filename of a static library for `target`.
2624
pub fn staticlib(name: &str, target: &str) -> String {
2725
if target.contains("windows") {
@@ -31,13 +29,6 @@ pub fn staticlib(name: &str, target: &str) -> String {
3129
}
3230
}
3331

34-
/// Returns the last-modified time for `path`, or zero if it doesn't exist.
35-
pub fn mtime(path: &Path) -> FileTime {
36-
fs::metadata(path).map(|f| {
37-
FileTime::from_last_modification_time(&f)
38-
}).unwrap_or(FileTime::zero())
39-
}
40-
4132
/// Copies a file from `src` to `dst`, attempting to use hard links and then
4233
/// falling back to an actually filesystem copy if necessary.
4334
pub fn copy(src: &Path, dst: &Path) {
@@ -132,34 +123,6 @@ pub fn add_lib_path(path: Vec<PathBuf>, cmd: &mut Command) {
132123
cmd.env(dylib_path_var(), t!(env::join_paths(list)));
133124
}
134125

135-
/// Returns whether `dst` is up to date given that the file or files in `src`
136-
/// are used to generate it.
137-
///
138-
/// Uses last-modified time checks to verify this.
139-
pub fn up_to_date(src: &Path, dst: &Path) -> bool {
140-
let threshold = mtime(dst);
141-
let meta = match fs::metadata(src) {
142-
Ok(meta) => meta,
143-
Err(e) => panic!("source {:?} failed to get metadata: {}", src, e),
144-
};
145-
if meta.is_dir() {
146-
dir_up_to_date(src, &threshold)
147-
} else {
148-
FileTime::from_last_modification_time(&meta) <= threshold
149-
}
150-
}
151-
152-
fn dir_up_to_date(src: &Path, threshold: &FileTime) -> bool {
153-
t!(fs::read_dir(src)).map(|e| t!(e)).all(|e| {
154-
let meta = t!(e.metadata());
155-
if meta.is_dir() {
156-
dir_up_to_date(&e.path(), threshold)
157-
} else {
158-
FileTime::from_last_modification_time(&meta) < *threshold
159-
}
160-
})
161-
}
162-
163126
/// Returns the environment variable which the dynamic library lookup path
164127
/// resides in for this platform.
165128
pub fn dylib_path_var() -> &'static str {

src/build_helper/Cargo.toml

+3
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,6 @@ authors = ["The Rust Project Developers"]
66
[lib]
77
name = "build_helper"
88
path = "lib.rs"
9+
10+
[dependencies]
11+
filetime = "0.1"

src/build_helper/lib.rs

+71
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,30 @@
1010

1111
#![deny(warnings)]
1212

13+
extern crate filetime;
14+
15+
use std::fs;
1316
use std::process::{Command, Stdio};
1417
use std::path::{Path, PathBuf};
1518

19+
use filetime::FileTime;
20+
21+
/// A helper macro to `unwrap` a result except also print out details like:
22+
///
23+
/// * The file/line of the panic
24+
/// * The expression that failed
25+
/// * The error itself
26+
///
27+
/// This is currently used judiciously throughout the build system rather than
28+
/// using a `Result` with `try!`, but this may change one day...
29+
#[macro_export]
30+
macro_rules! t {
31+
($e:expr) => (match $e {
32+
Ok(e) => e,
33+
Err(e) => panic!("{} failed with {}", stringify!($e), e),
34+
})
35+
}
36+
1637
pub fn run(cmd: &mut Command) {
1738
println!("running: {:?}", cmd);
1839
run_silent(cmd);
@@ -88,6 +109,56 @@ pub fn output(cmd: &mut Command) -> String {
88109
String::from_utf8(output.stdout).unwrap()
89110
}
90111

112+
pub fn rerun_if_changed_anything_in_dir(dir: &Path) {
113+
let mut stack = dir.read_dir().unwrap()
114+
.map(|e| e.unwrap())
115+
.filter(|e| &*e.file_name() != ".git")
116+
.collect::<Vec<_>>();
117+
while let Some(entry) = stack.pop() {
118+
let path = entry.path();
119+
if entry.file_type().unwrap().is_dir() {
120+
stack.extend(path.read_dir().unwrap().map(|e| e.unwrap()));
121+
} else {
122+
println!("cargo:rerun-if-changed={}", path.display());
123+
}
124+
}
125+
}
126+
127+
/// Returns the last-modified time for `path`, or zero if it doesn't exist.
128+
pub fn mtime(path: &Path) -> FileTime {
129+
fs::metadata(path).map(|f| {
130+
FileTime::from_last_modification_time(&f)
131+
}).unwrap_or(FileTime::zero())
132+
}
133+
134+
/// Returns whether `dst` is up to date given that the file or files in `src`
135+
/// are used to generate it.
136+
///
137+
/// Uses last-modified time checks to verify this.
138+
pub fn up_to_date(src: &Path, dst: &Path) -> bool {
139+
let threshold = mtime(dst);
140+
let meta = match fs::metadata(src) {
141+
Ok(meta) => meta,
142+
Err(e) => panic!("source {:?} failed to get metadata: {}", src, e),
143+
};
144+
if meta.is_dir() {
145+
dir_up_to_date(src, &threshold)
146+
} else {
147+
FileTime::from_last_modification_time(&meta) <= threshold
148+
}
149+
}
150+
151+
fn dir_up_to_date(src: &Path, threshold: &FileTime) -> bool {
152+
t!(fs::read_dir(src)).map(|e| t!(e)).all(|e| {
153+
let meta = t!(e.metadata());
154+
if meta.is_dir() {
155+
dir_up_to_date(&e.path(), threshold)
156+
} else {
157+
FileTime::from_last_modification_time(&meta) < *threshold
158+
}
159+
})
160+
}
161+
91162
fn fail(s: &str) -> ! {
92163
println!("\n\n{}\n\n", s);
93164
std::process::exit(1);

src/liballoc_jemalloc/build.rs

+27-30
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,20 @@
1010

1111
#![deny(warnings)]
1212

13+
#[macro_use]
1314
extern crate build_helper;
1415
extern crate gcc;
1516

1617
use std::env;
17-
use std::path::PathBuf;
18+
use std::fs::{self, File};
19+
use std::path::{Path, PathBuf};
1820
use std::process::Command;
19-
use build_helper::run;
21+
use build_helper::{run, rerun_if_changed_anything_in_dir, up_to_date};
2022

2123
fn main() {
2224
println!("cargo:rustc-cfg=cargobuild");
2325
println!("cargo:rerun-if-changed=build.rs");
2426

25-
let target = env::var("TARGET").expect("TARGET was not set");
26-
let host = env::var("HOST").expect("HOST was not set");
27-
let build_dir = PathBuf::from(env::var_os("OUT_DIR").unwrap());
28-
let src_dir = env::current_dir().unwrap();
29-
3027
// FIXME: This is a hack to support building targets that don't
3128
// support jemalloc alongside hosts that do. The jemalloc build is
3229
// controlled by a feature of the std crate, and if that feature
@@ -35,6 +32,8 @@ fn main() {
3532
// that the feature set used by std is the same across all
3633
// targets, which means we have to build the alloc_jemalloc crate
3734
// for targets like emscripten, even if we don't use it.
35+
let target = env::var("TARGET").expect("TARGET was not set");
36+
let host = env::var("HOST").expect("HOST was not set");
3837
if target.contains("rumprun") || target.contains("bitrig") || target.contains("openbsd") ||
3938
target.contains("msvc") || target.contains("emscripten") || target.contains("fuchsia") ||
4039
target.contains("redox") {
@@ -63,6 +62,23 @@ fn main() {
6362
return;
6463
}
6564

65+
let build_dir = env::var_os("RUSTBUILD_NATIVE_DIR").unwrap_or(env::var_os("OUT_DIR").unwrap());
66+
let build_dir = PathBuf::from(build_dir).join("jemalloc");
67+
let _ = fs::create_dir_all(&build_dir);
68+
69+
if target.contains("windows") {
70+
println!("cargo:rustc-link-lib=static=jemalloc");
71+
} else {
72+
println!("cargo:rustc-link-lib=static=jemalloc_pic");
73+
}
74+
println!("cargo:rustc-link-search=native={}/lib", build_dir.display());
75+
let src_dir = env::current_dir().unwrap().join("../jemalloc");
76+
rerun_if_changed_anything_in_dir(&src_dir);
77+
let timestamp = build_dir.join("rustbuild.timestamp");
78+
if up_to_date(&Path::new("build.rs"), &timestamp) && up_to_date(&src_dir, &timestamp) {
79+
return
80+
}
81+
6682
let compiler = gcc::Config::new().get_compiler();
6783
// only msvc returns None for ar so unwrap is okay
6884
let ar = build_helper::cc2ar(compiler.path(), &target).unwrap();
@@ -72,23 +88,8 @@ fn main() {
7288
.collect::<Vec<_>>()
7389
.join(" ");
7490

75-
let mut stack = src_dir.join("../jemalloc")
76-
.read_dir()
77-
.unwrap()
78-
.map(|e| e.unwrap())
79-
.filter(|e| &*e.file_name() != ".git")
80-
.collect::<Vec<_>>();
81-
while let Some(entry) = stack.pop() {
82-
let path = entry.path();
83-
if entry.file_type().unwrap().is_dir() {
84-
stack.extend(path.read_dir().unwrap().map(|e| e.unwrap()));
85-
} else {
86-
println!("cargo:rerun-if-changed={}", path.display());
87-
}
88-
}
89-
9091
let mut cmd = Command::new("sh");
91-
cmd.arg(src_dir.join("../jemalloc/configure")
92+
cmd.arg(src_dir.join("configure")
9293
.to_str()
9394
.unwrap()
9495
.replace("C:\\", "/c/")
@@ -164,6 +165,7 @@ fn main() {
164165
}
165166

166167
run(&mut cmd);
168+
167169
let mut make = Command::new(build_helper::make(&host));
168170
make.current_dir(&build_dir)
169171
.arg("build_lib_static");
@@ -176,13 +178,6 @@ fn main() {
176178

177179
run(&mut make);
178180

179-
if target.contains("windows") {
180-
println!("cargo:rustc-link-lib=static=jemalloc");
181-
} else {
182-
println!("cargo:rustc-link-lib=static=jemalloc_pic");
183-
}
184-
println!("cargo:rustc-link-search=native={}/lib", build_dir.display());
185-
186181
// The pthread_atfork symbols is used by jemalloc on android but the really
187182
// old android we're building on doesn't have them defined, so just make
188183
// sure the symbols are available.
@@ -193,4 +188,6 @@ fn main() {
193188
.file("pthread_atfork_dummy.c")
194189
.compile("libpthread_atfork_dummy.a");
195190
}
191+
192+
t!(File::create(&timestamp));
196193
}

0 commit comments

Comments
 (0)