I got following error, when I was running following command on Mac.
$ bazel run //:go_image
INFO: Analysed target //:go_image (23 packages loaded).
INFO: Found 1 target...
Target //:go_image up-to-date:
bazel-bin/go_image-layer.tar
INFO: Elapsed time: 11.514s, Critical Path: 11.10s
INFO: Build completed successfully, 27 total actions
INFO: Running command line: bazel-bin/go_image
Loaded image ID: sha256:25fabb67d3eea0c4bd5137090d621fafa9d07e6cfd0d87e28c5366ddcf4e9e8d
Tagging 25fabb67d3eea0c4bd5137090d621fafa9d07e6cfd0d87e28c5366ddcf4e9e8d as bazel:go_image
standard_init_linux.go:195: exec user process caused "exec format error"
ERROR: Non-zero return code '1' from command: Process exited with status 1
package main
import "fmt"
func main() {
fmt.Println("Hello, world!")
}
git_repository(
name = "io_bazel_rules_go",
remote = "https://github.com/bazelbuild/rules_go.git",
tag = "0.10.1",
)
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains", "go_repository")
go_rules_dependencies()
go_register_toolchains()
git_repository(
name = "io_bazel_rules_docker",
remote = "https://github.com/bazelbuild/rules_docker.git",
tag = "v0.4.0",
)
load(
"@io_bazel_rules_docker//container:container.bzl",
"container_pull",
container_repositories = "repositories",
)
container_repositories()
load(
"@io_bazel_rules_docker//go:image.bzl",
_go_image_repos = "repositories",
)
_go_image_repos()
load("@io_bazel_rules_docker//go:image.bzl", "go_image")
go_image(
name = "go_image",
srcs = ["main.go"],
pure = "on",
)
The go_binary isn't cross-compiling, so it's trying to run an OSX binary in a linux container.
What you want is this flag, which you can put into a .bazelrc in the root of your repo:
run --platforms=@io_bazel_rules_go//go/toolchain:linux_amd64
Most helpful comment
The
go_binaryisn't cross-compiling, so it's trying to run an OSX binary in a linux container.What you want is this flag, which you can put into a
.bazelrcin the root of your repo: