Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add support for a "build-all" task #357

Merged
merged 6 commits into from
Sep 6, 2024

Conversation

bcressey
Copy link
Contributor

Issue number:
N/A

Description of changes:
This is a follow-up to #282 that removes the last of buildsys's dependencies on BUILDSYS_VARIANT and friends. That in turn makes it possible to add a "build-all" target to Makefile.toml, which will help speed up CI runs.

(Note that there's still no "publish-all" target; pubsys continues to rely on BUILDSYS_VARIANT to know what to publish.)

Testing done:
For x86_64:

❯ cargo make build-all
...
[cargo-make][1] INFO - Running Task: build-all
   Compiling settings-plugins v0.1.0 (/home/fedora/brdev/packages/settings-plugins)
   Compiling settings-defaults v0.1.0 (/home/fedora/brdev/packages/settings-defaults)
   Compiling settings-migrations v0.1.0 (/home/fedora/brdev/packages/settings-migrations)
   Compiling common v0.0.0 (/home/fedora/brdev/packages/common)
   Compiling metal-k8s-1_28 v0.1.0 (/home/fedora/brdev/variants/metal-k8s-1.28)
   Compiling aws-k8s-1_27-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.27-nvidia)
   Compiling metal-k8s-1_29 v0.1.0 (/home/fedora/brdev/variants/metal-k8s-1.29)
   Compiling vmware-dev v0.1.0 (/home/fedora/brdev/variants/vmware-dev)
   Compiling aws-k8s-1_28 v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.28)
   Compiling metal-dev v0.1.0 (/home/fedora/brdev/variants/metal-dev)
   Compiling vmware-k8s-1_27 v0.1.0 (/home/fedora/brdev/variants/vmware-k8s-1.27)
   Compiling vmware-k8s-1_28 v0.1.0 (/home/fedora/brdev/variants/vmware-k8s-1.28)
   Compiling aws-k8s-1_24-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.24-nvidia)
   Compiling aws-k8s-1_27 v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.27)
   Compiling aws-k8s-1_28-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.28-nvidia)
   Compiling vmware-k8s-1_30 v0.1.0 (/home/fedora/brdev/variants/vmware-k8s-1.30)
   Compiling aws-k8s-1_30 v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.30)
   Compiling aws-k8s-1_30-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.30-nvidia)
   Compiling aws-k8s-1_25-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.25-nvidia)
   Compiling aws-k8s-1_26 v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.26)
   Compiling aws-k8s-1_23 v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.23)
   Compiling vmware-k8s-1_29 v0.1.0 (/home/fedora/brdev/variants/vmware-k8s-1.29)
   Compiling aws-k8s-1_25 v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.25)
   Compiling aws-ecs-2 v0.1.0 (/home/fedora/brdev/variants/aws-ecs-2)
   Compiling aws-k8s-1_26-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.26-nvidia)
   Compiling aws-k8s-1_24 v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.24)
   Compiling aws-k8s-1_23-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.23-nvidia)
   Compiling aws-k8s-1_29-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.29-nvidia)
   Compiling aws-ecs-1 v0.1.0 (/home/fedora/brdev/variants/aws-ecs-1)
   Compiling aws-ecs-1-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-ecs-1-nvidia)
   Compiling aws-ecs-2-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-ecs-2-nvidia)
   Compiling aws-k8s-1_29 v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.29)
   Compiling metal-k8s-1_27 v0.1.0 (/home/fedora/brdev/variants/metal-k8s-1.27)
   Compiling aws-dev v0.1.0 (/home/fedora/brdev/variants/aws-dev)
    Finished `dev` profile [optimized] target(s) in 7m 04s

And for aarch64:

