Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add MODULE.bazel to rules proto #147

Merged
merged 19 commits into from
Sep 22, 2022
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 60 additions & 22 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
@@ -1,31 +1,69 @@
---
build_targets: &build_targets
- "//..."
test_targets: &test_targets
- "//..."

build_targets_bzlmod: &build_targets_bzlmod
- "//..."
test_targets_bzlmod: &test_targets_bzlmod
- "//..."

buildifier:
version: latest
# skylark-comment fails because links to Bazel's docs for
# `ProtoInfo` and `proto_common` contain `/skylark/`.
warnings: "-skylark-comment"

platforms:
tasks:
ubuntu2004:
build_targets: *build_targets
test_targets: *test_targets
macos:
build_targets:
- "//..."
test_targets:
- "//..."

rbe_ubuntu1604:
build_targets:
- "//..."
test_targets:
- "//..."

ubuntu1804:
build_targets:
- "//..."
test_targets:
- "//..."

build_targets: *build_targets
test_targets: *test_targets
windows:
build_targets:
- "//..."
test_targets:
- "//..."
build_targets: *build_targets
test_targets: *test_targets
ubuntu2004_head:
bazel: last_green
platform: ubuntu2004
build_targets: *build_targets
test_targets: *test_targets
macos_head:
bazel: last_green
platform: macos
build_targets: *build_targets
test_targets: *test_targets
windows_head:
bazel: last_green
platform: windows
build_targets: *build_targets
test_targets: *test_targets
ubuntu2004_bzlmod:
bazel: last_green
platform: ubuntu2004
build_flags:
- "--config=bzlmod"
build_targets: *build_targets_bzlmod
test_flags:
- "--config=bzlmod"
test_targets: *test_targets_bzlmod
macos_bzlmod:
bazel: last_green
platform: macos
build_flags:
- "--config=bzlmod"
build_targets: *build_targets_bzlmod
test_flags:
- "--config=bzlmod"
test_targets: *test_targets_bzlmod
windows_bzlmod:
bazel: last_green
platform: windows
build_flags:
- "--config=bzlmod"
comius marked this conversation as resolved.
Show resolved Hide resolved
build_targets: *build_targets_bzlmod
test_flags:
- "--config=bzlmod"
test_targets: *test_targets_bzlmod
1 change: 1 addition & 0 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build:bzlmod --experimental_enable_bzlmod
comius marked this conversation as resolved.
Show resolved Hide resolved
6 changes: 6 additions & 0 deletions .bcr/metadata.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"homepage": "https://github.com/bazelbuild/rules_proto"
"maintainers": [],
"versions": [],
"yanked_versions": {}
}
8 changes: 8 additions & 0 deletions .bcr/presubmit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
matrix:
platform: ["centos7", "debian10", "macos", "ubuntu2004", "windows"]
tasks:
run_tests:
comius marked this conversation as resolved.
Show resolved Hide resolved
name: "Verify build targets"
platform: ${{ platform }}
build_targets:
- "@rules_proto//..."
5 changes: 5 additions & 0 deletions .bcr/source.template.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"integrity": "",
"strip_prefix": "{REPO}-{VERSION}",
"url": "https://github.com/{OWNER}/{REPO}/archive/refs/tags/{TAG}.tar.gz"
}
16 changes: 16 additions & 0 deletions MODULE.bazel
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
module(
name = "rules_proto",
compatibility_level = 1,
version = "5.3.0-21.5",
)

bazel_dep(name = "bazel_skylib", version = "1.1.1")
bazel_dep(name = "rules_cc", version = "0.0.1")
bazel_dep(name = "protobuf", repo_name = "com_google_protobuf", version = "3.19.0")
bazel_dep(name = "googletest", repo_name = "com_google_googletest", version = "1.11.0")
bazel_dep(name = "rules_java", version = "5.1.0")

# Importing non bzl-mod remote_coverage_tools
coverage_deps_ext = use_extension("//proto/private:bzlmod_deps.bzl", "coverage_deps_ext")
comius marked this conversation as resolved.
Show resolved Hide resolved

use_repo(coverage_deps_ext, "remote_coverage_tools")
Empty file added WORKSPACE.bzlmod
Empty file.
39 changes: 39 additions & 0 deletions proto/private/bzlmod_deps.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# Copyright 2022 The Bazel Authors. All rights reserved.
#
# 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.

# Redefine native symbols with a new name as a workaround for
# exporting them in `//proto:defs.bzl` with their original name.
#
# While we cannot force users to load these symbol due to the lack of a
# allowlisting mechanism, we can still export them and tell users to
# load it to make a future migration to pure Starlark easier.


"""Adding missing bzlmod dependencies."""

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

def remote_coverage_tools():
http_archive(
name = "remote_coverage_tools",
sha256 = "cd14f1cb4559e4723e63b7e7b06d09fcc3bd7ba58d03f354cdff1439bd936a7d",
urls = ["https://mirror.bazel.build/bazel_coverage_output_generator/releases/coverage_output_generator-v2.5.zip"],
)

def _coverage_deps_extension_impl(_ctx):
remote_coverage_tools()

coverage_deps_ext = module_extension(
implementation = _coverage_deps_extension_impl,
)
9 changes: 7 additions & 2 deletions tests/rules/proto_descriptor_set/proto_descriptor_set_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,12 @@ namespace {

std::string GetRlocation(const std::string& file) {
static std::unique_ptr<Runfiles> runfiles(Runfiles::CreateForTest());
return runfiles->Rlocation(file);
std::string path = runfiles->Rlocation(rulesproto::kWorkspaceRlocation + file);
std::ifstream input(path, std::ifstream::binary);
if (!input) {
path = runfiles->Rlocation(rulesproto::kWorkspaceRlocationBzlmod + file);
}
return path;
comius marked this conversation as resolved.
Show resolved Hide resolved
}

template <typename T, typename K>
Expand Down Expand Up @@ -66,7 +71,7 @@ void AssertFileDescriptorSetContains(
const std::vector<std::string>& expected_proto_files) {
std::vector<std::string> actual_proto_files =
ReadFileDescriptorSet(
GetRlocation(rulesproto::kWorkspaceRlocation + path));
GetRlocation(path));
EXPECT_EQ(expected_proto_files, actual_proto_files);
}

Expand Down
1 change: 1 addition & 0 deletions tests/utils/workspace_constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,6 @@
namespace rulesproto {

constexpr char kWorkspaceRlocation[] = "rules_proto/";
constexpr char kWorkspaceRlocationBzlmod[] = "__main__/";

} // namespace rulesproto