Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

Commit 00d3e90

Browse files
authored
Merge pull request #17 from pjbgf/sync-branches
2 parents 187e12a + 52e9a93 commit 00d3e90

File tree

10 files changed

+470
-96
lines changed

10 files changed

+470
-96
lines changed

.github/workflows/build.yaml

+28-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,34 @@ on:
1111
pull_request:
1212
paths-ignore:
1313
- README.md
14+
15+
permissions:
16+
packages: write # needed for ghcr access
17+
1418
jobs:
19+
20+
mac-build:
21+
runs-on: macos-11
22+
steps:
23+
- name: Checkout
24+
uses: actions/checkout@v2
25+
- name: Test build script for darwin-amd64
26+
run: |
27+
TARGET_DIR=${GITHUB_WORKSPACE}/build/libgit2-darwin-amd64 \
28+
BUILD_ROOT_DIR=${GITHUB_WORKSPACE}/libgit2/build/amd \
29+
./hack/static.sh all
30+
env:
31+
MACOSX_DEPLOYMENT_TARGET: 10.15
32+
- name: Test cross compile script for darwin-arm64
33+
run: |
34+
TARGET_DIR=${GITHUB_WORKSPACE}/build/libgit2-darwin-arm64 \
35+
BUILD_ROOT_DIR=${GITHUB_WORKSPACE}/libgit2/build/arm \
36+
TARGET_ARCH=arm64 \
37+
CMAKE_APPLE_SILICON_PROCESSOR=arm64 \
38+
./hack/static.sh all
39+
env:
40+
MACOSX_DEPLOYMENT_TARGET: 10.15
41+
1542
build:
1643
runs-on: ubuntu-latest
1744
env:
@@ -55,7 +82,7 @@ jobs:
5582
key: ${{ runner.os }}-buildx-ghcache-${{ github.sha }}
5683
restore-keys: |
5784
${{ runner.os }}-buildx-ghcache-
58-
- run: cat ./hack/Makefile
85+
- run: cat ./hack/static.sh
5986
- name: Build candidate image
6087
id: build_candidate
6188
uses: docker/build-push-action@v2

.github/workflows/release.yaml

