mirror of
https://github.com/bazel-contrib/bazel-lib
synced 2024-12-04 14:02:23 +00:00
4ad02b7795
* refactor(release): switch release integrity to be dynamic This matches rules_py as documented by https://blog.aspect.build/releasing-bazel-rulesets-rust It has the benefit that developers no longer get yelled at to vendor some updated integrity hashes into bazel-lib every time they touch the Go sources. * refactor: echo should produce trailing newline * chore: bump action-gh-release to avoid Node 16 warning * chore: update test that is sensitive to compilation mode We now only use --compilation_mode=opt when cutting a release
56 lines
2.1 KiB
Python
56 lines
2.1 KiB
Python
"""This module provides the macros for performing a release.
|
|
"""
|
|
|
|
load("@io_bazel_rules_go//go:def.bzl", "go_binary")
|
|
load(":hashes.bzl", "hashes")
|
|
|
|
PLATFORMS = [
|
|
struct(os = "darwin", arch = "amd64", ext = "", gc_linkopts = ["-s", "-w"]),
|
|
struct(os = "darwin", arch = "arm64", ext = "", gc_linkopts = ["-s", "-w"]),
|
|
struct(os = "freebsd", arch = "amd64", ext = "", gc_linkopts = ["-s", "-w"]),
|
|
struct(os = "linux", arch = "amd64", ext = "", gc_linkopts = ["-s", "-w"]),
|
|
struct(os = "linux", arch = "arm64", ext = "", gc_linkopts = ["-s", "-w"]),
|
|
struct(os = "windows", arch = "amd64", ext = ".exe", gc_linkopts = []),
|
|
]
|
|
|
|
def multi_platform_go_binaries(name, embed, prefix = "", **kwargs):
|
|
"""The multi_platform_go_binaries macro creates a go_binary for each platform.
|
|
|
|
Args:
|
|
name: the name of the filegroup containing all go_binary targets produced
|
|
by this macro.
|
|
embed: the list of targets passed to each go_binary target in this
|
|
macro.
|
|
prefix: an optional prefix added to the output Go binary file name.
|
|
**kwargs: extra arguments.
|
|
"""
|
|
targets = []
|
|
for platform in PLATFORMS:
|
|
target_name = "{}-{}-{}".format(name, platform.os, platform.arch)
|
|
target_label = Label("//{}:{}".format(native.package_name(), target_name))
|
|
go_binary(
|
|
name = target_name,
|
|
out = "{}{}-{}_{}{}".format(prefix, name, platform.os, platform.arch, platform.ext),
|
|
embed = embed,
|
|
gc_linkopts = platform.gc_linkopts,
|
|
goarch = platform.arch,
|
|
goos = platform.os,
|
|
pure = "on",
|
|
visibility = ["//visibility:public"],
|
|
**kwargs
|
|
)
|
|
hashes_name = "{}_hashes".format(target_name)
|
|
hashes_label = Label("//{}:{}".format(native.package_name(), hashes_name))
|
|
hashes(
|
|
name = hashes_name,
|
|
src = target_label,
|
|
**kwargs
|
|
)
|
|
targets.extend([target_label, hashes_label])
|
|
|
|
native.filegroup(
|
|
name = name,
|
|
srcs = targets,
|
|
**kwargs
|
|
)
|