From c71c3e4939765e82ef0096d0b09fdcb963ac9d8f Mon Sep 17 00:00:00 2001 From: Danielku15 Date: Thu, 12 Oct 2023 14:22:04 +0200 Subject: [PATCH 01/25] add node headers --- .gitmodules | 3 +++ externals/node-api-headers | 1 + 2 files changed, 4 insertions(+) create mode 160000 externals/node-api-headers diff --git a/.gitmodules b/.gitmodules index 7ee858f..b4cc47d 100644 --- a/.gitmodules +++ b/.gitmodules @@ -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 diff --git a/externals/node-api-headers b/externals/node-api-headers new file mode 160000 index 0000000..186e04b --- /dev/null +++ b/externals/node-api-headers @@ -0,0 +1 @@ +Subproject commit 186e04b5e40e54d7fd1655bc67081cc483f12488 From 2e78c1b309ca1be5216a66ec3d02ff38d9804db5 Mon Sep 17 00:00:00 2001 From: Danielku15 Date: Thu, 12 Oct 2023 17:52:26 +0200 Subject: [PATCH 02/25] Implement node addon and start with build pipeline --- .github/workflows/build.yml | 8 +- .github/workflows/test.yml | 17 + .vscode/settings.json | 2 +- build/Build.LibAlphaSkia.cs | 30 ++ build/Build.Linux.cs | 6 +- build/Variant.cs | 1 + lib/java/.idea/gradle.xml | 1 + lib/java/jni/src/AlphaSkiaImage.cpp | 2 +- lib/node/addon/addon.cpp | 763 ++++++++++++++++++++++++++++ wrapper/include/alphaskia.h | 6 +- 10 files changed, 824 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/test.yml create mode 100644 lib/node/addon/addon.cpp diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index dad380f..334e7e7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -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: @@ -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: @@ -98,7 +98,7 @@ jobs: fail-fast: false matrix: architecture: [x64, x86, arm, arm64] - variant: [shared, jni] + variant: [shared, jni, node] steps: - uses: actions/checkout@v3 with: @@ -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: diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml new file mode 100644 index 0000000..b26c405 --- /dev/null +++ b/.github/workflows/test.yml @@ -0,0 +1,17 @@ +on: + pull_request: + +jobs: + gyp: + runs-on: macos-latest + env: + V: 1 + steps: + - uses: actions/checkout@v3 + with: + repository: 'nodejs/node-addon-examples' + - uses: actions/setup-node@v3 + with: + node-version: 18.x + - run: npm install + working-directory: 2_function_arguments/napi \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index b83290b..57d5e46 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -117,6 +117,6 @@ "csignal": "cpp", "scoped_allocator": "cpp", "typeindex": "cpp", - "__std_stream": "cpp" + "__std_stream": "cpp", } } \ No newline at end of file diff --git a/build/Build.LibAlphaSkia.cs b/build/Build.LibAlphaSkia.cs index 20992ba..cc39bed 100644 --- a/build/Build.LibAlphaSkia.cs +++ b/build/Build.LibAlphaSkia.cs @@ -2,6 +2,7 @@ using System.IO; using System.Linq; using System.Text; +using System.Threading.Tasks; using Nuke.Common; using Nuke.Common.IO; @@ -115,6 +116,14 @@ partial class Build "../../lib/java/jni/src/AlphaSkiaImage.cpp", "../../lib/java/jni/src/AlphaSkiaTypeface.cpp" ] + } + alphaskia_build("libalphaskianode") { + public_configs = [ ":alphaskia_public" ] + configs += [ ":alphaskia_public" ] + sources = alphaskia_wrapper_sources + sources += [ + "../../lib/node/addon/addon.cpp" + ] } """; PatchSkiaFile(SkiaPath / "BUILD.gn", buildNew); @@ -196,6 +205,13 @@ void BuildAlphaSkia() AppendToFlagList(gnArgs, "extra_cflags", $"'-I{alphaSkiaInclude}', '-I{jniInclude}', '-I{jniPlatformInclude}'"); } + else if (Variant == Variant.Node) + { + buildTarget = "libalphaskianode"; + + var libPath = DownloadNodeLib(); + + } else { throw new ArgumentException("Unknown variant: " + Variant); @@ -249,4 +265,18 @@ void CopyBuildOutputTo(AbsolutePath path) throw new IOException("Copy files failed. existing files: " + string.Join(", ", fileList), e); } } + + string 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"; + HttpTasks.HttpDownloadFile(url, + TemporaryDirectory / $"libnode-{TargetOs.RuntimeIdentifier}-{Architecture}" / "node.lib"); + } + } } \ No newline at end of file diff --git a/build/Build.Linux.cs b/build/Build.Linux.cs index bc731be..8c63d48 100644 --- a/build/Build.Linux.cs +++ b/build/Build.Linux.cs @@ -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} libnode-dev{linuxArchSuffix}"); var scriptFile = TemporaryDirectory / "install_dependencies.sh"; File.WriteAllText(scriptFile, installDependencies.ToString()); diff --git a/build/Variant.cs b/build/Variant.cs index 7bfcf22..9e28674 100644 --- a/build/Variant.cs +++ b/build/Variant.cs @@ -7,5 +7,6 @@ public class Variant : Enumeration public static readonly Variant Static = new() { Value = "static", IsShared = false }; public static readonly Variant Shared = new() { Value = "shared", IsShared = true }; public static readonly Variant Jni = new() { Value = "jni", IsShared = true }; + public static readonly Variant Node = new() { Value = "node", IsShared = true }; public bool IsShared { get; private set; } } \ No newline at end of file diff --git a/lib/java/.idea/gradle.xml b/lib/java/.idea/gradle.xml index 5bd1ce6..397702e 100644 --- a/lib/java/.idea/gradle.xml +++ b/lib/java/.idea/gradle.xml @@ -10,6 +10,7 @@