Skip to content

Commit

Permalink
Merge pull request #156 from motiejus/macos-sdk
Browse files Browse the repository at this point in the history
CI and MacOS fixes
  • Loading branch information
motiejus authored Feb 13, 2024
2 parents 16592ba + 0cd9acc commit 57c4ad3
Show file tree
Hide file tree
Showing 21 changed files with 177 additions and 157 deletions.
5 changes: 4 additions & 1 deletion .bazelrc
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .bazelversion
Original file line number Diff line number Diff line change
@@ -1 +1 @@
7.0.0
7.0.2
28 changes: 0 additions & 28 deletions .buildkite/pipeline.yml

This file was deleted.

62 changes: 62 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -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'
6 changes: 2 additions & 4 deletions MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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",

Expand Down
2 changes: 1 addition & 1 deletion ci/lint
Original file line number Diff line number Diff line change
Expand Up @@ -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)"

Expand Down
6 changes: 3 additions & 3 deletions ci/prepare_git
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion ci/release
Original file line number Diff line number Diff line change
Expand Up @@ -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:"
Expand Down
35 changes: 1 addition & 34 deletions ci/zig-utils
Original file line number Diff line number Diff line change
@@ -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
4 changes: 1 addition & 3 deletions examples/bzlmod/MODULE.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,12 @@ 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",
)

bazel_dep(
name = "rules_go",
version = "0.41.0",
version = "0.45.1",
repo_name = "io_bazel_rules_go",
)
1 change: 1 addition & 0 deletions rules/platform.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ _attrs = {
"_cp": attr.label(
default = "//rules:cp",
allow_single_file = True,
cfg = "exec",
),
}

Expand Down
34 changes: 28 additions & 6 deletions test/c/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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",
],
)

[
Expand All @@ -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", []),
]
]
31 changes: 26 additions & 5 deletions test/c/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,34 @@
// Licensed under the MIT License

#include <stdio.h>
#if defined(_WIN64)
#include <windows.h>
#define OS "windows"
#elif __APPLE__
#define OS "macos"
#elif __linux__
#include <features.h>
#define OS "linux"
#else
# error "Unknown compiler!"
#endif

int main() {
#ifdef __GLIBC__
printf("glibc_%d.%d\n", __GLIBC__, __GLIBC_MINOR__);
#else
printf("non-glibc\n");
#endif
#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
printf("%s non-glibc\n", OS);
#endif
return 0;
}
5 changes: 5 additions & 0 deletions test/gorace/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
)

Expand Down
22 changes: 0 additions & 22 deletions test/windows/BUILD

This file was deleted.

19 changes: 0 additions & 19 deletions test/windows/main.c

This file was deleted.

Loading

0 comments on commit 57c4ad3

Please sign in to comment.