Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finish migration to bzlmod
Browse files Browse the repository at this point in the history
- bump bazel to 6.4.0
- bump rules_go, gazelle, platforms
- enable bzlmod
- clear WORKSPACE (cannot remove yet due to examples)
- remove `gofmt`, #136
- remove Go MacOS x86_64 tests, #10
Motiejus Jakštys committed Dec 19, 2023

Verified

This commit was signed with the committer’s verified signature.
flaeppe Petter Friberg
1 parent f3c605e commit ac66e89
Showing 16 changed files with 3,132 additions and 1,405 deletions.
4 changes: 3 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
common --enable_bzlmod

test --sandbox_default_allow_network=false
test --test_output=errors

@@ -7,4 +9,4 @@ build --worker_sandboxing
build --experimental_reuse_sandbox_directories
build --incompatible_enable_cc_toolchain_resolution
build --action_env BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1
build --experimental_output_directory_naming_scheme=diff_against_baseline
build --experimental_output_directory_naming_scheme=diff_against_dynamic_baseline
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.3.0
6.4.0
2 changes: 0 additions & 2 deletions .buildkite/pipeline.yml
Original file line number Diff line number Diff line change
@@ -23,8 +23,6 @@ steps:
command: ci/prepare_git && ci/test_example rules_cc override_repository
- label: "Test bzlmod example"
command: ci/prepare_git && ci/test_example bzlmod override_module
- label: "mod-tidy and update-repos"
command: tools/mod-tidy && git diff --exit-code
agents:
- "queue=init"
- "docker=*"
5 changes: 0 additions & 5 deletions BUILD
Original file line number Diff line number Diff line change
@@ -9,8 +9,3 @@ alias(
name = "gazelle",
actual = "//tools/gazelle:gazelle",
)

alias(
name = "gazelle-update-repos",
actual = "//tools/gazelle:gazelle-update-repos",
)
29 changes: 26 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -3,9 +3,9 @@ module(
version = "2.1.3",
)

bazel_dep(name = "platforms", version = "0.0.6")
bazel_dep(name = "platforms", version = "0.0.8")

bazel_dep(name = "rules_go", version = "0.41.0", dev_dependency = True)
bazel_dep(name = "rules_go", version = "0.43.0", dev_dependency = True)

