Skip to content

Commit

Permalink
fix: publish bazelisk-compat windows files
Browse files Browse the repository at this point in the history
  • Loading branch information
alexeagle committed Oct 3, 2024
1 parent 080b6c8 commit 3c39f76
Show file tree
Hide file tree
Showing 7 changed files with 89 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import %workspace%/.aspect/bazelrc/performance.bazelrc
### YOUR PROJECT SPECIFIC OPTIONS GO HERE ###
common --enable_platform_specific_config

common:release -c opt --stamp --workspace_status_command "${PWD}/tools/workspace_status.sh"
common:release -c opt --stamp --workspace_status_command="node tools/workspace_status.js"

# bzlmod causes issues with LLVM toolchain
common --noenable_bzlmod
Expand Down
9 changes: 4 additions & 5 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,12 @@ jobs:
repository-cache: true
# Bootstrap: the first time we release for windows, we don't have a windows version of Aspect CLI to build with
# So use environment variables to defeat the .bazeliskrc file.
- run: bazel build //release:aspect_windows_amd64
- run: cp $(bazel cquery //release:aspect_windows_amd64 --output=files) aspect_windows_amd64.exe
- name: smoke test
run: ./aspect_windows_amd64.exe --help
- run: bazel run --config=release //release:release.windows -- /tmp/aspect/release
# Verify that we built a functional executable
- run: ./$(bazel cquery //release:aspect-windows-x86_64.exe --output=files) --help
- uses: actions/upload-artifact@v4
id: upload
with:
name: windows
retention-days: 1
path: aspect_windows_amd64.exe
path: /tmp/aspect/release
23 changes: 20 additions & 3 deletions release/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ expand_template(
)

platform_transition_filegroup(
name = "aspect_windows_amd64",
name = "aspect-windows-x86_64.exe",
srcs = ["//cmd/aspect"],
tags = ["manual"],
target_compatible_with = [
"@platforms//os:windows",
"@platforms//cpu:x86_64",
Expand All @@ -30,7 +31,14 @@ platform_transition_filegroup(
)

bazelisk_artifacts(
name = "aspect_bazelisk_artifacts",
name = "windows_artifacts",
tags = ["manual"],
version_file = ":aspect_version",
windows_x86_64 = ":aspect-windows-x86_64.exe",
)

bazelisk_artifacts(
name = "linux_and_darwin_artifacts",
darwin_arm64 = ":aspect-macos-aarch64",
darwin_x86_64 = ":aspect-macos-x86_64",
linux_arm64 = ":aspect-linux-aarch64",
Expand All @@ -44,7 +52,16 @@ release(
tags = ["manual"],
targets = [
":aspect",
":aspect_bazelisk_artifacts",
":linux_and_darwin_artifacts",
],
)

release(
name = "release.windows",
tags = ["manual"],
targets = [
":aspect-windows-x86_64.exe",
":windows_artifacts",
],
)

Expand Down
48 changes: 26 additions & 22 deletions release/bazelisk_artifacts.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -7,29 +7,29 @@ release for Bazelisk downloads.
_ATTRS = {
"darwin_arm64": attr.label(
doc = "The artifact for the darwin-arm64 platform.",
mandatory = True,
allow_single_file = True,
),
"darwin_x86_64": attr.label(
doc = "The artifact for the darwin-x86_64 platform.",
mandatory = True,
allow_single_file = True,
),
"linux_arm64": attr.label(
doc = "The artifact for the linux-arm64 platform.",
mandatory = True,
allow_single_file = True,
),
"linux_x86_64": attr.label(
doc = "The artifact for the linux-arm64 platform.",
mandatory = True,
allow_single_file = True,
),
"version_file": attr.label(
doc = "The file that contains the semver of the artifacts.",
mandatory = True,
allow_single_file = True,
),
"windows_x86_64": attr.label(
doc = "The artifact for the windows-x86_64 platform.",
allow_single_file = True,
),
"_sha256sum": attr.label(
executable = True,
cfg = "exec",
Expand All @@ -39,27 +39,31 @@ _ATTRS = {

def _impl(ctx):
outdir = ctx.actions.declare_directory(ctx.label.name)

inputs = [
ctx.file.version_file,
ctx.file.darwin_arm64,
ctx.file.darwin_x86_64,
ctx.file.linux_arm64,
ctx.file.linux_x86_64,
]

inputs = [ctx.file.version_file]
args = ctx.actions.args()
args.add(ctx.executable._sha256sum.path)
args.add(outdir.path)
args.add(ctx.file.version_file)
args.add(ctx.file.darwin_arm64)
args.add("darwin-arm64")
args.add(ctx.file.darwin_x86_64)
args.add("darwin-x86_64")
args.add(ctx.file.linux_arm64)
args.add("linux-arm64")
args.add(ctx.file.linux_x86_64)
args.add("linux-x86_64")

if ctx.attr.windows_x86_64:
inputs.append(ctx.file.windows_x86_64)
args.add(ctx.file.windows_x86_64)
args.add("windows-x86_64.exe")
else:
inputs.extend([
ctx.file.darwin_arm64,
ctx.file.darwin_x86_64,
ctx.file.linux_arm64,
ctx.file.linux_x86_64,
])
args.add(ctx.file.darwin_arm64)
args.add("darwin-arm64")
args.add(ctx.file.darwin_x86_64)
args.add("darwin-x86_64")
args.add(ctx.file.linux_arm64)
args.add("linux-arm64")
args.add(ctx.file.linux_x86_64)
args.add("linux-x86_64")

ctx.actions.run_shell(
outputs = [outdir],
Expand All @@ -77,7 +81,7 @@ version="$(< "${version_file}")"
mkdir -p "${output_dir}"
while (("$#")); do
# Read args three at a time
# Read args in pairs
artifact_path="$1"
platform_suffix="$2"
shift 2
Expand Down
2 changes: 1 addition & 1 deletion release/release.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ def release(name, targets, **kwargs):
native.genrule(
name = name,
srcs = targets,
outs = ["release.sh"],
outs = [name + ".sh"],
executable = True,
cmd = "./$(location //release:create_release.sh) {locations} > \"$@\"".format(
locations = " ".join(["$(locations {})".format(target) for target in targets]),
Expand Down
37 changes: 37 additions & 0 deletions tools/workspace_status.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env node
// This script is called by Bazel when it needs info about the git state.
// The --workspace_status_command flag tells Bazel the location of this script.
// This is configured in `/.bazelrc`.
import { execSync } from 'node:child_process';

// "stable" keys, should remain constant over rebuilds, therefore changed values will cause a
// rebuild of any stamped action that uses ctx.info_file or genrule with stamp = True
// Note, BUILD_USER is automatically available in the stable-status.txt, it matches $USER
const has_local_changes = execSync('git status --porcelain').length > 0;
console.log(`STABLE_BUILD_SCM_SHA ${execSync('git rev-parse HEAD')}`);
console.log(`STABLE_BUILD_SCM_LOCAL_CHANGES ${has_local_changes}`);

const gitTags = execSync('git tag');
if (gitTags.length > 0) {
// Follows https://blog.aspect.build/versioning-releases-from-a-monorepo
const monorepo_version = execSync(
`git describe --tags --long --match="[0-9][0-9][0-9][0-9].[0-9][0-9]"`,
{ encoding: 'utf-8' }
)
.replace('-', '.')
.replace('-g', '-');

// Variant of monorepo_version that conforms with the version scheme Bazelisk supports.
// It assumes the upstream `bazel` binary releases are the only ones referenced,
// so we are forced to adopt a matching scheme.
// https://github.com/bazelbuild/bazelisk/blob/47f60477721681a117cbf905784ee5220100e68b/versions/versions.go#L20-L25
const bazelisk_compat_version = monorepo_version.substring(
0,
monorepo_version.indexOf('-')
);

console.log(
`STABLE_ASPECT_CLI_BAZELISK_COMPAT_VERSION ${bazelisk_compat_version}`
);
console.log(`STABLE_ASPECT_CLI_VERSION ${monorepo_version}`);
}
41 changes: 0 additions & 41 deletions tools/workspace_status.sh

This file was deleted.

0 comments on commit 3c39f76

Please sign in to comment.