mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Add multiple build scripts to unit deps
This commit is contained in:
parent
72290ad03a
commit
a24abd6fc2
@ -343,7 +343,11 @@ fn compute_deps(
|
|||||||
if unit.target.is_custom_build() {
|
if unit.target.is_custom_build() {
|
||||||
return Ok(ret);
|
return Ok(ret);
|
||||||
}
|
}
|
||||||
ret.extend(dep_build_script(unit, unit_for, state)?);
|
ret.extend(
|
||||||
|
dep_build_script(unit, unit_for, state)?
|
||||||
|
.into_iter()
|
||||||
|
.flatten(),
|
||||||
|
);
|
||||||
|
|
||||||
// If this target is a binary, test, example, etc, then it depends on
|
// If this target is a binary, test, example, etc, then it depends on
|
||||||
// the library of the same package. The call to `resolve.deps` above
|
// the library of the same package. The call to `resolve.deps` above
|
||||||
@ -645,7 +649,11 @@ fn compute_deps_doc(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Be sure to build/run the build script for documented libraries.
|
// Be sure to build/run the build script for documented libraries.
|
||||||
ret.extend(dep_build_script(unit, unit_for, state)?);
|
ret.extend(
|
||||||
|
dep_build_script(unit, unit_for, state)?
|
||||||
|
.into_iter()
|
||||||
|
.flatten(),
|
||||||
|
);
|
||||||
|
|
||||||
// If we document a binary/example, we need the library available.
|
// If we document a binary/example, we need the library available.
|
||||||
if unit.target.is_bin() || unit.target.is_example() {
|
if unit.target.is_bin() || unit.target.is_example() {
|
||||||
@ -731,11 +739,12 @@ fn dep_build_script(
|
|||||||
unit: &Unit,
|
unit: &Unit,
|
||||||
unit_for: UnitFor,
|
unit_for: UnitFor,
|
||||||
state: &State<'_, '_>,
|
state: &State<'_, '_>,
|
||||||
) -> CargoResult<Option<UnitDep>> {
|
) -> CargoResult<Option<Vec<UnitDep>>> {
|
||||||
|
Some(
|
||||||
unit.pkg
|
unit.pkg
|
||||||
.targets()
|
.targets()
|
||||||
.iter()
|
.iter()
|
||||||
.find(|t| t.is_custom_build())
|
.filter(|t| t.is_custom_build())
|
||||||
.map(|t| {
|
.map(|t| {
|
||||||
// The profile stored in the Unit is the profile for the thing
|
// The profile stored in the Unit is the profile for the thing
|
||||||
// the custom build script is running for.
|
// the custom build script is running for.
|
||||||
@ -778,6 +787,8 @@ fn dep_build_script(
|
|||||||
IS_NO_ARTIFACT_DEP,
|
IS_NO_ARTIFACT_DEP,
|
||||||
)
|
)
|
||||||
})
|
})
|
||||||
|
.collect(),
|
||||||
|
)
|
||||||
.transpose()
|
.transpose()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -436,13 +436,12 @@ fn custom_build_script_first_index_script_failed() {
|
|||||||
.with_status(101)
|
.with_status(101)
|
||||||
.with_stderr_data(str![[r#"
|
.with_stderr_data(str![[r#"
|
||||||
[COMPILING] foo v0.1.0 ([ROOT]/foo)
|
[COMPILING] foo v0.1.0 ([ROOT]/foo)
|
||||||
[RUNNING] `rustc --crate-name build_script_build1 --edition=2024 build1.rs [..]--crate-type bin [..]`
|
...
|
||||||
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build1`
|
|
||||||
[ERROR] failed to run custom build command for `foo v0.1.0 ([ROOT]/foo)`
|
[ERROR] failed to run custom build command for `foo v0.1.0 ([ROOT]/foo)`
|
||||||
|
|
||||||
Caused by:
|
Caused by:
|
||||||
process didn't exit successfully: `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build1` ([EXIT_STATUS]: 101)
|
process didn't exit successfully: `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build1` ([EXIT_STATUS]: 101)
|
||||||
|
...
|
||||||
"#]])
|
"#]])
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
@ -472,14 +471,15 @@ fn custom_build_script_second_index_script_failed() {
|
|||||||
|
|
||||||
p.cargo("check -v")
|
p.cargo("check -v")
|
||||||
.masquerade_as_nightly_cargo(&["multiple-build-scripts"])
|
.masquerade_as_nightly_cargo(&["multiple-build-scripts"])
|
||||||
.with_status(0)
|
.with_status(101)
|
||||||
.with_stderr_data(str![[r#"
|
.with_stderr_data(str![[r#"
|
||||||
[COMPILING] foo v0.1.0 ([ROOT]/foo)
|
[COMPILING] foo v0.1.0 ([ROOT]/foo)
|
||||||
[RUNNING] `rustc --crate-name build_script_build1 --edition=2024 build1.rs [..]--crate-type bin [..]`
|
...
|
||||||
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build1`
|
[ERROR] failed to run custom build command for `foo v0.1.0 ([ROOT]/foo)`
|
||||||
[RUNNING] `rustc --crate-name foo --edition=2024 src/main.rs [..] --crate-type bin [..]`
|
|
||||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
|
||||||
|
|
||||||
|
Caused by:
|
||||||
|
process didn't exit successfully: `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build2` ([EXIT_STATUS]: 101)
|
||||||
|
...
|
||||||
"#]])
|
"#]])
|
||||||
.run();
|
.run();
|
||||||
}
|
}
|
||||||
@ -602,7 +602,7 @@ fn build_script_with_conflicting_out_dirs() {
|
|||||||
.masquerade_as_nightly_cargo(&["multiple-build-scripts"])
|
.masquerade_as_nightly_cargo(&["multiple-build-scripts"])
|
||||||
.with_status(0)
|
.with_status(0)
|
||||||
.with_stdout_data(str![[r#"
|
.with_stdout_data(str![[r#"
|
||||||
Hello, from Build Script 1!
|
Hello, from Build Script 2!
|
||||||
|
|
||||||
"#]])
|
"#]])
|
||||||
.run();
|
.run();
|
||||||
@ -614,23 +614,34 @@ fn rerun_untracks_other_files() {
|
|||||||
.file(
|
.file(
|
||||||
"Cargo.toml",
|
"Cargo.toml",
|
||||||
r#"
|
r#"
|
||||||
|
cargo-features = ["multiple-build-scripts"]
|
||||||
|
|
||||||
[package]
|
[package]
|
||||||
name = "foo"
|
name = "foo"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
edition = "2024"
|
edition = "2024"
|
||||||
|
build = ["build1.rs", "build2.rs"]
|
||||||
"#,
|
"#,
|
||||||
)
|
)
|
||||||
.file("src/main.rs", "fn main() {}")
|
.file("src/main.rs", "fn main() {}")
|
||||||
.file(
|
.file(
|
||||||
"build.rs",
|
"build1.rs",
|
||||||
r#"
|
r#"
|
||||||
fn main() {
|
fn main() {
|
||||||
foo();
|
foo();
|
||||||
bar();
|
|
||||||
}
|
}
|
||||||
fn foo() {
|
fn foo() {
|
||||||
let _path = "assets/foo.txt";
|
let _path = "assets/foo.txt";
|
||||||
}
|
}
|
||||||
|
"#,
|
||||||
|
)
|
||||||
|
.file(
|
||||||
|
"build2.rs",
|
||||||
|
r#"
|
||||||
|
fn main() {
|
||||||
|
bar();
|
||||||
|
}
|
||||||
|
|
||||||
fn bar() {
|
fn bar() {
|
||||||
let path = "assets/bar.txt";
|
let path = "assets/bar.txt";
|
||||||
println!("cargo::rerun-if-changed={path}");
|
println!("cargo::rerun-if-changed={path}");
|
||||||
@ -639,27 +650,34 @@ fn bar() {
|
|||||||
.file("assets/foo.txt", "foo")
|
.file("assets/foo.txt", "foo")
|
||||||
.file("assets/bar.txt", "bar")
|
.file("assets/bar.txt", "bar")
|
||||||
.build();
|
.build();
|
||||||
p.cargo("check").run();
|
p.cargo("check")
|
||||||
|
.masquerade_as_nightly_cargo(&["multiple-build-scripts"])
|
||||||
// Editing foo.txt won't recompile, leading to unnoticed changes
|
.run();
|
||||||
|
|
||||||
|
// Editing foo.txt will also recompile now since they are separate build scripts
|
||||||
p.change_file("assets/foo.txt", "foo updated");
|
p.change_file("assets/foo.txt", "foo updated");
|
||||||
p.cargo("check -v")
|
p.cargo("check -v")
|
||||||
|
.masquerade_as_nightly_cargo(&["multiple-build-scripts"])
|
||||||
.with_stderr_data(str![[r#"
|
.with_stderr_data(str![[r#"
|
||||||
[FRESH] foo v0.1.0 ([ROOT]/foo)
|
[DIRTY] foo v0.1.0 ([ROOT]/foo): the [..]
|
||||||
|
[COMPILING] foo v0.1.0 ([ROOT]/foo)
|
||||||
|
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build1`
|
||||||
|
[RUNNING] `rustc --crate-name foo --edition=2024 src/main.rs [..] --crate-type bin [..]
|
||||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||||
|
|
||||||
"#]])
|
"#]])
|
||||||
.run();
|
.run();
|
||||||
|
|
||||||
// Editing bar.txt will recompile
|
// Editing bar.txt will also recompile now since they are separate build scripts
|
||||||
|
|
||||||
p.change_file("assets/bar.txt", "bar updated");
|
p.change_file("assets/bar.txt", "bar updated");
|
||||||
p.cargo("check -v")
|
p.cargo("check -v")
|
||||||
|
.masquerade_as_nightly_cargo(&["multiple-build-scripts"])
|
||||||
.with_stderr_data(str![[r#"
|
.with_stderr_data(str![[r#"
|
||||||
[DIRTY] foo v0.1.0 ([ROOT]/foo): the file `assets/bar.txt` has changed ([TIME_DIFF_AFTER_LAST_BUILD])
|
[DIRTY] foo v0.1.0 ([ROOT]/foo): the [..]
|
||||||
[COMPILING] foo v0.1.0 ([ROOT]/foo)
|
[COMPILING] foo v0.1.0 ([ROOT]/foo)
|
||||||
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build`
|
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build[..]`
|
||||||
|
[RUNNING] `[ROOT]/foo/target/debug/build/foo-[HASH]/build-script-build[..]`
|
||||||
[RUNNING] `rustc --crate-name foo --edition=2024 src/main.rs [..] --crate-type bin [..]
|
[RUNNING] `rustc --crate-name foo --edition=2024 src/main.rs [..] --crate-type bin [..]
|
||||||
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
[FINISHED] `dev` profile [unoptimized + debuginfo] target(s) in [ELAPSED]s
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user