Skip to content

Commit

Permalink
Add support for bzlmod (#43)
Browse files Browse the repository at this point in the history
* Adopt allowlist attr names
Bazel moved to using "allowlist" in Jun 2020 and dropped support for the
legacy names in Sep 2023, so newer versions of Bazel don't work.
* Update stardoc to v0.6.2
* Run system buildifier in CI
* Remove buildifier dependency
* Replace buildtools with hello_world in example
* Add support for bzlmod modules
  • Loading branch information
jwnrt authored Feb 22, 2024
1 parent e12fa95 commit 6001fac
Show file tree
Hide file tree
Showing 21 changed files with 239 additions and 119 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ jobs:
timeout-minutes: 30
steps:
- name: Checkout
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Dependencies
run: |
go install github.com/bazelbuild/buildtools/buildifier@latest
echo "~/go/bin/" >> "$GITHUB_PATH"
- name: Bazel cache
uses: actions/cache@v3
uses: actions/cache@v4
with:
path: |
~/.cache/bazel
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
**/bazel-*
MODULE.bazel.lock
6 changes: 0 additions & 6 deletions BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,10 @@
# See the License for the specific language governing permissions and
# limitations under the License.

load("@com_github_bazelbuild_buildtools//buildifier:def.bzl", "buildifier")

licenses(["notice"]) # Apache 2.0

exports_files([
"LICENSE",
"deps.bzl",
"setup.bzl",
])

buildifier(
name = "buildifier",
)
44 changes: 44 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Copyright 2024 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
#
# https://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 = "com_github_google_rules_install")

bazel_dep(name = "bazel_skylib", version = "1.3.0")

bazel_dep(
name = "com_github_google_rules_install_examples",
dev_dependency = True,
)
local_path_override(
module_name = "com_github_google_rules_install_examples",
path = "./examples",
)

bazel_dep(
name = "com_github_google_rules_install_docs",
dev_dependency = True,
)
local_path_override(
module_name = "com_github_google_rules_install_docs",
path = "./docs",
)

bazel_dep(
name = "com_github_google_rules_install_test_workspace",
dev_dependency = True,
)
local_path_override(
module_name = "com_github_google_rules_install_test_workspace",
path = "./tests/test_workspace",
)
41 changes: 0 additions & 41 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -31,51 +31,10 @@ local_repository(
path = "./tests/test_workspace",
)

http_archive(
name = "com_github_bazelbuild_buildtools",
sha256 = "e3bb0dc8b0274ea1aca75f1f8c0c835adbe589708ea89bf698069d0790701ea3",
strip_prefix = "buildtools-5.1.0",
urls = [
"https://github.com/bazelbuild/buildtools/archive/refs/tags/5.1.0.tar.gz",
],
)

http_archive(
name = "io_bazel_rules_go",
sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
],
)

http_archive(
name = "com_google_protobuf",
sha256 = "3bd7828aa5af4b13b99c191e8b1e884ebfa9ad371b0ce264605d347f135d2568",
strip_prefix = "protobuf-3.19.4",
urls = [
"https://github.com/protocolbuffers/protobuf/archive/v3.19.4.tar.gz",
],
)

load("@com_github_google_rules_install//:deps.bzl", "install_rules_dependencies")

install_rules_dependencies()

load("@com_github_google_rules_install//:setup.bzl", "install_rules_setup")

install_rules_setup()

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

go_rules_dependencies()

go_register_toolchains(version = "1.19.2")

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

protobuf_deps()

load("@com_github_bazelbuild_buildtools//buildifier:deps.bzl", "buildifier_dependencies")

buildifier_dependencies()
16 changes: 16 additions & 0 deletions WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 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
#
# https://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.

# This file overrides `WORKSPACE` when bzlmod is active. It is intentionally
# left blank.
27 changes: 27 additions & 0 deletions docs/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Copyright 2024 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
#
# https://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 = "com_github_google_rules_install_docs")

bazel_dep(name = "com_github_google_rules_install")
local_path_override(
module_name = "com_github_google_rules_install",
path = "..",
)

bazel_dep(
name = "stardoc",
version = "0.6.2",
repo_name = "io_bazel_stardoc",
)
36 changes: 27 additions & 9 deletions docs/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,42 @@

workspace(name = "com_github_google_rules_install_docs")

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

local_repository(
name = "com_github_google_rules_install",
path = "..",
)

git_repository(
http_archive(
name = "io_bazel_stardoc",
commit = "4378e9b6bb2831de7143580594782f538f461180", # 0.4.0
remote = "https://github.com/bazelbuild/stardoc.git",
shallow_since = "1570829166 -0400",
sha256 = "62bd2e60216b7a6fec3ac79341aa201e0956477e7c8f6ccc286f279ad1d96432",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/stardoc/releases/download/0.6.2/stardoc-0.6.2.tar.gz",
"https://github.com/bazelbuild/stardoc/releases/download/0.6.2/stardoc-0.6.2.tar.gz",
],
)

load("@com_github_google_rules_install//:deps.bzl", "install_rules_dependencies")

install_rules_dependencies()

load("@io_bazel_stardoc//:setup.bzl", "stardoc_repositories")