❯ cargo make -e BUILDSYS_ARCH=aarch64 build-all
...
[cargo-make][1] INFO - Running Task: build-all
   Compiling settings-defaults v0.1.0 (/home/fedora/brdev/packages/settings-defaults)
   Compiling settings-plugins v0.1.0 (/home/fedora/brdev/packages/settings-plugins)
   Compiling common v0.0.0 (/home/fedora/brdev/packages/common)
   Compiling settings-migrations v0.1.0 (/home/fedora/brdev/packages/settings-migrations)
   Compiling aws-ecs-1-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-ecs-1-nvidia)
   Compiling vmware-k8s-1_30 v0.1.0 (/home/fedora/brdev/variants/vmware-k8s-1.30)
   Compiling aws-k8s-1_27-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.27-nvidia)
   Compiling aws-ecs-2-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-ecs-2-nvidia)
   Compiling vmware-k8s-1_27 v0.1.0 (/home/fedora/brdev/variants/vmware-k8s-1.27)
   Compiling aws-k8s-1_24 v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.24)
   Compiling aws-k8s-1_29 v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.29)
   Compiling aws-k8s-1_30-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.30-nvidia)
   Compiling vmware-dev v0.1.0 (/home/fedora/brdev/variants/vmware-dev)
   Compiling aws-k8s-1_26-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.26-nvidia)
   Compiling aws-k8s-1_23 v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.23)
   Compiling aws-k8s-1_26 v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.26)
   Compiling aws-k8s-1_25 v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.25)
   Compiling aws-k8s-1_28 v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.28)
   Compiling vmware-k8s-1_28 v0.1.0 (/home/fedora/brdev/variants/vmware-k8s-1.28)
   Compiling aws-dev v0.1.0 (/home/fedora/brdev/variants/aws-dev)
   Compiling metal-k8s-1_27 v0.1.0 (/home/fedora/brdev/variants/metal-k8s-1.27)
   Compiling metal-dev v0.1.0 (/home/fedora/brdev/variants/metal-dev)
   Compiling metal-k8s-1_28 v0.1.0 (/home/fedora/brdev/variants/metal-k8s-1.28)
   Compiling aws-k8s-1_27 v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.27)
   Compiling aws-k8s-1_28-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.28-nvidia)
   Compiling aws-ecs-1 v0.1.0 (/home/fedora/brdev/variants/aws-ecs-1)
   Compiling aws-k8s-1_24-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.24-nvidia)
   Compiling aws-k8s-1_23-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.23-nvidia)
   Compiling metal-k8s-1_29 v0.1.0 (/home/fedora/brdev/variants/metal-k8s-1.29)
   Compiling aws-ecs-2 v0.1.0 (/home/fedora/brdev/variants/aws-ecs-2)
   Compiling aws-k8s-1_29-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.29-nvidia)
   Compiling aws-k8s-1_30 v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.30)
   Compiling aws-k8s-1_25-nvidia v0.1.0 (/home/fedora/brdev/variants/aws-k8s-1.25-nvidia)
   Compiling vmware-k8s-1_29 v0.1.0 (/home/fedora/brdev/variants/vmware-k8s-1.29)
warning: [email protected]: aarch64 is not one of the supported architectures (["x86_64"])
warning: [email protected]: aarch64 is not one of the supported architectures (["x86_64"])
warning: [email protected]: aarch64 is not one of the supported architectures (["x86_64"])
warning: [email protected]: aarch64 is not one of the supported architectures (["x86_64"])
warning: [email protected]: aarch64 is not one of the supported architectures (["x86_64"])
warning: [email protected]: aarch64 is not one of the supported architectures (["x86_64"])
warning: [email protected]: aarch64 is not one of the supported architectures (["x86_64"])
warning: [email protected]: aarch64 is not one of the supported architectures (["x86_64"])
    Finished `dev` profile [optimized] target(s) in 6m 40s
[cargo-make][1] INFO - Build Done in 402.34 seconds.

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

This was previously used to force variants to rebuild every time the
build was invoked. Now that the dependency tracking is more robust,
this can be safely dropped so that images will only be rebuilt when
one of their inputs has changed.

Signed-off-by: Ben Cressey <[email protected]>
When building all variants, `cargo` will start many builds at once,
which won't match up with the value in the environment variable.

Instead, use CARGO_MANIFEST_DIR to determine which variant is being
built. Parse that into its subcomponents at runtime to avoid needing
any of the other variant-related environment variables.

Signed-off-by: Ben Cressey <[email protected]>
Rather than failing the build for an unsupported architecture, emit a
warning. Otherwise, building all variants would always fail if any
variant definition did not support the requested architecture.

Signed-off-by: Ben Cressey <[email protected]>
`buildsys` now parses the variant components on its own, and ignores
these environment variables.

Signed-off-by: Ben Cressey <[email protected]>
Previously, this functionality was in a separate binary because the
environment variables needed to be set prior to `buildsys` invocation
so that `cargo` could track them for change detection purposes. Now
that packages can't be conditionally compiled based on the variant,
change detection isn't required, so the binary can be removed.

Signed-off-by: Ben Cressey <[email protected]>

# 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}/target/${BUILDSYS_ARCH}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit. might want quotes

Copy link
Contributor

@cbgbt cbgbt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cool!

@@ -894,6 +894,29 @@ ln -snf "${BUILDSYS_VERSION_FULL}" "${OUTPUT_LOGS_DIR}/latest"
'''
]

[tasks.build-all]
dependencies = ["fetch", "build-sbkeys", "publish-setup", "cargo-metadata"]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either this PR or #361 will need to rebase here. I have no problem doing so, and I think you have your approvals first!

Comment on lines 903 to 904
# 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.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This comment doesn't seem correct anymore, since we don't build host tools in Makefile.toml. Maybe we can just set CARGO_TARGET_DIR everywhere?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can just set CARGO_TARGET_DIR everywhere?

Maybe, though there could be unexpected interactions with other uses of cargo, like cargo test in the unit tests task.

Copy link
Contributor

@jmt-lab jmt-lab left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

`buildsys` no longer depends on BUILDSYS_VARIANT, so it's OK to have
a task that tells cargo to build everything in the workspace.

Since various scripts might depend on the "latest" symlink created by
the "build-variant" task, create the same links in the "build-all"
task.

Signed-off-by: Ben Cressey <[email protected]>
@bcressey
Copy link
Contributor Author

bcressey commented Sep 6, 2024

⬆️ force push to update CARGO_TARGET_DIR comments and add quotes where they were missing.

@bcressey bcressey merged commit f835018 into bottlerocket-os:develop Sep 6, 2024
1 check passed
@bcressey bcressey deleted the build-all-variants branch September 6, 2024 21:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants