Skip to content

Commit

Permalink
Fix the Dockerfiles
Browse files Browse the repository at this point in the history
  • Loading branch information
mattleibow committed Jul 10, 2024
1 parent a8895d3 commit 6bab23e
Show file tree
Hide file tree
Showing 20 changed files with 218 additions and 171 deletions.
10 changes: 9 additions & 1 deletion native/linux/build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ Task("libSkiaSharp")
var soname = GetVersion("libSkiaSharp", "soname");
var map = MakeAbsolute((FilePath)"libSkiaSharp/libSkiaSharp.map");

// This is terrible! But, Alpine (musl) does not define this
// so we are forced to for dng_sdk. If this ever becomes a problem
// for other libraries, we will need to find a better solution.
var wordSize = ReduceArch(arch).EndsWith("64") ? "64" : "32";
var wordSizeDefine = VARIANT.ToLower() == "alpine"
? $", '-D__WORDSIZE={wordSize}'"
: $"";

GnNinja($"{VARIANT}/{arch}", "SkiaSharp",
$"target_os='linux' " +
$"target_cpu='{arch}' " +
Expand All @@ -77,7 +85,7 @@ Task("libSkiaSharp")
$"skia_enable_skottie=true " +
$"skia_use_vulkan={SUPPORT_VULKAN} ".ToLower() +
$"extra_asmflags=[] " +
$"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_SYSCALL_GETRANDOM', '-DXML_DEV_URANDOM' ] " +
$"extra_cflags=[ '-DSKIA_C_DLL', '-DHAVE_SYSCALL_GETRANDOM', '-DXML_DEV_URANDOM' {wordSizeDefine} ] " +
$"extra_ldflags=[ '-static-libstdc++', '-static-libgcc', '-Wl,--version-script={map}' ] " +
COMPILERS +
$"linux_soname_version='{soname}' " +
Expand Down
37 changes: 12 additions & 25 deletions scripts/Docker/alpine/amd64/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,33 +1,20 @@
FROM amd64/alpine:3.9

# Arguments:
# DOTNET_SDK_VERSION - the version of dotnet for the Cake script [ 3.1.412 | * ]

RUN apk add -X https://dl-cdn.alpinelinux.org/alpine/v3.16/main -u alpine-keys --allow-untrusted
RUN apk add --no-cache bash curl wget python python3 git build-base ninja fontconfig-dev libintl clang

# use the specific commit before the tool switched to C++20 which is too new for this old alpine
RUN git clone https://gn.googlesource.com/gn /usr/share/gn \
&& cd /usr/share/gn \
&& git checkout d4be45bb28fbfc16a41a1e02c86137df6815f2dd \
&& python build/gen.py --allow-warning \
&& ninja -C out \
&& /usr/share/gn/out/gn --version
# DOTNET_SDK_VERSION - the version of dotnet for the Cake script [ 8.0 | * ]

ARG DOTNET_SDK_VERSION=3.1.412
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:alpine-3.17

RUN wget -O dotnet.tar.gz https://dotnetcli.azureedge.net/dotnet/Sdk/$DOTNET_SDK_VERSION/dotnet-sdk-$DOTNET_SDK_VERSION-linux-musl-x64.tar.gz \
&& dotnet_sha512='f81ec24d3550bd414fb0fa154007f88a2e2956c73d033c2a82a6cea3402f0a842d1f32e8ffc199c0d9ed86faa8005a76b7c3b130e9cd0c1bea71d0631c9a1bcd' \
&& echo "$dotnet_sha512 dotnet.tar.gz" | sha512sum -c - \
&& mkdir -p /usr/share/dotnet \
&& tar -C /usr/share/dotnet -xzf dotnet.tar.gz \
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet \
&& rm dotnet.tar.gz
# Install the skia build dependencies
RUN apk add --no-cache fontconfig-dev gn ninja

# Install the .NET SDK
ARG DOTNET_SDK_VERSION=8.0
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT 1
RUN wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh \
&& bash dotnet-install.sh --channel ${DOTNET_SDK_VERSION} --install-dir /usr/share/dotnet --verbose \
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet \
&& rm dotnet-install.sh \
&& dotnet help

RUN dotnet help

ENV GN_EXE=/usr/share/gn/out/gn
ENV CC=clang CXX=clang++ GN_EXE=/usr/bin/gn

WORKDIR /work
4 changes: 2 additions & 2 deletions scripts/Docker/alpine/amd64/build-local.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ set -e

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

(cd $DIR && docker build --tag skiasharp-alpine .)
(cd $DIR && docker build --tag skiasharp-alpine-x64 .)
(cd $DIR/../../../../ && \
docker run --rm --name skiasharp-alpine --volume $(pwd):/work skiasharp-alpine /bin/bash -c "\
docker run --rm --name skiasharp-alpine-x64 --volume $(pwd):/work skiasharp-alpine-x64 /bin/bash -c "\
dotnet tool restore ; \
dotnet cake --target=externals-linux --configuration=Release --buildarch=x64 --variant=alpine")
File renamed without changes.
20 changes: 20 additions & 0 deletions scripts/Docker/alpine/arm64v8/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Arguments:
# DOTNET_SDK_VERSION - the version of dotnet for the Cake script [ 8.0 | * ]

FROM mcr.microsoft.com/dotnet-buildtools/prereqs:alpine-3.17-arm64v8-local

# Install the skia build dependencies
RUN apk add --no-cache fontconfig-dev gn ninja

# Install the .NET SDK
ARG DOTNET_SDK_VERSION=8.0
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT 1
RUN wget https://dot.net/v1/dotnet-install.sh -O dotnet-install.sh \
&& bash dotnet-install.sh --channel ${DOTNET_SDK_VERSION} --install-dir /usr/share/dotnet --verbose \
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet \
&& rm dotnet-install.sh \
&& dotnet help

ENV CC=clang CXX=clang++ GN_EXE=/usr/bin/gn

WORKDIR /work
10 changes: 10 additions & 0 deletions scripts/Docker/alpine/arm64v8/build-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -e

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

(cd $DIR && docker build --tag skiasharp-alpine-arm64 .)
(cd $DIR/../../../../ && \
docker run --rm --name skiasharp-alpine-arm64 --volume $(pwd):/work skiasharp-alpine-arm64 /bin/bash -c "\
dotnet tool restore ; \
dotnet cake --target=externals-linux --configuration=Release --buildarch=arm64 --variant=alpine")
File renamed without changes.
22 changes: 22 additions & 0 deletions scripts/Docker/debian/amd64/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Arguments:
# DOTNET_SDK_VERSION - the version of dotnet for the Cake script [ 8.0 | * ]

FROM mcr.microsoft.com/dotnet-buildtools/prereqs:debian-11-amd64

# Install the skia build dependencies
RUN apt-get update \
&& apt-get install -y libfontconfig1-dev ninja-build \
&& rm -rf /var/lib/apt/lists/*

# Install the .NET SDK
ARG DOTNET_SDK_VERSION=8.0
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT 1
RUN curl https://dot.net/v1/dotnet-install.sh -L -o dotnet-install.sh \
&& bash dotnet-install.sh --channel ${DOTNET_SDK_VERSION} --install-dir /usr/share/dotnet --verbose \
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet \
&& rm dotnet-install.sh \
&& dotnet help

ENV CC=clang CXX=clang++

WORKDIR /work
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ set -e

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

(cd $DIR && docker build --tag skiasharp-linux .)
(cd $DIR && docker build --tag skiasharp-linux-x64 .)
(cd $DIR/../../../../ && \
docker run --rm --name skiasharp-linux --volume $(pwd):/work skiasharp-linux /bin/bash -c "\
docker run --rm --name skiasharp-linux-x64 --volume $(pwd):/work skiasharp-linux-x64 /bin/bash -c "\
dotnet tool restore ; \
dotnet cake --target=externals-linux --configuration=Release --buildarch=x64")
1 change: 1 addition & 0 deletions scripts/Docker/debian/arm64v8/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build-local.sh
22 changes: 22 additions & 0 deletions scripts/Docker/debian/arm64v8/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Arguments:
# DOTNET_SDK_VERSION - the version of dotnet for the Cake script [ 8.0 | * ]

FROM mcr.microsoft.com/dotnet-buildtools/prereqs:debian-11-arm64v8

# Install the skia build dependencies
RUN apt-get update \
&& apt-get install -y libfontconfig1-dev ninja-build \
&& rm -rf /var/lib/apt/lists/*

# Install the .NET SDK
ARG DOTNET_SDK_VERSION=8.0
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT 1
RUN curl https://dot.net/v1/dotnet-install.sh -L -o dotnet-install.sh \
&& bash dotnet-install.sh --channel ${DOTNET_SDK_VERSION} --install-dir /usr/share/dotnet --verbose \
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet \
&& rm dotnet-install.sh \
&& dotnet help

ENV CC=clang CXX=clang++

WORKDIR /work
10 changes: 10 additions & 0 deletions scripts/Docker/debian/arm64v8/build-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash
set -e

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

(cd $DIR && docker build --tag skiasharp-linux-arm64 .)
(cd $DIR/../../../../ && \
docker run --rm --name skiasharp-linux-arm64 --volume $(pwd):/work skiasharp-linux-arm64 /bin/bash -c "\
dotnet tool restore ; \
dotnet cake --target=externals-linux --configuration=Release --buildarch=arm64")
1 change: 1 addition & 0 deletions scripts/Docker/debian/clang-cross/.dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
build-local.sh
62 changes: 62 additions & 0 deletions scripts/Docker/debian/clang-cross/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Arguments:
# IMAGE_ARCH - the architecture of the image [ amd64 | arm64v8 ]
# DOTNET_SDK_VERSION - the version of dotnet for the Cake script [ 8.0 | * ]
# TOOLCHAIN_VERSION - the version of the GCC toolchain [ 9 | * ]
# TOOLCHAIN_ARCH - the architecture of the GCC toolchain [ arm-linux-gnueabihf | aarch64-linux-gnu]
# TOOLCHAIN_ARCH_SHORT - the short form architecture of the GCC toolchain [ armhf | arm64 ]
# FONTCONFIG_VERSION - the exact version of libfontconfig1 to use [ 2.13.1-2 | * ]

ARG IMAGE_ARCH=amd64
FROM mcr.microsoft.com/dotnet-buildtools/prereqs:debian-11-${IMAGE_ARCH}

# Install the skia build dependencies
RUN apt-get update \
&& apt-get install -y ninja-build \
&& rm -rf /var/lib/apt/lists/*

# Install the cross-compilation GCC toolchain
ARG TOOLCHAIN_VERSION=9
ARG TOOLCHAIN_ARCH=arm-linux-gnueabihf
ARG TOOLCHAIN_ARCH_SHORT=armhf
RUN apt-get update \
&& apt-get install -y \
libstdc++-${TOOLCHAIN_VERSION}-dev-${TOOLCHAIN_ARCH_SHORT}-cross \
libgcc-${TOOLCHAIN_VERSION}-dev-${TOOLCHAIN_ARCH_SHORT}-cross \
binutils-${TOOLCHAIN_ARCH} \
&& rm -rf /var/lib/apt/lists/*

# Make the script more flexible and use "current" instead of the actual version
RUN ln -s /usr/${TOOLCHAIN_ARCH}/include/c++/${TOOLCHAIN_VERSION} /usr/${TOOLCHAIN_ARCH}/include/c++/current \
&& sed -i "s/\/usr\/${TOOLCHAIN_ARCH}\/lib\///g" /usr/${TOOLCHAIN_ARCH}/lib/libpthread.so \
&& sed -i "s/\/usr\/${TOOLCHAIN_ARCH}\/lib\///g" /usr/${TOOLCHAIN_ARCH}/lib/libc.so

# Install the cross-compilation skia build dependencies (fontconfig)
ARG FONTCONFIG_VERSION=2.13.1-2
RUN (mkdir -p /skia-utils/libfontconfig1-dev \
&& cd /skia-utils/libfontconfig1-dev \
&& curl http://deb.debian.org/debian/pool/main/f/fontconfig/libfontconfig1-dev_${FONTCONFIG_VERSION}_${TOOLCHAIN_ARCH_SHORT}.deb -L -o libfontconfig1-dev.deb \
&& ar vx libfontconfig1-dev.deb \
&& tar -xJvf data.tar.xz \
&& rm libfontconfig1-dev.deb \
&& cp -R usr/lib/*/* /usr/${TOOLCHAIN_ARCH}/lib/ \
&& cp -R usr/include/* /usr/${TOOLCHAIN_ARCH}/include/ )
RUN (mkdir -p /skia-utils/libfontconfig1 \
&& cd /skia-utils/libfontconfig1 \
&& curl http://deb.debian.org/debian/pool/main/f/fontconfig/libfontconfig1_${FONTCONFIG_VERSION}_${TOOLCHAIN_ARCH_SHORT}.deb -L -o libfontconfig1.deb \
&& ar vx libfontconfig1.deb \
&& tar -xJvf data.tar.xz \
&& rm libfontconfig1.deb \
&& cp -R usr/lib/*/* /usr/${TOOLCHAIN_ARCH}/lib/ )

# Install the .NET SDK
ARG DOTNET_SDK_VERSION=8.0
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT 1
RUN curl https://dot.net/v1/dotnet-install.sh -L -o dotnet-install.sh \
&& bash dotnet-install.sh --channel ${DOTNET_SDK_VERSION} --install-dir /usr/share/dotnet --verbose \
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet \
&& rm dotnet-install.sh \
&& dotnet help

ENV CC=clang CXX=clang++

WORKDIR /work
23 changes: 23 additions & 0 deletions scripts/Docker/debian/clang-cross/build-local.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#!/usr/bin/env bash
set -ex

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

# the target architecture to build for
ARCH="${1:-arm}"
case $ARCH in
arm) BUILD_ARGS="--build-arg TOOLCHAIN_ARCH=arm-linux-gnueabihf --build-arg TOOLCHAIN_ARCH_SHORT=armhf" ;;
arm64) BUILD_ARGS="--build-arg TOOLCHAIN_ARCH=aarch64-linux-gnu --build-arg TOOLCHAIN_ARCH_SHORT=arm64" ;;
x86) BUILD_ARGS="--build-arg TOOLCHAIN_ARCH=i686-linux-gnu --build-arg TOOLCHAIN_ARCH_SHORT=i386" ;;
x64) BUILD_ARGS="--build-arg TOOLCHAIN_ARCH=x86-64-linux-gnu --build-arg TOOLCHAIN_ARCH_SHORT=amd64" ;;
*) echo "Unsupported architecture: $ARCH" && exit 1 ;;
esac

# the docker image architecture to use
IMAGE_ARCH="${2:-$([[ "$(uname -m)" == "arm64" ]] && echo "arm64v8" || echo "amd64")}"

(cd $DIR && docker build --tag skiasharp-linux-cross-$ARCH $BUILD_ARGS --build-arg IMAGE_ARCH=$IMAGE_ARCH .)
(cd $DIR/../../../../ &&
docker run --rm --name skiasharp-linux-cross-$ARCH --volume $(pwd):/work skiasharp-linux-cross-$ARCH /bin/bash -c "\
dotnet tool restore ; \
dotnet cake --target=externals-linux-clang-cross --configuration=Release --buildarch=$ARCH")
37 changes: 0 additions & 37 deletions scripts/Docker/debian9/amd64/Dockerfile

This file was deleted.

72 changes: 0 additions & 72 deletions scripts/Docker/debian9/clang-cross/Dockerfile

This file was deleted.

Loading

0 comments on commit 6bab23e

Please sign in to comment.