Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Android builds #22

Merged
merged 8 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 46 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/upload-artifact@v3
with:
name: alphaskia-windows-${{ matrix.architecture }}-${{ matrix.variant }}
path: dist
path: artifacts

windows-jni:
runs-on: windows-latest
Expand All @@ -40,7 +40,7 @@ jobs:
- uses: actions/upload-artifact@v3
with:
name: alphaskia-windows-jni-${{ matrix.architecture }}-${{ matrix.variant }}
path: dist
path: artifacts

linux:
runs-on: ubuntu-latest
Expand All @@ -59,7 +59,7 @@ jobs:
- uses: actions/upload-artifact@v3
with:
name: alphaskia-linux-${{ matrix.architecture }}-${{ matrix.variant }}
path: dist
path: artifacts

linux-jni:
runs-on: ubuntu-latest
Expand All @@ -82,7 +82,48 @@ jobs:
- uses: actions/upload-artifact@v3
with:
name: alphaskia-linux-jni-${{ matrix.architecture }}-${{ matrix.variant }}
path: artifacts

android:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
architecture: [x64, x86, arm, arm64]
variant: ['shared', 'static']

steps:
- uses: actions/checkout@v3
with:
submodules: true
- run: ./externals/skia/tools/install_dependencies.sh
- run: ./build.sh AndroidSkia --architecture ${{ matrix.architecture }} --variant ${{ matrix.variant }}
- uses: actions/upload-artifact@v3
with:
name: alphaskia-android-${{ matrix.architecture }}-${{ matrix.variant }}
path: artifacts

android-jni:
runs-on: ubuntu-latest
needs: [android]
strategy:
fail-fast: false
matrix:
architecture: [x64, x86, arm, arm64]
variant: ['shared']

steps:
- uses: actions/checkout@v3
with:
submodules: true
- uses: actions/download-artifact@v3
with:
path: dist
- run: ./build.cmd AndroidJni --architecture ${{ matrix.architecture }} --variant ${{ matrix.variant }}
- uses: actions/upload-artifact@v3
with:
name: alphaskia-android-jni-${{ matrix.architecture }}-${{ matrix.variant }}
path: artifacts

dotnet:
runs-on: windows-latest
Expand All @@ -104,7 +145,7 @@ jobs:

java:
runs-on: ubuntu-latest
needs: [windows-jni, linux-jni]
needs: [windows-jni, linux-jni, android-jni]
steps:
- uses: actions/checkout@v3
with:
Expand All @@ -119,4 +160,5 @@ jobs:
path: |
lib/java/main/build/libs/*.jar
lib/java/linux/build/libs/*.jar
lib/java/android/build/libs/*.jar
lib/java/windows/build/libs/*.jar
128 changes: 128 additions & 0 deletions build/Build.Android.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using Nuke.Common;
using static Nuke.Common.EnvironmentInfo;

partial class Build
{
[Parameter] readonly string NdkPath = GetVariable<string>("ANDROID_NDK_HOME") ?? FindNdk();

static string FindNdk()
{
if (OperatingSystem.IsWindows())
{
var candidates = new List<string>()
{
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Android", "Ndk")
};

return candidates.Select(c =>
{
if (!Directory.Exists(c))
{
return null;
}

if (File.Exists(Path.Combine(c, "package.xml")))
{
return c;
}

foreach (var subDir in Directory.EnumerateDirectories(c).OrderByDescending(Path.GetFileName))
{
if (File.Exists(Path.Combine(subDir, "package.xml")))
{
return subDir;
}
}

return null;
}).FirstOrDefault(d => d != null) ?? string.Empty;
}

return string.Empty;
}

public Target AndroidSkia => _ => _
.DependsOn(GitSyncDepsSkia, PatchSkiaBuildFiles)
.Requires(() => Architecture)
.Requires(() => Variant)
.Executes(() =>
{
BuildSkiaAndroidMain(Architecture, Variant);
});

public Target AndroidJni => _ => _
.DependsOn(PrepareGitHubArtifacts, GitSyncDepsJni, PatchSkiaBuildFiles)
.Requires(() => Architecture)
.Requires(() => Variant == Variant.Shared)
.Executes(() =>
{
BuildSkiaAndroidJni(Architecture, Variant);
});

void BuildSkiaAndroidMain(Architecture arch, Variant variant)
{
var gnArgs = new Dictionary<string, string>();
gnArgs["ndk"] = NdkPath;

string[] filesToCopy;
var isShared = variant == Variant.Shared;
if (isShared)
{
filesToCopy = new[]
{
"libAlphaSkia.so"
};
}
else
{
filesToCopy = new[]
{
"libAlphaSkia.a",
"libskia.a"
};
}

BuildSkiaAndroid("libAlphaSkia", arch, variant, gnArgs, filesToCopy);
}

void BuildSkiaAndroidJni(Architecture arch, Variant variant)
{
var gnArgs = new Dictionary<string, string>();
var alphaSkiaInclude = DistBasePath / "include";
var jniInclude = JavaHome / "include";
var jniWinInclude = JavaHome / "include" / "linux";
gnArgs["ndk"] = NdkPath;
gnArgs["extra_cflags"] = $"[ '-I{alphaSkiaInclude}', '-I{jniInclude}', '-I{jniWinInclude}' ]";

// Add Libs and lib search paths
var staticLibPath = DistBasePath / $"libAlphaSkia-android-{arch}-static";
gnArgs["extra_ldflags"] =
$"[ '-L{staticLibPath}', '-lAlphaSkia', '-lskia' ]";

BuildSkiaAndroid("libAlphaSkiaJni", arch, variant, gnArgs, new[] { "libAlphaSkiaJni.so" });
}

void BuildSkiaAndroid(string buildTarget, Architecture arch, Variant variant, Dictionary<string, string> gnArgs,
string[] filesToCopy)
{
if (OperatingSystem.IsWindows())
{
SetClangWindows(gnArgs);
}
else if (OperatingSystem.IsLinux())
{
SetClangLinux(arch, gnArgs);
}

// gnArgs["skia_enable_ganesh"] = "true";
gnArgs["skia_use_system_freetype2"] = "false";

// -Wdeprecated-declarations

BuildSkia(buildTarget, "android", arch, variant, gnArgs, filesToCopy);
}
}
3 changes: 0 additions & 3 deletions build/Build.Java.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using Nuke.Common;
using Nuke.Common.IO;
using Nuke.Common.Tooling;
using Nuke.Common.Tools.DotNet;
using static Nuke.Common.EnvironmentInfo;

partial class Build
Expand Down
17 changes: 10 additions & 7 deletions build/Build.Linux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,13 @@ void BuildSkiaLinuxMain(Architecture arch, Variant variant)
void BuildSkiaLinuxJni(Architecture arch, Variant variant)
{
var gnArgs = new Dictionary<string, string>();
var alphaSkiaInclude = RootDirectory / "dist" / "include";
var alphaSkiaInclude = DistBasePath / "include";
var jniInclude = JavaHome / "include";
var jniWinInclude = JavaHome / "include" / "linux";
gnArgs["extra_cflags"] = $"[ '-I{alphaSkiaInclude}', '-I{jniInclude}', '-I{jniWinInclude}' ]";

// Add Libs and lib search paths
var staticLibPath = RootDirectory / "dist" / $"libAlphaSkia-linux-{arch}-static";
var staticLibPath = DistBasePath / $"libAlphaSkia-linux-{arch}-static";
gnArgs["extra_ldflags"] =
$"[ '-L{staticLibPath}', '-lAlphaSkia', '-lskia' ]";

Expand All @@ -67,8 +67,15 @@ void BuildSkiaLinuxJni(Architecture arch, Variant variant)
void BuildSkiaLinux(string buildTarget, Architecture arch, Variant variant, Dictionary<string, string> gnArgs,
string[] filesToCopy)
{
gnArgs["skia_enable_ganesh"] = "true";
SetClangLinux(arch, gnArgs);

gnArgs["skia_use_system_freetype2"] = "false";

BuildSkia(buildTarget, "linux", arch, variant, gnArgs, filesToCopy);
}

void SetClangLinux(Architecture arch, Dictionary<string, string> gnArgs)
{
AppendToFlagList(gnArgs, "extra_cflags", "'-DHAVE_SYSCALL_GETRANDOM', '-DXML_DEV_URANDOM'");

if (arch == Architecture.X64)
Expand All @@ -93,9 +100,5 @@ void BuildSkiaLinux(string buildTarget, Architecture arch, Variant variant, Dict
}

// gnArgs["ar"] = "llvm-ar";
gnArgs["skia_use_system_freetype2"] = "false";


BuildSkia(buildTarget, "linux", arch, variant, gnArgs, filesToCopy);
}
}
Loading