From 491144c721927e110dc99e832ef0cca75eb5c471 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 24 Apr 2023 14:25:29 +0300 Subject: [PATCH] remove rules/rules_go 1. Go needed quite a few hacks to be made work with Go. From https://github.com/ziglang/zig/pull/15060 less hacks are needed (but still not zero, though now documented). 2. This file was never meant to be exposed as part of `hermetic_cc_toolchain`. I probably broke someone. Sorry. --- BUILD | 2 -- WORKSPACE | 2 +- rules/rules_go.bzl | 24 ------------------------ test/cgo/BUILD | 10 ++++++++-- test/gorace/BUILD | 3 +-- tools/releaser/BUILD | 3 +-- 6 files changed, 11 insertions(+), 33 deletions(-) delete mode 100644 rules/rules_go.bzl diff --git a/BUILD b/BUILD index 24209a3..1f87bc6 100644 --- a/BUILD +++ b/BUILD @@ -3,8 +3,6 @@ load("@bazel_gazelle//:def.bzl", "gazelle") -# gazelle:map_kind go_binary go_binary //rules:rules_go.bzl - # gazelle:build_file_name BUILD # gazelle:prefix github.com/uber/hermetic_cc_toolchain # gazelle:exclude tools.go diff --git a/WORKSPACE b/WORKSPACE index ad683cf..ca56f60 100644 --- a/WORKSPACE +++ b/WORKSPACE @@ -30,7 +30,7 @@ go_rules_dependencies() # use latest stable. go_download_sdk( name = "go_sdk", - version = "1.20", + version = "1.20.3", ) go_register_toolchains() diff --git a/rules/rules_go.bzl b/rules/rules_go.bzl deleted file mode 100644 index a830248..0000000 --- a/rules/rules_go.bzl +++ /dev/null @@ -1,24 +0,0 @@ -# Copyright 2023 Uber Technologies, Inc. -# Licensed under the MIT License - -load("@io_bazel_rules_go//go:def.bzl", go_binary_rule = "go_binary") - -""" -go_binary overrides go_binary from rules_go and provides default -gc_linkopts values that are needed to compile for macos target. -To use it, add this map_kind gazelle directive to your BUILD.bazel files -where target binary needs to be compiled with zig toolchain. - -Example: if this toolchain is registered as hermetic_cc_toolchain in your WORKSPACE, add this to -your root BUILD file -# gazelle:map_kind go_binary go_binary @hermetic_cc_toolchain//rules:rules_go.bzl -""" - -_MACOS_GC_LINKOPTS = ["-s", "-w", "-buildmode=pie"] - -def go_binary(**kwargs): - kwargs["gc_linkopts"] = select({ - "@platforms//os:macos": _MACOS_GC_LINKOPTS, - "//conditions:default": [], - }) + kwargs.pop("gc_linkopts", []) - go_binary_rule(**kwargs) diff --git a/test/cgo/BUILD b/test/cgo/BUILD index b362c6e..71c8d2a 100644 --- a/test/cgo/BUILD +++ b/test/cgo/BUILD @@ -1,8 +1,7 @@ # Copyright 2023 Uber Technologies, Inc. # Licensed under the MIT License -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") -load("//rules:rules_go.bzl", "go_binary") +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test") load("@hermetic_cc_toolchain//rules:platform.bzl", "platform_binary", "platform_test") go_library( @@ -22,6 +21,13 @@ go_test( go_binary( name = "cgo", embed = [":cgo_lib"], + gc_linkopts = select({ + "@platforms//os:macos": [ + "-w", # https://github.com/ziglang/zig/issues/15439 + "-buildmode=pie", # https://github.com/ziglang/zig/issues/15438 + ], + "//conditions:default": [], + }), visibility = ["//visibility:public"], ) diff --git a/test/gorace/BUILD b/test/gorace/BUILD index 402cc5a..398a9a7 100644 --- a/test/gorace/BUILD +++ b/test/gorace/BUILD @@ -1,8 +1,7 @@ # Copyright 2023 Uber Technologies, Inc. # Licensed under the MIT License -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") -load("//rules:rules_go.bzl", "go_binary") +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test") go_library( name = "gorace_lib", diff --git a/tools/releaser/BUILD b/tools/releaser/BUILD index 028926c..38ef526 100644 --- a/tools/releaser/BUILD +++ b/tools/releaser/BUILD @@ -1,8 +1,7 @@ # Copyright 2023 Uber Technologies, Inc. # Licensed under the MIT License -load("//rules:rules_go.bzl", "go_binary") -load("@io_bazel_rules_go//go:def.bzl", "go_library", "go_test") +load("@io_bazel_rules_go//go:def.bzl", "go_binary", "go_library", "go_test") go_library( name = "releaser_lib",