Skip to content

Releases: bazel-contrib/rules_go

0.7.0

03 Nov 17:58
0bd97fc
Compare
Choose a tag to compare
0.7.0 Pre-release
Pre-release

Improved 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

0.6.0

09 Oct 19:09
Compare
Choose a tag to compare
0.6.0 Pre-release
Pre-release

Go Rules

  • Go 1.8.4, 1.9, and 1.9.1 are now supported. The default SDK is now 1.9.1.
  • Major documentation overhaul (still in progress).
  • Rules now support an importpath attribute, which allows import paths to be set explicitly. If all rules in a repository use this, go_prefix is not needed.
  • Rules also support an embed attribute, which allows sources, dependencies, and data from multiple libraries to be combined. This is the same concept as the library attribute, but multiple libraries may be embedded instead of just one.
  • GoLibrary, GoBinary, and GoEmbed providers are now documented. These can be used to write rules compatible with the Go rules.
  • Actions are now specified using toolchains, which were recently added to Bazel. go_register_toolchains() must be called in WORKSPACE in order to make Bazel aware of toolchains.
  • Experimental: Cross compilation is supported using the new toolchains. Currently, only darwin-amd64 to linux-amd64 works, but we are working on supporting more platforms. You can try this with --cpu k8.
  • Experimental: New protocol buffer rules go_proto_library and go_grpc_library are defined in proto/def.bzl. This is a complete rewrite of proto support. The interface is not finalized yet and may change.

Gazelle

  • New protocol buffer rules are now generated for .proto files if other proto rules are not present already. Gazelle will replace the old rules when the fix command is used.
  • Rules that were generated by Gazelle are now removed if they are empty. For example, if all of the _test.go files are removed from a directory, Gazelle will delete the go_test rules.
  • Some Gazelle command line options may be specified using directives. Directives are special comments in build files, for example, # gazelle:build_tags foo,bar.
  • Added an experimental flat mode. In this mode, Gazelle will generate a single build file for an entire repository. This is intended to be used with new_http_archive and new_git_repository once we deprecate go_repository. You can try this out with the -experimental_flat command line option.

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.6.0/rules_go-0.6.0.tar.gz",
    sha256 = "ba6feabc94a5d205013e70792accb6cce989169476668fbaf98ea9b342e13b59",
)
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.6.0.tar.gz

0.5.5

13 Sep 13:53
Compare
Choose a tag to compare
0.5.5 Pre-release
Pre-release

This is a bug fix release, needed for #820. We fetched some of our dependencies using http_archive rules with sha256 sums. The tarballs downloaded by these rules are generated by GitHub on the fly and are not guaranteed to have a stable sha256 hash. We discovered this yesterday when the hashes changed due to a GitHub OS update.

With this release, all dependencies are fetched using either git_repository, http_archive with a known-stable sha256, or http_archive without sha256 from GitHub via HTTPS.

With this release and future releases, we will include a link to a stable archive of this repository and a sha256 sum so that developers may continue to use http_archive.

rules_go-0.5.5.tar.gz - sha256: ca58b0b856dc95473b93f2228ab117913b82a6617fc0deabd107346e3981522a

0.5.4

28 Aug 16:22
Compare
Choose a tag to compare
0.5.4 Pre-release
Pre-release

This release is a bug fix release before upcoming major changes.

  • Compatibility fixes for upcoming skylark alterations.
  • go_library rules now propagate transitive depsets of the GoLibrary provider rather than individual fields
  • Better support for coverage, now works on more than just the package under test
  • Experimental support for a GOPATH-like source export system to run tools on
  • Experimental support for generating "flat" build files in gazelle
  • Minor bug fixes

0.5.3

09 Aug 22:41
Compare
Choose a tag to compare
0.5.3 Pre-release
Pre-release

Go Rules

  • go_library supports cgo when the cgo = True argument is given. cgo_library is no longer needed and is now deprecated.
  • Race detection is supported. You can use it in tests with bazel test --features=race //....
  • go_embed_data (a new rule) lets you embed data files in generated Go code.
  • go_test accepts a rundir attribute that lets you specify where the test should run. Test binaries will no longer attempt to change directories when run outside of Bazel.
  • Lots of bug fixes and refactoring.

Gazelle

  • Gazelle now accepts the update and fix commands. update is the normal, default behavior. fix will revise existing build files with deprecated rules like cgo_library. We plan to add more commands with different flags in the future.
  • Rewrote the Gazelle documentation.
  • Lots of bug fixes and refactoring.

0.5.2

17 Jul 14:11
Compare
Choose a tag to compare
0.5.2 Pre-release
Pre-release

This is a quick fix release.

  • Fixed usage of declared providers and avoided mixing declared and old-style providers.
  • go_binary now produces static binaries through the static output group.
  • Bazel 0.5.2 is now the required minimum version.

0.5.1

10 Jul 22:30
Compare
Choose a tag to compare
0.5.1 Pre-release
Pre-release

