Skip to content

Commit 72346fd

Browse files
committed
Support -Zbuild-std
1 parent fb99ff7 commit 72346fd

File tree

2 files changed

+56
-4
lines changed

2 files changed

+56
-4
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
* Support `-Zbuild-std`.
13+
1214
### Fixed
1315

1416
### Changed

src/dependencies.rs

Lines changed: 54 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,26 @@ fn cfgs(config: &Config) -> Result<Vec<Cfg>, Errored> {
7878
Ok(cfgs)
7979
}
8080

81+
pub(crate) fn has_build_std(info: &DependencyBuilder) -> bool {
82+
let mut args = info.program.args.iter();
83+
84+
while let Some(arg) = args.next() {
85+
if arg == "-Z" {
86+
if let Some(arg) = args.next().map(|arg| arg.to_string_lossy()) {
87+
if arg.starts_with("build-std") {
88+
return true;
89+
}
90+
}
91+
}
92+
93+
if arg.to_string_lossy().starts_with("-Zbuild-std") {
94+
return true;
95+
}
96+
}
97+
98+
false
99+
}
100+
81101
/// Compiles dependencies and returns the crate names and corresponding rmeta files.
82102
fn build_dependencies_inner(
83103
config: &Config,
@@ -166,15 +186,18 @@ fn build_dependencies_inner(
166186
.target
167187
.crate_types
168188
.iter()
169-
.all(|ctype| !matches!(ctype.as_str(), "proc-macro" | "lib"))
189+
.all(|ctype| !matches!(ctype.as_str(), "proc-macro" | "lib" | "rlib"))
170190
{
171191
continue;
172192
}
173193
for filename in &artifact.filenames {
174194
import_paths.insert(filename.parent().unwrap().into());
175195
}
176196
let package_id = artifact.package_id;
177-
if let Some(prev) = artifacts.insert(package_id.clone(), Ok(artifact.filenames)) {
197+
if let Some(prev) = artifacts.insert(
198+
package_id.clone(),
199+
Ok((artifact.target.name, artifact.filenames)),
200+
) {
178201
artifacts.insert(
179202
package_id.clone(),
180203
Err(format!(
@@ -252,7 +275,7 @@ fn build_dependencies_inner(
252275
.unwrap();
253276

254277
// Then go over all of its dependencies
255-
let dependencies = root
278+
let mut dependencies = root
256279
.dependencies
257280
.iter()
258281
.filter(|dep| matches!(dep.kind, DependencyKind::Normal))
@@ -284,7 +307,7 @@ fn build_dependencies_inner(
284307
let id = &package.id;
285308
// Return the name chosen in `Cargo.toml` and the path to the corresponding artifact
286309
match artifacts.remove(id) {
287-
Some(Ok(artifacts)) => Some(Ok((name.replace('-', "_"), artifacts))),
310+
Some(Ok((_, artifacts))) => Some(Ok((name.replace('-', "_"), artifacts))),
288311
Some(Err(what)) => Some(Err(Errored {
289312
command: Command::new(what),
290313
errors: vec![],
@@ -306,6 +329,28 @@ fn build_dependencies_inner(
306329
.collect::<Result<Vec<_>, Errored>>()?;
307330
let import_paths = import_paths.into_iter().collect();
308331
let import_libs = import_libs.into_iter().collect();
332+
333+
if has_build_std(info) {
334+
let mut build_std_crates = HashSet::new();
335+
build_std_crates.insert("core");
336+
build_std_crates.insert("alloc");
337+
build_std_crates.insert("proc_macro");
338+
build_std_crates.insert("panic_unwind");
339+
build_std_crates.insert("compiler_builtins");
340+
build_std_crates.insert("std");
341+
build_std_crates.insert("test");
342+
build_std_crates.insert("panic_abort");
343+
344+
for (name, artifacts) in artifacts
345+
.into_iter()
346+
.filter_map(|(_, artifacts)| artifacts.ok())
347+
{
348+
if build_std_crates.remove(name.as_str()) {
349+
dependencies.push((format!("noprelude:{name}"), artifacts));
350+
}
351+
}
352+
}
353+
309354
return Ok(Dependencies {
310355
dependencies,
311356
import_paths,
@@ -381,6 +426,11 @@ pub fn build_dependencies(
381426
) -> Result<Vec<OsString>, Errored> {
382427
let dependencies = build_dependencies_inner(config, info)?;
383428
let mut args = vec![];
429+
430+
if has_build_std(info) {
431+
args.push("-Zunstable-options".into());
432+
}
433+
384434
for (name, artifacts) in dependencies.dependencies {
385435
for dependency in artifacts {
386436
args.push("--extern".into());

0 commit comments

Comments
 (0)