Skip to content

Commit

Permalink
Merge branch 'master' into googleapis
Browse files Browse the repository at this point in the history
  • Loading branch information
linzhp committed Jul 2, 2023
2 parents 954bfbe + 488384f commit 8513280
Show file tree
Hide file tree
Showing 6 changed files with 100 additions and 7 deletions.
15 changes: 15 additions & 0 deletions .bazelci/presubmit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,21 @@ tasks:
- "//..."
test_targets:
- "//..."
debian11_zig_cc:
platform: debian11
shell_commands:
- tests/core/cgo/generate_imported_dylib.sh
build_flags:
- "--config=incompatible"
- "--extra_toolchains=@zig_sdk//toolchain:linux_amd64_gnu.2.31"
test_flags:
- "--config=incompatible"
- "--extra_toolchains=@zig_sdk//toolchain:linux_amd64_gnu.2.31"
- "--test_env=ZIG_CC=1"
build_targets:
- "//..."
test_targets:
- "//..."
bcr_tests:
name: BCR test module
platform: ${{ platform }}
Expand Down
5 changes: 3 additions & 2 deletions .bazelrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
common --enable_platform_specific_config
test --test_output=errors

# Go requires a C toolchain that accepts options and emits errors like
# gcc or clang. The Go SDK does not support MSVC.
build:windows --cpu=x64_windows
build:windows --compiler=mingw-gcc

# NOTE(bazelbuild/bazel#10529): bazel doesn't register the mingw toolchain automatically.
# We also need the host and target platforms to have the mingw constraint value.
build:windows --extra_toolchains=@local_config_cc//:cc-toolchain-x64_windows_mingw
Expand All @@ -19,7 +21,6 @@ build:ci --sandbox_debug
build:ci --spawn_strategy=standalone
build:ci --genrule_strategy=standalone
test:ci --test_strategy=standalone
test:ci --test_output=errors

