0.7.0
Pre-releaseImproved cross-compilation
You can now cross-compile pure Go binaries (without cgo) for any platform that Go supports. For example:
bazel build --experimental_platforms=@io_bazel_rules_go//go/toolchain:linux_s390x //:my_binary
Just change the platform target to any GOOS / GOARCH combination supported by the Go SDK.
There are still a few known issues. In particular, the current version of Bazel doesn't allow us to add .exe extensions to binary files on Windows. This will be fixed in Bazel 0.8, so we'll tag another release with that as the minimum supported version as soon as it's available.
Improved build mode support
You can now build static, race, msan, and tsan binaries using Bazel feature flags. For example:
bazel build --features=static,msan //:my_binary
You can also specify static and pure modes on go_binary
rules using new attributes. This is useful if you have packaging rules that depend on binary rules built in specific configurations.
go_binary(
name = "my_binary",
...,
static = "on",
)
The old mechanism of using output groups to select build mode has been removed.
See build modes for more information.
Gazelle multi-platform support
Gazelle can generate build files that work on all platforms that Go supports. In order to avoid repetition, we've divided sources, dependencies, and options into separate OS-specific, arch-specific, and OS-and-arch-specific select
expressions. For example:
go_library(
name = "go_default_library",
srcs = [
"foo.go",
] + select({
"@io_bazel_rules_go//go/platform:linux": [
"foo_linux.go",
],
"//conditions:default": [],
}) + select({
"@io_bazel_rules_go//go/platform:amd64": [
"foo_amd64.go",
],
"//conditions:default": [],
}),
importpath = "github.com/example/project",
visibility = ["//visibility:public"],
)
This new functionality is off by default; you can try it out with the -experimental_platforms
flag.
At this time, the config_setting
rules in @io_bazel_rules_go//go/platform
can only match the cpu
value, which means we are limited to platforms where Bazel has a C++ toolchain. With Bazel 0.8, config_setting
rules will be able to match constraint_values
, which gives us much more flexibility. After that release, we'll remove the -experimental_platforms
flag and turn on the new functionality.
WORKSPACE code
To use this release, add this code to your WORKSPACE file:
http_archive(
name = "io_bazel_rules_go",
url = "https://github.com/bazelbuild/rules_go/releases/download/0.7.0/rules_go-0.7.0.tar.gz",
sha256 = "91fca9cf860a1476abdc185a5f675b641b60d3acf0596679a27b580af60bf19c",
)
load("@io_bazel_rules_go//go:def.bzl", "go_rules_dependencies", "go_register_toolchains")
go_rules_dependencies()
go_register_toolchains()
Direct download: rules_go-0.7.0.tar.gz