Skip to content

Commit 12d9b7e

Browse files
committed
Add riscv64 build support
1 parent cf545ba commit 12d9b7e

File tree

11 files changed

+99
-6
lines changed

11 files changed

+99
-6
lines changed

.devcontainer/devcontainer.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// Features to add to the dev container. More info: https://containers.dev/features.
99
"features": {
1010
"ghcr.io/devcontainers/features/dotnet:2": "latest",
11+
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
1112
},
1213

1314
// Use 'forwardPorts' to make a list of ports inside the container available locally.

binding/Binding.Shared/LibraryLoader.cs

+4
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,13 @@ public static IntPtr LoadLocalLibrary<T> (string libraryName)
4343

4444
static string GetLibraryPath (string libraryName)
4545
{
46+
#if NET
47+
var arch = RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant();
48+
#else
4649
var arch = PlatformConfiguration.Is64Bit
4750
? PlatformConfiguration.IsArm ? "arm64" : "x64"
4851
: PlatformConfiguration.IsArm ? "arm" : "x86";
52+
#endif
4953

5054
var libWithExt = libraryName;
5155
if (!libraryName.EndsWith (Extension, StringComparison.OrdinalIgnoreCase))

binding/HarfBuzzSharp.NativeAssets.Linux/HarfBuzzSharp.NativeAssets.Linux.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
<PackageFile Include="..\..\output\native\linux\x86\libHarfBuzzSharp*" PackagePath="runtimes\linux-x86\native\%(Filename)%(Extension)" />
1111
<PackageFile Include="..\..\output\native\linux\arm64\libHarfBuzzSharp*" PackagePath="runtimes\linux-arm64\native\%(Filename)%(Extension)" />
1212
<PackageFile Include="..\..\output\native\linux\arm\libHarfBuzzSharp*" PackagePath="runtimes\linux-arm\native\%(Filename)%(Extension)" />
13+
<PackageFile Include="..\..\output\native\linux\riscv64\libHarfBuzzSharp*" PackagePath="runtimes\linux-riscv64\native\%(Filename)%(Extension)" />
1314
<!-- Musl -->
1415
<PackageFile Include="..\..\output\native\alpine\x64\libHarfBuzzSharp*" PackagePath="runtimes\linux-musl-x64\native\%(Filename)%(Extension)" />
1516
<PackageFile Include="..\..\output\native\alpine\x86\libHarfBuzzSharp*" PackagePath="runtimes\linux-musl-x86\native\%(Filename)%(Extension)" />
1617
<PackageFile Include="..\..\output\native\alpine\arm64\libHarfBuzzSharp*" PackagePath="runtimes\linux-musl-arm64\native\%(Filename)%(Extension)" />
1718
<PackageFile Include="..\..\output\native\alpine\arm\libHarfBuzzSharp*" PackagePath="runtimes\linux-musl-arm\native\%(Filename)%(Extension)" />
19+
<PackageFile Include="..\..\output\native\alpine\riscv64\libHarfBuzzSharp*" PackagePath="runtimes\linux-musl-riscv64\native\%(Filename)%(Extension)" />
1820
</ItemGroup>
1921
<Target Name="IncludeAdditionalTfmSpecificPackageFiles">
2022
<ItemGroup Condition="$(TargetFramework.StartsWith('net4'))">

binding/SkiaSharp.NativeAssets.Linux.NoDependencies/SkiaSharp.NativeAssets.Linux.NoDependencies.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@ The excluded dependencies are:
2121
<PackageFile Include="..\..\output\native\linuxnodeps\x86\libSkiaSharp*.so" PackagePath="runtimes\linux-x86\native\%(Filename)%(Extension)" />
2222
<PackageFile Include="..\..\output\native\linuxnodeps\arm64\libSkiaSharp*.so" PackagePath="runtimes\linux-arm64\native\%(Filename)%(Extension)" />
2323
<PackageFile Include="..\..\output\native\linuxnodeps\arm\libSkiaSharp*.so" PackagePath="runtimes\linux-arm\native\%(Filename)%(Extension)" />
24+
<PackageFile Include="..\..\output\native\linuxnodeps\riscv64\libSkiaSharp*.so" PackagePath="runtimes\linux-riscv64\native\%(Filename)%(Extension)" />
2425
<!-- Musl -->
2526
<PackageFile Include="..\..\output\native\alpinenodeps\x64\libSkiaSharp*.so" PackagePath="runtimes\linux-musl-x64\native\%(Filename)%(Extension)" />
2627
<PackageFile Include="..\..\output\native\alpinenodeps\x86\libSkiaSharp*.so" PackagePath="runtimes\linux-musl-x86\native\%(Filename)%(Extension)" />
2728
<PackageFile Include="..\..\output\native\alpinenodeps\arm64\libSkiaSharp*.so" PackagePath="runtimes\linux-musl-arm64\native\%(Filename)%(Extension)" />
2829
<PackageFile Include="..\..\output\native\alpinenodeps\arm\libSkiaSharp*.so" PackagePath="runtimes\linux-musl-arm\native\%(Filename)%(Extension)" />
30+
<PackageFile Include="..\..\output\native\alpinenodeps\riscv64\libSkiaSharp*.so" PackagePath="runtimes\linux-musl-riscv64\native\%(Filename)%(Extension)" />
2931
</ItemGroup>
3032
<Target Name="IncludeAdditionalTfmSpecificPackageFiles">
3133
<ItemGroup Condition="$(TargetFramework.StartsWith('net4'))">

binding/SkiaSharp.NativeAssets.Linux.NoDependencies/buildTransitive/net4/SkiaSharp.targets

+6
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<_NativeSkiaSharpFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\linux-arm64\native\libSkiaSharp*.so">
2323
<Dir>arm64\</Dir>
2424
</_NativeSkiaSharpFile>
25+
<_NativeSkiaSharpFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\linux-riscv64\native\libSkiaSharp*.so">
26+
<Dir>riscv64\</Dir>
27+
</_NativeSkiaSharpFile>
2528

2629
<!-- Musl -->
2730
<_NativeSkiaSharpFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\linux-musl-x86\native\libSkiaSharp*.so">
@@ -36,6 +39,9 @@
3639
<_NativeSkiaSharpFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\linux-musl-arm64\native\libSkiaSharp*.so">
3740
<Dir>musl-arm64\</Dir>
3841
</_NativeSkiaSharpFile>
42+
<_NativeSkiaSharpFile Include="$(MSBuildThisFileDirectory)..\..\runtimes\linux-musl-riscv64\native\libSkiaSharp*.so">
43+
<Dir>musl-riscv64\</Dir>
44+
</_NativeSkiaSharpFile>
3945

4046
<!-- include everything -->
4147
<Content Include="@(_NativeSkiaSharpFile)">

binding/SkiaSharp.NativeAssets.Linux/SkiaSharp.NativeAssets.Linux.csproj

+2
Original file line numberDiff line numberDiff line change
@@ -10,11 +10,13 @@
1010
<PackageFile Include="..\..\output\native\linux\x86\libSkiaSharp*" PackagePath="runtimes\linux-x86\native\%(Filename)%(Extension)" />
1111
<PackageFile Include="..\..\output\native\linux\arm64\libSkiaSharp*" PackagePath="runtimes\linux-arm64\native\%(Filename)%(Extension)" />
1212
<PackageFile Include="..\..\output\native\linux\arm\libSkiaSharp*" PackagePath="runtimes\linux-arm\native\%(Filename)%(Extension)" />
13+
<PackageFile Include="..\..\output\native\linux\riscv64\libSkiaSharp*" PackagePath="runtimes\linux-riscv64\native\%(Filename)%(Extension)" />
1314
<!-- Musl -->
1415
<PackageFile Include="..\..\output\native\alpine\x64\libSkiaSharp*" PackagePath="runtimes\linux-musl-x64\native\%(Filename)%(Extension)" />
1516
<PackageFile Include="..\..\output\native\alpine\x86\libSkiaSharp*" PackagePath="runtimes\linux-musl-x86\native\%(Filename)%(Extension)" />
1617
<PackageFile Include="..\..\output\native\alpine\arm64\libSkiaSharp*" PackagePath="runtimes\linux-musl-arm64\native\%(Filename)%(Extension)" />
1718
<PackageFile Include="..\..\output\native\alpine\arm\libSkiaSharp*" PackagePath="runtimes\linux-musl-arm\native\%(Filename)%(Extension)" />
19+
<PackageFile Include="..\..\output\native\alpine\riscv64\libSkiaSharp*" PackagePath="runtimes\linux-musl-riscv64\native\%(Filename)%(Extension)" />
1820
</ItemGroup>
1921
<Target Name="IncludeAdditionalTfmSpecificPackageFiles">
2022
<ItemGroup Condition="$(TargetFramework.StartsWith('net4'))">
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
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-linux-gnueabihf | aarch64-linux-gnu | riscv64-linux-gnu ]
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 ninja-build xz-utils \
16+
&& rm -rf /var/lib/apt/lists/*
17+
18+
# Install the cross-compilation GCC toolchain
19+
ARG TOOLCHAIN_VERSION=12
20+
ARG TOOLCHAIN_ARCH=arm-linux-gnueabihf
21+
ARG TOOLCHAIN_ARCH_SHORT=armhf
22+
RUN apt-get update \
23+
&& apt-get install -y \
24+
libstdc++-${TOOLCHAIN_VERSION}-dev-${TOOLCHAIN_ARCH_SHORT}-cross \
25+
libgcc-${TOOLCHAIN_VERSION}-dev-${TOOLCHAIN_ARCH_SHORT}-cross \
26+
binutils-${TOOLCHAIN_ARCH} \
27+
&& rm -rf /var/lib/apt/lists/*
28+
29+
# Make the script more flexible and use "current" instead of the actual version
30+
RUN ln -s /usr/${TOOLCHAIN_ARCH}/include/c++/${TOOLCHAIN_VERSION} /usr/${TOOLCHAIN_ARCH}/include/c++/current \
31+
&& sed -i "s/\/usr\/${TOOLCHAIN_ARCH}\/lib\///g" /usr/${TOOLCHAIN_ARCH}/lib/libpthread.so || true \
32+
&& sed -i "s/\/usr\/${TOOLCHAIN_ARCH}\/lib\///g" /usr/${TOOLCHAIN_ARCH}/lib/libc.so
33+
34+
# Install the cross-compilation skia build dependencies (fontconfig)
35+
ARG FONTCONFIG_VERSION=2.15.0-2
36+
RUN (mkdir -p /skia-utils/libfontconfig1-dev \
37+
&& cd /skia-utils/libfontconfig1-dev \
38+
&& curl http://deb.debian.org/debian/pool/main/f/fontconfig/libfontconfig-dev_${FONTCONFIG_VERSION}_${TOOLCHAIN_ARCH_SHORT}.deb -L -o libfontconfig1-dev.deb \
39+
&& ar vx libfontconfig1-dev.deb \
40+
&& tar -xJvf data.tar.xz \
41+
&& rm libfontconfig1-dev.deb \
42+
&& cp -R usr/lib/*/* /usr/${TOOLCHAIN_ARCH}/lib/ \
43+
&& cp -R usr/include/* /usr/${TOOLCHAIN_ARCH}/include/ )
44+
RUN (mkdir -p /skia-utils/libfontconfig1 \
45+
&& cd /skia-utils/libfontconfig1 \
46+
&& curl http://deb.debian.org/debian/pool/main/f/fontconfig/libfontconfig1_${FONTCONFIG_VERSION}_${TOOLCHAIN_ARCH_SHORT}.deb -L -o libfontconfig1.deb \
47+
&& ar vx libfontconfig1.deb \
48+
&& tar -xJvf data.tar.xz \
49+
&& rm libfontconfig1.deb \
50+
&& cp -R usr/lib/*/* /usr/${TOOLCHAIN_ARCH}/lib/ )
51+
52+
# Install the .NET SDK
53+
ARG DOTNET_SDK_VERSION=8.0
54+
ENV DOTNET_SYSTEM_GLOBALIZATION_INVARIANT 1
55+
RUN curl https://dot.net/v1/dotnet-install.sh -L -o dotnet-install.sh \
56+
&& bash dotnet-install.sh --channel ${DOTNET_SDK_VERSION} --install-dir /usr/share/dotnet --verbose \
57+
&& ln -s /usr/share/dotnet/dotnet /usr/bin/dotnet \
58+
&& rm dotnet-install.sh \
59+
&& dotnet help \
60+
&& dotnet --info
61+
62+
ENV CC=clang-19 CXX=clang++-19
63+
64+
WORKDIR /work

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

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
66
# the target architecture to build for
77
ARCH="${1:-arm}"
88
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-
x86) BUILD_ARGS="--build-arg TOOLCHAIN_ARCH=i686-linux-gnu --build-arg TOOLCHAIN_ARCH_SHORT=i386" ;;
12-
x64) BUILD_ARGS="--build-arg TOOLCHAIN_ARCH=x86-64-linux-gnu --build-arg TOOLCHAIN_ARCH_SHORT=amd64" ;;
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=aarch64-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" ;;
1314
*) echo "Unsupported architecture: $ARCH" && exit 1 ;;
1415
esac
1516

