Skip to content

Commit

Permalink
Windows ARM Support (#120)
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperxpro authored Dec 3, 2023
1 parent 397cf0e commit 9d99fb6
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 0 deletions.
16 changes: 16 additions & 0 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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\
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down Expand Up @@ -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.
Expand Down
5 changes: 5 additions & 0 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@
<artifactId>native-windows-x86_64</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>native-windows-aarch64</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</dependencyManagement>

Expand Down
17 changes: 17 additions & 0 deletions brotli4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,23 @@
</dependencies>
</profile>

<profile>
<id>windows-aarch64</id>
<activation>
<os>
<family>Windows</family>
<arch>aarch64</arch>
</os>
</activation>
<dependencies>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>native-windows-aarch64</artifactId>
<version>${project.parent.version}</version>
</dependency>
</dependencies>
</profile>

<profile>
<id>osx-x86_64</id>
<activation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down
15 changes: 15 additions & 0 deletions natives/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<module>linux-ppc64le</module>
<module>linux-riscv64</module>
<module>windows-x86_64</module>
<module>windows-aarch64</module>
<module>osx-x86_64</module>
<module>osx-aarch64</module>
</modules>
Expand Down Expand Up @@ -140,6 +141,19 @@
</modules>
</profile>

<profile>
<id>windows-aarch64</id>
<activation>
<os>
<family>Windows</family>
<arch>aarch64</arch>
</os>
</activation>
<modules>
<module>windows-aarch64</module>
</modules>
</profile>

<profile>
<id>osx-x86_64</id>
<activation>
Expand Down Expand Up @@ -176,6 +190,7 @@
<module>linux-ppc64le</module>
<module>linux-riscv64</module>
<module>windows-x86_64</module>
<module>windows-aarch64</module>
<module>osx-x86_64</module>
<module>osx-aarch64</module>
</modules>
Expand Down
41 changes: 41 additions & 0 deletions natives/windows-aarch64/build.bat
Original file line number Diff line number Diff line change
@@ -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
116 changes: 116 additions & 0 deletions natives/windows-aarch64/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>natives</artifactId>
<groupId>com.aayushatharva.brotli4j</groupId>
<version>1.13.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>native-windows-aarch64</artifactId>
<packaging>jar</packaging>

<properties>
<javaModuleName>com.aayushatharva.brotli4j.windows.aarch64</javaModuleName>
</properties>

<build>
<plugins>
<plugin>
<groupId>org.moditect</groupId>
<artifactId>moditect-maven-plugin</artifactId>
<version>1.0.0.RC2</version>
<executions>
<execution>
<id>add-module-infos</id>
<phase>package</phase>
<goals>
<goal>add-module-info</goal>
</goals>
<configuration>
<jvmVersion>9</jvmVersion>
<module>
<moduleInfoSource>
module ${javaModuleName} {
requires com.aayushatharva.brotli4j.service;
exports ${javaModuleName} to com.aayushatharva.brotli4j;
provides com.aayushatharva.brotli4j.service.BrotliNativeProvider with
${javaModuleName}.NativeLoader;
}
</moduleInfoSource>
</module>
<jdepsExtraArgs>
<arg>--multi-release</arg>
<arg>9</arg>
</jdepsExtraArgs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>windows-aarch64</id>
<activation>
<os>
<family>Windows</family>
<arch>aarch64</arch>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>Execute-Native-Compile</id>
<phase>process-classes</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${project.basedir}/build.bat</executable>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>

<profile>
<id>release</id>
<build>
<resources>
<resource>
<directory>resources</directory>
</resource>
</resources>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -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";
}
}
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@
<java.version>1.8</java.version>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<overwriteExistingFiles>true</overwriteExistingFiles>
</properties>

<profiles>
Expand Down

0 comments on commit 9d99fb6

Please sign in to comment.