+102
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
---
2+
name: 'Release MacOS static libraries'
3+
on:
4+
push:
5+
tags:
6+
- '**'
7+
8+
workflow_dispatch:
9+
inputs:
10+
tag:
11+
description: 'release prefix'
12+
default: 'rc'
13+
required: true
14+
15+
permissions:
16+
contents: write # needed to write releases
17+
18+
jobs:
19+
20+
mac-build:
21+
# This job builds and releases "universal libraries" that are
22+
# supported by both darwin-amd64 and darwin-arm64.
23+
#
24+
# First builds in amd64, then cross-compile in arm64. Later combining
25+
# both outcomes onto a single binary for each static library.
26+
#
27+
# `macos-11` has been picked as support for arm64 was only added on Xcode 12.
28+
# Although some minor versions of Catalina 10.15 can support it, at the time
29+
# of testing, GitHub's macos-10.15 did not seem to.
30+
# Cross-compiling to arm64 on that runner consistently failed.
31+
runs-on: macos-11
32+
steps:
33+
- name: Checkout
34+
uses: actions/checkout@v2
35+
- name: Build universal static libraries for Darwin
36+
run: |
37+
TARGET_DIR=${GITHUB_WORKSPACE}/build/libgit2-darwin-amd64 \
38+
BUILD_ROOT_DIR=${GITHUB_WORKSPACE}/libgit2/build/amd \
39+
./hack/static.sh all
40+
41+
TARGET_DIR=${GITHUB_WORKSPACE}/build/libgit2-darwin-arm64 \
42+
BUILD_ROOT_DIR=${GITHUB_WORKSPACE}/libgit2/build/arm \
43+
TARGET_ARCH=arm64 \
44+
CMAKE_APPLE_SILICON_PROCESSOR=arm64 \
45+
./hack/static.sh all
46+
47+
mkdir -p ./libgit2-darwin/lib
48+
mv ${GITHUB_WORKSPACE}/build/libgit2-darwin-amd64/include ./libgit2-darwin/
49+
mv ${GITHUB_WORKSPACE}/build/libgit2-darwin-amd64/share ./libgit2-darwin/
50+
mv ${GITHUB_WORKSPACE}/build/libgit2-darwin-amd64/lib/cmake ./libgit2-darwin/lib/
51+
mv ${GITHUB_WORKSPACE}/build/libgit2-darwin-amd64/lib/engines-3 ./libgit2-darwin/lib/
52+
mv ${GITHUB_WORKSPACE}/build/libgit2-darwin-amd64/lib/ossl-modules ./libgit2-darwin/lib/
53+
mv ${GITHUB_WORKSPACE}/build/libgit2-darwin-amd64/lib/pkgconfig ./libgit2-darwin/lib/
54+
55+
libtool -static -o ./libgit2-darwin/lib/libcrypto.a \
56+
${GITHUB_WORKSPACE}/build/libgit2-darwin-amd64/lib/libcrypto.a \
57+
${GITHUB_WORKSPACE}/build/libgit2-darwin-arm64/lib/libcrypto.a
58+
libtool -static -o ./libgit2-darwin/lib/libgit2.a \
59+
${GITHUB_WORKSPACE}/build/libgit2-darwin-amd64/lib/libgit2.a \
60+
${GITHUB_WORKSPACE}/build/libgit2-darwin-arm64/lib/libgit2.a
61+
libtool -static -o ./libgit2-darwin/lib/libssh2.a \
62+
${GITHUB_WORKSPACE}/build/libgit2-darwin-amd64/lib/libssh2.a \
63+
${GITHUB_WORKSPACE}/build/libgit2-darwin-arm64/lib/libssh2.a
64+
libtool -static -o ./libgit2-darwin/lib/libssl.a \
65+
${GITHUB_WORKSPACE}/build/libgit2-darwin-amd64/lib/libssl.a \
66+
${GITHUB_WORKSPACE}/build/libgit2-darwin-arm64/lib/libssl.a
67+
libtool -static -o ./libgit2-darwin/lib/libz.a \
68+
${GITHUB_WORKSPACE}/build/libgit2-darwin-amd64/lib/libz.a \
69+
${GITHUB_WORKSPACE}/build/libgit2-darwin-arm64/lib/libz.a
70+
71+
tar -zcvf darwin-libs.tar.gz ./libgit2-darwin
72+
env:
73+
MACOSX_DEPLOYMENT_TARGET: 10.15
74+
75+
- name: Prepare
76+
id: prep
77+
run: |
78+
VERSION="${{ github.event.inputs.tag }}-${GITHUB_SHA::8}"
79+
if [[ $GITHUB_REF == refs/tags/* ]]; then
80+
VERSION=${GITHUB_REF/refs\/tags\//}
81+
fi
82+
echo ::set-output name=VERSION::${VERSION}
83+
- name: Create Release
84+
id: create_release
85+
uses: actions/create-release@v1
86+
env:
87+
GITHUB_TOKEN: ${{ github.token }}
88+
with:
89+
release_name: ${{ steps.prep.outputs.VERSION }}
90+
tag_name: ${{ steps.prep.outputs.VERSION }}
91+
draft: false
92+
prerelease: true
93+
- name: Upload Release Asset
94+
id: upload-release-asset
95+
uses: actions/upload-release-asset@v1
96+
env:
97+
GITHUB_TOKEN: ${{ github.token }}
98+
with:
99+
upload_url: ${{ steps.create_release.outputs.upload_url }}
100+
asset_path: ./darwin-libs.tar.gz
101+
asset_name: darwin-libs.tar.gz
102+
asset_content_type: application/gzip

Dockerfile

+24-21
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
# This Dockerfile tests the hack/Makefile output against git2go.
22
ARG BASE_VARIANT=alpine
3-
ARG GO_VERSION=1.17.6
3+
ARG GO_VERSION=1.17
44
ARG XX_VERSION=1.1.0
55

66
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
77

8-
FROM golang:${GO_VERSION}-${BASE_VARIANT} as gostable
9-
10-
FROM gostable AS go-linux
11-
12-
FROM --platform=$BUILDPLATFORM ${BASE_VARIANT} AS build-deps
8+
FROM --platform=$BUILDPLATFORM ${BASE_VARIANT} AS build-base
139

1410
RUN apk add --no-cache \
1511
bash \
@@ -26,15 +22,10 @@ RUN apk add --no-cache \
2622

2723
COPY --from=xx / /
2824

29-
ARG TARGETPLATFORM
30-
31-
RUN xx-apk add --no-cache \
32-
xx-c-essentials
33-
34-
RUN xx-apk add --no-cache \
35-
xx-cxx-essentials
25+
FROM build-base AS build-cross
3626

3727
ARG TARGETPLATFORM
28+
3829
RUN xx-apk add --no-cache \
3930
build-base \
4031
pkgconfig \
@@ -48,7 +39,6 @@ RUN xx-apk add --no-cache \
4839
WORKDIR /build
4940
COPY hack/static.sh .
5041

51-
ARG TARGETPLATFORM
5242
ENV CC=xx-clang
5343
ENV CXX=xx-clang++
5444

@@ -68,12 +58,25 @@ RUN ./static.sh build_libssh2
6858
RUN ./static.sh build_libgit2
6959

7060

71-
FROM go-${TARGETOS} AS build
61+
# trimmed removes all non necessary files (i.e. openssl binary).
62+
FROM build-cross AS trimmed
7263

73-
# Copy cross-compilation tools
74-
COPY --from=xx / /
75-
# Copy compiled libraries
76-
COPY --from=build-deps /usr/local/ /usr/local/
64+
ARG TARGETPLATFORM
65+
RUN mkdir -p /trimmed/usr/local/$(xx-info triple)/ && \
66+
mkdir -p /trimmed/usr/local/$(xx-info triple)/share
67+
68+
RUN cp -r /usr/local/$(xx-info triple)/lib/ /trimmed/usr/local/$(xx-info triple)/ && \
69+
cp -r /usr/local/$(xx-info triple)/lib64/ /trimmed/usr/local/$(xx-info triple)/ | true && \
70+
cp -r /usr/local/$(xx-info triple)/include/ /trimmed/usr/local/$(xx-info triple)/ && \
71+
cp -r /usr/local/$(xx-info triple)/share/doc/ /trimmed/usr/local/$(xx-info triple)/share/
72+
73+
FROM scratch as libs-arm64
74+
COPY --from=trimmed /trimmed/ /
75+
76+
FROM scratch as libs-amd64
77+
COPY --from=trimmed /trimmed/ /
78+
79+
FROM scratch as libs-armv7
80+
COPY --from=trimmed /trimmed/ /
7781

78-
COPY ./hack/Makefile /Makefile
79-
COPY ./hack/static.sh /static.sh
82+
FROM libs-$TARGETARCH$TARGETVARIANT as libs

Dockerfile.test

+53-34
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
# This Dockerfile tests the hack/Makefile output against git2go.
22
ARG BASE_VARIANT=alpine
3-
ARG GO_VERSION=1.17.6
3+
ARG GO_VERSION=1.17
44
ARG XX_VERSION=1.1.0
55

66
FROM --platform=$BUILDPLATFORM tonistiigi/xx:${XX_VERSION} AS xx
77

8-
FROM golang:${GO_VERSION}-${BASE_VARIANT} as gostable
9-
10-
FROM gostable AS go-linux
11-
12-
FROM --platform=$BUILDPLATFORM ${BASE_VARIANT} AS build-deps
8+
FROM --platform=$BUILDPLATFORM ${BASE_VARIANT} AS build-base
139

1410
RUN apk add --no-cache \
1511
bash \
@@ -26,15 +22,10 @@ RUN apk add --no-cache \
2622

2723
COPY --from=xx / /
2824

29-
ARG TARGETPLATFORM
30-
31-
RUN xx-apk add --no-cache \
32-
xx-c-essentials
33-
34-
RUN xx-apk add --no-cache \
35-
xx-cxx-essentials
25+
FROM build-base AS build-cross
3626

3727
ARG TARGETPLATFORM
28+
3829
RUN xx-apk add --no-cache \
3930
build-base \
4031
pkgconfig \
@@ -48,7 +39,6 @@ RUN xx-apk add --no-cache \
4839
WORKDIR /build
4940
COPY hack/static.sh .
5041

51-
ARG TARGETPLATFORM
5242
ENV CC=xx-clang
5343
ENV CXX=xx-clang++
5444

@@ -68,40 +58,76 @@ RUN ./static.sh build_libssh2
6858
RUN ./static.sh build_libgit2
6959

7060

71-
FROM go-${TARGETOS} AS build
61+
# trimmed removes all non necessary files (i.e. openssl binary).
62+
FROM build-cross AS trimmed
7263

73-
# Copy cross-compilation tools
74-
COPY --from=xx / /
75-
# Copy compiled libraries
76-
COPY --from=build-deps /usr/local/ /usr/local/
64+
ARG TARGETPLATFORM
65+
RUN mkdir -p /trimmed/usr/local/$(xx-info triple)/ && \
66+
mkdir -p /trimmed/usr/local/$(xx-info triple)/share
67+
68+
RUN cp -r /usr/local/$(xx-info triple)/lib/ /trimmed/usr/local/$(xx-info triple)/ && \
69+
cp -r /usr/local/$(xx-info triple)/lib64/ /trimmed/usr/local/$(xx-info triple)/ | true && \
70+
cp -r /usr/local/$(xx-info triple)/include/ /trimmed/usr/local/$(xx-info triple)/ && \
71+
cp -r /usr/local/$(xx-info triple)/share/doc/ /trimmed/usr/local/$(xx-info triple)/share/
72+
73+
FROM scratch as libs-arm64
74+
COPY --from=trimmed /trimmed/ /
75+
76+
FROM scratch as libs-amd64
77+
COPY --from=trimmed /trimmed/ /
78+
79+
FROM scratch as libs-armv7
80+
COPY --from=trimmed /trimmed/ /
81+
82+
FROM libs-$TARGETARCH$TARGETVARIANT as libs
83+
84+
# Everything above this line is a copy from Dockefile.
85+
86+
FROM --platform=$BUILDPLATFORM golang:${GO_VERSION}-${BASE_VARIANT} as gostable
87+
88+
FROM gostable AS go-linux
89+
90+
# Build-base consists of build platform dependencies and xx.
91+
# These will be used at current arch to yield execute the cross compilations.
92+
FROM go-${TARGETOS} AS go-base
7793

7894
RUN apk add clang lld pkgconfig
7995

96+
COPY --from=xx / /
97+
98+
# build-go-mod can still be cached at build platform architecture.
99+
FROM go-base as build-go-mod
100+
80101
WORKDIR /root/smoketest
81102
COPY tests/smoketest/go.mod .
82103
COPY tests/smoketest/go.sum .
83104
RUN go mod download
84105

106+
# Build stage install per target platform
107+
# dependency and effectively cross compile the application.
108+
FROM build-go-mod as build
109+
85110
ARG TARGETPLATFORM
86111

87112
# Some dependencies have to installed
88113
# for the target platform: https://github.com/tonistiigi/xx#go--cgo
89-
RUN xx-apk add --no-cache \
90-
musl-dev \
91-
gcc
114+
RUN xx-apk add musl-dev gcc clang lld
92115

116+
WORKDIR /root/smoketest
93117

94118
COPY tests/smoketest/main.go .
119+
COPY --from=libs /usr/local/ /usr/local/
95120

96121
ENV CGO_ENABLED=1
97-
RUN export LIBRARY_PATH="/usr/local/$(xx-info triple)/lib:/usr/local/$(xx-info triple)/lib64:${LIBRARY_PATH}" && \
122+
RUN export LIBRARY_PATH="/usr/local/$(xx-info triple):/usr/local/$(xx-info triple)/lib64" && \
98123
export PKG_CONFIG_PATH="/usr/local/$(xx-info triple)/lib/pkgconfig:/usr/local/$(xx-info triple)/lib64/pkgconfig" && \
99-
export FLAGS="$(pkg-config --static --libs --cflags libssh2 openssl libgit2)" && \
100-
CGO_LDFLAGS="${FLAGS} -static" \
101-
xx-go build \
124+
export FLAGS="$(pkg-config --static --libs --cflags libssh2 openssl libgit2)" && \
125+
export CGO_LDFLAGS="${FLAGS} -static" && \
126+
xx-go build \
102127
-ldflags "-s -w" \
103128
-tags 'netgo,osusergo,static_build' \
104-
-o static-test-runner -trimpath main.go;
129+
-o static-test-runner -trimpath main.go
130+
105131

106132
# Ensure that the generated binary is valid for the target platform
107133
RUN xx-verify --static static-test-runner
@@ -119,11 +145,4 @@ COPY --from=build \
119145

120146
ENV SSL_CERT_FILE=/etc/ssl/certs/ca-certificates.crt
121147

122-
# To do docker run instead, replace the RUN statement with:
123-
# ENTRYPOINT [ "/root/smoketest/static-test-runner" ]
124-
125-
# The approach below was preferred as it provides a way to
126-
# assert the functionality across the supported architectures
127-
# without any extra steps.
128-
129148
RUN /root/smoketest/static-test-runner

0 commit comments

Comments
 (0)