Skip to content

Commit 6efb3b2

Browse files
authored
Rollup merge of rust-lang#40236 - petrochenkov:btweak, r=alexcrichton
rustbuild: A few tweaks Fixes rust-lang#40016 Fixes rust-lang#39507 r? @alexcrichton
2 parents 9f9c2eb + 384f64a commit 6efb3b2

File tree

23 files changed

+177
-152
lines changed

23 files changed

+177
-152
lines changed

src/Cargo.lock

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

src/bootstrap/bootstrap.py

+15-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
# option. This file may not be copied, modified, or distributed
99
# except according to those terms.
1010

11+
from __future__ import print_function
1112
import argparse
1213
import contextlib
1314
import datetime
@@ -501,7 +502,7 @@ def build_triple(self):
501502

502503
return "{}-{}".format(cputype, ostype)
503504

504-
def main():
505+
def bootstrap():
505506
parser = argparse.ArgumentParser(description='Build rust')
506507
parser.add_argument('--config')
507508
parser.add_argument('--clean', action='store_true')
@@ -564,8 +565,6 @@ def main():
564565
rb._rustc_channel, rb._rustc_date = data['rustc'].split('-', 1)
565566
rb._cargo_rev = data['cargo']
566567

567-
start_time = time()
568-
569568
# Fetch/build the bootstrap
570569
rb.build = rb.build_triple()
571570
rb.download_stage0()
@@ -582,9 +581,19 @@ def main():
582581
env["BOOTSTRAP_PARENT_ID"] = str(os.getpid())
583582
rb.run(args, env)
584583

585-
end_time = time()
586-
587-
print("Build completed in %s" % format_build_time(end_time - start_time))
584+
def main():
585+
start_time = time()
586+
try:
587+
bootstrap()
588+
print("Build completed successfully in %s" % format_build_time(time() - start_time))
589+
except (SystemExit, KeyboardInterrupt) as e:
590+
if hasattr(e, 'code') and isinstance(e.code, int):
591+
exit_code = e.code
592+
else:
593+
exit_code = 1
594+
print(e)
595+
print("Build completed unsuccessfully in %s" % format_build_time(time() - start_time))
596+
sys.exit(exit_code)
588597

589598
if __name__ == '__main__':
590599
main()

src/bootstrap/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -733,7 +733,7 @@ impl Build {
733733
} else {
734734
let base = self.llvm_out(&self.config.build).join("build");
735735
let exe = exe("FileCheck", target);
736-
if self.config.build.contains("msvc") {
736+
if !self.config.ninja && self.config.build.contains("msvc") {
737737
base.join("Release/bin").join(exe)
738738
} else {
739739
base.join("bin").join(exe)

src/bootstrap/native.rs

+21-15
Original file line numberDiff line numberDiff line change
@@ -41,28 +41,32 @@ pub fn llvm(build: &Build, target: &str) {
4141
}
4242
}
4343

44-
// If the cleaning trigger is newer than our built artifacts (or if the
45-
// artifacts are missing) then we keep going, otherwise we bail out.
46-
let dst = build.llvm_out(target);
47-
let stamp = build.src.join("src/rustllvm/llvm-auto-clean-trigger");
48-
let mut stamp_contents = String::new();
49-
t!(t!(File::open(&stamp)).read_to_string(&mut stamp_contents));
50-
let done_stamp = dst.join("llvm-finished-building");
44+
let clean_trigger = build.src.join("src/rustllvm/llvm-auto-clean-trigger");
45+
let mut clean_trigger_contents = String::new();
46+
t!(t!(File::open(&clean_trigger)).read_to_string(&mut clean_trigger_contents));
47+
48+
let out_dir = build.llvm_out(target);
49+
let done_stamp = out_dir.join("llvm-finished-building");
5150
if done_stamp.exists() {
5251
let mut done_contents = String::new();
5352
t!(t!(File::open(&done_stamp)).read_to_string(&mut done_contents));
54-
if done_contents == stamp_contents {
53+
54+
// LLVM was already built previously.
55+
// We don't track changes in LLVM sources, so we need to choose between reusing
56+
// what was built previously, or cleaning the directory and doing a fresh build.
57+
// The choice depends on contents of the clean-trigger file.
58+
// If the contents are the same as during the previous build, then no action is required.
59+
// If the contents differ from the previous build, then cleaning is triggered.
60+
if done_contents == clean_trigger_contents {
5561
return
62+
} else {
63+
t!(fs::remove_dir_all(&out_dir));
5664
}
5765
}
58-
drop(fs::remove_dir_all(&dst));
5966

6067
println!("Building LLVM for {}", target);
61-
6268
let _time = util::timeit();
63-
let _ = fs::remove_dir_all(&dst.join("build"));
64-
t!(fs::create_dir_all(&dst.join("build")));
65-
let assertions = if build.config.llvm_assertions {"ON"} else {"OFF"};
69+
t!(fs::create_dir_all(&out_dir));
6670

6771
// http://llvm.org/docs/CMake.html
6872
let mut cfg = cmake::Config::new(build.src.join("src/llvm"));
@@ -82,9 +86,11 @@ pub fn llvm(build: &Build, target: &str) {
8286
None => "X86;ARM;AArch64;Mips;PowerPC;SystemZ;JSBackend;MSP430;Sparc;NVPTX",
8387
};
8488

89+
let assertions = if build.config.llvm_assertions {"ON"} else {"OFF"};
90+
8591
cfg.target(target)
8692
.host(&build.config.build)
87-
.out_dir(&dst)
93+
.out_dir(&out_dir)
8894
.profile(profile)
8995
.define("LLVM_ENABLE_ASSERTIONS", assertions)
9096
.define("LLVM_TARGETS_TO_BUILD", llvm_targets)
@@ -142,7 +148,7 @@ pub fn llvm(build: &Build, target: &str) {
142148
// tools and libs on all platforms.
143149
cfg.build();
144150

145-
t!(t!(File::create(&done_stamp)).write_all(stamp_contents.as_bytes()));
151+
t!(t!(File::create(&done_stamp)).write_all(clean_trigger_contents.as_bytes()));
146152
}
147153

148154
fn check_llvm_version(build: &Build, llvm_config: &Path) {

src/bootstrap/step.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,7 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
302302
});
303303
};
304304

305+
suite("check-ui", "src/test/ui", "ui", "ui");
305306
suite("check-rpass", "src/test/run-pass", "run-pass", "run-pass");
306307
suite("check-cfail", "src/test/compile-fail", "compile-fail", "compile-fail");
307308
suite("check-pfail", "src/test/parse-fail", "parse-fail", "parse-fail");
@@ -362,7 +363,7 @@ pub fn build_rules<'a>(build: &'a Build) -> Rules {
362363
});
363364
};
364365

