Skip to content

Commit 7358641

Browse files
authored
Use the official approach for building liballoc (#25)
This means that we don't have to compile core separately. We also don't need to set RUSTFLAGS for building the sysroot, which fixes an issue reported in 5a26976#r31742585.
1 parent c34fc21 commit 7358641

File tree

1 file changed

+12
-36
lines changed

1 file changed

+12
-36
lines changed

src/sysroot.rs

+12-36
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,7 @@ fn build(
4444
let dst = rustlib.parent().join("lib");
4545
util::mkdir(&dst)?;
4646

47-
build_libcore(cmode, &ctoml, home, src, &dst, verbose)?;
48-
build_liballoc(cmode, &ctoml, home, src, &dst, config, verbose)?;
47+
build_liballoc(cmode, &ctoml, src, &dst, config, verbose)?;
4948

5049
// Create hash file
5150
util::write(&rustlib.parent().join(".hash"), &hash.to_string())?;
@@ -58,7 +57,6 @@ fn build_crate(
5857
mut stoml: String,
5958
cmode: &CompilationMode,
6059
ctoml: &cargo::Toml,
61-
home: &Home,
6260
dst: &Path,
6361
verbose: bool,
6462
) -> Result<()> {
@@ -113,7 +111,6 @@ fn build_crate(
113111
}
114112

115113
cmd.arg("--");
116-
cmd.env("RUSTFLAGS", &format!("--sysroot {}", home.display()));
117114
cmd.arg("-Z");
118115
cmd.arg("force-unstable-if-unmarked");
119116

@@ -131,39 +128,9 @@ fn build_crate(
131128
Ok(())
132129
}
133130

134-
fn build_libcore(
135-
cmode: &CompilationMode,
136-
ctoml: &cargo::Toml,
137-
home: &Home,
138-
src: &Src,
139-
dst: &Path,
140-
verbose: bool,
141-
) -> Result<()> {
142-
const TOML: &'static str = r#"
143-
[package]
144-
authors = ["The Rust Project Developers"]
145-
name = "sysroot"
146-
version = "0.0.0"
147-
"#;
148-
149-
let mut stoml = TOML.to_owned();
150-
151-
let path = src.path().join("libcore").display().to_string();
152-
let mut core_dep = Table::new();
153-
core_dep.insert("path".to_owned(), Value::String(path));
154-
let mut deps = Table::new();
155-
deps.insert("core".to_owned(), Value::Table(core_dep));
156-
let mut map = Table::new();
157-
map.insert("dependencies".to_owned(), Value::Table(deps));
158-
stoml.push_str(&Value::Table(map).to_string());
159-
160-
build_crate("core", stoml, cmode, ctoml, home, dst, verbose)
161-
}
162-
163131
fn build_liballoc(
164132
cmode: &CompilationMode,
165133
ctoml: &cargo::Toml,
166-
home: &Home,
167134
src: &Src,
168135
dst: &Path,
169136
config: &Config,
@@ -182,9 +149,18 @@ version = "0.1.0"
182149
let mut stoml = TOML.to_owned();
183150

184151
if config.memcpy {
185-
stoml.push_str("features = [\"mem\"]\n");
152+
stoml.push_str("features = [\"mem\", \"core\"]\n");
153+
} else {
154+
stoml.push_str("features = [\"rustc-std-workspace-core\"]\n");
186155
}
187156

157+
stoml.push_str("[dependencies.core]\n");
158+
stoml.push_str(&format!("path = \"{}\"\n", src.path().join("libcore").display()));
159+
160+
stoml.push_str("[patch.crates-io.rustc-std-workspace-core]\n");
161+
stoml.push_str(&format!("path = '{}'\n",
162+
src.path().join("tools/rustc-std-workspace-core").display()));
163+
188164
let path = src.path().join("liballoc/lib.rs").display().to_string();
189165
let mut map = Table::new();
190166
let mut lib = Table::new();
@@ -193,7 +169,7 @@ version = "0.1.0"
193169
map.insert("lib".to_owned(), Value::Table(lib));
194170
stoml.push_str(&Value::Table(map).to_string());
195171

196-
build_crate("alloc", stoml, cmode, ctoml, home, dst, verbose)
172+
build_crate("alloc", stoml, cmode, ctoml, dst, verbose)
197173
}
198174

199175
fn old_hash(cmode: &CompilationMode, home: &Home) -> Result<Option<u64>> {

0 commit comments

Comments
 (0)