-
Notifications
You must be signed in to change notification settings - Fork 696
Description
I am trying to compile a go_image target on macOS, and this is failing with an error about missing imports:
$ bazel build //service.api.ping:image
(20:41:03) INFO: Invocation ID: f27684c3-962f-4aba-a5d7-57245f4da640
(20:41:03) INFO: Current date is 2019-02-12
(20:41:03) INFO: Analysed target //service.api.ping:image (0 packages loaded, 0 targets configured).
(20:41:03) INFO: Found 1 target...
(20:41:04) ERROR: /private/var/tmp/_bazel_oliver/40333f6e8ec32396acff18e2ad143eea/external/org_golang_google_grpc/internal/syscall/BUILD.bazel:3:1: GoCompile external/org_golang_google_grpc/internal/syscall/linux_amd64_pure_stripped/go_default_library%/google.golang.org/grpc/internal/syscall.a failed (Exit 1) compile failed: error executing command bazel-out/host/bin/external/io_bazel_rules_go/go/tools/builders/darwin_amd64_stripped/compile -sdk external/go_sdk -installsuffix linux_amd64 -src ... (remaining 14 argument(s) skipped)
Use --sandbox_debug to see verbose messages from the sandbox
GoCompile: missing strict dependencies:
/private/var/tmp/_bazel_oliver/40333f6e8ec32396acff18e2ad143eea/sandbox/darwin-sandbox/1/execroot/wearedev/external/org_golang_google_grpc/internal/syscall/syscall_linux.go: import of "golang.org/x/sys/unix"
Known dependencies are:
google.golang.org/grpc/grpclog
Check that imports in Go sources match importpath attributes in deps.
Target //service.api.ping:image failed to build
Use --verbose_failures to see the command lines of failed build steps.
(20:41:04) INFO: Elapsed time: 0.600s, Critical Path: 0.20s
(20:41:04) INFO: 2 processes: 2 darwin-sandbox.
(20:41:04) FAILED: Build did NOT complete successfully
The BUILD file that I am building this from specifies goarch and goos, which I think is as you recommend it:
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library")
go_library(
deps = [
"//bedrock:go_default_library",
"//bedrock/filter:go_default_library",
"//service.api.ping/handler:go_default_library",
],
importpath = "github.com/monzo/wearedev/service.api.ping",
name = "go_default_library",
srcs = ["main.go"],
visibility = ["//service.api.ping:__subpackages__"],
)
go_binary(
embed = [":go_default_library"],
name = "service.api.ping",
out = "service.api.ping",
visibility = ["//visibility:public"],
)
go_image(
embed = [":go_default_library"],
goarch = "amd64",
goos = "linux",
name = "image",
pure = "on",
visibility = ["//visibility:public"],
)However, if I specify the platform explicitly like so, it does work:
$ bazel build --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64 //service.api.ping:image
It's a little difficult to unpick precisely what's happening, but the failing compilation rule looks to be defined in rules_go, and it does look like the dependency on @org_golang_x_sys//unix:go_default_library is properly specified for the Linux platform:
I am pretty sure that this worked without needing to explicitly specify --platforms in a previous release, so I wonder:
- Is there a way to make this "just work" without requiring a user specify this flag?
- If not, can I somehow specify that this rule can only be built for the
linux_amd64platform? The "build platforms roadmap" seems to indicate that this is possible ("execution platform filtering") but I can't work out how to actually make use of this.
Thanks 🙏
- Bazel version 0.22.0
- rules_go version 0.17.0
- rules_docker version 0.7.0