stardoc_repositories()

load("@rules_jvm_external//:repositories.bzl", "rules_jvm_external_deps")

rules_jvm_external_deps()

load("@rules_jvm_external//:setup.bzl", "rules_jvm_external_setup")

rules_jvm_external_setup()

load("@io_bazel_stardoc//:deps.bzl", "stardoc_external_deps")

stardoc_external_deps()

load("@stardoc_maven//:defs.bzl", stardoc_pinned_maven_install = "pinned_maven_install")

stardoc_pinned_maven_install()

load("@com_github_google_rules_install//:deps.bzl", "install_rules_dependencies")

install_rules_dependencies()
16 changes: 16 additions & 0 deletions docs/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 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
#
# https://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.

# This file overrides `WORKSPACE` when bzlmod is active. It is intentionally
# left blank.
18 changes: 11 additions & 7 deletions docs/installer_rule.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
<!-- Generated with Stardoc: http://skydoc.bazel.build -->

<a name="#installer"></a>
Installer Rules

Skylark rules for installing files using Bazel.

<a id="installer"></a>

## installer

Expand All @@ -19,11 +23,11 @@ argument to the installer.


| Name | Description | Default Value |
| :-------------: | :-------------: | :-------------: |
| name | A unique name of this rule. | none |
| data | Targets to be installed. File names will not be changed. | none |
| compilation_mode | If not empty, sets compilation_mode of targets in data. | <code>"opt"</code> |
| executable | If True, the copied files will be set as executable. | <code>True</code> |
| target_subdir | Optional subdir under the prefix where the files will be placed. | <code>""</code> |
| :------------- | :------------- | :------------- |
| <a id="installer-name"></a>name | A unique name of this rule. | none |
| <a id="installer-data"></a>data | Targets to be installed. File names will not be changed. | none |
| <a id="installer-compilation_mode"></a>compilation_mode | If not empty, sets compilation_mode of targets in data. | `"opt"` |
| <a id="installer-executable"></a>executable | If True, the copied files will be set as executable. | `True` |
| <a id="installer-target_subdir"></a>target_subdir | Optional subdir under the prefix where the files will be placed. | `""` |


9 changes: 7 additions & 2 deletions examples/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ load("@com_github_google_rules_install//installer:def.bzl", "installer")

licenses(["notice"]) # Apache 2.0

cc_binary(
name = "hello_world",
srcs = ["hello_world.c"],
)

installer(
name = "install_buildifier",
data = ["@com_github_bazelbuild_buildtools//buildifier"],
name = "install_hello_world",
data = [":hello_world"],
)
21 changes: 21 additions & 0 deletions examples/MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Copyright 2024 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
#
# https://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 = "com_github_google_rules_install_examples")

bazel_dep(name = "com_github_google_rules_install")
local_path_override(
module_name = "com_github_google_rules_install",
path = "..",
)
6 changes: 2 additions & 4 deletions examples/README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
# Example of using install rules for [Bazel](https://bazel.build)

To install
[buildifier from bazelbuild/buildtools](https://github.com/bazelbuild/buildtools/blob/master/buildifier/README.md)
in `~/bin` run:
To install a "hello world" binary in `~/bin` run:

```shell
rules_install/examples$ bazel run -c opt //:install_buildifier ~/bin
rules_install/examples$ bazel run -c opt //:install_hello_world ~/bin
```
42 changes: 0 additions & 42 deletions examples/WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -24,45 +24,3 @@ local_repository(
load("@com_github_google_rules_install//:deps.bzl", "install_rules_dependencies")

install_rules_dependencies()

http_archive(
name = "com_github_bazelbuild_buildtools",
strip_prefix = "buildtools-5.1.0",
urls = [
"https://github.com/bazelbuild/buildtools/archive/refs/tags/5.1.0.tar.gz",
],
)

load("@com_github_bazelbuild_buildtools//buildifier:deps.bzl", "buildifier_dependencies")

buildifier_dependencies()

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

http_archive(
name = "io_bazel_rules_go",
sha256 = "099a9fb96a376ccbbb7d291ed4ecbdfd42f6bc822ab77ae6f1b5cb9e914e94fa",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
"https://github.com/bazelbuild/rules_go/releases/download/v0.35.0/rules_go-v0.35.0.zip",
],
)

http_archive(
name = "com_google_protobuf",
sha256 = "3bd7828aa5af4b13b99c191e8b1e884ebfa9ad371b0ce264605d347f135d2568",
strip_prefix = "protobuf-3.19.4",
urls = [
"https://github.com/protocolbuffers/protobuf/archive/v3.19.4.tar.gz",
],
)

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

go_rules_dependencies()

go_register_toolchains(version = "1.19.2")

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

protobuf_deps()
16 changes: 16 additions & 0 deletions examples/WORKSPACE.bzlmod
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Copyright 2024 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
#
# https://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.

# This file overrides `WORKSPACE` when bzlmod is active. It is intentionally
# left blank.
5 changes: 5 additions & 0 deletions examples/hello_world.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#include <stdio.h>

int main() {
printf("Hello, world!\n");
}
Loading

0 comments on commit 6001fac

Please sign in to comment.