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

Make rules_go compatible with --incompatible_load_proto_rules_from_bzl #2315

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all 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
19 changes: 12 additions & 7 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ go_rules_dependencies()

go_register_toolchains()

git_repository(
name = "com_google_protobuf",
commit = "09745575a923640154bcf307fba8aedff47f240a",
remote = "https://github.com/protocolbuffers/protobuf",
shallow_since = "1558721209 -0700",
http_archive(
name = "rules_proto",
sha256 = "73ebe9d15ba42401c785f9d0aeebccd73bd80bf6b8ac78f74996d31f2c0ad7a6",
strip_prefix = "rules_proto-2c0468366367d7ed97a1f702f9cd7155ab3f73c5",
urls = [
"https://mirror.bazel.build/github.com/bazelbuild/rules_proto/archive/2c0468366367d7ed97a1f702f9cd7155ab3f73c5.tar.gz",
"https://github.com/bazelbuild/rules_proto/archive/2c0468366367d7ed97a1f702f9cd7155ab3f73c5.tar.gz",
],
)

load("@com_google_protobuf//:protobuf_deps.bzl", "protobuf_deps")
load("@rules_proto//proto:repositories.bzl", "rules_proto_dependencies", "rules_proto_toolchains")

rules_proto_dependencies()

protobuf_deps()
rules_proto_toolchains()

load("@io_bazel_rules_go//extras:embed_data_deps.bzl", "go_embed_data_dependencies")

Expand Down
2 changes: 1 addition & 1 deletion go/private/BUILD.nogo.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package(default_visibility = [ "//visibility:public" ])
package(default_visibility = ["//visibility:public"])

alias(
name = "nogo",
Expand Down
21 changes: 12 additions & 9 deletions go/private/BUILD.sdk.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,23 @@ filegroup(

filegroup(
name = "tools",
srcs = glob(["pkg/tool/**", "bin/gofmt*"])
srcs = glob([
"pkg/tool/**",
"bin/gofmt*",
]),
)

go_sdk(
name = "go_sdk",
goos = "{goos}",
srcs = [":srcs"],
go = "bin/go{exe}",
goarch = "{goarch}",
root_file = "ROOT",
package_list = ":package_list",
libs = [":libs"],
goos = "{goos}",
headers = [":headers"],
srcs = [":srcs"],
libs = [":libs"],
package_list = ":package_list",
root_file = "ROOT",
tools = [":tools"],
go = "bin/go{exe}",
)

go_tool_binary(
Expand All @@ -51,14 +54,14 @@ go_tool_binary(
package_list(
name = "package_list",
srcs = [":srcs"],
root_file = "ROOT",
out = "packages.txt",
root_file = "ROOT",
)

declare_toolchains(
builder = ":builder",
host = "{goos}_{goarch}",
sdk = ":go_sdk",
builder = ":builder",
)

filegroup(
Expand Down
9 changes: 5 additions & 4 deletions go/private/compat/compat_repo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,13 @@ _go_rules_compat = repository_rule(

def go_rules_compat(**kwargs):
bzl_impl_labels = (
((0, 23, 0), "@io_bazel_rules_go//go/private:compat/v23.bzl"),
((0, 25, 0), "@io_bazel_rules_go//go/private:compat/v25.bzl"),
((0, 23, 0), "@io_bazel_rules_go//go/private:compat/v0_23.bzl"),
((0, 25, 0), "@io_bazel_rules_go//go/private:compat/v0_25.bzl"),
((1, 0, 0), "@io_bazel_rules_go//go/private:compat/v1_0.bzl"),
)
platforms_build_labels = (
((0, 23, 0), "@io_bazel_rules_go//go/private:compat/BUILD.platforms.v23.bzl"),
((0, 28, 0), "@io_bazel_rules_go//go/private:compat/BUILD.platforms.v28.bzl"),
((0, 23, 0), "@io_bazel_rules_go//go/private:compat/BUILD.platforms.v0_23.bzl"),
((0, 28, 0), "@io_bazel_rules_go//go/private:compat/BUILD.platforms.v0_28.bzl"),
)
_go_rules_compat(
impl = _choose(bzl_impl_labels),
Expand Down
File renamed without changes.
File renamed without changes.
100 changes: 100 additions & 0 deletions go/private/compat/v1_0.bzl
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
# Copyright 2019 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.

load("@io_bazel_rules_go//go/private:common.bzl", "as_iterable")
load(
"@bazel_tools//tools/cpp:toolchain_utils.bzl",
"find_cpp_toolchain",
)

# Compatibility for --incompatible_load_proto_rules_from_bzl
load("@rules_proto//proto:defs.bzl", "ProtoInfo")

# Compatibility for --incompatible_disable_legacy_cc_provider

CC_PROVIDER_NAME = CcInfo

def has_cc(target):
return CcInfo in target

def cc_transitive_headers(target):
return target[CcInfo].compilation_context.headers

def cc_defines(target):
return target[CcInfo].compilation_context.defines.to_list()

def cc_system_includes(target):
return target[CcInfo].compilation_context.system_includes.to_list()

def cc_includes(target):
return target[CcInfo].compilation_context.includes.to_list()

def cc_quote_includes(target):
return target[CcInfo].compilation_context.quote_includes.to_list()

def cc_link_flags(target):
return target[CcInfo].linking_context.user_link_flags

def cc_libs(target):
# Copied from get_libs_for_static_executable in migration instructions
# from bazelbuild/bazel#7036.
libraries_to_link = as_iterable(target[CcInfo].linking_context.libraries_to_link)
libs = []
for library_to_link in libraries_to_link:
if library_to_link.static_library != None:
libs.append(library_to_link.static_library)
elif library_to_link.pic_static_library != None:
libs.append(library_to_link.pic_static_library)
elif library_to_link.interface_library != None:
libs.append(library_to_link.interface_library)
elif library_to_link.dynamic_library != None:
libs.append(library_to_link.dynamic_library)
return libs

def cc_toolchain_all_files(ctx):
return find_cpp_toolchain(ctx).all_files.to_list()

# Compatibility for --incompatible_disable_legacy_proto_provider

PROTO_PROVIDER_NAME = ProtoInfo

def has_proto(target):
return ProtoInfo in target

def get_proto(target):
return target[ProtoInfo]

def proto_check_deps_sources(target):
return target[ProtoInfo].check_deps_sources

def proto_source_root(target):
return target[ProtoInfo].proto_source_root

# Compatibility for --incompatible_disallow_struct_provider
def providers_with_coverage(ctx, source_attributes, dependency_attributes, extensions, providers):
return providers + [coverage_common.instrumented_files_info(
ctx,
source_attributes = source_attributes,
dependency_attributes = dependency_attributes,
extensions = extensions,
)]

# Compatibility for --incompatible_require_ctx_in_configure_features
def cc_configure_features(ctx, cc_toolchain, requested_features, unsupported_features):
return cc_common.configure_features(
ctx = ctx,
cc_toolchain = cc_toolchain,
requested_features = requested_features,
unsupported_features = unsupported_features,
)
1 change: 1 addition & 0 deletions go/private/rules/cgo.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def cgo_configure(go, srcs, cdeps, cppopts, copts, cxxopts, clinkopts):
deps_direct = []
lib_opts = []
runfiles = go._ctx.runfiles(collect_data = True)

# Always include the sandbox as part of the build. Bazel does this, but it
# doesn't appear in the CompilationContext.
_include_unique(cppopts, "-iquote", ".", seen_quote_includes)
Expand Down
1 change: 0 additions & 1 deletion go/private/tools/single_output_test.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ _single_output_test = rule(
test = True,
)


def single_output_test(name, dep, **kwargs):
"""Checks that a dependency produces a single output file.

Expand Down
2 changes: 1 addition & 1 deletion go/tools/bazel_testing/def.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def go_bazel_test(rule_files = None, **kwargs):

# Add dependency on bazel_testing library.
kwargs.setdefault("deps", [])

bazel_testing_library = "@io_bazel_rules_go//go/tools/bazel_testing:go_default_library"
if bazel_testing_library not in kwargs["deps"]:
kwargs["deps"] += [bazel_testing_library]
Expand Down
2 changes: 1 addition & 1 deletion tests/core/cgo/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ go_test(
"cgo_link_test.go",
"cgo_ref.go",
],
cgo = True,
cdeps = [":cgo_link_dep"],
cgo = True,
)

cc_library(
Expand Down
2 changes: 1 addition & 1 deletion tests/core/go_binary/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,9 @@ go_test(
go_binary(
name = "static_bin",
srcs = ["static_bin.go"],
deps = ["@org_golang_x_sys//unix:go_default_library"],
static = "on",
tags = ["manual"],
deps = ["@org_golang_x_sys//unix:go_default_library"],
)

go_binary(
Expand Down
2 changes: 1 addition & 1 deletion tests/core/go_path/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,6 @@ go_test(
":link_path",
":nodata_path",
],
deps = ["//go/tools/bazel:go_default_library"],
rundir = ".",
deps = ["//go/tools/bazel:go_default_library"],
)
2 changes: 1 addition & 1 deletion tests/core/go_path/pkg/lib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ go_library(
go_library(
name = "vendored",
srcs = ["vendored.go"],
importpath = "example.com/repo2",
importmap = "example.com/repo/vendor/example.com/repo2",
importpath = "example.com/repo2",
visibility = ["//visibility:public"],
)
1 change: 1 addition & 0 deletions tests/core/go_proto_library/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

Expand Down
5 changes: 3 additions & 2 deletions tests/core/go_proto_library_importmap/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_test")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

Expand All @@ -8,9 +9,9 @@ proto_library(

go_proto_library(
name = "foo_go_proto",
proto = ":foo_proto",
importpath = "github.com/bazelbuild/rules_go/tests/core/go_proto_library_importmap",
importmap = "never/gonna/give/you/up",
importpath = "github.com/bazelbuild/rules_go/tests/core/go_proto_library_importmap",
proto = ":foo_proto",
)

go_test(
Expand Down
2 changes: 1 addition & 1 deletion tests/core/output_groups/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test", "go_binary")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test")

go_library(
name = "lib",
Expand Down
2 changes: 1 addition & 1 deletion tests/core/stdlib/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ load(":stdlib_files.bzl", "stdlib_files")
go_test(
name = "buildid_test",
srcs = ["buildid_test.go"],
rundir = ".",
data = [":stdlib_files"],
rundir = ".",
)

stdlib_files(name = "stdlib_files")
4 changes: 2 additions & 2 deletions tests/examples/executable_name/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_test", "go_source")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_source", "go_test")

go_binary(
name = "some_binary",
Expand All @@ -16,5 +16,5 @@ sh_test(
name = "executable_name",
size = "small",
srcs = ["name_test.sh"],
data = [ ":normalised_binary" ],
data = [":normalised_binary"],
)
3 changes: 2 additions & 1 deletion tests/integration/googleapis/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

Expand All @@ -23,8 +24,8 @@ go_proto_library(

go_library(
name = "color_service",
importpath = "github.com/bazelbuild/rules_go/tests/integration/googleapis/color_service",
srcs = ["color_service.go"],
importpath = "github.com/bazelbuild/rules_go/tests/integration/googleapis/color_service",
deps = [
":color_service_go_proto",
"@go_googleapis//google/rpc:code_go_proto",
Expand Down
1 change: 1 addition & 0 deletions tests/legacy/examples/proto/dep/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

Expand Down
1 change: 1 addition & 0 deletions tests/legacy/examples/proto/embed/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

Expand Down
1 change: 1 addition & 0 deletions tests/legacy/examples/proto/gogo/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

Expand Down
1 change: 1 addition & 0 deletions tests/legacy/examples/proto/gostyle/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

Expand Down
1 change: 1 addition & 0 deletions tests/legacy/examples/proto/grpc/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_grpc_library", "go_proto_library")

Expand Down
1 change: 1 addition & 0 deletions tests/legacy/examples/proto/lib/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

Expand Down
2 changes: 1 addition & 1 deletion tests/legacy/go_embed_data/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ go_test(
"//:AUTHORS",
"@com_google_protobuf//:LICENSE",
],
deps = ["//go/tools/bazel:go_default_library"],
embed = [":go_default_library"],
deps = ["//go/tools/bazel:go_default_library"],
)

go_library(
Expand Down
1 change: 1 addition & 0 deletions tests/legacy/proto_ignore_go_package_option/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
load("@rules_proto//proto:defs.bzl", "proto_library")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")

proto_library(
Expand Down