From 187091e6e95428ba8c0ec6954576d5c84572f979 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 12 Feb 2024 14:47:06 +0200 Subject: [PATCH 01/12] releaser: add "yes" when the file is found this call can take a while, so let's be clear when it ends --- tools/releaser/main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/releaser/main.go b/tools/releaser/main.go index 24c52622..6640de2f 100644 --- a/tools/releaser/main.go +++ b/tools/releaser/main.go @@ -124,6 +124,7 @@ This utility is intended to handle many of the steps to release a new version. out, ) } + log("yes") if err := checkZigMirrored(repoRoot); err != nil { return fmt.Errorf("zig is correctly mirrored: %w", err) @@ -482,6 +483,8 @@ func checkZigMirrored(repoRoot string) error { return fmt.Errorf("got non-200: %s", resp.Status) } + log("yes") + return nil } From bef0f1f00bd751938a6ed3977b188419842f358f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 12 Feb 2024 10:10:29 +0200 Subject: [PATCH 02/12] macos: add libc/darwin Zig SDK is looking for lib/cdarwin/SDKSettings.json when compiling to MacOS. --- toolchain/private/defs.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/toolchain/private/defs.bzl b/toolchain/private/defs.bzl index e3ddad6e..8394012f 100644 --- a/toolchain/private/defs.bzl +++ b/toolchain/private/defs.bzl @@ -61,6 +61,7 @@ def _target_macos(gocpu, zigcpu): zigtarget = "{}-macos-none".format(zigcpu), includes = [ "libunwind/include", + "libc/darwin", "libc/include/any-macos-any", ] + _INCLUDE_TAIL, linkopts = ["-Wl,-headerpad_max_install_names"], From eb4f79b2bbe6ec0633eba1ebf29199a1b8917c36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 12 Feb 2024 10:12:54 +0200 Subject: [PATCH 03/12] move Zig SDK archives to a separate file Will become useful later when calculating cache keys for github actions. --- toolchain/defs.bzl | 28 +++++++++------------------- toolchain/private/zig_sdk.bzl | 16 ++++++++++++++++ tools/releaser/main.go | 11 ++++++----- tools/releaser/main_test.go | 10 +++++----- 4 files changed, 36 insertions(+), 29 deletions(-) create mode 100644 toolchain/private/zig_sdk.bzl diff --git a/toolchain/defs.bzl b/toolchain/defs.bzl index 575ff60f..a145f328 100644 --- a/toolchain/defs.bzl +++ b/toolchain/defs.bzl @@ -1,6 +1,13 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") load("@bazel_tools//tools/build_defs/repo:utils.bzl", "read_user_netrc", "use_netrc") load("@hermetic_cc_toolchain//toolchain/private:defs.bzl", "target_structs", "zig_tool_path") +load( + "@hermetic_cc_toolchain//toolchain/private:zig_sdk.bzl", + "HOST_PLATFORM_SHA256", + "URL_FORMAT_NIGHTLY", + "URL_FORMAT_RELEASE", + "VERSION", +) _BUILTIN_TOOLS = ["ar", "ld.lld", "lld-link"] @@ -11,23 +18,6 @@ _DEFAULT_INCLUDE_DIRECTORIES = [ "libunwind/include", ] -# Official recommended version. Should use this when we have a usable release. -URL_FORMAT_RELEASE = "https://ziglang.org/download/{version}/zig-{host_platform}-{version}.{_ext}" - -# Caution: nightly releases are purged from ziglang.org after ~90 days. Use the -# Bazel mirror or your own. -URL_FORMAT_NIGHTLY = "https://ziglang.org/builds/zig-{host_platform}-{version}.{_ext}" - -_VERSION = "0.12.0-dev.2631+3069669bc" - -_HOST_PLATFORM_SHA256 = { - "linux-aarch64": "ea6bd76d5de66a39a2c36286fe96a02c37ae7956924bd9e45879facd3a76ebab", - "linux-x86_64": "fcc7d3e6b69c129d755653b3a7b4efc49fe2f7cee535dadc99999be7416977e7", - "macos-aarch64": "23ddbde196c4a62de96bf671306bade8454ee776f0d675cb5fc8bfd38f63a22e", - "macos-x86_64": "64268cb562d2a89c86c51f3c23d82a27690741e77fd980962a1b282b98adc5a4", - "windows-x86_64": "5216ceda34a7133117bf54fb857d5d1cb47f0f3b834172ee9e707621e2b9d2b3", -} - _HOST_PLATFORM_EXT = { "linux-aarch64": "tar.xz", "linux-x86_64": "tar.xz", @@ -67,9 +57,9 @@ After commenting on the issue, `rm -fr {cache_prefix}` and re-run your command. """ def toolchains( - version = _VERSION, + version = VERSION, url_formats = [], - host_platform_sha256 = _HOST_PLATFORM_SHA256, + host_platform_sha256 = HOST_PLATFORM_SHA256, host_platform_ext = _HOST_PLATFORM_EXT): """ Download zig toolchain and declare bazel toolchains. diff --git a/toolchain/private/zig_sdk.bzl b/toolchain/private/zig_sdk.bzl new file mode 100644 index 00000000..c1b19fec --- /dev/null +++ b/toolchain/private/zig_sdk.bzl @@ -0,0 +1,16 @@ +VERSION = "0.12.0-dev.2631+3069669bc" + +HOST_PLATFORM_SHA256 = { + "linux-aarch64": "ea6bd76d5de66a39a2c36286fe96a02c37ae7956924bd9e45879facd3a76ebab", + "linux-x86_64": "fcc7d3e6b69c129d755653b3a7b4efc49fe2f7cee535dadc99999be7416977e7", + "macos-aarch64": "23ddbde196c4a62de96bf671306bade8454ee776f0d675cb5fc8bfd38f63a22e", + "macos-x86_64": "64268cb562d2a89c86c51f3c23d82a27690741e77fd980962a1b282b98adc5a4", + "windows-x86_64": "5216ceda34a7133117bf54fb857d5d1cb47f0f3b834172ee9e707621e2b9d2b3", +} + +# Official recommended version. Should use this when we have a usable release. +URL_FORMAT_RELEASE = "https://ziglang.org/download/{version}/zig-{host_platform}-{version}.{_ext}" + +# Caution: nightly releases are purged from ziglang.org after ~90 days. Use the +# Bazel mirror or your own. +URL_FORMAT_NIGHTLY = "https://ziglang.org/builds/zig-{host_platform}-{version}.{_ext}" diff --git a/tools/releaser/main.go b/tools/releaser/main.go index 6640de2f..1a0dcb33 100644 --- a/tools/releaser/main.go +++ b/tools/releaser/main.go @@ -44,6 +44,7 @@ var ( "v2.1.0": "892b0dd7aa88c3504a8821e65c44fd22f32c16afab12d89e9942fff492720b37", "v2.1.1": "86ace5cd211d0ae49a729a11afb344843698b64464f2095a776c57ebbdf06698", "v2.1.3": "a5caccbf6d86d4f60afd45b541a05ca4cc3f5f523aec7d3f7711e584600fb075", + "v2.2.1": "3b8107de0d017fe32e6434086a9568f97c60a111b49dc34fc7001e139c30fdea", } _boilerplateFiles = []string{ @@ -459,13 +460,13 @@ type zigUpstream struct { // check if zig sdk is properly mirrored func checkZigMirrored(repoRoot string) error { - upstream, err := parseZigUpstream(path.Join(repoRoot, "toolchain", "defs.bzl")) + upstream, err := parseZigUpstream(path.Join(repoRoot, "toolchain", "private", "zig_sdk.bzl")) if err != nil { return err } // spot-checking only windows-x86_64, because: - // - to check all platforms, we should parse much more of defs.bzl. + // - to check all platforms, we should parse much more of zig_sdk.bzl. // - so we'd rather pick a single platform and test it. // - because windows coverage is smallest, let's take the windows platform. url := strings.Replace(upstream.urlTemplate, "{host_platform}", "windows-x86_64", 1) @@ -488,7 +489,7 @@ func checkZigMirrored(repoRoot string) error { return nil } -// parseZigUpstrem parses "_VERSION" from toolchain/defs.bzl +// parseZigUpstrem parses "VERSION" from toolchain/private/zig_sdk.bzl func parseZigUpstream(defsPath string) (zigUpstream, error) { ret := zigUpstream{} @@ -512,7 +513,7 @@ func parseZigUpstream(defsPath string) (zigUpstream, error) { var to *string switch key.Name { - case "_VERSION": + case "VERSION": to = &ret.version case "URL_FORMAT_RELEASE": to = &releaseFormat @@ -531,7 +532,7 @@ func parseZigUpstream(defsPath string) (zigUpstream, error) { } if ret.version == "" { - return zigUpstream{}, errors.New("_VERSION not found") + return zigUpstream{}, errors.New("VERSION not found") } if strings.Contains(ret.version, "dev") { ret.urlTemplate = nightlyFormat diff --git a/tools/releaser/main_test.go b/tools/releaser/main_test.go index 28b27aa6..c991d306 100644 --- a/tools/releaser/main_test.go +++ b/tools/releaser/main_test.go @@ -49,7 +49,7 @@ func TestParseZigVersion(t *testing.T) { }{ { name: "released url", - contents: `_VERSION = "0.11.0"; URL_FORMAT_RELEASE = "https://ziglang.org/download/{version}/zig-{host_platform}-{version}.{_ext}"`, + contents: `VERSION = "0.11.0"; URL_FORMAT_RELEASE = "https://ziglang.org/download/{version}/zig-{host_platform}-{version}.{_ext}"`, want: zigUpstream{ version: "0.11.0", urlTemplate: "https://mirror.bazel.build/ziglang.org/download/{version}/zig-{host_platform}-{version}.{_ext}", @@ -57,7 +57,7 @@ func TestParseZigVersion(t *testing.T) { }, { name: "nightly url", - contents: `_VERSION = "0.11.0-dev.2619+bd3e248c7"; URL_FORMAT_NIGHTLY = "https://ziglang.org/builds/zig-{host_platform}-{version}.{_ext}"`, + contents: `VERSION = "0.11.0-dev.2619+bd3e248c7"; URL_FORMAT_NIGHTLY = "https://ziglang.org/builds/zig-{host_platform}-{version}.{_ext}"`, want: zigUpstream{ version: "0.11.0-dev.2619+bd3e248c7", urlTemplate: "https://mirror.bazel.build/ziglang.org/builds/zig-{host_platform}-{version}.{_ext}", @@ -65,17 +65,17 @@ func TestParseZigVersion(t *testing.T) { }, { name: "not an assignment", - contents: `def _VERSION(x): return x`, + contents: `def VERSION(x): return x`, wantErr: "got a non-string expression", }, { name: "missing version assignment", contents: "x1 = 1", - wantErr: "assign statement _VERSION = <...> not found", + wantErr: "assign statement VERSION = <...> not found", }, { name: "missing url assignment", - contents: `_VERSION = "0.11.0"; URL_FORMAT_NIGHTLY = "https://ziglang.org/builds/zig-{host_platform}-{version}.{_ext}"`, + contents: `VERSION = "0.11.0"; URL_FORMAT_NIGHTLY = "https://ziglang.org/builds/zig-{host_platform}-{version}.{_ext}"`, wantErr: "url format for '0.11.0' not found", }, } From 1931bfaa9b885ee2ac398e0a5ac67a929b11c7e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 12 Feb 2024 10:14:34 +0200 Subject: [PATCH 04/12] link: add lib/tsan directory Looks like there weren't many TSAN users before, so this was missed for such a long time. --- toolchain/defs.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/toolchain/defs.bzl b/toolchain/defs.bzl index a145f328..54ae5759 100644 --- a/toolchain/defs.bzl +++ b/toolchain/defs.bzl @@ -284,6 +284,7 @@ def declare_files(os): "lib/libunwind/**", "lib/compiler_rt/**", "lib/std/**", + "lib/tsan/**", "lib/*.zig", "lib/*.h", ]), From 3a183e43b9b6b6f42a1ce14a5ccc256f8eb33f26 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 12 Feb 2024 10:16:02 +0200 Subject: [PATCH 05/12] chore: bump bazel to 7.0.2 --- .bazelversion | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.bazelversion b/.bazelversion index 66ce77b7..a8907c02 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -7.0.0 +7.0.2 From 1d2ba724c249b5fb25e9a94622a8162e99633103 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 12 Feb 2024 10:16:51 +0200 Subject: [PATCH 06/12] ci/release: ignore 2.2.3 too 2.2.3 is a broken tag too, ignore that. --- ci/release | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/release b/ci/release index 2cfba6a4..72121cbb 100755 --- a/ci/release +++ b/ci/release @@ -8,7 +8,7 @@ set -xeuo pipefail cd "$(git rev-parse --show-toplevel)" >&2 echo "--- releaser :flag-lt:" -TAG=$(git -c 'versionsort.suffix=-rc' tag --sort=v:refname | grep -v v2.2.2 | tail -1) +TAG=$(git -c 'versionsort.suffix=-rc' tag --sort=v:refname | grep -vE '2\.2\.(2|3)' | tail -1) tools/bazel run //tools/releaser -- -tag "$TAG" -skipBranchCheck >&2 echo "--- git diff :git:" From 3d2679932eb678ef896747ab24fa5cace66ce1f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 12 Feb 2024 10:19:04 +0200 Subject: [PATCH 07/12] rules/zig_binary.bzl: cfg = "exec" `cp` is mean to run on the host. --- rules/platform.bzl | 1 + 1 file changed, 1 insertion(+) diff --git a/rules/platform.bzl b/rules/platform.bzl index 5e408a83..b05b4dec 100644 --- a/rules/platform.bzl +++ b/rules/platform.bzl @@ -49,6 +49,7 @@ _attrs = { "_cp": attr.label( default = "//rules:cp", allow_single_file = True, + cfg = "exec", ), } From 37a78bc84d9d4f90ed55d06206603d2d54805895 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 12 Feb 2024 10:21:43 +0200 Subject: [PATCH 08/12] chore: bump gazelle and rules_go --- MODULE.bazel | 4 ++-- examples/bzlmod/MODULE.bazel | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/MODULE.bazel b/MODULE.bazel index c22fbfb5..5824ec96 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -5,7 +5,7 @@ module( bazel_dep(name = "platforms", version = "0.0.8") -bazel_dep(name = "rules_go", version = "0.43.0", dev_dependency = True) +bazel_dep(name = "rules_go", version = "0.45.1", dev_dependency = True) go_sdk = use_extension( "@rules_go//go:extensions.bzl", @@ -14,7 +14,7 @@ go_sdk = use_extension( ) use_repo(go_sdk, "go_default_sdk") -bazel_dep(name = "gazelle", version = "0.34.0", dev_dependency = True) +bazel_dep(name = "gazelle", version = "0.35.0", dev_dependency = True) go_deps = use_extension( "@gazelle//:extensions.bzl", diff --git a/examples/bzlmod/MODULE.bazel b/examples/bzlmod/MODULE.bazel index df3ee306..3d800e26 100644 --- a/examples/bzlmod/MODULE.bazel +++ b/examples/bzlmod/MODULE.bazel @@ -27,6 +27,6 @@ register_toolchains( bazel_dep( name = "rules_go", - version = "0.41.0", + version = "0.45.1", repo_name = "io_bazel_rules_go", ) From 4608b5431fe2e0f1714ca9b42e2f791d0f14d661 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 12 Feb 2024 10:22:32 +0200 Subject: [PATCH 09/12] Do not register MacOS toolchains Since `hermetic_cc_toolchain` does not support MacOS SDK, registering it as the default C++ toolchain causes a lot of headaches to run/skip the CGo tests. --- .bazelrc | 5 ++++- MODULE.bazel | 2 -- examples/bzlmod/MODULE.bazel | 2 -- test/c/BUILD | 34 ++++++++++++++++++++++++++++------ test/c/main.c | 13 +++++++++++-- 5 files changed, 43 insertions(+), 13 deletions(-) diff --git a/.bazelrc b/.bazelrc index ba57c2f8..beffe3f4 100644 --- a/.bazelrc +++ b/.bazelrc @@ -5,6 +5,9 @@ build --incompatible_disallow_empty_glob build --verbose_failures build --worker_sandboxing -build --action_env BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 +# TODO: turn this back on when Zig can build CGo (https://github.com/uber/hermetic_cc_toolchain/issues/10) +#build --action_env BAZEL_DO_NOT_DETECT_CPP_TOOLCHAIN=1 build --experimental_output_directory_naming_scheme=diff_against_dynamic_baseline build --sandbox_add_mount_pair=/tmp + +build:darwin_toolchains --extra_toolchains @zig_sdk//toolchain:darwin_amd64,@zig_sdk//toolchain:darwin_arm64 diff --git a/MODULE.bazel b/MODULE.bazel index 5824ec96..7cc26c83 100644 --- a/MODULE.bazel +++ b/MODULE.bazel @@ -36,8 +36,6 @@ register_toolchains( # (linux,darwin,windows)x(amd64,arm64) "@zig_sdk//toolchain:linux_amd64_gnu.2.28", "@zig_sdk//toolchain:linux_arm64_gnu.2.28", - "@zig_sdk//toolchain:darwin_amd64", - "@zig_sdk//toolchain:darwin_arm64", "@zig_sdk//toolchain:windows_amd64", "@zig_sdk//toolchain:windows_arm64", diff --git a/examples/bzlmod/MODULE.bazel b/examples/bzlmod/MODULE.bazel index 3d800e26..94d6d090 100644 --- a/examples/bzlmod/MODULE.bazel +++ b/examples/bzlmod/MODULE.bazel @@ -19,8 +19,6 @@ use_repo(toolchains, "zig_sdk") register_toolchains( "@zig_sdk//toolchain:linux_amd64_gnu.2.31", "@zig_sdk//toolchain:linux_arm64_gnu.2.31", - "@zig_sdk//toolchain:darwin_amd64", - "@zig_sdk//toolchain:darwin_arm64", "@zig_sdk//toolchain:windows_amd64", "@zig_sdk//toolchain:windows_arm64", ) diff --git a/test/c/BUILD b/test/c/BUILD index 92c831b3..de8c7b96 100644 --- a/test/c/BUILD +++ b/test/c/BUILD @@ -3,9 +3,6 @@ load("@hermetic_cc_toolchain//rules:platform.bzl", "platform_binary") cc_binary( name = "which_libc", srcs = ["main.c"], - target_compatible_with = [ - "@platforms//os:linux", - ], ) [ @@ -26,8 +23,33 @@ cc_binary( ), ) for name, platform, want in [ - ("linux_amd64_musl", "//libc_aware/platform:linux_amd64_musl", "non-glibc"), - ("linux_amd64_gnu.2.28", "//libc_aware/platform:linux_amd64_gnu.2.28", "glibc_2.28"), - ("linux_amd64", "//platform:linux_amd64", "glibc_2.28"), + ("linux_amd64_musl", "//libc_aware/platform:linux_amd64_musl", "linux non-glibc"), + ("linux_amd64_gnu.2.28", "//libc_aware/platform:linux_amd64_gnu.2.28", "linux glibc_2.28"), + ("linux_amd64", "//platform:linux_amd64", "linux glibc_2.28"), + ] +] + +[ + ( + platform_binary( + name = "which_libc_{}".format(name), + src = "which_libc", + platform = platform, + tags = tags, + ), + ) + for name, platform, tags in [ + ( + "darwin_amd64", + "//platform:darwin_amd64", + ["darwin_c"], + ), + ( + "darwin_arm64", + "//platform:darwin_arm64", + ["darwin_c"], + ), + ("windows_amd64", "//platform:windows_amd64", []), + ("windows_arm64", "//platform:windows_arm64", []), ] ] diff --git a/test/c/main.c b/test/c/main.c index eed1f90a..1ae2b26d 100644 --- a/test/c/main.c +++ b/test/c/main.c @@ -2,13 +2,22 @@ // Licensed under the MIT License #include +#if defined(_WIN64) +#define OS "windows" +#elif __APPLE__ +#define OS "macos" +#elif __linux__ +#define OS "linux" #include +#else +# error "Unknown compiler!" +#endif int main() { #ifdef __GLIBC__ - printf("glibc_%d.%d\n", __GLIBC__, __GLIBC_MINOR__); + printf("%s glibc_%d.%d\n", OS, __GLIBC__, __GLIBC_MINOR__); #else - printf("non-glibc\n"); + printf("%s non-glibc\n", OS); #endif return 0; } From 5d7a644bfed0e05d590d3c0bf2cf0f0133b3f558 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 12 Feb 2024 13:17:31 +0200 Subject: [PATCH 10/12] move test/windows to test/c --- test/c/main.c | 20 ++++++++++++++++---- test/windows/BUILD | 22 ---------------------- test/windows/main.c | 19 ------------------- 3 files changed, 16 insertions(+), 45 deletions(-) delete mode 100644 test/windows/BUILD delete mode 100644 test/windows/main.c diff --git a/test/c/main.c b/test/c/main.c index 1ae2b26d..72280b89 100644 --- a/test/c/main.c +++ b/test/c/main.c @@ -3,21 +3,33 @@ #include #if defined(_WIN64) +#include #define OS "windows" #elif __APPLE__ #define OS "macos" #elif __linux__ -#define OS "linux" #include +#define OS "linux" #else # error "Unknown compiler!" #endif int main() { - #ifdef __GLIBC__ +#if defined(_WIN64) + DWORD version = GetVersion(); + DWORD majorVersion = (DWORD)(LOBYTE(LOWORD(version))); + DWORD minorVersion = (DWORD)(HIBYTE(LOWORD(version))); + + DWORD build = 0; + if (version < 0x80000000) { + build = (DWORD)(HIWORD(version)); + } + + printf("%s %lu.%lu (%lu).\n", OS, majorVersion, minorVersion, build); +#elif defined __GLIBC__ printf("%s glibc_%d.%d\n", OS, __GLIBC__, __GLIBC_MINOR__); - #else +#else printf("%s non-glibc\n", OS); - #endif +#endif return 0; } diff --git a/test/windows/BUILD b/test/windows/BUILD deleted file mode 100644 index 41912153..00000000 --- a/test/windows/BUILD +++ /dev/null @@ -1,22 +0,0 @@ -# Copyright 2023 Uber Technologies, Inc. -# Licensed under the MIT License - -load("@hermetic_cc_toolchain//rules:platform.bzl", "platform_binary", "platform_test") - -cc_binary( - name = "winver", - srcs = ["main.c"], - tags = ["manual"], -) - -platform_binary( - name = "winver_windows_amd64", - src = "winver", - platform = "//platform:windows_amd64", -) - -platform_binary( - name = "winver_windows_arm64", - src = "winver", - platform = "//platform:windows_arm64", -) diff --git a/test/windows/main.c b/test/windows/main.c deleted file mode 100644 index 7621f8f8..00000000 --- a/test/windows/main.c +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright 2023 Uber Technologies, Inc. -// Licensed under the MIT License - -#include -#include - -int main() { - DWORD version = GetVersion(); - DWORD majorVersion = (DWORD)(LOBYTE(LOWORD(version))); - DWORD minorVersion = (DWORD)(HIBYTE(LOWORD(version))); - - DWORD build = 0; - if (version < 0x80000000) { - build = (DWORD)(HIWORD(version)); - } - - printf("Running Windows version %d.%d (%d).\n", majorVersion, minorVersion, build); - return 0; -} From 2889b7bd4bab20ed583c1c7d7d308a29ba0aa809 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 12 Feb 2024 14:45:40 +0200 Subject: [PATCH 11/12] ci scripts: set -x; replace 'buildkite' with 'generic ci' --- ci/lint | 2 +- ci/prepare_git | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ci/lint b/ci/lint index 4e1404e7..366729d6 100755 --- a/ci/lint +++ b/ci/lint @@ -3,7 +3,7 @@ # Copyright 2023 Uber Technologies, Inc. # Licensed under the MIT License -set -euo pipefail +set -xeuo pipefail cd "$(git rev-parse --show-toplevel)" diff --git a/ci/prepare_git b/ci/prepare_git index 10fc79a7..7e2385db 100755 --- a/ci/prepare_git +++ b/ci/prepare_git @@ -1,5 +1,5 @@ #!/bin/sh -set -x +set -ex -git config --global user.email "buildkite@example.com" -git config --global user.name "Buildkite Bot" +git config --global user.email "ci@example.com" +git config --global user.name "CI Bot" From 0cd9acc07efb27cb2c704cdf9a225321d60d8eaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Motiejus=20Jak=C5=A1tys?= Date: Mon, 12 Feb 2024 10:25:06 +0200 Subject: [PATCH 12/12] replace buildkite with github actions Thus we gain Windows and MacOS hosts. --- .buildkite/pipeline.yml | 28 ------------------ .github/workflows/ci.yaml | 62 +++++++++++++++++++++++++++++++++++++++ ci/zig-utils | 35 +--------------------- test/gorace/BUILD | 5 ++++ 4 files changed, 68 insertions(+), 62 deletions(-) delete mode 100644 .buildkite/pipeline.yml create mode 100644 .github/workflows/ci.yaml diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml deleted file mode 100644 index 1ac4a4c3..00000000 --- a/.buildkite/pipeline.yml +++ /dev/null @@ -1,28 +0,0 @@ -# Copyright 2023 Uber Technologies, Inc. -# Licensed under the MIT License - -# The commands are in a single line due to this warning in buildkite: -# ⚠️ The command received has multiple lines. -# ⚠️ The Docker Plugin may not correctly run multiple commands in the step-level configuration. -# ⚠️ You will need to use a single command, a script or the plugin's command option. - -steps: - - label: "Test" - command: ci/test - - label: "Lint" - command: ci/lint - - label: "List Platforms" - command: ci/list_toolchains_platforms - - label: "Test Release" - command: ci/prepare_git && echo "--- ci/release" && ci/release - - label: "Test zig utilities" - command: ci/zig-utils - env: - HERMETIC_CC_TOOLCHAIN_SKIP_WINE: 1 - - label: "Test rules_cc example" - command: ci/prepare_git && ci/test_example rules_cc override_repository - - label: "Test bzlmod example" - command: ci/prepare_git && ci/test_example bzlmod override_module -agents: - - "queue=init" - - "docker=*" diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 00000000..d8e09d1b --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,62 @@ +--- +name: ci +on: + push: + pull_request: +defaults: + run: + shell: bash +concurrency: + # Cancels pending runs when a PR gets updated. + group: ${{ github.head_ref || github.run_id }}-${{ github.actor }} + cancel-in-progress: true +jobs: + + build-and-test: + strategy: + matrix: + os: [windows-latest, ubuntu-latest, macos-13, macos-14] + runs-on: ${{ matrix.os }} + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + fetch-tags: true + - uses: actions/cache@v4 + name: cache bazelisk and zig-cache directories + with: + key: cache-${{ runner.os }}-${{ hashFiles('.bazelversion', 'toolchain/private/zig_sdk.bzl', '.github/workflows/ci.yaml') }} + path: | + ${{ runner.os == 'Windows' && 'C:\Temp\hermetic_cc_toolchain' || '/tmp/zig-cache' }} + ${{ runner.os == 'Windows' && '~\AppData\Local\bazelisk' || '~/.cache/bazelisk' }} + + - run: brew install bash + if: runner.os == 'macOS' + + # Linux, macOS and Windows + - run: ci/list_toolchains_platforms + - run: ci/zig-utils + + # Linux and macOS + - run: ci/release + if: runner.os == 'Linux' || runner.os == 'macOS' + - run: ci/lint + if: runner.os == 'Linux' || runner.os == 'macOS' + # TODO: releaser is broken on windows + - run: ci/prepare_git && ci/test_example rules_cc override_repository + if: runner.os == 'Linux' || runner.os == 'macOS' + + # Linux and Windows + - run: tools/bazel build --config=darwin_toolchains //... + if: runner.os == 'Linux' || runner.os == 'Windows' + + # Linux + - run: ci/test --config=darwin_toolchains + if: runner.os == 'Linux' + # TODO windows: broken releaser. MacOS: cgo. + - run: ci/prepare_git && ci/test_example bzlmod override_module + if: runner.os == 'Linux' + + # macOS + - run: tools/bazel build --config=darwin_toolchains --build_tag_filters=darwin_c //... + if: runner.os == 'macOS' diff --git a/ci/zig-utils b/ci/zig-utils index e551989f..aadab828 100755 --- a/ci/zig-utils +++ b/ci/zig-utils @@ -1,43 +1,10 @@ #!/usr/bin/env bash -# Copyright 2023 Uber Technologies, Inc. -# Licensed under the MIT License - set -xeuo pipefail echo "--- which zig" ZIG=${ZIG:-$(tools/bazel run "$@" --run_under=echo @zig_sdk//:zig)} for zigfile in $(git ls-files '*.zig'); do - echo "--- compile $zigfile for various architectures" - for target in \ - aarch64-linux-gnu.2.28 \ - aarch64-macos-none \ - x86_64-linux-gnu.2.28 \ - x86_64-macos-none \ - x86_64-windows-gnu - do - if [[ $target == aarch64-macos-none ]]; then - mcpu=apple_a14 - else - mcpu=baseline - fi - $ZIG build-exe -fno-emit-bin -target $target -mcpu=$mcpu "$zigfile" - done - - - # until hermetic_cc_toolchain gets a zig toolchain, run zig programs' unit tests here. - echo "--- zig test $zigfile" - $ZIG test "$zigfile" - - # as of 2023-10 yours truly (@motiejus) was not able to install wine64 - # on CI. See the commit message for details. - if [[ -z "${HERMETIC_CC_TOOLCHAIN_SKIP_WINE:-}" ]]; then - echo "--- test $zigfile via wine64" - $ZIG test \ - -target x86_64-windows-gnu \ - --test-cmd wine64-stable \ - --test-cmd-bin \ - "$zigfile" - fi + $ZIG test "$zigfile" done diff --git a/test/gorace/BUILD b/test/gorace/BUILD index 78a487c9..79bd9440 100644 --- a/test/gorace/BUILD +++ b/test/gorace/BUILD @@ -9,6 +9,11 @@ go_library( # keep cgo = True, importpath = "github.com/uber/hermetic_cc_toolchain/test/gorace", + # TODO lld-link: error: undefined symbol: WaitOnAddress on Windows + target_compatible_with = [ + "@platforms//os:linux", + "@platforms//os:macos", + ], visibility = ["//visibility:private"], )