Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c71c3e4
add node headers
Danielku15 Oct 12, 2023
2e78c1b
Implement node addon and start with build pipeline
Danielku15 Oct 12, 2023
1ec421a
Node addon compilation
Danielku15 Oct 12, 2023
78639eb
Disable libnode and check results
Danielku15 Oct 12, 2023
10a3702
Define flags like node-gyp
Danielku15 Oct 12, 2023
fb6b213
Adjust linker settings for linux and macos
Danielku15 Oct 12, 2023
252f047
Adjust build matrix and fix syntax error
Danielku15 Oct 12, 2023
338bde6
Reorder defines
Danielku15 Oct 12, 2023
c212f34
Fix GN definition
Danielku15 Oct 12, 2023
7d0f028
Check what happens if we remove the linker flags
Danielku15 Oct 12, 2023
971eb56
Sert linker flags as actually needed
Danielku15 Oct 12, 2023
3760647
Implement wrapper
Danielku15 Oct 13, 2023
848197a
Fix some bugs and setup packaging pipeline
Danielku15 Oct 13, 2023
5ae6738
Compile dotnet on linux
Danielku15 Oct 13, 2023
8342135
Don't wait for android build on node
Danielku15 Oct 13, 2023
5724113
Avoid missing libs when required
Danielku15 Oct 13, 2023
b867848
Adjust lib paths for dotnet
Danielku15 Oct 13, 2023
84c955e
Fix syntax error
Danielku15 Oct 13, 2023
515d9cd
Fixed casing
Danielku15 Oct 13, 2023
608ec24
Alternative linker setting
Danielku15 Oct 13, 2023
e43a800
Move libs into Build.GN for correct handling everywhere
Danielku15 Oct 13, 2023
3f6b02e
Adjust lib options for windows
Danielku15 Oct 13, 2023
ef7ff44
Fixed various build and output related issues
Danielku15 Oct 13, 2023
74fb12d
some fixes and improvements
Danielku15 Oct 13, 2023
22ef93f
Add missing target dependency for java
Danielku15 Oct 13, 2023
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
23 changes: 19 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
fail-fast: false
matrix:
architecture: [x64, x86, arm64]
variant: [shared, jni]
variant: [shared, jni, node]
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:
fail-fast: false
matrix:
architecture: [x64, x86, arm, arm64]
variant: [shared, jni]
variant: [shared, jni, node]
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -130,7 +130,7 @@ jobs:
fail-fast: false
matrix:
architecture: [x64, arm64]
variant: [shared, jni]
variant: [shared, jni, node]
steps:
- uses: actions/checkout@v3
with:
Expand Down Expand Up @@ -190,7 +190,7 @@ jobs:
#
# Libraries
dotnet:
runs-on: windows-latest
runs-on: ubuntu-latest
needs: [windows-alphaskia, linux-alphaskia, android-alphaskia, macos-alphaskia, ios-alphaskia]
steps:
- uses: actions/checkout@v3
Expand Down Expand Up @@ -219,3 +219,18 @@ jobs:
name: Jars
path: |
lib/java/*/build/libs/*.jar

node:
runs-on: ubuntu-latest
needs: [windows-alphaskia, linux-alphaskia, macos-alphaskia]
steps:
- uses: actions/checkout@v3
- uses: actions/download-artifact@v3
with:
path: dist
- run: ./build.cmd Node
- uses: actions/upload-artifact@v3
with:
name: NodeTars
path: |
lib/node/*/*.tgz
4 changes: 3 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -713,4 +713,6 @@ fabric.properties

