diff --git a/.github/workflows/release_prep.sh b/.github/workflows/release_prep.sh index d6033f4..54e0dee 100755 --- a/.github/workflows/release_prep.sh +++ b/.github/workflows/release_prep.sh @@ -12,9 +12,9 @@ git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}') cat << EOF -## Using Bzlmod with Bazel 6 +## Using Bzlmod with Bazel 6 or greater -1. Enable with \`common --enable_bzlmod\` in \`.bazelrc\`. +1. (Bazel 6 only) Enable with \`common --enable_bzlmod\` in \`.bazelrc\`. 2. Add to your \`MODULE.bazel\` file: \`\`\`starlark diff --git a/MODULE.bazel b/MODULE.bazel index a1ca7f5..bb58a81 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -22,7 +22,7 @@ bazel_dep(name = "container_structure_test", version = "1.16.0", dev_dependency aws = use_extension("//aws:extensions.bzl", "aws") aws.toolchain(aws_cli_version = "2.13.0") -use_repo(aws, "aws_darwin", "aws_linux-aarch64", "aws_linux-x86_64", "aws_toolchains") +use_repo(aws, "aws", "aws_darwin", "aws_linux-aarch64", "aws_linux-x86_64", "aws_toolchains") oci = use_extension( "@rules_oci//oci:extensions.bzl", diff --git a/aws/repositories.bzl b/aws/repositories.bzl index d84634c..f51604b 100644 --- a/aws/repositories.bzl +++ b/aws/repositories.bzl @@ -110,7 +110,8 @@ def _aws_repo_impl(rctx): # Generated by aws/repositories.bzl load("@aspect_rules_aws//aws:toolchain.bzl", "aws_toolchain") aws_toolchain(name = "aws_toolchain", target_tool_path = "{}") -""".format(target_tool_path) +alias(name = "aws", actual = "//installed:{}/aws", visibility = ["//visibility:public"]) +""".format(target_tool_path, version_dir) # Base BUILD file for this repository rctx.file("BUILD.bazel", build_content) @@ -147,6 +148,31 @@ aws_repositories = repository_rule( attrs = _ATTRS, ) +def _aws_alias_impl(rctx): + rctx.file("BUILD.bazel", """\ +load("@bazel_skylib//rules:native_binary.bzl", "native_binary") + +native_binary( + name = "aws", + src = select( + {{ + "@bazel_tools//src/conditions:linux_x86_64": "@@{0}_linux-x86_64//:aws", + "@bazel_tools//src/conditions:linux_aarch64": "@@{0}_linux-aarch64//:aws", + "@bazel_tools//src/conditions:darwin_x86_64": "@@{0}_darwin//:aws", + "@bazel_tools//src/conditions:darwin_arm64": "@@{0}_darwin//:aws", + }}, + ), + out = "aws", + visibility = ["//visibility:public"], +) +""".format(rctx.name)) + +aws_alias = repository_rule( + _aws_alias_impl, + doc = "Create a repository that provides the AWS CLI aliases for host platforms", + attrs = {}, +) + # Wrapper macro around everything above, this is the primary API def aws_register_toolchains(name, register = True, **kwargs): """Convenience macro for users which does typical setup. @@ -163,6 +189,7 @@ def aws_register_toolchains(name, register = True, **kwargs): Should be True for WORKSPACE users, but false when used under bzlmod extension **kwargs: passed to each node_repositories call """ + aws_alias(name = name) for platform in PLATFORMS.keys(): aws_repositories( name = name + "_" + platform,