Go rules

  • Dependency checking is now strict: go_library, go_binary, and go_test must now include a library in deps for each package they import. Previously, transitive deps were allowed. This lets us speed up the build by only passing direct deps to the compiler.
  • cgo_genrule is deprecated. It now just invokes cgo_library with tags = ["manual"]. Please use cgo_library directly when possible.
  • Several internal improvements were made to cgo_library. We are planning to consolidate it with go_library some time in the future.
  • deps are now propagated through the library attribute. This means, for example, a go_test rule doesn't need to repeat deps specified in a go_library under test, though doing so is encouraged if the go_test references those dependencies itself.
  • go_test will now always change to the package directory before running test cases. This was previously broken for tests in external repositories.

Gazelle

  • Generated .go files will now be included in rules that Gazelle creates. Gazelle discovers these files by looking at filenames in out and outs attributes of other rules in BUILD files.
  • Gazelle only generate BUILD files in testdata directories if there are no .go files, BUILD files, or BUILD.bazel files in any subdirectory. Previously, Gazelle did not recurse into testdata directories at all.
  • Go release tags (e.g., go1.8) are treated as unknown (neither true nor false). Gazelle will include files with these tags, whether or not they are negated. This avoids some confusing situations where Gazelle is compiled with a different version of Go than the one used to build a project.
  • Several improvements for merging with existing files. copts and clinkopts attributes are now merged. visibility won't be added if a package rule with a default_visibility attribute is present. Comments are preserved on existing elements. deps are now sorted according to buildifier rules.

0.5.0

13 Jun 16:53
Compare
Choose a tag to compare
0.5.0 Pre-release
Pre-release

Features

  • go_repository replaces new_go_repository for dependencies with
    and without BUILD or BUILD.bazel files. go_repository will
    generate these files using Gazelle if they are not already present.
  • Import paths may be specified explicitly using the importpath in
    go_library. This allows for Go subtrees that aren't at the top of
    a repository. It also allows flat BUILD files.
  • Gazelle generates BUILD files for multiple platforms. Sources with
    build constraints (tags or filename suffixes) and dependencies
    imported from them are now compiled conditionally using select.
  • Link stamping in multiple packages is now supported via the x_defs
    attribute. x_defs may now contain values wrapped in braces (for
    example: {VAR}) which are replaced with values from the workspace
    status files.
  • Rules are substantially cleaned up and organized. Assemble, compile,
    and link actions are rewritten in Go, avoiding incompatibilities and
    quoting problems with Bash.
  • Preliminary support for toolchains.

Bug fixes

  • cgo_library now allows sources in multiple directories.
  • cgo_library no longer assumes srcs is a list (it can now include
    select calls).
  • go_binary and go_test no longer expose .a files in outputs.
  • All rules now allow target names with slashes.
  • If multiple packages are present after applying build constraints,
    Gazelle will generate BUILD files for the package matching the
    directory name. If there is no match, Gazelle will report an error.
  • Gazelle is much faster when running in external mode on repositories
    with lots of external dependencies.
  • Gazelle no longer removes # keep comments from existing sources.
  • Many more...

0.4.4

05 May 21:46
Compare
Choose a tag to compare
0.4.4 Pre-release
Pre-release

This release is a cherry-pick of #428 on top of 0.4.3. This adds support for the darwin_x86_64 cpu value, which will become standard in Bazel soon.

0.4.3

12 Apr 14:27
Compare
Choose a tag to compare
0.4.3 Pre-release
Pre-release

Features

  • Upgraded to Go 1.8.1 and provided backward compatibility for tests in 1.7.5.
  • Support for build constraints (build tags and filename suffixes) in go_library, cgo_library, go_test, and go_binary. You can now add all your sources to your rules, and they will be filtered during compilation.
    • Note: Gazelle also filters sources with build constraints. This behavior will be removed when #339 is fixed.
  • go_repositories now supports custom Go versions. Versions can be specified with a simple version string (e.g., "1.8.0") or by declaring a separate Bazel repository and providing that through the go_linux or go_darwin attributes.
  • go_repository now supports vcs and importpath attributes. This enables repositories with different URLs and import paths.
  • gc_goopts and gc_linkopts attributes can be used to pass additional options to the compiler and linker.
  • protoc and protoc_gen_go can now be overridden in go_proto_library. Also added an ignore_go_package attribute.
  • Gazelle now adds a data dependency on testdata directories.

Bug fixes

  • Fixed repositories rules that depended on the real names of repositories. This broke when one of our dependencies (github.com/bazelbuild/buildifier) was renamed to buildtools. A quick fix was backported to 0.4.2 and 0.3.4.
  • Fixed -mode diff in Gazelle. It now produces a regular textual diff.
  • Gazelle no longer attempts to rename files with -mode fix or -mode print.
  • Gazelle can now find # gazelle:ignore comments that aren't at the top of a file.
  • Bash scripts generated by rules are now executed as commands instead of executable files. This is required on Windows.
  • Fixed an infinite recursion issue on Windows.
  • data files are now propagated transitively across dependencies.