Skip to content

Commit e0a6914

Browse files
committed
Rework standard library building
1 parent 5e69cf5 commit e0a6914

File tree

5 files changed

+117
-30
lines changed

5 files changed

+117
-30
lines changed

build_sysroot/Cargo.lock

Lines changed: 102 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

build_sysroot/Cargo.toml

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,10 @@
1-
[package]
2-
name = "sysroot"
3-
version = "0.0.0"
4-
5-
[dependencies]
6-
core = { path = "./sysroot_src/library/core" }
7-
alloc = { path = "./sysroot_src/library/alloc" }
8-
std = { path = "./sysroot_src/library/std", features = ["panic_unwind", "backtrace"] }
9-
test = { path = "./sysroot_src/library/test" }
10-
proc_macro = { path = "./sysroot_src/library/proc_macro" }
1+
[workspace]
2+
members = ["./library/sysroot"]
113

124
[patch.crates-io]
13-
rustc-std-workspace-core = { path = "./sysroot_src/library/rustc-std-workspace-core" }
14-
rustc-std-workspace-alloc = { path = "./sysroot_src/library/rustc-std-workspace-alloc" }
15-
rustc-std-workspace-std = { path = "./sysroot_src/library/rustc-std-workspace-std" }
5+
rustc-std-workspace-core = { path = "./library/rustc-std-workspace-core" }
6+
rustc-std-workspace-alloc = { path = "./library/rustc-std-workspace-alloc" }
7+
rustc-std-workspace-std = { path = "./library/rustc-std-workspace-std" }
168

179
[profile.dev]
1810
lto = "off"

build_sysroot/src/lib.rs

Lines changed: 0 additions & 1 deletion
This file was deleted.

build_system/build_sysroot.rs

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -156,11 +156,10 @@ impl SysrootTarget {
156156
}
157157

158158
pub(crate) static ORIG_BUILD_SYSROOT: RelPath = RelPath::SOURCE.join("build_sysroot");
159-
pub(crate) static BUILD_SYSROOT: RelPath = RelPath::BUILD.join("sysroot");
160-
pub(crate) static SYSROOT_RUSTC_VERSION: RelPath = BUILD_SYSROOT.join("rustc_version");
161-
pub(crate) static SYSROOT_SRC: RelPath = BUILD_SYSROOT.join("sysroot_src");
159+
pub(crate) static STDLIB_SRC: RelPath = RelPath::BUILD.join("stdlib");
160+
pub(crate) static SYSROOT_RUSTC_VERSION: RelPath = STDLIB_SRC.join("rustc_version");
162161
pub(crate) static STANDARD_LIBRARY: CargoProject =
163-
CargoProject::new(&BUILD_SYSROOT, "build_sysroot");
162+
CargoProject::new(&STDLIB_SRC.join("library/sysroot"), "stdlib_target");
164163
pub(crate) static RTSTARTUP_SYSROOT: RelPath = RelPath::BUILD.join("rtstartup");
165164

166165
#[must_use]
@@ -277,7 +276,7 @@ fn build_clif_sysroot_for_triple(
277276
if channel == "release" {
278277
build_cmd.arg("--release");
279278
}
280-
build_cmd.arg("--features").arg("std/compiler-builtins-no-asm");
279+
build_cmd.arg("--features").arg("compiler-builtins-no-asm backtrace panic-unwind");
281280
build_cmd.arg("--locked");
282281
build_cmd.env("__CARGO_DEFAULT_LIB_METADATA", "cg_clif");
283282
if compiler.triple.contains("apple") {
@@ -307,7 +306,7 @@ fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option<SysrootTarget> {
307306

308307
RTSTARTUP_SYSROOT.ensure_fresh(dirs);
309308

310-
let rtstartup_src = SYSROOT_SRC.to_path(dirs).join("library").join("rtstartup");
309+
let rtstartup_src = STDLIB_SRC.to_path(dirs).join("library").join("rtstartup");
311310
let mut target_libs = SysrootTarget { triple: compiler.triple.clone(), libs: vec![] };
312311

313312
for file in ["rsbegin", "rsend"] {

build_system/prepare.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::fs;
33
use std::path::{Path, PathBuf};
44
use std::process::Command;
55

6-
use super::build_sysroot::{BUILD_SYSROOT, ORIG_BUILD_SYSROOT, SYSROOT_RUSTC_VERSION, SYSROOT_SRC};
6+
use super::build_sysroot::{ORIG_BUILD_SYSROOT, STDLIB_SRC, SYSROOT_RUSTC_VERSION};
77
use super::path::{Dirs, RelPath};
88
use super::rustc_info::{get_default_sysroot, get_rustc_version};
99
use super::utils::{
@@ -28,15 +28,10 @@ fn prepare_stdlib(dirs: &Dirs, rustc: &Path) {
2828
let sysroot_src_orig = get_default_sysroot(rustc).join("lib/rustlib/src/rust");
2929
assert!(sysroot_src_orig.exists());
3030

31-
eprintln!("[COPY] stdlib src");
31+
apply_patches(dirs, "stdlib", &sysroot_src_orig, &STDLIB_SRC.to_path(dirs));
3232

3333
// FIXME ensure builds error out or update the copy if any of the files copied here change
34-
BUILD_SYSROOT.ensure_fresh(dirs);
35-
copy_dir_recursively(&ORIG_BUILD_SYSROOT.to_path(dirs), &BUILD_SYSROOT.to_path(dirs));
36-
37-
fs::create_dir_all(SYSROOT_SRC.to_path(dirs).join("library")).unwrap();
38-
39-
apply_patches(dirs, "stdlib", &sysroot_src_orig, &SYSROOT_SRC.to_path(dirs));
34+
copy_dir_recursively(&ORIG_BUILD_SYSROOT.to_path(dirs), &STDLIB_SRC.to_path(dirs));
4035

4136
let rustc_version = get_rustc_version(rustc);
4237
fs::write(SYSROOT_RUSTC_VERSION.to_path(dirs), &rustc_version).unwrap();
@@ -251,6 +246,8 @@ fn get_patches(dirs: &Dirs, crate_name: &str) -> Vec<PathBuf> {
251246
pub(crate) fn apply_patches(dirs: &Dirs, crate_name: &str, source_dir: &Path, target_dir: &Path) {
252247
// FIXME avoid copy and patch if src, patches and target are unchanged
253248

249+
eprintln!("[COPY] {crate_name} source");
250+
254251
remove_dir_if_exists(target_dir);
255252
fs::create_dir_all(target_dir).unwrap();
256253
copy_dir_recursively(source_dir, target_dir);

0 commit comments

Comments
 (0)