Skip to content

Commit

Permalink
go_proto_compiler: remove dependence on C/C++ toolchain
Browse files Browse the repository at this point in the history
The C compiler was used to set PATH. No idea why that was useful though.

Fixes bazel-contrib#2089
  • Loading branch information
Jay Conrod committed Jun 18, 2019
1 parent a1f357e commit 9883e56
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 3 deletions.
2 changes: 0 additions & 2 deletions go/tools/builders/protoc.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ func run(args []string) error {
outPath := flags.String("out_path", "", "The base output path to write to.")
plugin := flags.String("plugin", "", "The go plugin to use.")
importpath := flags.String("importpath", "", "The importpath for the generated sources.")
compilerPath := flags.String("compiler_path", "", "The value for PATH.")
flags.Var(&options, "option", "The plugin options.")
flags.Var(&descriptors, "descriptor_set", "The descriptor set to read.")
flags.Var(&expected, "expected", "The expected output files.")
Expand Down Expand Up @@ -85,7 +84,6 @@ func run(args []string) error {
}
protoc_args = append(protoc_args, flags.Args()...)
cmd := exec.Command(*protoc, protoc_args...)
cmd.Env = append(os.Environ(), fmt.Sprintf("PATH=%s", *compilerPath))
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
if err := cmd.Run(); err != nil {
Expand Down
1 change: 0 additions & 1 deletion proto/compiler.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ def go_proto_compile(go, compiler, protos, imports, importpath):
args.add("-plugin", compiler.plugin)

# TODO(jayconrod): can we just use go.env instead?
args.add("-compiler_path", go.cgo_tools.c_compiler_path.rpartition("/")[0])
args.add_all(compiler.options, before_each = "-option")
if compiler.import_path_option:
args.add_all([importpath], before_each = "-option", format_each = "import_path=%s")
Expand Down
21 changes: 21 additions & 0 deletions tests/core/cross/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_source", "go_test")
load("@io_bazel_rules_go//proto:def.bzl", "go_proto_library")
load("@io_bazel_rules_go//tests:bazel_tests.bzl", "bazel_test")

test_suite(
Expand Down Expand Up @@ -80,3 +81,23 @@ go_library(
importpath = "github.com/bazelbuild/rules_go/tests/core/cross/ios_lib",
tags = ["manual"],
)

bazel_test(
name = "proto_test",
args = ["--platforms=@io_bazel_rules_go//go/toolchain:ios_amd64"],
command = "build",
targets = [":cross_go_proto"],
)

proto_library(
name = "cross_proto",
srcs = ["cross.proto"],
tags = ["manual"],
)

go_proto_library(
name = "cross_go_proto",
importpath = "github.com/bazelbuild/rules_go/tests/core/cross",
protos = [":cross_proto"],
tags = ["manual"],
)
4 changes: 4 additions & 0 deletions tests/core/cross/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,7 @@ a dependency using ``@io_bazel_rules_go//go/platform:darwin``, which is true
when building for iOS (tested by ``ios_select_test``) and macOS
(tested by ``use_ios_lib``).

proto_test
----------

Tests that a ``go_proto_library`` can be cross-compiled with ``--platforms``.
9 changes: 9 additions & 0 deletions tests/core/cross/cross.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
syntax = "proto3";

package cross;

option go_package = "github.com/bazelbuild/rules_go/tests/core/cross";

message Foo {
int64 x = 1;
}

0 comments on commit 9883e56

Please sign in to comment.