Skip to content

Commit

Permalink
Add Windows ARM64 and Refactored Targets (#601)
Browse files Browse the repository at this point in the history
* bzlmod: removed legacy repo_name override for rules_go and gazelle

* applied buildifier reformat

* ws: update godoc to reference bazel 7.2.1 instead of 6.3.0

* re-generate targets using gazelle

* add "gazelle:ignore" to root BUILD file to prevent gazelle from generating a new go_test target

* update aspect_rules_js to latest 1.x version

* add windows-arm target / refactor root BUILD to dinamically generate go_binary targets (stripped and not stripped)
  • Loading branch information
albertocavalcante committed Aug 6, 2024
1 parent 99ab439 commit 4448ad1
Show file tree
Hide file tree
Showing 12 changed files with 76 additions and 107 deletions.
106 changes: 40 additions & 66 deletions BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@aspect_rules_js//npm:defs.bzl", "npm_package", "stamped_package_json")
load("@gazelle//:def.bzl", "gazelle")
load("@rules_go//go:def.bzl", "go_binary", "go_library", "go_test")

# gazelle:ignore
# gazelle:prefix github.com/bazelbuild/bazelisk
gazelle(name = "gazelle")

Expand Down Expand Up @@ -72,33 +73,43 @@ go_binary(
visibility = ["//visibility:public"],
)

go_binary(
name = "bazelisk-darwin-amd64",
out = "bazelisk-darwin_amd64",
embed = [":bazelisk_lib"],
gc_linkopts = [
"-s",
"-w",
],
goarch = "amd64",
goos = "darwin",
pure = "on",
visibility = ["//visibility:public"],
)
[
go_binary(
name = "bazelisk-%s-%s" % (os, arch),
out = "bazelisk-%s_%s" % (os, arch),
embed = [":bazelisk_lib"],
gc_linkopts = [
"-s",
"-w",
],
goarch = arch,
goos = os,
pure = "on",
visibility = ["//visibility:public"],
)
for os, arch in [
("darwin", "amd64"),
("darwin", "arm64"),
("linux", "amd64"),
("linux", "arm64")
]
]

go_binary(
name = "bazelisk-darwin-arm64",
out = "bazelisk-darwin_arm64",
embed = [":bazelisk_lib"],
gc_linkopts = [
"-s",
"-w",
],
goarch = "arm64",
goos = "darwin",
pure = "on",
visibility = ["//visibility:public"],
)
[
go_binary(
name = "bazelisk-%s-%s" % (os, arch),
out = "bazelisk-%s_%s.exe" % (os, arch),
embed = [":bazelisk_lib"],
goarch = arch,
goos = os,
pure = "on",
visibility = ["//visibility:public"],
)
for os, arch in [
("windows", "amd64"),
("windows", "arm64")
]
]

genrule(
name = "bazelisk-darwin-universal",
Expand All @@ -114,44 +125,6 @@ genrule(
],
)

go_binary(
name = "bazelisk-linux-amd64",
out = "bazelisk-linux_amd64",
embed = [":bazelisk_lib"],
gc_linkopts = [
"-s",
"-w",
],
goarch = "amd64",
goos = "linux",
pure = "on",
visibility = ["//visibility:public"],
)

go_binary(
name = "bazelisk-linux-arm64",
out = "bazelisk-linux_arm64",
embed = [":bazelisk_lib"],
gc_linkopts = [
"-s",
"-w",
],
goarch = "arm64",
goos = "linux",
pure = "on",
visibility = ["//visibility:public"],
)

go_binary(
name = "bazelisk-windows-amd64",
out = "bazelisk-windows_amd64.exe",
embed = [":bazelisk_lib"],
goarch = "amd64",
goos = "windows",
pure = "on",
visibility = ["//visibility:public"],
)

stamped_package_json(
name = "package",
# This key is defined by /stamp.sh
Expand All @@ -170,6 +143,7 @@ npm_package(
":bazelisk-linux-amd64",
":bazelisk-linux-arm64",
":bazelisk-windows-amd64",
":bazelisk-windows-arm64",
":package",
],
package = "@bazel/bazelisk",
Expand Down
17 changes: 10 additions & 7 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,19 +1,22 @@
module(name = "bazelisk", version="")
module(
name = "bazelisk",
version = "",
)

bazel_dep(name = "gazelle", version = "0.38.0", repo_name = "bazel_gazelle")
bazel_dep(name = "gazelle", version = "0.38.0")
bazel_dep(name = "platforms", version = "0.0.10")
bazel_dep(name = "rules_go", version = "0.49.0", repo_name = "io_bazel_rules_go")
bazel_dep(name = "aspect_rules_js", version = "1.39.1")
bazel_dep(name = "rules_go", version = "0.49.0")
bazel_dep(name = "aspect_rules_js", version = "1.42.3")

go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
go_sdk = use_extension("@rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(version = "1.22.5")

go_deps = use_extension("@bazel_gazelle//:extensions.bzl", "go_deps")
go_deps = use_extension("@gazelle//:extensions.bzl", "go_deps")
go_deps.from_file(go_mod = "//:go.mod")
use_repo(
go_deps,
"com_github_bgentry_go_netrc",
"com_github_hashicorp_go_version",
"com_github_mitchellh_go_homedir",
"com_github_bgentry_go_netrc",
"org_golang_x_term",
)
5 changes: 4 additions & 1 deletion build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ go build
//:bazelisk-darwin-universal \
//:bazelisk-linux-amd64 \
//:bazelisk-linux-arm64 \
//:bazelisk-windows-amd64
//:bazelisk-windows-amd64 \
//:bazelisk-windows-arm64
echo

cp bazel-out/*-opt*/bin/bazelisk-darwin_amd64 bin/bazelisk-darwin-amd64
Expand All @@ -36,6 +37,7 @@ cp bazel-out/*-opt*/bin/bazelisk-darwin_universal bin/bazelisk-darwin
cp bazel-out/*-opt*/bin/bazelisk-linux_amd64 bin/bazelisk-linux-amd64
cp bazel-out/*-opt*/bin/bazelisk-linux_arm64 bin/bazelisk-linux-arm64
cp bazel-out/*-opt*/bin/bazelisk-windows_amd64.exe bin/bazelisk-windows-amd64.exe
cp bazel-out/*-opt*/bin/bazelisk-windows_arm64.exe bin/bazelisk-windows-arm64.exe
rm -f bazelisk

### Build release artifacts using `go build`.
Expand All @@ -45,6 +47,7 @@ rm -f bazelisk
# GOOS=darwin GOARCH=arm64 go build -o bin/bazelisk-darwin-arm64
# lipo -create -output bin/bazelisk-darwin bin/bazelisk-darwin-amd64 bin/bazelisk-darwin-arm64
# GOOS=windows GOARCH=amd64 go build -o bin/bazelisk-windows-amd64.exe
# GOOS=windows GOARCH=arm64 go build -o bin/bazelisk-windows-arm64.exe

### Print some information about the generated binaries.
echo "== Bazelisk binaries are ready =="
Expand Down
7 changes: 2 additions & 5 deletions config/BUILD
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@rules_go//go:def.bzl", "go_library")

go_library(
name = "config",
srcs = ["config.go"],
importpath = "github.com/bazelbuild/bazelisk/config",
visibility = ["//visibility:public"],
deps = [
"//ws",
"@com_github_mitchellh_go_homedir//:go_default_library",
],
deps = ["//ws"],
)
5 changes: 3 additions & 2 deletions core/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "core",
Expand All @@ -15,7 +15,7 @@ go_library(
"//platforms",
"//versions",
"//ws",
"@com_github_mitchellh_go_homedir//:go_default_library",
"@com_github_mitchellh_go_homedir//:go-homedir",
],
)

Expand All @@ -28,5 +28,6 @@ go_test(
embed = [":core"],
deps = [
"//config",
"//platforms",
],
)
12 changes: 5 additions & 7 deletions httputil/BUILD
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@gazelle//:def.bzl", "gazelle")
load("@rules_go//go:def.bzl", "go_library", "go_test")

# gazelle:prefix github.com/bazelbuild/bazelisk/httputil
gazelle(name = "gazelle")
Expand All @@ -15,15 +15,13 @@ go_library(
deps = [
"//config",
"//httputil/progress",
"@com_github_bgentry_go_netrc//netrc:go_default_library",
"@com_github_mitchellh_go_homedir//:go_default_library",
"@com_github_bgentry_go_netrc//netrc",
"@com_github_mitchellh_go_homedir//:go-homedir",
],
)

go_test(
name = "httputil_test",
srcs = [
"httputil_test.go",
],
srcs = ["httputil_test.go"],
embed = [":httputil"],
)
14 changes: 5 additions & 9 deletions httputil/progress/BUILD
Original file line number Diff line number Diff line change
@@ -1,26 +1,22 @@
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@gazelle//:def.bzl", "gazelle")
load("@rules_go//go:def.bzl", "go_library", "go_test")

# gazelle:prefix github.com/bazelbuild/bazelisk/httputil/progress
gazelle(name = "gazelle")

go_library(
name = "progress",
srcs = [
"progress.go",
],
srcs = ["progress.go"],
importpath = "github.com/bazelbuild/bazelisk/httputil/progress",
visibility = ["//visibility:public"],
deps = [
"//config",
"@org_golang_x_term//:go_default_library",
"@org_golang_x_term//:term",
],
)

go_test(
name = "progress_test",
srcs = [
"progress_test.go",
],
srcs = ["progress_test.go"],
embed = [":progress"],
)
4 changes: 2 additions & 2 deletions platforms/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@rules_go//go:def.bzl", "go_library", "go_test")

go_library(
name = "platforms",
Expand All @@ -8,7 +8,7 @@ go_library(
deps = [
"//config",
"//versions",
"@com_github_hashicorp_go_version//:go_default_library",
"@com_github_hashicorp_go_version//:go-version",
],
)

Expand Down
2 changes: 1 addition & 1 deletion repositories/BUILD
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@rules_go//go:def.bzl", "go_library")

go_library(
name = "repositories",
Expand Down
4 changes: 2 additions & 2 deletions versions/BUILD
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@rules_go//go:def.bzl", "go_library")

go_library(
name = "versions",
srcs = ["versions.go"],
importpath = "github.com/bazelbuild/bazelisk/versions",
visibility = ["//visibility:public"],
deps = [
"@com_github_hashicorp_go_version//:go_default_library",
"@com_github_hashicorp_go_version//:go-version",
],
)
5 changes: 1 addition & 4 deletions ws/BUILD
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@rules_go//go:def.bzl", "go_library")

go_library(
name = "ws",
srcs = ["ws.go"],
importpath = "github.com/bazelbuild/bazelisk/ws",
visibility = ["//visibility:public"],
deps = [
"@com_github_mitchellh_go_homedir//:go_default_library",
],
)
2 changes: 1 addition & 1 deletion ws/ws.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func FindWorkspaceRoot(root string) string {

// isValidWorkspace returns true if the supplied path is the workspace root, defined by the presence of
// a file named MODULE.bazel, REPO.bazel, WORKSPACE.bazel, or WORKSPACE
// see https://github.com/bazelbuild/bazel/blob/6.3.0/src/main/cpp/workspace_layout.cc#L34
// see https://github.com/bazelbuild/bazel/blob/7.2.1/src/main/cpp/workspace_layout.cc#L34
func isValidWorkspace(path string) bool {
info, err := os.Stat(path)
if err != nil {
Expand Down

0 comments on commit 4448ad1

Please sign in to comment.