Skip to content

Commit

Permalink
Misc cleanups (#216)
Browse files Browse the repository at this point in the history
- Prepare for BCR release as 0.10.0
- Rename repo name to toolchains_llvm
- Upgrade Go version in tests and remove -nopie flag
- Combine lint and tests workflow
  • Loading branch information
siddharthab authored Sep 14, 2023
1 parent 1cf6ea8 commit bb94933
Show file tree
Hide file tree
Showing 13 changed files with 92 additions and 65 deletions.
25 changes: 0 additions & 25 deletions .github/workflows/lint.yml

This file was deleted.

28 changes: 20 additions & 8 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,26 @@
name: Tests

on:
push:
branches: [master]
pull_request:
branches: [master]

concurrency:
group: ${{ github.head_ref || github.run_id }}
cancel-in-progress: true

permissions: read-all

jobs:
lint:
runs-on: ubuntu-latest
permissions:
checks: write # For trunk to post annotations
contents: read # For repo checkout
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Trunk Check
uses: trunk-io/trunk-action@v1
test:
strategy:
fail-fast: false
Expand All @@ -25,7 +37,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: test
- name: Test
env:
USE_BAZEL_VERSION: ${{ matrix.bazel_version }}
USE_BZLMOD: ${{ matrix.bzlmod }}
Expand All @@ -40,7 +52,7 @@ jobs:
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v3
- name: external_test
- name: Test
env:
USE_BAZEL_VERSION: ${{ matrix.bazel_version }}
USE_BZLMOD: ${{ matrix.bzlmod }}
Expand All @@ -63,19 +75,19 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: test
- name: Test
run: tests/scripts/${{ matrix.script }}_test.sh
xcompile_test:
runs-on: macos-latest
steps:
- uses: actions/checkout@v3
- name: test
- name: Test
run: tests/scripts/run_xcompile_tests.sh
abs_paths_test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: test
- name: Test
run: tests/scripts/run_tests.sh -t @llvm_toolchain_with_absolute_paths//:cc-toolchain-x86_64-linux
sys_paths_test:
runs-on: ubuntu-latest
Expand All @@ -88,5 +100,5 @@ jobs:
ext: .tar.xz
local_path: /tmp/llvm-15
run: wget --no-verbose "https://github.com/llvm/llvm-project/releases/download/${release}/${archive}${ext}" && tar -xf "${archive}${ext}" && mv "${archive}" "${local_path}"
- name: test
- name: Test
run: tests/scripts/run_tests.sh -t @llvm_toolchain_with_system_llvm//:cc-toolchain-x86_64-linux
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/bazel-*
/tests/bazel-*
/toolchain/tools/__pycache__
/toolchain/tools/host_os_key.pyc
Expand Down
20 changes: 17 additions & 3 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,9 +1,23 @@
# Copyright 2023 The Bazel Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module(
name = "llvm_toolchain",
version = "0.0.0",
name = "toolchains_llvm",
version = "0.10.0",
compatibility_level = 0,
)

bazel_dep(name = "bazel_skylib", version = "1.4.2")
bazel_dep(name = "rules_cc", version = "0.0.8")
bazel_dep(name = "platforms", version = "0.0.6")
bazel_dep(name = "platforms", version = "0.0.7")
18 changes: 9 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ Minimum bazel version: **6.0.0** (6.1.0 if using blzmod)
If you're using `bzlmod`, add the following to `MODULE.bazel`:

```starlark
bazel_dep(name = "llvm_toolchain", version = "0.9")
bazel_dep(name = "toolchains_llvm", version = "0.10.0")

llvm = use_extension("@llvm_toolchain//toolchain/extensions:llvm.bzl", "llvm")
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")
llvm.toolchain(
llvm_version = "15.0.6",
llvm_version = "16.0.0",
)

use_repo(llvm, "llvm_toolchain")
Expand All @@ -46,25 +46,25 @@ BAZEL_TOOLCHAIN_TAG = "0.9"
BAZEL_TOOLCHAIN_SHA = "95f0bab6982c7e5a83447e08bf32fa7a47f210169da5e5ec62411fef0d8e7f59"

http_archive(
name = "com_grail_bazel_toolchain",
name = "toolchains_llvm",
sha256 = BAZEL_TOOLCHAIN_SHA,
strip_prefix = "bazel-toolchain-{tag}".format(tag = BAZEL_TOOLCHAIN_TAG),
canonical_id = BAZEL_TOOLCHAIN_TAG,
url = "https://github.com/grailbio/bazel-toolchain/archive/refs/tags/{tag}.tar.gz".format(tag = BAZEL_TOOLCHAIN_TAG),
)

load("@com_grail_bazel_toolchain//toolchain:deps.bzl", "bazel_toolchain_dependencies")
load("@toolchains_llvm//toolchain:deps.bzl", "bazel_toolchain_dependencies")

bazel_toolchain_dependencies()

load("@com_grail_bazel_toolchain//toolchain:rules.bzl", "llvm_toolchain")
load("@toolchains_llvm//toolchain:rules.bzl", "llvm_toolchain")

llvm_toolchain(
name = "llvm_toolchain",
llvm_version = "16.0.0",
)

load("@llvm_toolchain//:toolchains.bzl", "llvm_register_toolchains")
load("@toolchains_llvm//:toolchains.bzl", "llvm_register_toolchains")

llvm_register_toolchains()
```
Expand Down Expand Up @@ -194,7 +194,7 @@ The following mechanisms are available for using an LLVM toolchain:
attribute. When using a bazel package path, each of the values is typically
a package in the user's workspace or configured through `local_repository` or
`http_archive`; the BUILD file of the package should be similar to
`@com_grail_bazel_toolchain//toolchain:BUILD.llvm_repo`. If using only
`@toolchains_llvm//toolchain:BUILD.llvm_repo`. If using only
`http_archive`, maybe consider using the `urls` attribute instead to get more
flexibility if you need.
4. All the above options rely on host OS information, and are not suited for
Expand Down Expand Up @@ -233,7 +233,7 @@ the [test script](tests/scripts/run_xcompile_tests.sh) for cross-compilation.

```sh
bazel build \
--platforms=@com_grail_bazel_toolchain//platforms:linux-x86_64 \
--platforms=@toolchains_llvm//platforms:linux-x86_64 \
--extra_toolchains=@llvm_toolchain_with_sysroot//:cc-toolchain-x86_64-linux \
//...
```
Expand Down
2 changes: 1 addition & 1 deletion WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@
# limitations under the License.

workspace(
name = "com_grail_bazel_toolchain",
name = "toolchains_llvm",
)
35 changes: 29 additions & 6 deletions tests/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
module(name = "com_grail_bazel_toolchain_tests")

bazel_dep(name = "llvm_toolchain", version = "0.8.2", repo_name = "com_grail_bazel_toolchain")
# Copyright 2023 The Bazel Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

module(name = "toolchains_llvm_tests")

bazel_dep(name = "toolchains_llvm", version = "0.0.0")
local_path_override(
module_name = "llvm_toolchain",
module_name = "toolchains_llvm",
path = "..",
)

bazel_dep(name = "bazel_skylib", version = "1.4.2")
bazel_dep(name = "platforms", version = "0.0.6")
bazel_dep(name = "platforms", version = "0.0.7")
bazel_dep(name = "rules_cc", version = "0.0.8")
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")
Expand Down Expand Up @@ -38,6 +52,15 @@ git_override(
remote = "https://github.com/bazelbuild/rules_rust.git",
)

go_sdk = use_extension("@io_bazel_rules_go//go:extensions.bzl", "go_sdk")
go_sdk.download(
name = "go_sdk",
version = "1.21.0",
)
use_repo(go_sdk, "go_toolchains")

register_toolchains("@go_toolchains//:all")

