Skip to content

Commit

Permalink
Minor cleanup for recent bzlmod support
Browse files Browse the repository at this point in the history
  • Loading branch information
Siddhartha Bagaria committed Sep 12, 2023
1 parent 5c6f806 commit 42a5552
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 31 deletions.
11 changes: 9 additions & 2 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,15 @@ jobs:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest]
bazel_version: [latest, 6.3.0]
bazel_version: [latest, 6.0.0]
bzlmod: [true, false]
# bzlmod needs 6.1.0 (issue unrelated to this project)
exclude:
- bazel_version: 6.0.0
bzlmod: true
include:
- bazel_version: 6.1.0
bzlmod: true
steps:
- uses: actions/checkout@v3
- name: test
Expand All @@ -28,7 +35,7 @@ jobs:
fail-fast: false
matrix:
os: [macos-latest, ubuntu-latest]
bazel_version: [latest, 6.3.0]
bazel_version: [latest] # rules_rust bzlmod support is experimental and needs latest version as of now (20230912).
bzlmod: [true, false]
steps:
- uses: actions/checkout@v2
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/tests/bazel-*
/toolchain/tools/__pycache__
/toolchain/tools/host_os_key.pyc
MODULE.bazel.lock
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ implementation, please let me know and I can redirect people there.

## Quickstart

Minimum bazel version: **6.0.0**
Minimum bazel version: **6.0.0** (6.1.0 if using blzmod)

If you're using `bzlmod`, add the following to `MODULE.bazel`:

Expand Down
40 changes: 27 additions & 13 deletions tests/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,22 +1,42 @@
module(name = "com_grail_bazel_toolchain_tests")

bazel_dep(name = "llvm_toolchain", version = "0.8.2", repo_name = "com_grail_bazel_toolchain")
local_path_override(module_name = "llvm_toolchain", path = "..")
local_path_override(
module_name = "llvm_toolchain",
path = "..",
)

bazel_dep(name = "bazel_skylib", version = "1.4.2")
bazel_dep(name = "platforms", version = "0.0.6")
bazel_dep(name = "rules_cc", version = "0.0.8")
bazel_dep(name = "rules_go", version = "0.40.1", repo_name = "io_bazel_rules_go")
bazel_dep(name = "rules_go", version = "0.41.0", repo_name = "io_bazel_rules_go")
bazel_dep(name = "rules_foreign_cc", version = "0.9.0")
bazel_dep(name = "rules_rust", version = "0.27.0")

# We have to patch abseil-cpp to add a dep on googletest
bazel_dep(name = "abseil-cpp", repo_name = "com_google_absl")
archive_override(module_name = "abseil-cpp", urls = ["https://github.com/abseil/abseil-cpp/archive/refs/tags/20230125.3.tar.gz"], patches = ["//patches:abseil-cpp.patch"], strip_prefix = "abseil-cpp-20230125.3")
archive_override(
module_name = "abseil-cpp",
patches = ["//patches:abseil-cpp.patch"],
strip_prefix = "abseil-cpp-20230125.3",
urls = ["https://github.com/abseil/abseil-cpp/archive/refs/tags/20230125.3.tar.gz"],
)

# Temporary overrides until newer versions of these rulesets are released in the central registry
git_override(module_name = "rules_foreign_cc", remote = "https://github.com/bazelbuild/rules_foreign_cc.git", commit = "6ecc134b114f6e086537f5f0148d166467042226")
git_override(module_name = "rules_rust", remote = "https://github.com/bazelbuild/rules_rust.git", commit = "4dbb81a008f4031c9ad65138fa2a49f32352f80f")
# Temporary override until newer version is released to the central registry.
# https://github.com/bazelbuild/rules_foreign_cc/issues/1080
git_override(
module_name = "rules_foreign_cc",
commit = "60813d57a0e99be1a009c1a0e9627cdbe81fcd19",
remote = "https://github.com/bazelbuild/rules_foreign_cc.git",
)

# rules_rust is not yet released to the central registry.
# https://github.com/bazelbuild/rules_rust/issues/1493
git_override(
module_name = "rules_rust",
commit = "4dbb81a008f4031c9ad65138fa2a49f32352f80f",
remote = "https://github.com/bazelbuild/rules_rust.git",
)

rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(edition = "2021")
Expand All @@ -42,8 +62,8 @@ llvm.toolchain(
"darwin-x86_64": "15.0.7",
},
)

use_repo(llvm, "llvm_toolchain", "llvm_toolchain_llvm")

register_toolchains("@llvm_toolchain//:all")

# Example toolchain with user provided URLs.
Expand Down Expand Up @@ -71,7 +91,6 @@ llvm.toolchain(
"darwin-x86_64": ["https://github.com/llvm/llvm-project/releases/download/llvmorg-15.0.7/clang+llvm-15.0.7-x86_64-apple-darwin21.0.tar.xz"],
},
)

