Skip to content

Commit 5bf7f9c

Browse files
authored
Extend clang-cross to support alpine (#3200)
1 parent 6e5a111 commit 5bf7f9c

File tree

7 files changed

+149
-27
lines changed

7 files changed

+149
-27
lines changed

native/linux-clang-cross/build.cake

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,20 @@ if (BUILD_ARCH.Length == 0)
77

88
string GetGnArgs(string arch)
99
{
10+
var (vendor, abi, sysrootarg, linker) = BUILD_VARIANT switch
11+
{
12+
"alpine" or "alpinenodeps" => ("-alpine", "musl", "'--sysroot=/alpine', ", "'-fuse-ld=lld'"),
13+
_ => ("", "gnu", "", ""),
14+
};
1015
var (toolchainArch, targetArch) = arch switch
1116
{
12-
"arm" => ("arm-linux-gnueabihf", "armv7a-linux-gnueabihf"),
13-
"arm64" => ("aarch64-linux-gnu", "aarch64-linux-gnu"),
14-
_ => ($"{arch}-linux-gnu", $"{arch}-linux-gnu"),
17+
"arm" => ($"arm{vendor}-linux-{abi}eabihf", $"armv7a{vendor}-linux-{abi}eabihf"),
18+
"arm64" => ($"aarch64{vendor}-linux-{abi}", $"aarch64{vendor}-linux-{abi}"),
19+
_ => ($"{arch}{vendor}-linux-{abi}", $"{arch}{vendor}-linux-{abi}"),
1520
};
1621

1722
var sysroot = $"/usr/{toolchainArch}";
18-
var init = $"'--target={targetArch}'";
23+
var init = $"{sysrootarg} '--target={targetArch}'";
1924
var bin = $"'-B{sysroot}/bin/' ";
2025
var libs = $"'-L{sysroot}/lib/' ";
2126
var includes =
@@ -26,7 +31,7 @@ string GetGnArgs(string arch)
2631
return
2732
$"extra_asmflags+=[ {init}, '-no-integrated-as', {bin}, {includes} ] " +
2833
$"extra_cflags+=[ {init}, {bin}, {includes} ] " +
29-
$"extra_ldflags+=[ {init}, {bin}, {libs} ] " +
34+
$"extra_ldflags+=[ {init}, {bin}, {libs}, {linker} ] " +
3035
ADDITIONAL_GN_ARGS;
3136
}
3237

@@ -38,6 +43,7 @@ Task("libSkiaSharp")
3843
RunCake("../linux/build.cake", "libSkiaSharp", new Dictionary<string, string> {
3944
{ "arch", arch },
4045
{ "gnArgs", GetGnArgs(arch) },
46+
{ "variant", BUILD_VARIANT },
4147
});
4248
}
4349
});
@@ -50,6 +56,7 @@ Task("libHarfBuzzSharp")
5056
RunCake("../linux/build.cake", "libHarfBuzzSharp", new Dictionary<string, string> {
5157
{ "arch", arch },
5258
{ "gnArgs", GetGnArgs(arch) },
59+
{ "variant", BUILD_VARIANT },
5360
});
5461
}
5562
});