go_sdk = use_extension(
"@rules_go//go:extensions.bzl",
@@ -14,7 +14,7 @@ go_sdk = use_extension(
)
use_repo(go_sdk, "go_default_sdk")

bazel_dep(name = "gazelle", version = "0.32.0", dev_dependency = True)
bazel_dep(name = "gazelle", version = "0.34.0", dev_dependency = True)

go_deps = use_extension(
"@gazelle//:extensions.bzl",
@@ -25,4 +25,27 @@ go_deps.from_file(go_mod = "//:go.mod")
use_repo(
go_deps,
"com_github_bazelbuild_buildtools",
"com_github_stretchr_testify",
)

toolchains = use_extension("//toolchain:ext.bzl", "toolchains")
use_repo(toolchains, "zig_sdk")

register_toolchains(
# if no `--platform` is specified, these toolchains will be used for
# (linux,darwin,windows)x(amd64,arm64)
"@zig_sdk//toolchain:linux_amd64_gnu.2.28",
"@zig_sdk//toolchain:linux_arm64_gnu.2.28",
"@zig_sdk//toolchain:darwin_amd64",
"@zig_sdk//toolchain:darwin_arm64",
"@zig_sdk//toolchain:windows_amd64",
"@zig_sdk//toolchain:windows_arm64",

# amd64 toolchains for libc-aware platforms:
"@zig_sdk//libc_aware/toolchain:linux_amd64_gnu.2.28",
"@zig_sdk//libc_aware/toolchain:linux_amd64_gnu.2.31",
"@zig_sdk//libc_aware/toolchain:linux_amd64_musl",
# arm64 toolchains for libc-aware platforms:
"@zig_sdk//libc_aware/toolchain:linux_arm64_gnu.2.28",
"@zig_sdk//libc_aware/toolchain:linux_arm64_musl",
)
1,954 changes: 1,605 additions & 349 deletions MODULE.bazel.lock

Large diffs are not rendered by default.

86 changes: 0 additions & 86 deletions WORKSPACE
Original file line number Diff line number Diff line change
@@ -1,86 +0,0 @@
workspace(name = "hermetic_cc_toolchain")

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")

RULESGO_VERSION = "v0.39.1"

http_archive(
name = "io_bazel_rules_go",
sha256 = "6dc2da7ab4cf5d7bfc7c949776b1b7c733f05e56edc4bcd9022bb249d2e2a996",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/{0}/rules_go-{0}.zip".format(RULESGO_VERSION),
"https://github.com/bazelbuild/rules_go/releases/download/{0}/rules_go-{0}.zip".format(RULESGO_VERSION),
],
)

PROTOBUF_VERSION = "23.0"

http_archive(
name = "com_google_protobuf",
sha256 = "b29fc5fc13926f347b7a8b676ae1e63f7ccdb92c2fc8ca326bc3a883dcc168ac",
strip_prefix = "protobuf-{}".format(PROTOBUF_VERSION),
urls = [
"https://github.com/protocolbuffers/protobuf/releases/download/v{0}/protobuf-{0}.tar.gz".format(PROTOBUF_VERSION),
],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")

protobuf_deps()

GAZELLE_VERSION = "v0.30.0"

http_archive(
name = "bazel_gazelle",
sha256 = "727f3e4edd96ea20c29e8c2ca9e8d2af724d8c7778e7923a854b2c80952bc405",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/bazel-gazelle/releases/download/{0}/bazel-gazelle-{0}.tar.gz".format(GAZELLE_VERSION),
"https://github.com/bazelbuild/bazel-gazelle/releases/download/{0}/bazel-gazelle-{0}.tar.gz".format(GAZELLE_VERSION),
],
)

load("@io_bazel_rules_go//go:deps.bzl", "go_download_sdk", "go_register_toolchains", "go_rules_dependencies")
load("@bazel_gazelle//:deps.bzl", "gazelle_dependencies")

go_rules_dependencies()

# use latest stable.
go_download_sdk(
name = "go_sdk",
version = "1.20.4",
)

go_register_toolchains()

load("//:repositories.bzl", "go_repositories")

# gazelle:repository_macro repositories.bzl%go_repositories
go_repositories()

gazelle_dependencies(go_repository_default_config = "@//:WORKSPACE")

load(
"//toolchain:defs.bzl",
zig_toolchains = "toolchains",
)

zig_toolchains()

register_toolchains(
# if no `--platform` is specified, these toolchains will be used for
# (linux,darwin,windows)x(amd64,arm64)
"@zig_sdk//toolchain:linux_amd64_gnu.2.28",
"@zig_sdk//toolchain:linux_arm64_gnu.2.28",
"@zig_sdk//toolchain:darwin_amd64",
"@zig_sdk//toolchain:darwin_arm64",
"@zig_sdk//toolchain:windows_amd64",
"@zig_sdk//toolchain:windows_arm64",

# amd64 toolchains for libc-aware platforms:
"@zig_sdk//libc_aware/toolchain:linux_amd64_gnu.2.28",
"@zig_sdk//libc_aware/toolchain:linux_amd64_gnu.2.31",
"@zig_sdk//libc_aware/toolchain:linux_amd64_musl",
# arm64 toolchains for libc-aware platforms:
"@zig_sdk//libc_aware/toolchain:linux_arm64_gnu.2.28",
"@zig_sdk//libc_aware/toolchain:linux_arm64_musl",
)
9 changes: 6 additions & 3 deletions ci/lint
Original file line number Diff line number Diff line change
@@ -26,9 +26,12 @@ mapfile -t zigfiles < <(git ls-files '*.zig')
>&2 echo "--- zig fmt ${zigfiles[*]}"
$ZIG fmt "${zigfiles[@]}"

>&2 echo "--- go fmt :go:"
mapfile -t gofiles < <(git ls-files '**/*.go')
tools/bazel run @go_sdk//:bin/gofmt -- -w "${gofiles[@]}"
# TODO
# https://github.com/uber/hermetic_cc_toolchain/issues/136
>&2 echo "--- Skipping go fmt :go:"
#>&2 echo "--- go fmt :go:"
#mapfile -t gofiles < <(git ls-files '**/*.go')
#tools/bazel run @rules_go//go -- fmt -w "${gofiles[@]}"

>&2 echo "--- buildifier :bazel:"
tools/buildifier -r -mode fix "$PWD"
2,168 changes: 1,474 additions & 694 deletions examples/bzlmod/MODULE.bazel.lock

Large diffs are not rendered by default.

234 changes: 0 additions & 234 deletions repositories.bzl

This file was deleted.

21 changes: 12 additions & 9 deletions test/cgo/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2023 Uber Technologies, Inc.
# Licensed under the MIT License

load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
load("@rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
load("@hermetic_cc_toolchain//rules:platform.bzl", "platform_binary", "platform_test")

go_library(
@@ -21,13 +21,14 @@ go_test(
go_binary(
name = "cgo",
embed = [":cgo_lib"],
gc_linkopts = select({
"@platforms//os:macos": [
"-w", # https://github.com/ziglang/zig/issues/15439
"-buildmode=pie", # https://github.com/ziglang/zig/issues/15438
],
"//conditions:default": [],
}),
# darwin targets are disabled, see below
#gc_linkopts = select({
# "@platforms//os:macos": [
# "-w", # https://github.com/ziglang/zig/issues/15439
# "-buildmode=pie", # https://github.com/ziglang/zig/issues/15438
# ],
# "//conditions:default": [],
#}),
visibility = ["//visibility:public"],
)

@@ -42,7 +43,9 @@ go_binary(
("linux_amd64_gnu.2.28", "//libc_aware/platform:linux_amd64_gnu.2.28"),
("linux_arm64_musl", "//libc_aware/platform:linux_arm64_musl"),
("linux_arm64_gnu.2.28", "//libc_aware/platform:linux_arm64_gnu.2.28"),
("darwin_amd64", "//platform:darwin_amd64"),
# https://github.com/uber/hermetic_cc_toolchain/issues/10
# ("darwin_amd64", "//platform:darwin_amd64"),
# ("darwin_arm64", "//platform:darwin_arm64"),
]
]

2 changes: 1 addition & 1 deletion test/gorace/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2023 Uber Technologies, Inc.
# Licensed under the MIT License

load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
load("@rules_go//go:def.bzl", "go_binary", "go_library", "go_test")

go_library(
name = "gorace_lib",
13 changes: 1 addition & 12 deletions tools/gazelle/BUILD
Original file line number Diff line number Diff line change
@@ -1,17 +1,6 @@
load("@bazel_gazelle//:def.bzl", "gazelle")
load("@gazelle//:def.bzl", "gazelle")

gazelle(
name = "gazelle",
visibility = ["//visibility:public"],
)

gazelle(
name = "gazelle-update-repos",
args = [
"-from_file=go.mod",
"-to_macro=repositories.bzl%go_repositories",
"-prune",
],
command = "update-repos",
visibility = ["//visibility:public"],
)
5 changes: 1 addition & 4 deletions tools/mod-tidy
Original file line number Diff line number Diff line change
@@ -6,7 +6,4 @@ set -xeu

cd "$(git rev-parse --show-toplevel)"
echo "--- go mod tidy"
tools/bazel run @go_sdk//:bin/go -- mod tidy "$@"

echo "--- gazelle-update-repos"
exec tools/bazel run //:gazelle-update-repos
tools/bazel run @rules_go//go -- mod tidy "$@"
2 changes: 1 addition & 1 deletion tools/releaser/BUILD
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Copyright 2023 Uber Technologies, Inc.
# Licensed under the MIT License

load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")
load("@rules_go//go:def.bzl", "go_binary", "go_library", "go_test")

go_library(
name = "releaser_lib",
1 change: 1 addition & 0 deletions tools/releaser/main.go
Original file line number Diff line number Diff line change
@@ -43,6 +43,7 @@ var (
"v2.0.0": "57f03a6c29793e8add7bd64186fc8066d23b5ffd06fe9cc6b0b8c499914d3a65",
"v2.1.0": "892b0dd7aa88c3504a8821e65c44fd22f32c16afab12d89e9942fff492720b37",
"v2.1.1": "86ace5cd211d0ae49a729a11afb344843698b64464f2095a776c57ebbdf06698",
"v2.1.3": "a5caccbf6d86d4f60afd45b541a05ca4cc3f5f523aec7d3f7711e584600fb075",
}

_boilerplateFiles = []string{

0 comments on commit ac66e89

Please sign in to comment.