rust = use_extension("@rules_rust//rust:extensions.bzl", "rust")
rust.toolchain(edition = "2021")
use_repo(
Expand All @@ -47,7 +70,7 @@ use_repo(

register_toolchains("@rust_toolchains//:all")

llvm = use_extension("@com_grail_bazel_toolchain//toolchain/extensions:llvm.bzl", "llvm")
llvm = use_extension("@toolchains_llvm//toolchain/extensions:llvm.bzl", "llvm")

# When updating this version, also update the versions associated with
# llvm_toolchain below, sys_paths_test in the workflows file, and xcompile_test
Expand Down
15 changes: 9 additions & 6 deletions tests/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.

workspace(name = "com_grail_bazel_toolchain_tests")
workspace(name = "toolchains_llvm_tests")

local_repository(
name = "com_grail_bazel_toolchain",
name = "toolchains_llvm",
path = "..",
)

load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive")
load("@com_grail_bazel_toolchain//toolchain:deps.bzl", "bazel_toolchain_dependencies")
load("@toolchains_llvm//toolchain:deps.bzl", "bazel_toolchain_dependencies")

bazel_toolchain_dependencies()

load("@com_grail_bazel_toolchain//toolchain:rules.bzl", "llvm_toolchain")
load("@toolchains_llvm//toolchain:rules.bzl", "llvm_toolchain")

# When updating this version, also update the versions associated with
# llvm_toolchain below, sys_paths_test in the workflows file, and xcompile_test
Expand Down Expand Up @@ -186,11 +186,14 @@ http_archive(
],
)

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

go_rules_dependencies()

go_register_toolchains(version = "1.20.5")
go_download_sdk(
name = "go_sdk",
version = "1.21.0",
)

# For testing rules_rust.

Expand Down
2 changes: 1 addition & 1 deletion tests/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
workspace(name = "com_grail_bazel_toolchain_tests")
workspace(name = "toolchains_llvm_tests")

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

Expand Down
4 changes: 2 additions & 2 deletions tests/openssl/openssl.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ CONF_FILES = [

genrule(
name = "configure",
srcs = [("@com_grail_bazel_toolchain//tests/openssl:" + f) for f in CONF_FILES],
srcs = [("@toolchains_llvm_tests//openssl:" + f) for f in CONF_FILES],
outs = CONF_FILES,
cmd = "\n".join([
"cp $(location @com_grail_bazel_toolchain//tests/openssl:{0}) $(location {0})".format(f)
"cp $(location @toolchains_llvm_tests//openssl:{0}) $(location {0})".format(f)
for f in CONF_FILES
]),
visibility = ["//visibility:private"],
Expand Down
1 change: 0 additions & 1 deletion tests/scripts/run_external_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ fi

test_args=(
"${common_test_args[@]}"
"--linkopt=-nopie" # Not needed after https://github.com/bazelbuild/rules_go/pull/3692.
"--copt=-Wno-deprecated-builtins" # https://github.com/abseil/abseil-cpp/issues/1201
)

Expand Down
2 changes: 1 addition & 1 deletion tests/scripts/run_xcompile_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ echo ""
echo "Testing static linked user libraries and dynamic linked system libraries"
build_args=(
--incompatible_enable_cc_toolchain_resolution
--platforms=@com_grail_bazel_toolchain//platforms:linux-x86_64
--platforms=@toolchains_llvm//platforms:linux-x86_64
--extra_toolchains=@llvm_toolchain_with_sysroot//:cc-toolchain-x86_64-linux
--symlink_prefix=/
--color=yes
Expand Down
4 changes: 2 additions & 2 deletions toolchain/extensions/llvm.bzl
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
"""LLVM extension for use with bzlmod"""

load("@llvm_toolchain//toolchain:rules.bzl", "llvm_toolchain")
load("@toolchains_llvm//toolchain:rules.bzl", "llvm_toolchain")
load(
"@llvm_toolchain//toolchain/internal:repo.bzl",
"@toolchains_llvm//toolchain/internal:repo.bzl",
_llvm_config_attrs = "llvm_config_attrs",
_llvm_repo_attrs = "llvm_repo_attrs",
)
Expand Down

0 comments on commit bb94933

Please sign in to comment.