!/build
!/lib
/lib/java/**/test-outputs
/lib/java/**/test-outputs
/lib/node/**/test-outputs
/lib/node/*.tgz
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,6 @@
path = externals/skia
url = https://skia.googlesource.com/skia.git
branch = chrome/m117
[submodule "externals/node-api-headers"]
path = externals/node-api-headers
url = https://github.com/nodejs/node-api-headers.git
13 changes: 13 additions & 0 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,19 @@
"DotNetPack",
"DotNetTest",
"Java",
"JavaBuild",
"JavaPack",
"LibAlphaSkia",
"LibAlphaSkiaGitSyncDeps",
"LibAlphaSkiaPatchSkiaBuildFiles",
"LibSkia",
"LibSkiaGitSyncDeps",
"LibSkiaPatchSkiaBuildFiles",
"LibSkiaWithCache",
"Node",
"NodeBuild",
"NodePack",
"NodeTest",
"PrepareGitHubArtifacts",
"SetupDepotTools"
]
Expand All @@ -134,13 +140,19 @@
"DotNetPack",
"DotNetTest",
"Java",
"JavaBuild",
"JavaPack",
"LibAlphaSkia",
"LibAlphaSkiaGitSyncDeps",
"LibAlphaSkiaPatchSkiaBuildFiles",
"LibSkia",
"LibSkiaGitSyncDeps",
"LibSkiaPatchSkiaBuildFiles",
"LibSkiaWithCache",
"Node",
"NodeBuild",
"NodePack",
"NodeTest",
"PrepareGitHubArtifacts",
"SetupDepotTools"
]
Expand All @@ -164,6 +176,7 @@
"type": "string",
"enum": [
"Jni",
"Node",
"Shared",
"Static"
]
Expand Down
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,6 @@
"csignal": "cpp",
"scoped_allocator": "cpp",
"typeindex": "cpp",
"__std_stream": "cpp"
"__std_stream": "cpp",
}
}
14 changes: 13 additions & 1 deletion build/Build.Java.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,22 @@ partial class Build
Tool GradlewTool => ToolResolver.GetTool(GradlewExe);

public Target Java => _ => _
.DependsOn(PrepareGitHubArtifacts)
.DependsOn(JavaPack);

public Target JavaPack => _ => _
.DependsOn(JavaBuild)
.Executes(() =>
{
GradlewTool("assemble",
workingDirectory: RootDirectory / "lib" / "java");
});


public Target JavaBuild => _ => _
.DependsOn(PrepareGitHubArtifacts)
.Executes(() =>
{
GradlewTool("build",
workingDirectory: RootDirectory / "lib" / "java");
});
}
100 changes: 83 additions & 17 deletions build/Build.LibAlphaSkia.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
Expand Down Expand Up @@ -69,19 +70,41 @@ partial class Build
config("alphaskia_public") {
defines = [ "_SILENCE_CXX17_CODECVT_HEADER_DEPRECATION_WARNING", "ALPHASKIA_IMPLEMENTATION=1" ]
include_dirs = [ "." ]


if (is_shared_alphaskia) {
defines += [ "ALPHASKIA_DLL" ]
}

if (is_win) {
libs = [ "skia.lib", "user32.lib", "OpenGL32.lib" ]
}

if (is_linux) {
libs = [ "skia", "fontconfig" ]
}

if (is_android) {
libs = [ "skia" ]
}

if (is_mac) {
libs = [ "skia" ]

frameworks = [
"AppKit.framework",
"ApplicationServices.framework",

"OpenGL.framework",

"Metal.framework",
"Foundation.framework",

"Foundation.framework"
]
}

if (is_ios) {
libs = [ "skia" ]

frameworks = [
"Foundation.framework",
"CoreFoundation.framework",
Expand All @@ -91,13 +114,9 @@ partial class Build
"MobileCoreServices.framework",

"Metal.framework",
"UIKit.framework",
"UIKit.framework"
]
}

if (is_shared_alphaskia) {
defines += [ "ALPHASKIA_DLL" ]
}
}

alphaskia_build("libalphaskia") {
Expand All @@ -116,12 +135,25 @@ partial class Build
"../../lib/java/jni/src/AlphaSkiaTypeface.cpp"
]
}
alphaskia_build("libalphaskianode") {
public_configs = [ ":alphaskia_public" ]
configs += [ ":alphaskia_public" ]
defines = [ "NODE_GYP_MODULE_NAME=libalphaskianode", "USING_UV_SHARED=1", "USING_V8_SHARED=1", "V8_DEPRECATION_WARNINGS=1", "BUILDING_NODE_EXTENSION" ]
sources = alphaskia_wrapper_sources
output_extension = "node"
sources += [
"../../lib/node/addon/addon.cpp"
]
if( is_win ) {
sources += [ "../../lib/node/addon/win_delay_load_hook.cpp"]
}
}
""";
PatchSkiaFile(SkiaPath / "BUILD.gn", buildNew);
PatchSkiaToolchain();
});


void PatchSkiaFile(AbsolutePath file, string newText)
{
var existingText = file.ReadAllText();
Expand Down Expand Up @@ -160,7 +192,8 @@ void BuildAlphaSkia()
{
var gnArgs = PrepareNativeBuild(Variant);
var staticLibPath = DistBasePath / GetLibDirectory(variant: Variant.Static);

var gnFlags = new Dictionary<string, string>();

string buildTarget;
if (Variant == Variant.Static)
{
Expand Down Expand Up @@ -194,7 +227,26 @@ void BuildAlphaSkia()
throw new PlatformNotSupportedException();
}

AppendToFlagList(gnArgs, "extra_cflags", $"'-I{alphaSkiaInclude}', '-I{jniInclude}', '-I{jniPlatformInclude}'");
AppendToFlagList(gnArgs, "extra_cflags",
$"'-I{alphaSkiaInclude}', '-I{jniInclude}', '-I{jniPlatformInclude}'");
}
else if (Variant == Variant.Node)
{
buildTarget = "libalphaskianode";

if (OperatingSystem.IsWindows())
{
// windows requires a lib to link against, fetch it from the node downloads
var nodeLibPath = DownloadNodeLib();
AppendToFlagList(gnArgs, "extra_ldflags",
$"'/DELAYLOAD:node.exe', '/LIBPATH:{nodeLibPath}', 'node.lib', 'DelayImp.lib'");
}
else if(OperatingSystem.IsMacOS() && TargetOs == TargetOperatingSystem.MacOs)
{
// disable need of a libnode.dylib dependencies are resolve dynamically during runtime
// and as the node binary has them built-in
AppendToFlagList(gnArgs, "extra_ldflags", "'-undefined', 'dynamic_lookup'");
}
}
else
{
Expand All @@ -205,15 +257,11 @@ void BuildAlphaSkia()
{
// TODO: check if clang-cl also works with the linux flags
AppendToFlagList(gnArgs, "extra_ldflags",
$"'/LIBPATH:{staticLibPath}', 'skia.lib', 'user32.lib', 'OpenGL32.lib'");
}
else if(TargetOs == TargetOperatingSystem.Linux)
{
AppendToFlagList(gnArgs, "extra_ldflags", $" '-L{staticLibPath}', '-lskia', '-lGL'");
$"'/LIBPATH:{staticLibPath}'");
}
else
{
AppendToFlagList(gnArgs, "extra_ldflags", $" '-L{staticLibPath}', '-lskia'");
AppendToFlagList(gnArgs, "extra_ldflags", $"'-L{staticLibPath}'");
}

var libDir = GetLibDirectory(buildTarget, TargetOs, Architecture, Variant);
Expand All @@ -222,7 +270,7 @@ void BuildAlphaSkia()
var outDir = SkiaPath / "out" / libDir;
var libExtension = GetLibExtension(Variant);

GnNinja($"out/{libDir}", buildTarget, gnArgs, SkiaPath);
GnNinja($"out/{libDir}", buildTarget, gnArgs, gnFlags, SkiaPath);

try
{
Expand All @@ -249,4 +297,22 @@ void CopyBuildOutputTo(AbsolutePath path)
throw new IOException("Copy files failed. existing files: " + string.Join(", ", fileList), e);
}
}

AbsolutePath DownloadNodeLib()
{
if (OperatingSystem.IsWindows() && TargetOs == TargetOperatingSystem.Windows)
{
// libs are available at urls like:
// https://nodejs.org/dist/latest/win-x64/node.lib
// https://nodejs.org/dist/latest/win-x86/node.lib
// https://nodejs.org/dist/latest/win-arm64/node.lib
var url = $"https://nodejs.org/dist/latest/{TargetOs.RuntimeIdentifier}-{Architecture}/node.lib";
var libDir = TemporaryDirectory / $"libnode-{TargetOs.RuntimeIdentifier}-{Architecture}";
HttpTasks.HttpDownloadFile(url,
libDir / "node.lib");
return libDir;
}

return null;
}
}
5 changes: 3 additions & 2 deletions build/Build.LibSkia.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.IO;
using Nuke.Common;
using Nuke.Common.IO;
Expand Down Expand Up @@ -106,7 +107,7 @@ partial class Build
void BuildSkia()
{
var gnArgs = PrepareNativeBuild(Variant.Static);

var gnFlags = new Dictionary<string, string>();
var libDir = GetLibDirectory("libskia", TargetOs, Architecture, Variant.Static);
var artifactsLibPath = IsGitHubActions ? ArtifactBasePath / libDir : null;
var distPath = DistBasePath / libDir;
Expand Down Expand Up @@ -145,7 +146,7 @@ void BuildSkia()
gnArgs["skia_enable_ganesh"] = "true";
gnArgs["skia_use_vulkan"] = "true";

GnNinja($"out/{libDir}", "skia", gnArgs, SkiaPath);
GnNinja($"out/{libDir}", "skia", gnArgs, gnFlags, SkiaPath);

void CopyBuildOutputTo(AbsolutePath path)
{
Expand Down
6 changes: 3 additions & 3 deletions build/Build.Linux.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,10 @@ void InstallDependenciesLinux()
linuxArch = "";
}

// skia libraries
var libuxArchSuffix = string.IsNullOrEmpty(linuxArch) ? "" : $":{linuxArch}";
// dependent libraries
var linuxArchSuffix = string.IsNullOrEmpty(linuxArch) ? "" : $":{linuxArch}";
installDependencies.AppendLine("echo Installing libs");
installDependencies.AppendLine($"aptitude install -y libfontconfig-dev{libuxArchSuffix} libgl1-mesa-dev{libuxArchSuffix} libglu1-mesa-dev{libuxArchSuffix} freeglut3-dev{libuxArchSuffix}");
installDependencies.AppendLine($"aptitude install -y libfontconfig-dev{linuxArchSuffix} libgl1-mesa-dev{linuxArchSuffix} libglu1-mesa-dev{linuxArchSuffix} freeglut3-dev{linuxArchSuffix}");

var scriptFile = TemporaryDirectory / "install_dependencies.sh";
File.WriteAllText(scriptFile, installDependencies.ToString());
Expand Down
Loading