Bug 1814798 - pt 1. Add bool to enable/disable PHC at runtime r=glandium
[gecko.git] / build / build-rust / rust-vendor-std.patch
blob01b4a6f730f5d9db6733767f1fc3afafaee4cc0a
1 Teaches Rust's build system to vendor std's dependencies into the
2 rust-src component.
4 This was originally landed in https://github.com/rust-lang/rust/pull/78790
5 but was backed out for causing some breakage for distro maintainers who
6 need to build Rust itself in a vendored/offline context. It doesn't actually
7 fetch anything interesting from crates.io, just the magic fake std/core crates
8 that exist to make the build work right. Those crates *are* vendored but
9 their contents are ignored in favour of the actual stdlib.
11 For firefox's purposes, these patches still work fine, and are necessary
12 to make -Zbuild-std work in a vendored environment.
14 diff --git a/src/bootstrap/dist.rs b/src/bootstrap/dist.rs
15 index 3cb0eccd324..a3b8154c024 100644
16 --- a/src/bootstrap/dist.rs
17 +++ b/src/bootstrap/dist.rs
18 @@ -905,6 +905,31 @@ fn run(self, builder: &Builder<'_>) -> GeneratedTarball {
19 builder.copy(&builder.src.join(file), &dst_src.join(file));
22 + // libsysroot includes std and everything else, so vendoring it
23 + // creates exactly what's needed for `cargo -Zbuild-std` or any
24 + // other analysis of the stdlib's source. Cargo also needs help
25 + // finding the lock, so we copy it to libsysroot temporarily.
26 + //
27 + // Note that this requires std to only have one version of each
28 + // crate. e.g. two versions of getopts won't be patchable.
29 + let dst_libsysroot = dst_src.join("library/sysroot");
30 + let dst_vendor = dst_src.join("vendor");
31 + let root_lock = dst_src.join("Cargo.lock");
32 + let temp_lock = dst_libsysroot.join("Cargo.lock");
34 + // `cargo vendor` will delete everything from the lockfile that
35 + // isn't used by libsysroot, so we need to not use any links!
36 + builder.really_copy(&root_lock, &temp_lock);
38 + let mut cmd = Command::new(&builder.initial_cargo);
39 + cmd.arg("vendor").arg(dst_vendor).current_dir(&dst_libsysroot);
40 + cmd.env("RUSTC_BOOTSTRAP", "1");
41 + builder.info("Dist src");
42 + let _time = timeit(builder);
43 + builder.run(&mut cmd);
45 + builder.remove(&temp_lock);
47 tarball.generate()
50 diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs
51 index 3ed53452309..1fc0d887748 100644
52 --- a/src/bootstrap/lib.rs
53 +++ b/src/bootstrap/lib.rs
54 @@ -1437,6 +1437,27 @@ fn read_stamp_file(&self, stamp: &Path) -> Vec<(PathBuf, DependencyType)> {
55 paths
58 + /// Copies a file from `src` to `dst` and doesn't use links, so
59 + /// that the copy can be modified without affecting the original.
60 + pub fn really_copy(&self, src: &Path, dst: &Path) {
61 + if self.config.dry_run() {
62 + return;
63 + }
64 + self.verbose_than(1, &format!("Copy {:?} to {:?}", src, dst));
65 + if src == dst {
66 + return;
67 + }
68 + let _ = fs::remove_file(&dst);
69 + let metadata = t!(src.symlink_metadata());
70 + if let Err(e) = fs::copy(src, dst) {
71 + panic!("failed to copy `{}` to `{}`: {}", src.display(), dst.display(), e)
72 + }
73 + t!(fs::set_permissions(dst, metadata.permissions()));
74 + let atime = FileTime::from_last_access_time(&metadata);
75 + let mtime = FileTime::from_last_modification_time(&metadata);
76 + t!(filetime::set_file_times(dst, atime, mtime));
77 + }
79 /// Copies a file from `src` to `dst`
80 pub fn copy(&self, src: &Path, dst: &Path) {
81 self.copy_internal(src, dst, false);