From 18c6be33606a0f8c8b6fcfa140983841c7c3bbc7 Mon Sep 17 00:00:00 2001 From: Tom Kirchner Date: Mon, 21 Jun 2021 09:55:27 -0700 Subject: [PATCH] Store build artifacts per architecture Previously, switching between architectures would rebuild all artifacts, which can make building and testing changes painful. This change makes cargo and buildsys store their state in arch-specific directories, so when you switch, they can find the last artifacts they built for that arch. --- Makefile.toml | 11 +++++++++++ tools/buildsys/src/builder.rs | 11 ++++++----- 2 files changed, 17 insertions(+), 5 deletions(-) diff --git a/Makefile.toml b/Makefile.toml index 2134bea385e..191a901e269 100644 --- a/Makefile.toml +++ b/Makefile.toml @@ -325,7 +325,13 @@ if [ -z "${PACKAGE}" ]; then echo "cargo make build-package -e PACKAGE=kernel" exit 1 fi + export PATH="${BUILDSYS_TOOLS_DIR}/bin:${PATH}" + +# Save built artifacts for each architecture. We don't set this everywhere +# because we build host tools with cargo as well, like buildsys and pubsys. +export CARGO_TARGET_DIR=${BUILDSYS_ROOT_DIR}/variants/target/${BUILDSYS_ARCH} + cargo build \ ${CARGO_BUILD_ARGS} \ ${CARGO_MAKE_CARGO_ARGS} \ @@ -339,6 +345,11 @@ dependencies = ["build-tools", "publish-setup"] script = [ ''' export PATH="${BUILDSYS_TOOLS_DIR}/bin:${PATH}" + +# Save built artifacts for each architecture. We don't set this everywhere +# because we build host tools with cargo as well, like buildsys and pubsys. +export CARGO_TARGET_DIR=${BUILDSYS_ROOT_DIR}/variants/target/${BUILDSYS_ARCH} + cargo build \ ${CARGO_BUILD_ARGS} \ ${CARGO_MAKE_CARGO_ARGS} \ diff --git a/tools/buildsys/src/builder.rs b/tools/buildsys/src/builder.rs index 05e92aac584..19afa0fa837 100644 --- a/tools/buildsys/src/builder.rs +++ b/tools/buildsys/src/builder.rs @@ -103,7 +103,7 @@ impl PackageBuilder { arch = arch, ); - build(BuildType::Package, &package, args, &tag, &output_dir)?; + build(BuildType::Package, &package, &arch, args, &tag, &output_dir)?; Ok(Self) } @@ -160,7 +160,7 @@ impl VariantBuilder { arch = arch ); - build(BuildType::Variant, &variant, args, &tag, &output_dir)?; + build(BuildType::Variant, &variant, &arch, args, &tag, &output_dir)?; Ok(Self) } @@ -177,6 +177,7 @@ enum BuildType { fn build( kind: BuildType, what: &str, + arch: &str, build_args: Vec, tag: &str, output_dir: &PathBuf, @@ -200,7 +201,7 @@ fn build( let nocache = rand::thread_rng().gen::(); // Create a directory for tracking outputs before we move them into position. - let build_dir = create_build_dir(&kind, &what)?; + let build_dir = create_build_dir(&kind, &what, &arch)?; // Clean up any previous outputs we have tracked. clean_build_files(&build_dir, &output_dir)?; @@ -318,13 +319,13 @@ enum Retry<'a> { // =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= /// Create a directory for build artifacts. -fn create_build_dir(kind: &BuildType, name: &str) -> Result { +fn create_build_dir(kind: &BuildType, name: &str, arch: &str) -> Result { let prefix = match kind { BuildType::Package => "packages", BuildType::Variant => "variants", }; - let path = [&getenv("BUILDSYS_STATE_DIR")?, prefix, name] + let path = [&getenv("BUILDSYS_STATE_DIR")?, arch, prefix, name] .iter() .collect();