use_repo(llvm, "llvm_toolchain_with_urls")

# # This is the latest version of LLVM that seems to work with rules_go; later
Expand All @@ -80,7 +99,6 @@ llvm.toolchain(
name = "llvm_toolchain_14_0_0",
llvm_version = "14.0.0",
)

use_repo(llvm, "llvm_toolchain_14_0_0")

# # This is the last known LLVM version with zlib support in ld.lld. Without zlib
Expand All @@ -91,7 +109,6 @@ llvm.toolchain(
name = "llvm_toolchain_13_0_0",
llvm_version = "13.0.0",
)

use_repo(llvm, "llvm_toolchain_13_0_0")

# ## Toolchain example with absolute paths; tested in GitHub CI.
Expand All @@ -104,7 +121,6 @@ llvm.toolchain(
"": "@llvm_toolchain_llvm//",
},
)

use_repo(llvm, "llvm_toolchain_with_absolute_paths")

# ## Toolchain example with system LLVM; tested in GitHub CI.
Expand All @@ -115,7 +131,6 @@ llvm.toolchain(
# A path in /tmp to be part of system tmp cleanup schedule.
toolchain_roots = {"": "/tmp/llvm-15"},
)

use_repo(llvm, "llvm_toolchain_with_system_llvm")

# ## Toolchain example with a sysroot.
Expand All @@ -135,5 +150,4 @@ llvm.toolchain(
"": "@llvm_toolchain_llvm//",
},
)

use_repo(llvm, "llvm_toolchain_with_sysroot")
8 changes: 4 additions & 4 deletions tests/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -186,18 +186,18 @@ http_archive(

http_archive(
name = "io_bazel_rules_go",
sha256 = "56d8c5a5c91e1af73eca71a6fab2ced959b67c86d12ba37feedb0a2dfea441a6",
sha256 = "278b7ff5a826f3dc10f04feaf0b70d48b68748ccd512d7f98bf442077f043fe3",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.37.0/rules_go-v0.37.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.37.0/rules_go-v0.37.0.zip",
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.41.0/rules_go-v0.41.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.41.0/rules_go-v0.41.0.zip",
],
)

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

go_rules_dependencies()

go_register_toolchains(version = "1.19.3")
go_register_toolchains(version = "1.20.5")

# For testing rules_rust.

Expand Down
19 changes: 12 additions & 7 deletions tests/scripts/bazel.sh
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,23 @@ fi
readonly arch

# Use bazelisk to catch migration problems.
readonly bazelisk_version="v1.11.0"
readonly bazelisk_version="v1.18.0"
readonly url="https://github.com/bazelbuild/bazelisk/releases/download/${bazelisk_version}/bazelisk-${os}-${arch}"
bazel="${TMPDIR:-/tmp}/bazelisk"
readonly bazel

common_args=(
"--enable_bzlmod=${USE_BZLMOD:-false}"
)

common_test_args=(
--incompatible_enable_cc_toolchain_resolution
--symlink_prefix=/
--color=yes
--show_progress_rate_limit=30
--keep_going
--test_output=errors
"${common_args[@]}"
"--symlink_prefix=/"
"--incompatible_enable_cc_toolchain_resolution"
"--color=yes"
"--show_progress_rate_limit=30"
"--keep_going"
"--test_output=errors"
)

# TODO: Remove this once we no longer support bazel 6.x.
Expand Down
5 changes: 2 additions & 3 deletions tests/scripts/run_external_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,16 @@ source "${scripts_dir}/bazel.sh"
cd "${scripts_dir}"

# Generate some files needed for the tests.
"${bazel}" fetch @io_bazel_rules_go//tests/core/cgo:all
"${bazel}" query "${common_args[@]}" @io_bazel_rules_go//tests/core/cgo:dylib_test >/dev/null
if [[ "$USE_BZLMOD" == "true" ]]; then
"$("${bazel}" info output_base)/external/rules_go~0.40.1/tests/core/cgo/generate_imported_dylib.sh"
"$("${bazel}" info output_base)/external/rules_go~0.41.0/tests/core/cgo/generate_imported_dylib.sh"
else
"$("${bazel}" info output_base)/external/io_bazel_rules_go/tests/core/cgo/generate_imported_dylib.sh"
fi

set -x
test_args=(
"${common_test_args[@]}"
"--enable_bzlmod=${USE_BZLMOD:-false}"
# Fix LLVM version to be 14.0.0 because that's the last known version with
# which the tests in rules_go pass.
"--extra_toolchains=@llvm_toolchain_14_0_0//:all"
Expand Down
1 change: 0 additions & 1 deletion tests/scripts/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ cd "${scripts_dir}"

set -x
test_args=(
"--enable_bzlmod=${USE_BZLMOD:-false}"
"--extra_toolchains=${toolchain_name}"
"--copt=-v"
"--linkopt=-Wl,-t"
Expand Down

0 comments on commit 42a5552

Please sign in to comment.