scripts/Docker/_clang-cross-common.sh

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
5+
DOCKER_DIR="$1"
6+
7+
# the target architecture to build for
8+
ARCH="${2:-arm}"
9+
10+
# the docker image architecture to use
11+
MACHINE_ARCH="$(uname -m)"
12+
[ "$MACHINE_ARCH" = "arm64" ] && MACHINE_ARCH=aarch64
13+
IMAGE_ARCH="${3:-$([[ "$MACHINE_ARCH" == "aarch64" ]] && echo "arm64v8" || echo "amd64")}"
14+
15+
DISTRO_VERSION=$4
16+
ABI=$5
17+
VENDOR=$6
18+
19+
case $ARCH in
20+
arm) TOOLCHAIN_ARCH=arm$VENDOR-linux-${ABI}eabihf ; TOOLCHAIN_ARCH_SHORT=armhf ; TARGET_MACHINE_ARCH=armhf ;;
21+
arm64) TOOLCHAIN_ARCH=aarch64$VENDOR-linux-$ABI ; TOOLCHAIN_ARCH_SHORT=arm64 ; TARGET_MACHINE_ARCH=aarch64 ;;
22+
riscv64) TOOLCHAIN_ARCH=riscv64$VENDOR-linux-$ABI ; TOOLCHAIN_ARCH_SHORT=riscv64 ; TARGET_MACHINE_ARCH=riscv64 ;;
23+
x86) TOOLCHAIN_ARCH=i686$VENDOR-linux-$ABI ; TOOLCHAIN_ARCH_SHORT=i386 ; TARGET_MACHINE_ARCH=x86 ;;
24+
x64) TOOLCHAIN_ARCH=x86-64$VENDOR-linux-$ABI ; TOOLCHAIN_ARCH_SHORT=amd64 ; TARGET_MACHINE_ARCH=x86_64 ;;
25+
*) echo "Unsupported architecture: $ARCH" && exit 1 ;;
26+
esac
27+
28+
(cd $DIR && docker build --tag skiasharp-linux-$ABI-cross-$ARCH \
29+
--build-arg TOOLCHAIN_ARCH=$TOOLCHAIN_ARCH \
30+
--build-arg TOOLCHAIN_ARCH_SHORT=$TOOLCHAIN_ARCH_SHORT \
31+
--build-arg IMAGE_ARCH=$IMAGE_ARCH \
32+
--build-arg MACHINE_ARCH=$MACHINE_ARCH \
33+
--build-arg TARGET_MACHINE_ARCH=$TARGET_MACHINE_ARCH \
34+
--build-arg DISTRO_VERSION=$DISTRO_VERSION \
35+
$DOCKER_DIR)
36+
37+
if [ "$VENDOR" = "-alpine" ]; then vendor=alpine; fi
38+
39+
(cd $DIR/../.. &&
40+
docker run --rm --name skiasharp-linux-$ABI-cross-$ARCH --volume $(pwd):/work skiasharp-linux-$ABI-cross-$ARCH /bin/bash -c "\
41+
dotnet tool restore &&
42+
dotnet cake --target=externals-linux-clang-cross --configuration=Release --buildarch=$ARCH --variant=$vendor")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
build-local.sh
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# Arguments:
2+
# IMAGE_ARCH - the architecture of the image [ amd64 | arm64v8 | riscv64 ]
3+
# DOTNET_SDK_VERSION - the version of dotnet for the Cake script [ 8.0 | * ]
4+
# TOOLCHAIN_VERSION - the version of the GCC toolchain [ 9 | * ]
5+
# TOOLCHAIN_ARCH - the architecture of the GCC toolchain [ arm-alpine-linux-musleabihf | aarch64-alpine-linux-musl | riscv64-alpine-linux-musl ]
6+
# TOOLCHAIN_ARCH_SHORT - the short form architecture of the GCC toolchain [ armhf | arm64 ]
7+
# FONTCONFIG_VERSION - the exact version of libfontconfig1 to use [ 2.13.1-2 | * ]
8+
9+
ARG IMAGE_ARCH=amd64
10+
FROM ${IMAGE_ARCH}/debian:12
11+
12+
# Install the required packages
13+
RUN apt-get update \
14+
&& apt-get install -y \
15+
curl python3 git clang-19 lld-19 ninja-build xz-utils curl \
16+
&& rm -rf /var/lib/apt/lists/*
17+
18+
# Install the cross-compilation musl toolchain
19+
ARG DISTRO_VERSION=3.17
20+
ARG TOOLCHAIN_ARCH_SHORT=armhf
21+
ARG MACHINE_ARCH=x86_64
22+
ARG TARGET_MACHINE_ARCH=armhf
23+
24+
# obtain apk.static from gitlab.alpinelinux.org/alpine/apk-tools/-/releases/v2.12.14
25+
RUN APK_DIR="$(mktemp -d)" && \
26+
curl -SLO --create-dirs --output-dir "$APK_DIR" "https://gitlab.alpinelinux.org/api/v4/projects/5/packages/generic/v2.12.14/$MACHINE_ARCH/apk.static" && \
27+
chmod +x "$APK_DIR/apk.static" && \
28+
"$APK_DIR/apk.static" \
29+
-X "http://dl-cdn.alpinelinux.org/alpine/v$DISTRO_VERSION/main" \
30+
-X "http://dl-cdn.alpinelinux.org/alpine/v$DISTRO_VERSION/community" \
31+
-U --allow-untrusted --root /alpine --arch "$TARGET_MACHINE_ARCH" --initdb add && \
32+
"$APK_DIR/apk.static" \
33+
-X "http://dl-cdn.alpinelinux.org/alpine/v$DISTRO_VERSION/main" \
34+
-X "http://dl-cdn.alpinelinux.org/alpine/v$DISTRO_VERSION/community" \
35+
-U --allow-untrusted --root /alpine --arch "$TARGET_MACHINE_ARCH" --no-scripts \
36+
add fontconfig-dev build-base linux-headers
37+
38+
# Install the .NET SDK
39+
ARG DOTNET_SDK_VERSION=8.0
40+
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT 1
41+
RUN curl https://dot.net/v1/dotnet-install.sh -L -o dotnet-install.sh \
42+
&& bash dotnet-install.sh --channel ${DOTNET_SDK_VERSION} --install-dir /usr/share/dotnet --verbose \
43+
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet \
44+
&& rm dotnet-install.sh \
45+
&& dotnet help \
46+
&& dotnet --info
47+
48+
ENV CC=clang-19 CXX=clang++-19
49+
50+
WORKDIR /work
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
#!/usr/bin/env bash
2+
set -ex
3+
4+
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
5+
6+
ARCH=$1
7+
ALPINE_VERSION=$3
8+
if [ -z "$ALPINE_VERSION" ]; then
9+
case $ARCH in
10+
riscv64) ALPINE_VERSION=3.20 ;;
11+
*) ALPINE_VERSION=3.17 ;;
12+
esac
13+
fi
14+
15+
$DIR/../../_clang-cross-common.sh "$DIR" "$ARCH" "$2" "$ALPINE_VERSION" "musl" "-alpine"

scripts/Docker/debian/clang-cross/build-local.sh

100644100755
Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,13 @@ set -ex
33

44
DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
55

6-
# the target architecture to build for
7-
ARCH="${1:-arm}"
8-
case $ARCH in
9-
arm) BUILD_ARGS="--build-arg TOOLCHAIN_ARCH=arm-linux-gnueabihf --build-arg TOOLCHAIN_ARCH_SHORT=armhf" ;;
10-
arm64) BUILD_ARGS="--build-arg TOOLCHAIN_ARCH=aarch64-linux-gnu --build-arg TOOLCHAIN_ARCH_SHORT=arm64" ;;
11-
riscv64) BUILD_ARGS="--build-arg TOOLCHAIN_ARCH=riscv64-linux-gnu --build-arg TOOLCHAIN_ARCH_SHORT=riscv64" ;;
12-
x86) BUILD_ARGS="--build-arg TOOLCHAIN_ARCH=i686-linux-gnu --build-arg TOOLCHAIN_ARCH_SHORT=i386" ;;
13-
x64) BUILD_ARGS="--build-arg TOOLCHAIN_ARCH=x86-64-linux-gnu --build-arg TOOLCHAIN_ARCH_SHORT=amd64" ;;
14-
*) echo "Unsupported architecture: $ARCH" && exit 1 ;;
15-
esac
16-
17-
# the docker image architecture to use
18-
IMAGE_ARCH="${2:-$([[ "$(uname -m)" == "arm64" ]] && echo "arm64v8" || echo "amd64")}"
19-
20-
DEBIAN_VERSION=${3:-11}
21-
22-
(cd $DIR && docker build --tag skiasharp-linux-cross-$ARCH $BUILD_ARGS --build-arg IMAGE_ARCH=$IMAGE_ARCH $DEBIAN_VERSION)
23-
(cd $DIR/../../../../ &&
24-
docker run --rm --name skiasharp-linux-cross-$ARCH --volume $(pwd):/work skiasharp-linux-cross-$ARCH /bin/bash -c "\
25-
dotnet tool restore ; \
26-
dotnet cake --target=externals-linux-clang-cross --configuration=Release --buildarch=$ARCH")
6+
ARCH=$1
7+
DEBIAN_VERSION=$3
8+
if [ -z "$DEBIAN_VERSION" ]; then
9+
case $ARCH in
10+
riscv64) DEBIAN_VERSION=12 ;;
11+
*) DEBIAN_VERSION=11 ;;
12+
esac
13+
fi
14+
15+
$DIR/../../_clang-cross-common.sh "$DIR/$DEBIAN_VERSION" "$ARCH" "$2" "$DEBIAN_VERSION" "gnu"

scripts/azure-templates-stages.yml

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,17 @@ stages:
374374
target: externals-linux-clang-cross
375375
- arch: riscv64
376376
docker: scripts/Docker/debian/clang-cross/12
377-
dockerArgs: --build-arg TOOLCHAIN_ARCH=riscv64-linux-gnu --build-arg TOOLCHAIN_ARCH_SHORT=riscv64
377+
dockerArgs: --build-arg TOOLCHAIN_ARCH=riscv64-linux-gnu --build-arg TOOLCHAIN_ARCH_SHORT=riscv64 --build-arg DISTRO_VERSION=12
378+
target: externals-linux-clang-cross
379+
- arch: arm64
380+
variant: alpine
381+
docker: scripts/Docker/alpine/clang-cross
382+
dockerArgs: --build-arg TOOLCHAIN_ARCH=aarch64-alpine-linux-musl --build-arg TOOLCHAIN_ARCH_SHORT=arm64 --build-arg TARGET_MACHINE_ARCH=aarch64
383+
target: externals-linux-clang-cross
384+
- arch: riscv64
385+
variant: alpine
386+
docker: scripts/Docker/alpine/clang-cross
387+
dockerArgs: --build-arg TOOLCHAIN_ARCH=riscv64-alpine-linux-musl --build-arg TOOLCHAIN_ARCH_SHORT=riscv64 --build-arg TARGET_MACHINE_ARCH=riscv64 --build-arg DISTRO_VERSION=3.20
378388
target: externals-linux-clang-cross
379389
- template: /scripts/azure-templates-bootstrapper.yml@self # Build Native Tizen (Linux)
380390
parameters:
@@ -518,10 +528,14 @@ stages:
518528
# tvOS
519529
- name: native_tvos_macos
520530
# Linux
531+
- name: native_linux_arm64_alpine_linux
532+
- name: native_linux_arm64_alpine_nodeps_linux
521533
- name: native_linux_arm64_linux
522534
- name: native_linux_arm64_nodeps_linux
523535
- name: native_linux_arm_linux
524536
- name: native_linux_arm_nodeps_linux
537+
- name: native_linux_riscv64_alpine_linux
538+
- name: native_linux_riscv64_alpine_nodeps_linux
525539
- name: native_linux_riscv64_linux
526540
- name: native_linux_riscv64_nodeps_linux
527541
- name: native_linux_x64_alpine_linux
@@ -561,8 +575,12 @@ stages:
561575
# Linux
562576
- name: native_linux_arm64_linux
563577
- name: native_linux_arm64_nodeps_linux
578+
- name: native_linux_arm64_alpine_linux
579+
- name: native_linux_arm64_alpine_nodeps_linux
564580
- name: native_linux_arm_linux
565581
- name: native_linux_arm_nodeps_linux
582+
- name: native_linux_riscv64_alpine_linux
583+
- name: native_linux_riscv64_alpine_nodeps_linux
566584
- name: native_linux_riscv64_linux
567585
- name: native_linux_riscv64_nodeps_linux
568586
- name: native_linux_x64_alpine_linux

0 commit comments

Comments
 (0)