Skip to content

Commit

Permalink
Adjust JNI loading for Android and bump Skia to m120 (#47)
Browse files Browse the repository at this point in the history
  • Loading branch information
Danielku15 authored Dec 24, 2023
1 parent e50e838 commit 7eeedcb
Show file tree
Hide file tree
Showing 53 changed files with 562 additions and 959 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ jobs:
uses: ./.github/workflows/~reusable-full-build.yml
with:
use-skia-cache: ${{ inputs.use-skia-cache }}
alphaskia-version: "1.0"
alphaskia-version: "2.0"
is-release-build: false
secrets: inherit
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
uses: ./.github/workflows/~reusable-full-build.yml
with:
use-skia-cache: ${{ inputs.use-skia-cache }}
alphaskia-version: "1.0"
alphaskia-version: "2.0"
is-release-build: ${{ inputs.is-release-build }}
secrets: inherit

Expand Down
12 changes: 9 additions & 3 deletions .github/workflows/~dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ jobs:
dotnet:
runs-on: ubuntu-latest
steps:
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8'
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
Expand All @@ -40,19 +43,22 @@ jobs:
include:
- runs-on: ubuntu-latest
architecture: x64
framework: net6.0
framework: net8.0
- runs-on: macos-latest
architecture: x64
framework: net6.0
framework: net8.0
- runs-on: windows-latest
architecture: x64
framework: net6.0
framework: net8.0
- runs-on: windows-latest
architecture: x64
framework: net48
runs-on: ${{ matrix.runs-on }}
needs: [dotnet]
steps:
- uses: actions/setup-dotnet@v4
with:
dotnet-version: '8'
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
Expand Down
5 changes: 4 additions & 1 deletion .github/workflows/~java.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ jobs:
SONATYPE_SIGNING_PASSWORD: ${{ secrets.SONATYPE_SIGNING_PASSWORD }}
SONATYPE_STAGING_PROFILE_ID: ${{ secrets.SONATYPE_STAGING_PROFILE_ID }}
steps:
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
Expand All @@ -49,7 +53,6 @@ jobs:
runs-on: ${{ matrix.runs-on }}
needs: [java]
steps:
# even though it is installed, not all Operating systems are configured the same
- uses: actions/setup-java@v3
with:
distribution: 'temurin'
Expand Down
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[submodule "externals/skia"]
path = externals/skia
url = https://skia.googlesource.com/skia.git
branch = chrome/m117
branch = chrome/m120
[submodule "externals/node-api-headers"]
path = externals/node-api-headers
url = https://github.com/nodejs/node-api-headers.git
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ alphaSkia is a special cross platform [Skia](https://skia.org/) wrapper used in
alphaSkia a slightly adapted [Semantic Versioning](https://semver.org/) scheme where the `PATCH` part indicates
the Skia milestone version we have integrated.

Currently we are on [Skia m117](https://github.com/CoderLine/alphaSkia/blob/main/.gitmodules#L8)
Currently we are on [Skia m120](https://github.com/CoderLine/alphaSkia/blob/main/.gitmodules#L8)

Given a version number `MAJOR.MINOR.SKIA`:

Expand Down
12 changes: 5 additions & 7 deletions build/Build.Java.cs
Original file line number Diff line number Diff line change
Expand Up @@ -110,26 +110,24 @@ string JavaVersion
get
{
string semVer;
if (IsLocalBuild)
if (IsReleaseBuild)
{
semVer = $"{VersionInfo.FileVersion.ToString(3)}-LOCAL";
semVer = $"{VersionInfo.FileVersion.ToString(3)}";
}
else if (!IsReleaseBuild)
else if (IsLocalBuild)
{
semVer = $"{VersionInfo.FileVersion.ToString(3)}-SNAPSHOT";
semVer = $"{VersionInfo.FileVersion.ToString(3)}-LOCAL";
}
else
{
semVer = $"{VersionInfo.FileVersion.ToString(3)}";
semVer = $"{VersionInfo.FileVersion.ToString(3)}-SNAPSHOT";
}

return semVer;
}
}

public Target JavaPublish => _ => _
.DependsOn(PrepareGitHubArtifacts)
.Requires(() => IsGitHubActions)
.Executes(() =>
{
// workaround until we know how to upload existing maven packages
Expand Down
20 changes: 15 additions & 5 deletions build/Build.LibAlphaSkia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -252,25 +252,35 @@ void BuildAlphaSkia()
var alphaSkiaInclude = DistBasePath / "include";
var jniInclude = JavaHome / "include";
AbsolutePath jniPlatformInclude;
if (OperatingSystem.IsWindows())
if (OperatingSystem.IsWindows() && TargetOs == TargetOperatingSystem.Windows)
{
jniPlatformInclude = jniInclude / "win32";
}
else if (OperatingSystem.IsLinux())
else if (OperatingSystem.IsLinux() && TargetOs == TargetOperatingSystem.Linux)
{
jniPlatformInclude = jniInclude / "linux";
}
else if (OperatingSystem.IsMacOS())
else if (OperatingSystem.IsMacOS() && TargetOs == TargetOperatingSystem.MacOs)
{
jniPlatformInclude = jniInclude / "darwin";
}
else if(TargetOs == TargetOperatingSystem.Android)
{
jniPlatformInclude = null;
}
else
{
throw new PlatformNotSupportedException();
}

AppendToFlagList(gnArgs, "extra_cflags",
$"'-I{alphaSkiaInclude}', '-I{jniInclude}', '-I{jniPlatformInclude}'");
if(jniPlatformInclude != null)
{
AppendToFlagList(gnArgs, "extra_cflags", $"'-I{alphaSkiaInclude}', '-I{jniInclude}', '-I{jniPlatformInclude}'");
}
else
{
AppendToFlagList(gnArgs, "extra_cflags", $"'-I{alphaSkiaInclude}'");
}
}
else if (Variant == Variant.Node)
{
Expand Down
1 change: 0 additions & 1 deletion build/Build.LibSkia.cs
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,6 @@ void BuildSkia()
gnArgs["skia_use_sfntly"] = "false";
gnArgs["skia_enable_skshaper"] = "true";
gnArgs["skia_pdf_subset_harfbuzz"] = "false";
gnArgs["skia_use_expat"] = "false";
gnArgs["skia_enable_pdf"] = "false";
gnArgs["skia_use_dng_sdk"] = "false";
gnArgs["skia_use_libjpeg_turbo_decode"] = "false";
Expand Down
1 change: 1 addition & 0 deletions build/Build.Native.cs
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ Dictionary<string, string> PrepareNativeBuild(Variant variant)
if (TargetOs == TargetOperatingSystem.Android)
{
gnArgs["ndk"] = NdkPath;
AppendToFlagList(gnArgs, "extra_ldflags", $"'-llog'");
}

gnArgs["target_os"] = TargetOs.SkiaTargetOs;
Expand Down
2 changes: 1 addition & 1 deletion build/Build.Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ void PrepareTgzForTest()
var files = new System.Collections.Generic.List<string>();
foreach (var tgz in (RootDirectory / "dist" / "nodetars").GetFiles("*.tgz"))
{
// coderline-alphaskia-1.0.0-local.0.tgz
// coderline-alphaskia-2.0.0-local.0.tgz
var nameWithoutVersion = string.Join("-",
tgz.NameWithoutExtension.Split('-').TakeWhile(p => !char.IsDigit(p[0])))
+ tgz.Extension;
Expand Down
41 changes: 22 additions & 19 deletions build/Build.Windows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,30 +34,33 @@ string VsInstall

void SetClangWindows(Dictionary<string, string> gnArgs)
{
if (!string.IsNullOrEmpty(LlvmHome))
if(TargetOs == TargetOperatingSystem.Windows)
{
gnArgs["clang_win"] = LlvmHome;
if (!string.IsNullOrEmpty(LlvmHome))
{
gnArgs["clang_win"] = LlvmHome;

// there is a problem in the BUILDCONFIG.gn of Skia looking for a version number like 16.0.0
// but with the installation on windows it is simply 16.
var version = ((AbsolutePath)LlvmHome) / "lib" / "clang";
var newestVersion = version.GetDirectories().MaxBy(d => d.Name);
if (!string.IsNullOrEmpty(newestVersion))
{
gnArgs["clang_win_version"] = newestVersion.Name;
}
}

// there is a problem in the BUILDCONFIG.gn of Skia looking for a version number like 16.0.0
// but with the installation on windows it is simply 16.
var version = ((AbsolutePath)LlvmHome) / "lib" / "clang";
var newestVersion = version.GetDirectories().MaxBy(d => d.Name);
if (!string.IsNullOrEmpty(newestVersion))
// override win_vc with the command line args
var vsInstall = VsInstall;
if (!string.IsNullOrEmpty(vsInstall))
{
gnArgs["clang_win_version"] = newestVersion.Name;
AbsolutePath winVc = vsInstall;
winVc /= "VC";
gnArgs["win_vc"] = winVc;
}
}

// override win_vc with the command line args
var vsInstall = VsInstall;
if (!string.IsNullOrEmpty(vsInstall))
{
AbsolutePath winVc = vsInstall;
winVc /= "VC";
gnArgs["win_vc"] = winVc;
AppendToFlagList(gnArgs, "extra_cflags", "'/MT', '/EHsc', '/Z7', '-D_HAS_AUTO_PTR_ETC=1'");
AppendToFlagList(gnArgs, "extra_ldflags", "'/DEBUG:FULL'");
}

AppendToFlagList(gnArgs, "extra_cflags", "'/MT', '/EHsc', '/Z7', '-D_HAS_AUTO_PTR_ETC=1'");
AppendToFlagList(gnArgs, "extra_ldflags", "'/DEBUG:FULL'");
}
}
2 changes: 1 addition & 1 deletion externals/skia
Submodule skia updated from beb4d7 to 349c11
4 changes: 2 additions & 2 deletions lib/dotnet/AlphaSkia/AlphaSkiaCanvas.cs
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ public void FillText(string text, AlphaSkiaTypeface typeface, float fontSize, fl
AlphaSkiaTextBaseline baseline)
{
CheckDisposed();
NativeMethods.alphaskia_canvas_fill_text(Handle, text, typeface.Handle, fontSize, x, y, textAlign, baseline);
NativeMethods.alphaskia_canvas_fill_text(Handle, text, text.Length, typeface.Handle, fontSize, x, y, textAlign, baseline);
}

/// <summary>
Expand All @@ -285,7 +285,7 @@ public void FillText(string text, AlphaSkiaTypeface typeface, float fontSize, fl
public float MeasureText(string text, AlphaSkiaTypeface typeface, float fontSize)
{
CheckDisposed();
return NativeMethods.alphaskia_canvas_measure_text(Handle, text, typeface.Handle, fontSize);
return NativeMethods.alphaskia_canvas_measure_text(Handle, text, text.Length, typeface.Handle, fontSize);
}

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions lib/dotnet/AlphaSkia/NativeMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,13 +150,15 @@ public static extern void alphaskia_canvas_bezier_curve_to(alphaskia_canvas_t ca
public static extern void alphaskia_canvas_fill_text(alphaskia_canvas_t canvas,
[MarshalAs(UnmanagedType.LPWStr)]
string text,
int text_length,
alphaskia_typeface_t type_face, float font_size, float x, float y, AlphaSkiaTextAlign text_align,
AlphaSkiaTextBaseline baseline);

[DllImport(AlphaSkiaNativeLibName, CallingConvention = CallingConvention.Cdecl)]
public static extern float alphaskia_canvas_measure_text(alphaskia_canvas_t canvas,
[MarshalAs(UnmanagedType.LPWStr)]
string text,
int text_length,
alphaskia_typeface_t type_face, float font_size);

[DllImport(AlphaSkiaNativeLibName, CallingConvention = CallingConvention.Cdecl)]
Expand Down
2 changes: 1 addition & 1 deletion lib/dotnet/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
<Version Condition=" '$(Version)' == '' ">1.0.0</Version>
<Version Condition=" '$(Version)' == '' ">2.0.0</Version>
<AssemblyVersion Condition=" '$(AssemblyVersion)' == '' ">$(Version).0</AssemblyVersion>
<FileVersion Condition=" '$(FileVersion)' == '' ">$(AssemblyVersion)</FileVersion>
<NeutralLanguage>en</NeutralLanguage>
Expand Down
2 changes: 1 addition & 1 deletion lib/java/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion lib/java/.idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

63 changes: 49 additions & 14 deletions lib/java/android/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,38 +1,73 @@
import com.android.build.gradle.internal.api.BaseVariantOutputImpl
import com.android.build.gradle.internal.tasks.factory.dependsOn

plugins {
id("java-library")
id("com.android.library")
`maven-publish`
signing
}

java {
toolchain{
languageVersion.set(JavaLanguageVersion.of(17))
}
withSourcesJar()
withJavadocJar()
dependencies {
implementation(project(":main"))
}

tasks.jar {
archiveBaseName = "alphaSkia-android"
tasks.register<Copy>("copyJniForAndroid") {
// https://developer.android.com/studio/projects/gradle-external-native-builds#jniLibs
// https://developer.android.com/ndk/guides/abis#sa

into("native/android-x64/") {
into("src/main/jniLibs/x86_64") {
from(rootProject.projectDir.resolve("../../dist/libalphaskiajni-android-x64-jni/")) {
include("*.so")
}
}
into("native/android-x86/") {
into("src/main/jniLibs/x86") {
from(rootProject.projectDir.resolve("../../dist/libalphaskiajni-android-x86-jni/")) {
include("*.so")
}
}
into("native/android-arm64/") {
into("src/main/jniLibs/arm64-v8a") {
from(rootProject.projectDir.resolve("../../dist/libalphaskiajni-android-arm64-jni/")) {
include("*.so")
}
}
into("native/android-arm/") {
into("src/main/jniLibs/armeabi-v7a") {
from(rootProject.projectDir.resolve("../../dist/libalphaskiajni-android-arm-jni/")) {
include("*.so")
}
}
}

destinationDir = projectDir
}
tasks.preBuild.dependsOn("copyJniForAndroid")


android {
namespace = "net.alphatab.alphaskia.android"
compileSdk = 34

defaultConfig {
minSdk = 26
ndk {
abiFilters += listOf("x86", "x86_64", "armeabi-v7a", "arm64-v8a")
}
setProperty("archivesBaseName", "alphaSkia-android")
}

buildTypes {
release {
isMinifyEnabled = false
}
}
compileOptions {
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
}

publishing {
singleVariant("release") {
withSourcesJar()
withJavadocJar()
}
}
}

Loading

0 comments on commit 7eeedcb

Please sign in to comment.