365-
suite("check-ui", "src/test/ui", "ui", "ui");
366+
suite("check-ui-full", "src/test/ui-fulldeps", "ui", "ui-fulldeps");
366367
suite("check-rpass-full", "src/test/run-pass-fulldeps",
367368
"run-pass", "run-pass-fulldeps");
368369
suite("check-rfail-full", "src/test/run-fail-fulldeps",
@@ -1504,7 +1505,8 @@ mod tests {
15041505
assert!(plan.iter().all(|s| s.host == "A"));
15051506
assert!(plan.iter().all(|s| s.target == "C"));
15061507

1507-
assert!(!plan.iter().any(|s| s.name.contains("-ui")));
1508+
assert!(plan.iter().any(|s| s.name.contains("-ui")));
1509+
assert!(!plan.iter().any(|s| s.name.contains("ui-full")));
15081510
assert!(plan.iter().any(|s| s.name.contains("cfail")));
15091511
assert!(!plan.iter().any(|s| s.name.contains("cfail-full")));
15101512
assert!(plan.iter().any(|s| s.name.contains("codegen-units")));

src/build_helper/lib.rs

+43-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212

1313
extern crate filetime;
1414

15-
use std::fs;
15+
use std::{fs, env};
16+
use std::fs::File;
1617
use std::process::{Command, Stdio};
1718
use std::path::{Path, PathBuf};
1819

@@ -148,6 +149,47 @@ pub fn up_to_date(src: &Path, dst: &Path) -> bool {
148149
}
149150
}
150151

152+
#[must_use]
153+
pub struct NativeLibBoilerplate {
154+
pub src_dir: PathBuf,
155+
pub out_dir: PathBuf,
156+
}
157+
158+
impl Drop for NativeLibBoilerplate {
159+
fn drop(&mut self) {
160+
t!(File::create(self.out_dir.join("rustbuild.timestamp")));
161+
}
162+
}
163+
164+
// Perform standard preparations for native libraries that are build only once for all stages.
165+
// Emit rerun-if-changed and linking attributes for Cargo, check if any source files are
166+
// updated, calculate paths used later in actual build with CMake/make or C/C++ compiler.
167+
// If Err is returned, then everything is up-to-date and further build actions can be skipped.
168+
// Timestamps are created automatically when the result of `native_lib_boilerplate` goes out
169+
// of scope, so all the build actions should be completed until then.
170+
pub fn native_lib_boilerplate(src_name: &str,
171+
out_name: &str,
172+
link_name: &str,
173+
search_subdir: &str)
174+
-> Result<NativeLibBoilerplate, ()> {
175+
let current_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
176+
let src_dir = current_dir.join("..").join(src_name);
177+
rerun_if_changed_anything_in_dir(&src_dir);
178+
179+
let out_dir = env::var_os("RUSTBUILD_NATIVE_DIR").unwrap_or(env::var_os("OUT_DIR").unwrap());
180+
let out_dir = PathBuf::from(out_dir).join(out_name);
181+
let _ = fs::create_dir_all(&out_dir);
182+
println!("cargo:rustc-link-lib=static={}", link_name);
183+
println!("cargo:rustc-link-search=native={}", out_dir.join(search_subdir).display());
184+
185+
let timestamp = out_dir.join("rustbuild.timestamp");
186+
if !up_to_date(Path::new("build.rs"), &timestamp) || !up_to_date(&src_dir, &timestamp) {
187+
Ok(NativeLibBoilerplate { src_dir: src_dir, out_dir: out_dir })
188+
} else {
189+
Err(())
190+
}
191+
}
192+
151193
fn dir_up_to_date(src: &Path, threshold: &FileTime) -> bool {
152194
t!(fs::read_dir(src)).map(|e| t!(e)).all(|e| {
153195
let meta = t!(e.metadata());

src/liballoc_jemalloc/build.rs

+14-31
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,15 @@
1010

1111
#![deny(warnings)]
1212

13-
#[macro_use]
1413
extern crate build_helper;
1514
extern crate gcc;
1615

1716
use std::env;
18-
use std::fs::{self, File};
19-
use std::path::{Path, PathBuf};
17+
use std::path::PathBuf;
2018
use std::process::Command;
21-
use build_helper::{run, rerun_if_changed_anything_in_dir, up_to_date};
19+
use build_helper::{run, native_lib_boilerplate};
2220

2321
fn main() {
24-
println!("cargo:rerun-if-changed=build.rs");
25-
2622
// FIXME: This is a hack to support building targets that don't
2723
// support jemalloc alongside hosts that do. The jemalloc build is
2824
// controlled by a feature of the std crate, and if that feature
@@ -61,22 +57,11 @@ fn main() {
6157
return;
6258
}
6359

64-
let build_dir = env::var_os("RUSTBUILD_NATIVE_DIR").unwrap_or(env::var_os("OUT_DIR").unwrap());
65-
let build_dir = PathBuf::from(build_dir).join("jemalloc");
66-
let _ = fs::create_dir_all(&build_dir);
67-
68-
if target.contains("windows") {
69-
println!("cargo:rustc-link-lib=static=jemalloc");
70-
} else {
71-
println!("cargo:rustc-link-lib=static=jemalloc_pic");
72-
}
73-
println!("cargo:rustc-link-search=native={}/lib", build_dir.display());
74-
let src_dir = env::current_dir().unwrap().join("../jemalloc");
75-
rerun_if_changed_anything_in_dir(&src_dir);
76-
let timestamp = build_dir.join("rustbuild.timestamp");
77-
if up_to_date(&Path::new("build.rs"), &timestamp) && up_to_date(&src_dir, &timestamp) {
78-
return
79-
}
60+
let link_name = if target.contains("windows") { "jemalloc" } else { "jemalloc_pic" };
61+
let native = match native_lib_boilerplate("jemalloc", "jemalloc", link_name, "lib") {
62+
Ok(native) => native,
63+
_ => return,
64+
};
8065

8166
let compiler = gcc::Config::new().get_compiler();
8267
// only msvc returns None for ar so unwrap is okay
@@ -88,12 +73,12 @@ fn main() {
8873
.join(" ");
8974

9075
let mut cmd = Command::new("sh");
91-
cmd.arg(src_dir.join("configure")
92-
.to_str()
93-
.unwrap()
94-
.replace("C:\\", "/c/")
95-
.replace("\\", "/"))
96-
.current_dir(&build_dir)
76+
cmd.arg(native.src_dir.join("configure")
77+
.to_str()
78+
.unwrap()
79+
.replace("C:\\", "/c/")
80+
.replace("\\", "/"))
81+
.current_dir(&native.out_dir)
9782
.env("CC", compiler.path())
9883
.env("EXTRA_CFLAGS", cflags.clone())
9984
// jemalloc generates Makefile deps using GCC's "-MM" flag. This means
@@ -166,7 +151,7 @@ fn main() {
166151
run(&mut cmd);
167152

168153
let mut make = Command::new(build_helper::make(&host));
169-
make.current_dir(&build_dir)
154+
make.current_dir(&native.out_dir)
170155
.arg("build_lib_static");
171156

172157
// mingw make seems... buggy? unclear...
@@ -187,6 +172,4 @@ fn main() {
187172
.file("pthread_atfork_dummy.c")
188173
.compile("libpthread_atfork_dummy.a");
189174
}
190-
191-
t!(File::create(&timestamp));
192175
}

src/libcompiler_builtins/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ doc = false
1515
core = { path = "../libcore" }
1616

1717
[build-dependencies]
18+
build_helper = { path = "../build_helper" }
1819
gcc = "0.3.27"

0 commit comments

Comments
 (0)