From 9d99fb6bd36479a2bb6334b98ba60c9867537155 Mon Sep 17 00:00:00 2001 From: Aayush Atharva Date: Sun, 3 Dec 2023 16:10:13 +0530 Subject: [PATCH] Windows ARM Support (#120) --- .github/workflows/maven.yml | 16 +++ README.md | 5 + all/pom.xml | 5 + brotli4j/pom.xml | 17 +++ .../brotli4j/Brotli4jLoader.java | 2 + natives/pom.xml | 15 +++ natives/windows-aarch64/build.bat | 41 +++++++ natives/windows-aarch64/pom.xml | 116 ++++++++++++++++++ .../windows/aarch64/NativeLoader.java | 30 +++++ pom.xml | 1 + 10 files changed, 248 insertions(+) create mode 100644 natives/windows-aarch64/build.bat create mode 100644 natives/windows-aarch64/pom.xml create mode 100644 natives/windows-aarch64/src/main/java/com/aayushatharva/brotli4j/windows/aarch64/NativeLoader.java diff --git a/.github/workflows/maven.yml b/.github/workflows/maven.yml index 669c267c..b3e18eeb 100644 --- a/.github/workflows/maven.yml +++ b/.github/workflows/maven.yml @@ -753,3 +753,19 @@ jobs: uses: ilammy/msvc-dev-cmd@v1.12.0 - name: Build with Maven run: mvn -B --show-version -ntp --file pom.xml clean package + + Windows-ARM-Build-JDK11: + runs-on: self-hosted + steps: + - uses: actions/checkout@v3 + - name: Enable Developer Command Prompt + uses: ilammy/msvc-dev-cmd@v1.12.0 + with: + arch: arm64 + - name: Build with Maven + run: .\mvnw -B --show-version -ntp --file pom.xml clean package + - name: Upload the build + uses: actions/upload-artifact@v3 + with: + name: Windows-ARM-Build-JDK8 + path: C:\Users\HyperXPro\Desktop\actions-runner\_work\Brotli4j\ diff --git a/README.md b/README.md index 4548f61f..c3127d74 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,7 @@ Brotli4j provides Brotli compression and decompression for Java. | Module | Architecture | Tested On | |:------------------------------|:------------:|--------------------------------:| | Windows (Windows Server 2022) | x64 | JDK 1.8, JDK 11, JDK 17, JDK 21 | +| Windows 11 | Aarch64 | JDK 11 | | Linux (CentOS 6) | x64 | JDK 1.8, JDK 11, JDK 17, JDK 21 | | Linux (Ubuntu 18.04) | Aarch64 | JDK 1.8, JDK 11, JDK 17, JDK 21 | | Linux (Ubuntu 18.04) | ARMv7 | JDK 1.8, JDK 11, JDK 17 | @@ -208,6 +209,10 @@ public class Example { ### Additional Notes +* Windows-AArch64: Brotli4j is compiled with JDK 11 with JDK 8 as target because JDK 8 Windows Aarch64 builds are not available at the moment. +However, it should not cause any problem on running it on JDK 8 or plus. +__________________________________________________________________ + * RISC-V64: This platform is only supported by JDK 11+ (i.e. JDK 11, JDK 17, JDK 21, atm.). However, Since Brotli4j was always compiled with JDK 8, we're cross-compiling RISC-V64 native module bytecode with JDK 8. This should not break existing application using Broti4j. However, you should use JDK 11+ for using Brotli4j on RISC-V64 platform. diff --git a/all/pom.xml b/all/pom.xml index 272b8fb3..6f29ed41 100644 --- a/all/pom.xml +++ b/all/pom.xml @@ -89,6 +89,11 @@ native-windows-x86_64 ${project.version} + + com.aayushatharva.brotli4j + native-windows-aarch64 + ${project.version} + diff --git a/brotli4j/pom.xml b/brotli4j/pom.xml index 07cc4787..3e16aa15 100644 --- a/brotli4j/pom.xml +++ b/brotli4j/pom.xml @@ -161,6 +161,23 @@ + + windows-aarch64 + + + Windows + aarch64 + + + + + com.aayushatharva.brotli4j + native-windows-aarch64 + ${project.parent.version} + + + + osx-x86_64 diff --git a/brotli4j/src/main/java/com/aayushatharva/brotli4j/Brotli4jLoader.java b/brotli4j/src/main/java/com/aayushatharva/brotli4j/Brotli4jLoader.java index 33ae1a26..7b036989 100644 --- a/brotli4j/src/main/java/com/aayushatharva/brotli4j/Brotli4jLoader.java +++ b/brotli4j/src/main/java/com/aayushatharva/brotli4j/Brotli4jLoader.java @@ -136,6 +136,8 @@ private static String getPlatform() { } else if (osName.startsWith("Windows")) { if ("amd64".equalsIgnoreCase(archName)) { return "windows-x86_64"; + } else if ("aarch64".equalsIgnoreCase(archName)) { + return "windows-aarch64"; } } else if (osName.startsWith("Mac")) { if ("x86_64".equalsIgnoreCase(archName)) { diff --git a/natives/pom.xml b/natives/pom.xml index 2b3dabf5..8fb8d355 100644 --- a/natives/pom.xml +++ b/natives/pom.xml @@ -35,6 +35,7 @@ linux-ppc64le linux-riscv64 windows-x86_64 + windows-aarch64 osx-x86_64 osx-aarch64 @@ -140,6 +141,19 @@ + + windows-aarch64 + + + Windows + aarch64 + + + + windows-aarch64 + + + osx-x86_64 @@ -176,6 +190,7 @@ linux-ppc64le linux-riscv64 windows-x86_64 + windows-aarch64 osx-x86_64 osx-aarch64 diff --git a/natives/windows-aarch64/build.bat b/natives/windows-aarch64/build.bat new file mode 100644 index 00000000..904b8721 --- /dev/null +++ b/natives/windows-aarch64/build.bat @@ -0,0 +1,41 @@ +@ECHO OFF + +REM +REM Minimal script to compile the native resources +REM +REM Requirements +REM -------------- +REM o Java 1.8 JDK installed, needs JAVA_HOME set +REM o cmake 3.0 + installed and available via PATH +REM o nmake installed (comes e.g. with Visual Studio), call "vcvarsall.bat x64" before to activate 64bit tools +REM + +:ENSURE_WORKING_DIRECTORY +cd "%~dp0" + +:PREPARE_FOLDERS +if not exist "%~dp0target" mkdir "%~dp0target" +if not exist "%~dp0target\classes" mkdir "%~dp0target\classes" +if not exist "%~dp0target\classes\lib" mkdir "%~dp0target\classes\lib" +SET TARGET_CLASSES_PATH=%~dp0target\classes\lib\windows-aarch64 +if not exist "%TARGET_CLASSES_PATH%" mkdir "%TARGET_CLASSES_PATH%" + +:PREPARE_MAKEFILES +cd "%~dp0target" +cmake -DCMAKE_BUILD_TYPE=RELEASE -G "NMake Makefiles" ..\..\..\ || goto ERROR + +:MAKE_ALL +cd "%~dp0target" +nmake || goto ERROR + +:COPY_DLL_FOR_MAVEN_PACKAGING +copy /Y "%~dp0target\brotli.dll" "%TARGET_CLASSES_PATH%" || goto ERROR + +:ENSURE_WORKING_DIRECTORY +cd %~dp0 +goto :EOF + +:ERROR +cd %~dp0 +echo "*** An error occurred. Please check log messages. ***" +exit /b -1 diff --git a/natives/windows-aarch64/pom.xml b/natives/windows-aarch64/pom.xml new file mode 100644 index 00000000..7a69bdab --- /dev/null +++ b/natives/windows-aarch64/pom.xml @@ -0,0 +1,116 @@ + + + + + natives + com.aayushatharva.brotli4j + 1.13.0 + + 4.0.0 + + native-windows-aarch64 + jar + + + com.aayushatharva.brotli4j.windows.aarch64 + + + + + + org.moditect + moditect-maven-plugin + 1.0.0.RC2 + + + add-module-infos + package + + add-module-info + + + 9 + + + module ${javaModuleName} { + requires com.aayushatharva.brotli4j.service; + exports ${javaModuleName} to com.aayushatharva.brotli4j; + provides com.aayushatharva.brotli4j.service.BrotliNativeProvider with + ${javaModuleName}.NativeLoader; + } + + + + --multi-release + 9 + + + + + + + + + + + windows-aarch64 + + + Windows + aarch64 + + + + + + org.codehaus.mojo + exec-maven-plugin + 3.0.0 + + + Execute-Native-Compile + process-classes + + exec + + + ${project.basedir}/build.bat + + + + + + + + + + release + + + + resources + + + + + + + diff --git a/natives/windows-aarch64/src/main/java/com/aayushatharva/brotli4j/windows/aarch64/NativeLoader.java b/natives/windows-aarch64/src/main/java/com/aayushatharva/brotli4j/windows/aarch64/NativeLoader.java new file mode 100644 index 00000000..714bfc60 --- /dev/null +++ b/natives/windows-aarch64/src/main/java/com/aayushatharva/brotli4j/windows/aarch64/NativeLoader.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2020-2023, Aayush Atharva + * + * Brotli4j licenses this file to you under the + * Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.aayushatharva.brotli4j.windows.aarch64; + +import com.aayushatharva.brotli4j.service.BrotliNativeProvider; + +/** + * Service class to access the native lib in a JPMS context + */ +public class NativeLoader implements BrotliNativeProvider { + + @Override + public String platformName() { + return "windows-aarch64"; + } +} diff --git a/pom.xml b/pom.xml index 92014c1c..85ddbdcd 100644 --- a/pom.xml +++ b/pom.xml @@ -65,6 +65,7 @@ 1.8 1.8 1.8 + true