Skip to content

Commit afda0c1

Browse files
authored
macOS builds (#5)
1 parent 55f2c42 commit afda0c1

6 files changed

+199
-0
lines changed

.github/buildomat/SHA256SUMS

+4
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
11
4cdd2bc664724dc7db94ad51b503512c5ae7220951cac568120f64f8e94399fc go1.17.13.linux-amd64.tar.gz
2+
c101beaa232e0f448fab692dc036cd6b4677091ff89c4889cc8754b1b29c6608 go1.17.13.darwin-amd64.tar.gz
3+
e4ccc9c082d91eaa0b866078b591fc97d24b91495f12deb3dd2d8eda4e55a6ea go1.17.13.darwin-arm64.tar.gz
24
874463523f26ed528634580247f403d200ba17a31adf2de98a7b124c6eb33d87 node-v16.20.2-linux-x64.tar.xz
5+
107ae8d56a9c0aa85c8952231ac44d5e6df7c1ea3e9a36e2ef022ae36c98ccec node-v16.20.2-darwin-x64.tar.xz
6+
fb87e01f0b2c8545afb8dd0769f7eb2439fb4fc8731efa956744fb0e0bc98105 node-v16.20.2-darwin-arm64.tar.xz
37
1ba910c84256998c4bf4b925857c2693adebdc962a2e3075f4f8b67045f45105 yarn-1.22.22.js
+61
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#!/bin/bash
2+
3+
# This Source Code Form is subject to the terms of the Mozilla Public
4+
# License, v. 2.0. If a copy of the MPL was not distributed with this
5+
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
6+
#
7+
# Copyright Oxide Computer Company
8+
9+
set -o errexit
10+
set -o pipefail
11+
set -o xtrace
12+
13+
# We use `--netrc` in these calls in order to use the GitHub token Buildomat
14+
# provides us. This is not strictly necessary for all APIs we use, _except_ the
15+
# one to download artifacts. But using it for all calls keeps us from hitting
16+
# rate limits!
17+
18+
API_BASE="https://api.github.com/repos/$GITHUB_REPOSITORY"
19+
20+
# Buildomat creates at most one check suite per commit per repository, but
21+
# GitHub Actions will generally make several. We need to choose which run we
22+
# care about, ideally picking the one most closely related to this Buildomat
23+
# check suite. We first look for the most recently-created "push" run, but if
24+
# none are found we fall back to the most recently-created "pull_request" run.
25+
#
26+
# We check 10 times with 30 second pauses in between; if we don't have a check
27+
# run within about five minutes it'll probably never show up.
28+
for attempt in {1..10}; do
29+
runs=$(curl -sSfL --netrc "$API_BASE/actions/runs?head_sha=$GITHUB_SHA" \
30+
| jq -r --arg name "$1" '
31+
.workflow_runs
32+
| sort_by(.created_at) | reverse
33+
| .[] | select(.name == $name)
34+
| {id: .id, event: .event}
35+
')
36+
for event in push pull_request; do
37+
run_id=$(jq -r --arg event "$event" 'select(.event == $event) | .id' <<<"$runs" | head -n 1)
38+
[[ -n "$run_id" ]] && break 2
39+
done
40+
sleep 30
41+
done
42+
if [[ -z "$run_id" ]]; then
43+
echo >&2 "no check run found"
44+
exit 1
45+
fi
46+
47+
# Wait for the run to complete.
48+
until [[ $(curl -sSfL --netrc "$API_BASE/actions/runs/$run_id" | jq -r .status) == completed ]]; do
49+
sleep 60
50+
done
51+
52+
# Get information about artifacts and download them.
53+
artifacts=$(curl -sSfL --netrc "$API_BASE/actions/runs/$run_id/artifacts" \
54+
| jq -r '.artifacts[] | {id: .id, name: .name}')
55+
for artifact_id in $(jq -r '.id' <<<"$artifacts"); do
56+
artifact_name=$(jq -r --argjson id "$artifact_id" 'select(.id == $id) | .name' <<<"$artifacts")
57+
# Artifact names are not allowed to contain special filesystem characters:
58+
# https://github.com/actions/upload-artifact/issues/22
59+
curl -sSfL --netrc -o "$artifact_name.zip" \
60+
"$API_BASE/actions/artifacts/$artifact_id/zip"
61+
done
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
#!/bin/bash
2+
#:
3+
#: name = "artifacts-macos"
4+
#: variety = "basic"
5+
#: target = "ubuntu-22.04"
6+
#: output_rules = [
7+
#: "=/work/oxidecomputer/cockroach/cockroach.tgz",
8+
#: "=/work/oxidecomputer/cockroach/cockroach.tgz.sha256",
9+
#: ]
10+
#:
11+
#: [[publish]]
12+
#: series = "darwin-amd64"
13+
#: name = "cockroach.tgz"
14+
#: from_output = "=/work/oxidecomputer/cockroach/cockroach.tgz"
15+
#:
16+
#: [[publish]]
17+
#: series = "darwin-amd64"
18+
#: name = "cockroach.tgz.sha256"
19+
#: from_output = "=/work/oxidecomputer/cockroach/cockroach.tgz.sha256"
20+
21+
set -o errexit
22+
set -o pipefail
23+
set -o xtrace
24+
25+
sudo apt-get install -y jq unzip
26+
timeout 30m .github/buildomat/fetch-gh-artifacts.sh build-macos
27+
unzip build.zip

.github/workflows/build-macos.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: build-macos
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build:
9+
runs-on: macos-13
10+
steps:
11+
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
12+
with:
13+
ref: ${{ github.event.pull_request.head.sha }} # to match buildomat behavior
14+
- name: Toolchain setup
15+
run: |
16+
set -o xtrace
17+
source .github/workflows/macos-setup.sh
18+
echo "PATH=$PATH" >>"$GITHUB_ENV"
19+
- name: Build
20+
run: gmake -j`sysctl -n hw.ncpu` cockroach.tgz BUILDTYPE=release
21+
env:
22+
BROWSERSLIST_IGNORE_OLD_DATA: 1
23+
- uses: actions/upload-artifact@b4b15b8c7c6ac21ea08fcf65892d2ee8f75cf882 # v4.4.3
24+
with:
25+
name: build
26+
path: |
27+
cockroach.tgz
28+
cockroach.tgz.sha256
29+
if-no-files-found: error
30+
compression-level: 0
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
From e66f895667cd51d0d28c42d369a803c12db8bb35 Mon Sep 17 00:00:00 2001
2+
From: Alex Brachet <abrachet@google.com>
3+
Date: Thu, 19 May 2022 16:58:46 +0000
4+
Subject: [PATCH] cmd/cgo: allow DW_TAG_variable's with no name
5+
6+
https://reviews.llvm.org/D123534 is emitting DW_TAG_variable's
7+
that don't have a DW_AT_name. This is allowed in the DWARF
8+
standard. It is adding DIE's for string literals for better
9+
symbolization on buffer overlows etc on these strings. They
10+
no associated name because they are not user provided variables.
11+
12+
Fixes #53000
13+
14+
Change-Id: I2cf063160508687067c7672cef0517bccd707d7b
15+
Reviewed-on: https://go-review.googlesource.com/c/go/+/406816
16+
TryBot-Result: Gopher Robot <gobot@golang.org>
17+
Run-TryBot: Ian Lance Taylor <iant@google.com>
18+
Auto-Submit: Ian Lance Taylor <iant@google.com>
19+
Reviewed-by: Ian Lance Taylor <iant@google.com>
20+
---
21+
src/cmd/cgo/gcc.go | 17 ++++++++++++++++-
22+
1 file changed, 16 insertions(+), 1 deletion(-)
23+
24+
diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go
25+
index 855309edfa255..4d1a5bd8de1f3 100644
26+
--- a/src/cmd/cgo/gcc.go
27+
+++ b/src/cmd/cgo/gcc.go
28+
@@ -576,8 +576,23 @@ func (p *Package) loadDWARF(f *File, conv *typeConv, names []*Name) {
29+
switch e.Tag {
30+
case dwarf.TagVariable:
31+
name, _ := e.Val(dwarf.AttrName).(string)
32+
+ // As of https://reviews.llvm.org/D123534, clang
33+
+ // now emits DW_TAG_variable DIEs that have
34+
+ // no name (so as to be able to describe the
35+
+ // type and source locations of constant strings
36+
+ // like the second arg in the call below:
37+
+ //
38+
+ // myfunction(42, "foo")
39+
+ //
40+
+ // If a var has no name we won't see attempts to
41+
+ // refer to it via "C.<name>", so skip these vars
42+
+ //
43+
+ // See issue 53000 for more context.
44+
+ if name == "" {
45+
+ break
46+
+ }
47+
typOff, _ := e.Val(dwarf.AttrType).(dwarf.Offset)
48+
- if name == "" || typOff == 0 {
49+
+ if typOff == 0 {
50+
if e.Val(dwarf.AttrSpecification) != nil {
51+
// Since we are reading all the DWARF,
52+
// assume we will see the variable elsewhere.

.github/workflows/macos-setup.sh

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
SOURCE_DIR=$PWD
2+
source .github/buildomat/versions.sh
3+
4+
brew install coreutils make
5+
6+
mkdir "$HOME/toolchain"
7+
pushd "$HOME/toolchain"
8+
curl -sSfL --retry 10 -O "https://go.dev/dl/go$GO_VERSION.darwin-amd64.tar.gz"
9+
curl -sSfL --retry 10 -O "https://nodejs.org/dist/v$NODE_VERSION/node-v$NODE_VERSION-darwin-x64.tar.xz"
10+
curl -sSfL --retry 10 -O "https://github.com/yarnpkg/yarn/releases/download/v$YARN_VERSION/yarn-$YARN_VERSION.js"
11+
sha256sum --ignore-missing -c "$OLDPWD/.github/buildomat/SHA256SUMS"
12+
tar xf "go$GO_VERSION.darwin-amd64.tar.gz"
13+
tar xf "node-v$NODE_VERSION-darwin-x64.tar.xz"
14+
mv "yarn-$YARN_VERSION.js" "node-v$NODE_VERSION-darwin-x64/bin/yarn"
15+
chmod a+x "node-v$NODE_VERSION-darwin-x64/bin/yarn"
16+
export PATH="$PWD/go/bin:$PWD/node-v$NODE_VERSION-darwin-x64/bin:$PATH"
17+
18+
# Apply patch to fix golang/go#53000
19+
pushd go/src
20+
patch -p2 <"$SOURCE_DIR/.github/workflows/e66f895667cd51d0d28c42d369a803c12db8bb35.patch"
21+
go build cmd/cgo
22+
popd
23+
mv go/src/cgo go/pkg/tool/darwin_amd64/cgo
24+
25+
popd

0 commit comments

Comments
 (0)