scripts/azure-templates-stages.yml

+11-2
Original file line numberDiff line numberDiff line change
@@ -366,12 +366,16 @@ stages:
366366
variant: alpine
367367
docker: scripts/Docker/alpine/amd64
368368
- arch: arm
369-
docker: scripts/Docker/debian/clang-cross
369+
docker: scripts/Docker/debian/clang-cross/11
370370
target: externals-linux-clang-cross
371371
- arch: arm64
372-
docker: scripts/Docker/debian/clang-cross
372+
docker: scripts/Docker/debian/clang-cross/11
373373
dockerArgs: --build-arg TOOLCHAIN_ARCH=aarch64-linux-gnu --build-arg TOOLCHAIN_ARCH_SHORT=arm64
374374
target: externals-linux-clang-cross
375+
- arch: riscv64
376+
docker: scripts/Docker/debian/clang-cross/12
377+
dockerArgs: --build-arg TOOLCHAIN_ARCH=riscv64-linux-gnu --build-arg TOOLCHAIN_ARCH_SHORT=riscv64
378+
target: externals-linux-clang-cross
375379
- template: /scripts/azure-templates-bootstrapper.yml@self # Build Native Tizen (Linux)
376380
parameters:
377381
name: native_tizen_linux
@@ -518,6 +522,8 @@ stages:
518522
- name: native_linux_arm64_nodeps_linux
519523
- name: native_linux_arm_linux
520524
- name: native_linux_arm_nodeps_linux
525+
- name: native_linux_riscv64_linux
526+
- name: native_linux_riscv64_nodeps_linux
521527
- name: native_linux_x64_alpine_linux
522528
- name: native_linux_x64_alpine_nodeps_linux
523529
- name: native_linux_x64_linux
@@ -557,6 +563,8 @@ stages:
557563
- name: native_linux_arm64_nodeps_linux
558564
- name: native_linux_arm_linux
559565
- name: native_linux_arm_nodeps_linux
566+
- name: native_linux_riscv64_linux
567+
- name: native_linux_riscv64_nodeps_linux
560568
- name: native_linux_x64_alpine_linux
561569
- name: native_linux_x64_alpine_nodeps_linux
562570
- name: native_linux_x64_linux
@@ -884,6 +892,7 @@ stages:
884892
requiredArtifacts:
885893
- name: native_linux_x64_linux
886894
- name: native_linux_arm64_linux
895+
- name: native_linux_riscv64_linux
887896
postBuildSteps:
888897
- task: PublishTestResults@2
889898
displayName: Publish the .NET Core test results

scripts/cake/native-shared.cake

+2
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ string ReduceArch(string arch)
117117
case "aarch64":
118118
case "arm64":
119119
return "arm64";
120+
case "riscv64":
121+
return "riscv64";
120122
}
121123

122124
throw new Exception($"Unknown architecture: {arch}");

0 commit comments

Comments
 (0)