Skip to content

Commit 97df2c9

Browse files
committed
use multiarch/crossbuild and multiarch/alpine docker images for linux build
reduce the number of dockerfiles
1 parent 8250287 commit 97df2c9

12 files changed

+41
-62
lines changed

.github/workflows/ci.yml

+7
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ jobs:
3131
name: linux-musl-x64
3232
- os: ubuntu-20.04
3333
name: linux-arm64
34+
- os: ubuntu-20.04
35+
name: linux-musl-arm
36+
- os: ubuntu-20.04
37+
name: linux-musl-arm64
3438
- os: ubuntu-20.04
3539
name: linux-arm
3640
- os: macos-10.15
@@ -49,6 +53,9 @@ jobs:
4953
- name: Build macOS
5054
if: runner.os == 'macOS'
5155
run: ./build.libgit2.sh
56+
- name: Setup QEMU
57+
run: docker run --rm --privileged multiarch/qemu-user-static:register --reset
58+
if: matrix.name == 'linux-musl-arm' || matrix.name == 'linux-musl-arm64'
5259
- name: Build Linux
5360
if: runner.os == 'Linux'
5461
run: ./dockerbuild.sh

CMakeLists.arm.txt

-6
This file was deleted.

CMakeLists.arm64.txt

-6
This file was deleted.

Dockerfile.linux

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
FROM multiarch/crossbuild
2+
ARG ARCH='amd64'
3+
ENV CROSS_TRIPLE=${ARCH}
4+
RUN apt update && apt -y install pkg-config
5+
6+
WORKDIR /nativebinaries
7+
COPY . /nativebinaries/
8+
9+
CMD ["/bin/bash", "-c", "./build.libgit2.sh"]

Dockerfile.linux-arm

-9
This file was deleted.

Dockerfile.linux-arm64

-9
This file was deleted.

Dockerfile.linux-musl

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
ARG ARCH='amd64'
2+
FROM multiarch/alpine:${ARCH}-v3.12
3+
RUN apk add --no-cache bash build-base cmake
4+
5+
WORKDIR /nativebinaries
6+
COPY . /nativebinaries/
7+
8+
CMD ["/bin/bash", "-c", "./build.libgit2.sh"]

Dockerfile.linux-musl-x64

-7
This file was deleted.

Dockerfile.linux-x64

-9
This file was deleted.

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ the following platforms:
1111

1212
- Windows (x86, x64, arm64)
1313
- macOS (x64, arm64)
14-
- Linux (arm, arm64, x64)
14+
- Linux (arm, arm64, x64, musl-x64, linux-musl-arm, linux-musl-arm64)
1515

1616
[lg2s-nb]: https://www.nuget.org/packages/LibGit2Sharp.NativeBinaries
1717
[lg2]: https://libgit2.github.com/

build.libgit2.sh

-14
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ set -e
55
LIBGIT2SHA=`cat ./nuget.package/libgit2/libgit2_hash.txt`
66
SHORTSHA=${LIBGIT2SHA:0:7}
77
OS=`uname`
8-
ARCH=`uname -m`
98
PACKAGEPATH="nuget.package/runtimes"
109
OSXARCHITECTURE="x86_64"
1110

@@ -22,18 +21,6 @@ rm -rf libgit2/build
2221
mkdir libgit2/build
2322
pushd libgit2/build
2423

25-
export _BINPATH=`pwd`
26-
27-
if [[ $RID == *arm ]]; then
28-
export TOOLCHAIN_FILE=/nativebinaries/CMakeLists.arm.txt
29-
fi
30-
31-
if [[ $RID == *arm64 ]]; then
32-
if [[ $OS != "Darwin" ]]; then
33-
export TOOLCHAIN_FILE=/nativebinaries/CMakeLists.arm64.txt
34-
fi
35-
fi
36-
3724
cmake -DCMAKE_BUILD_TYPE:STRING=Release \
3825
-DBUILD_CLAR:BOOL=OFF \
3926
-DUSE_SSH=OFF \
@@ -42,7 +29,6 @@ cmake -DCMAKE_BUILD_TYPE:STRING=Release \
4229
-DCMAKE_OSX_ARCHITECTURES=$OSXARCHITECTURE \
4330
-DUSE_HTTPS=$USEHTTPS \
4431
-DUSE_BUNDLED_ZLIB=ON \
45-
-DCMAKE_TOOLCHAIN_FILE=${TOOLCHAIN_FILE} \
4632
..
4733
cmake --build .
4834

dockerbuild.sh

+16-1
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
11
#!/bin/bash
22

33
set -e
4+
echo "building for $RID"
45

5-
docker build -t $RID -f Dockerfile.$RID .
6+
if [[ $RID =~ arm64 ]]; then
7+
arch="arm64"
8+
elif [[ $RID =~ arm ]]; then
9+
arch="armhf"
10+
else
11+
arch="amd64"
12+
fi
13+
14+
if [[ $RID == linux-musl* ]]; then
15+
dockerfile="Dockerfile.linux-musl"
16+
else
17+
dockerfile="Dockerfile.linux"
18+
fi
19+
20+
docker buildx build -t $RID -f $dockerfile --build-arg ARCH=$arch .
621

722
docker run -t -e RID=$RID --name=$RID $RID
823

0 commit comments

Comments
 (0)