Skip to content

Commit

Permalink
models build.rs: remove early exit for target toolchain
Browse files Browse the repository at this point in the history
This is a partial revert of 79465cd; the nicer
structure for main() is kept, but the actual early-exit is removed.

We don't actually need the early-exit if it's safe to run this build.rs in
parallel, which it is since 3943a32 introduced
safe link swapping.  The other action it takes, README generation, is skipped
during production builds, and would be obvious if it went wrong during local
builds due to version controlled changes, though it should also be safe there
as long as our READMEs don't balloon and become unsafe to write in parallel.

The reason for removing this is that it effectively worked by chance, because
we were running non-static builds before static builds.  We'd like to run both
sets of builds in parallel to save a significant amount of time.  Static
builds, as run in os.spec, only run build.rs once, with a vendor of
"bottlerocket".  This means build.rs was skipped, and unless non-static builds
won the race and ran their build.rs before static builds got to that crate, the
link wouldn't be created and the build would fail.
  • Loading branch information
tjkirch committed Mar 5, 2021
1 parent 3cf102d commit a7f68d7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
4 changes: 2 additions & 2 deletions sources/api/storewolf/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ merge-toml = { path = "merge-toml" }
# We have a models build-dep because we read default settings from the models
# directory and need its build.rs to run first; we also reflect the dependency
# with cargo:rerun-if-changed statements in our build.rs. The models build.rs
# runs twice, once for the above dependency and once for this build-dependency;
# there's a check in models build.rs to skip running the second time.
# runs twice, once for the above dependency and once for this build-dependency,
# so it's important that it remains reentrant.
models = { path = "../../models" }
snafu = "0.6"
toml = "0.5"
Expand Down
10 changes: 2 additions & 8 deletions sources/models/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,12 @@ const MOD_LINK: &str = "src/variant/mod.rs";
const VARIANT_ENV: &str = "VARIANT";

fn main() {
// Tell cargo when we have to rerun, regardless of early-exit below.
// Tell cargo when we have to rerun; we always want variant links to be correct, especially
// after changing the variant we're building for.
println!("cargo:rerun-if-env-changed={}", VARIANT_ENV);
println!("cargo:rerun-if-changed={}", VARIANT_LINK);
println!("cargo:rerun-if-changed={}", MOD_LINK);

// This build.rs runs once as a build-dependency of storewolf, and again as a (regular)
// dependency of storewolf. There's no reason to do this work twice.
if env::var("CARGO_CFG_TARGET_VENDOR").unwrap_or_else(|_| String::new()) == "bottlerocket" {
println!("cargo:warning=Already ran model build.rs for host, skipping for target");
process::exit(0);
}

generate_readme();
link_current_variant();
}
Expand Down

0 comments on commit a7f68d7

Please sign in to comment.