Skip to content

Commit

Permalink
Merge pull request bottlerocket-os#1630 from tjkirch/build-track-arch
Browse files Browse the repository at this point in the history
Store build artifacts per architecture
  • Loading branch information
tjkirch authored Jun 29, 2021
2 parents e593086 + 18c6be3 commit d1854a7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
11 changes: 11 additions & 0 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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} \
Expand All @@ -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} \
Expand Down
11 changes: 6 additions & 5 deletions tools/buildsys/src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down Expand Up @@ -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)
}
Expand All @@ -177,6 +177,7 @@ enum BuildType {
fn build(
kind: BuildType,
what: &str,
arch: &str,
build_args: Vec<String>,
tag: &str,
output_dir: &PathBuf,
Expand All @@ -200,7 +201,7 @@ fn build(
let nocache = rand::thread_rng().gen::<u32>();

// 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)?;
Expand Down Expand Up @@ -318,13 +319,13 @@ enum Retry<'a> {
// =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=

/// Create a directory for build artifacts.
fn create_build_dir(kind: &BuildType, name: &str) -> Result<PathBuf> {
fn create_build_dir(kind: &BuildType, name: &str, arch: &str) -> Result<PathBuf> {
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();

Expand Down

0 comments on commit d1854a7

Please sign in to comment.