# Incompatible flags to test in a dedicated CI pipeline.
build:incompatible --incompatible_load_proto_rules_from_bzl
Expand All @@ -30,5 +31,5 @@ build:incompatible --incompatible_disallow_empty_glob
build:incompatible --incompatible_disable_starlark_host_transitions
# Also enable all incompatible flags in go_bazel_test by default.
# TODO: Add --incompatible_disallow_empty_glob once
# https://github.com/bazelbuild/bazel-gazelle/pull/1405 has been released.
# https://github.com/bazelbuild/bazel-gazelle/pull/1405 has been released.
test:incompatible --test_env=GO_BAZEL_TEST_BAZELFLAGS='--incompatible_load_proto_rules_from_bzl --incompatible_enable_cc_toolchain_resolution --incompatible_config_setting_private_default_visibility --incompatible_enforce_config_setting_visibility --incompatible_disable_starlark_host_transitions'
21 changes: 21 additions & 0 deletions WORKSPACE
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,27 @@ load(

apple_support_dependencies()

# For testing the compatibility with a hermetic cc toolchain. Users should not have to enable it.

http_archive(
name = "hermetic_cc_toolchain",
sha256 = "bd2234acd0837251361be3270d7d3ce599b418be123d902d84762302e31a3014",
strip_prefix = "hermetic_cc_toolchain-13c904dce0cb9b6d07f0d557e6ce3cf7013a562e",
urls = ["https://github.com/uber/hermetic_cc_toolchain/archive/13c904dce0cb9b6d07f0d557e6ce3cf7013a562e.zip"],
)

load("@hermetic_cc_toolchain//toolchain:defs.bzl", zig_toolchains = "toolchains")

zig_toolchains(
host_platform_sha256 = {
"linux-aarch64": "12be476ed53c219507e77737dbb7f2a77b280760b8acbc6ba2eaaeb42b7d145e",
"linux-x86_64": "1b1c115c4ccbdc215cc3b07833c7957336d9f5fff816f97e5cafee556a9d8be8",
"macos-aarch64": "3943612c560dd066fba5698968317a146a0f585f6cdaa1e7c1df86685c7c4eaf",
"macos-x86_64": "0c89e5d934ecbf9f4d2dea6e3b8dfcc548a3d4184a856178b3db74e361031a2b",
},
version = "0.11.0-dev.3886+0c1bfe271",
)

load("@googleapis//:repository_rules.bzl", "switched_rules_by_language")

switched_rules_by_language(
Expand Down
3 changes: 2 additions & 1 deletion go/private/extensions.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,8 @@ def _default_go_sdk_name(*, module, multi_version, tag_type, index):
# Keep the version out of the repository name if possible to prevent unnecessary rebuilds when
# it changes.
return "{name}_{version}_{tag_type}_{index}".format(
name = module.name,
# "main_" is not a valid module name and thus can't collide.
name = module.name or "main_",
version = module.version if multi_version else "",
tag_type = tag_type,
index = index,
Expand Down
57 changes: 53 additions & 4 deletions tests/core/cgo/cc_libs_linux_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ package cc_libs_test

import (
"debug/elf"
"os"
"path"
"strings"
"testing"
Expand All @@ -30,16 +31,16 @@ func TestBinaries(t *testing.T) {
}{
{
shortPath: "tests/core/cgo/pure_bin",
wantLibs: map[string]bool{"libc": false, "libstdc++": false},
wantLibs: map[string]bool{"libc": false},
}, {
shortPath: "tests/core/cgo/c_srcs_bin",
wantLibs: map[string]bool{"libc": true, "libstdc++": false},
wantLibs: map[string]bool{"libc": true},
}, {
shortPath: "tests/core/cgo/cc_srcs_bin",
wantLibs: map[string]bool{"libc": true, "libstdc++": true},
wantLibs: map[string]bool{"libc": true},
}, {
shortPath: "tests/core/cgo/cc_deps_bin",
wantLibs: map[string]bool{"libc": true, "libstdc++": true},
wantLibs: map[string]bool{"libc": true},
},
} {
t.Run(path.Base(test.shortPath), func(t *testing.T) {
Expand Down Expand Up @@ -67,6 +68,54 @@ func TestBinaries(t *testing.T) {
}
}

// zig cc statically links libstdc++: https://github.com/ziglang/zig/issues/12147
// Consider merging this into TestBinaries once the above issue is resolved.
func TestBinaries_libstdcpp(t *testing.T) {
if os.Getenv("ZIG_CC") == "1" {
t.Skip()
}

for _, test := range []struct {
shortPath string
wantLibs map[string]bool
}{
{
shortPath: "tests/core/cgo/pure_bin",
wantLibs: map[string]bool{"libstdc++": false},
}, {
shortPath: "tests/core/cgo/c_srcs_bin",
wantLibs: map[string]bool{"libstdc++": false},
}, {
shortPath: "tests/core/cgo/cc_srcs_bin",
wantLibs: map[string]bool{"libstdc++": true},
}, {
shortPath: "tests/core/cgo/cc_deps_bin",
wantLibs: map[string]bool{"libstdc++": true},
},
} {
t.Run(path.Base(test.shortPath), func(t *testing.T) {
libs, err := listLibs(test.shortPath)
if err != nil {
t.Fatal(err)
}
haveLibs := make(map[string]bool)
for _, lib := range libs {
haveLibs[lib] = true
}
for haveLib := range haveLibs {
if wantLib, ok := test.wantLibs[haveLib]; ok && !wantLib {
t.Errorf("unexpected dependency on library %q", haveLib)
}
}
for wantLib, want := range test.wantLibs {
if want && !haveLibs[wantLib] {
t.Errorf("wanted dependency on library %q", wantLib)
}
}
})
}
}

func listLibs(shortPath string) ([]string, error) {
binPath, err := bazel.Runfile(shortPath)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions tests/core/go_binary/static_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,19 @@ package static_cgo_test

import (
"debug/elf"
"os"
"testing"

"github.com/bazelbuild/rules_go/go/tools/bazel"
)

func TestStatic(t *testing.T) {
for _, name := range []string{"static_bin", "static_cgo_bin", "static_pure_bin"} {
if name != "static_pure_bin" && os.Getenv("ZIG_CC") == "1" {
// zig does not statically link glibc, by design or accident.
t.Skip()
}

t.Run(name, func(t *testing.T) {
path, ok := bazel.FindBinary("tests/core/go_binary", name)
if !ok {
Expand Down

0 comments on commit 8513280

Please sign in to comment.