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 new architecture support (Linux x86, Windows x86, Windows ArmV7) and improve build system #141

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
43b572b
Add support for linux x86, windows x86, and windows armv7
Kale-Ko May 26, 2024
506e28e
Temp disable testing
Kale-Ko May 27, 2024
1e426c4
Improve maven.yml by using matrices (linux is wip)
Kale-Ko May 27, 2024
da6d4e6
Move platform checking logic to individual natives
Kale-Ko May 27, 2024
71d4599
Only build an architecture when requested (linux should work now)
Kale-Ko May 27, 2024
66b05d7
Add a complete build containing all platforms and archs
Kale-Ko May 28, 2024
6992bd7
Test full build
Kale-Ko May 28, 2024
6899cf6
Update dependencies
Kale-Ko May 28, 2024
fe2e750
Add proper java service definitions
Kale-Ko May 29, 2024
eb81091
Start work on getting tests working
Kale-Ko May 29, 2024
26823e1
Linux tests
Kale-Ko May 29, 2024
f3a1088
Use Path instead of File
Kale-Ko May 30, 2024
2350458
Windows and Mac tests
Kale-Ko May 30, 2024
d5eaf0e
[skip ci] Update README.md and add back self-hosted aarch64 runner
Kale-Ko Jun 1, 2024
c2c9463
Fix dependency include
Kale-Ko Jun 1, 2024
0d10a9f
Run linux build in ubuntu 18.04 docker
Kale-Ko Jun 4, 2024
82e7b46
Run complete build in docker too
Kale-Ko Jun 5, 2024
6557348
Use a combination of Docker and QEMU tests
Kale-Ko Jun 5, 2024
2938b58
Update README
Kale-Ko Jun 5, 2024
0e886fb
Skip memory intensive tests on windows x86
Kale-Ko Jun 5, 2024
f24b428
Extract large script to file
Kale-Ko Jun 10, 2024
4dc79b1
Allow running extra tests in different ubuntu versions
Kale-Ko Jun 10, 2024
f3971fa
Build x86_64 on CentOS
Kale-Ko Jun 10, 2024
aef2572
Add back self-hosted windows aarch64 runner
Kale-Ko Jun 11, 2024
8b303e0
Fix missing dir (windows is weird sometimes)
Kale-Ko Jun 28, 2024
7d1945a
Merge branch 'main' into newarchs
hyperxpro Jun 30, 2024
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
1,235 changes: 513 additions & 722 deletions .github/workflows/maven.yml

Large diffs are not rendered by default.

152 changes: 76 additions & 76 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,76 +1,76 @@
cmake_minimum_required(VERSION 3.0.0)
project (brotli4j)
find_package(Java REQUIRED COMPONENTS Development)
find_package(JNI REQUIRED)
if (JNI_FOUND)
message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
endif()
include_directories(${JNI_INCLUDE_DIRS})
SET (BROTLI_INCLUDE_DIRS "brotli/include" "brotli/common")
include_directories(${BROTLI_INCLUDE_DIRS})
SET (LIB_TYPE SHARED)
SET (CMAKE_JNI_TARGET TRUE)
SET (CMAKE_VERBOSE_MAKEFILE ON)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
SET (CMAKE_BUILD_TYPE Release)
endif()
message(STATUS "Build type is '${CMAKE_BUILD_TYPE}'")
SET (CMAKE_C_FLAGS "-flto")
SET (CMAKE_CXX_FLAGS "-Wall -flto")
SET (CMAKE_CXX_STANDARD 11)
SET (CMAKE_CXX_STANDARD_REQUIRED ON)
if(WIN32)
SET(STATIC_LIBRARY_CXX_FLAGS /MD)
add_compile_options(/EHsc)
string(REPLACE "/O2" "/Ox" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
else(WIN32)
SET(STATIC_LIBRARY_CXX_FLAGS)
endif()
add_library (brotli ${LIB_TYPE}
"brotli/common/constants.c"
"brotli/common/context.c"
"brotli/common/dictionary.c"
"brotli/common/platform.c"
"brotli/common/shared_dictionary.c"
"brotli/common/transform.c"
"brotli/dec/bit_reader.c"
"brotli/dec/decode.c"
"brotli/dec/huffman.c"
"brotli/dec/state.c"
"brotli/enc/backward_references.c"
"brotli/enc/backward_references_hq.c"
"brotli/enc/bit_cost.c"
"brotli/enc/block_splitter.c"
"brotli/enc/brotli_bit_stream.c"
"brotli/enc/cluster.c"
"brotli/enc/command.c"
"brotli/enc/compound_dictionary.c"
"brotli/enc/compress_fragment.c"
"brotli/enc/compress_fragment_two_pass.c"
"brotli/enc/dictionary_hash.c"
"brotli/enc/encode.c"
"brotli/enc/encoder_dict.c"
"brotli/enc/entropy_encode.c"
"brotli/enc/fast_log.c"
"brotli/enc/histogram.c"
"brotli/enc/literal_cost.c"
"brotli/enc/memory.c"
"brotli/enc/metablock.c"
"brotli/enc/static_dict.c"
"brotli/enc/utf8_util.c"
"brotli/tools/brotli.c"
"natives/src/main/cpp/common_jni.cc"
"natives/src/main/cpp/decoder_jni.cc"
"natives/src/main/cpp/encoder_jni.cc"
)
SET_TARGET_PROPERTIES (brotli PROPERTIES LINKER_LANGUAGE CXX)
cmake_minimum_required(VERSION 3.5)

project (brotli4j)

find_package(Java REQUIRED COMPONENTS Development)
find_package(JNI REQUIRED)

if (JNI_FOUND)
message (STATUS "JNI_INCLUDE_DIRS=${JNI_INCLUDE_DIRS}")
message (STATUS "JNI_LIBRARIES=${JNI_LIBRARIES}")
endif()
include_directories(${JNI_INCLUDE_DIRS})

SET (BROTLI_INCLUDE_DIRS "brotli/include" "brotli/common")
include_directories(${BROTLI_INCLUDE_DIRS})

SET (LIB_TYPE SHARED)
SET (CMAKE_JNI_TARGET TRUE)
SET (CMAKE_VERBOSE_MAKEFILE ON)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
SET (CMAKE_BUILD_TYPE Release)
endif()
message(STATUS "Build type is '${CMAKE_BUILD_TYPE}'")
SET (CMAKE_C_FLAGS "")
SET (CMAKE_CXX_FLAGS "-Wall")

SET (CMAKE_CXX_STANDARD 11)
SET (CMAKE_CXX_STANDARD_REQUIRED ON)

if(WIN32)
SET(STATIC_LIBRARY_CXX_FLAGS /MD)
add_compile_options(/EHsc)
string(REPLACE "/O2" "/Ox" CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE}")
else(WIN32)
SET(STATIC_LIBRARY_CXX_FLAGS)
endif()

add_library (brotli ${LIB_TYPE}
"brotli/common/constants.c"
"brotli/common/context.c"
"brotli/common/dictionary.c"
"brotli/common/platform.c"
"brotli/common/shared_dictionary.c"
"brotli/common/transform.c"
"brotli/dec/bit_reader.c"
"brotli/dec/decode.c"
"brotli/dec/huffman.c"
"brotli/dec/state.c"
"brotli/enc/backward_references.c"
"brotli/enc/backward_references_hq.c"
"brotli/enc/bit_cost.c"
"brotli/enc/block_splitter.c"
"brotli/enc/brotli_bit_stream.c"
"brotli/enc/cluster.c"
"brotli/enc/command.c"
"brotli/enc/compound_dictionary.c"
"brotli/enc/compress_fragment.c"
"brotli/enc/compress_fragment_two_pass.c"
"brotli/enc/dictionary_hash.c"
"brotli/enc/encode.c"
"brotli/enc/encoder_dict.c"
"brotli/enc/entropy_encode.c"
"brotli/enc/fast_log.c"
"brotli/enc/histogram.c"
"brotli/enc/literal_cost.c"
"brotli/enc/memory.c"
"brotli/enc/metablock.c"
"brotli/enc/static_dict.c"
"brotli/enc/utf8_util.c"
"brotli/tools/brotli.c"
"natives/src/main/cpp/common_jni.cc"
"natives/src/main/cpp/decoder_jni.cc"
"natives/src/main/cpp/encoder_jni.cc"
)

SET_TARGET_PROPERTIES (brotli PROPERTIES LINKER_LANGUAGE CXX)
140 changes: 63 additions & 77 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,23 @@ Brotli4j provides Brotli compression and decompression for Java.

## Supported Platforms:

| 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 |
| Linux (Ubuntu 18.04) | s390x | JDK 1.8, JDK 11 |
| Linux (Ubuntu 18.04) | ppc64le | JDK 1.8, JDK 11 |
| Linux (Ubuntu 20.04) | RISC-v64 | JDK 1.8, JDK 11, JDK 17, JDK 21 |
| macOS (Catalina) | x64 | JDK 1.8, JDK 11, JDK 17, JDK 21 |
| macOS (Catalina) | Aarch64 | JDK 1.8, JDK 11, JDK 17, JDK 21 |
| Module | Architecture | Built On | Tested On | Tested JDKS |
|:--------|:---------------:|--------------------:|--------------------:|-------------------------------:|
| Windows | x86_64 (x64) | Windows Server 2022 | Windows Server 2022 | JDK 8, JDK 11, JDK 17, JDK 21 |
| Windows | x86 (i386) | Windows Server 2022 | Windows Server 2022 | JDK 8, JDK 11, JDK 17 |
| Windows | aarch64 (arm64) | Windows Server 2022 | Windows 11 | JDK 11, JDK 17, JDK 21 |
| Windows | ARMv7 (arm) | Windows Server 2022 | Untested | Untested |
| Linux | x86_64 (x64) | Ubuntu 18.04 | Ubuntu 18.04, 24.04 | JDK 8, JDK 11, JDK 17, JDK 21 |
| Linux | x86 (i386) | Ubuntu 18.04 | Ubuntu 22.04 | JDK 8, JDK 11, JDK 17, JDK 21 |
| Linux | aarch64 (arm64) | Ubuntu 18.04 | Ubuntu 18.04, 24.04 | JDK 8, JDK 11, JDK 17, JDK 21 |
| Linux | armv7 (arm) | Ubuntu 18.04 | Ubuntu 24.04 | JDK 8, JDK 11 |
| Linux | ppc64le | Ubuntu 18.04 | Ubuntu 24.04 | JDK 8, JDK 11, JDK 17, JDK 21 |
| Linux | s390x | Ubuntu 18.04 | Ubuntu 24.04 | JDK 11, JDK 17, JDK 21 |
| Linux | riscv64 | Ubuntu 18.04 | Ubuntu 24.04 | JDK 17, JDK 21 |
| macOS | x86_64 (x64) | MacOS 14 | MacOS 14 | JDK 8, JDK 11, JDK 17, JDK 21 |
| macOS | aarch64 (arm64) | MacOS 14 | MacOS 14 | JDK 8, JDK 11, JDK 17, JDK 21 |

All platforms are built using JDK 8

#### *Install [Microsoft Visual C++ Redistributable](https://learn.microsoft.com/en-US/cpp/windows/latest-supported-vc-redist?view=msvc-170) before running this library on Windows

Expand All @@ -32,7 +37,7 @@ For maven, the natives will
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>brotli4j</artifactId>
<version>1.16.0</version>
<version>1.17.0</version>
</dependency>
```

Expand All @@ -46,49 +51,40 @@ Of course, you can add native(s) as dependency manually also.
```kotlin
import org.gradle.nativeplatform.platform.internal.Architectures
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform
import org.gradle.nativeplatform.operatingsystem.OperatingSystem

val brotliVersion = "1.16.0"
val operatingSystem: OperatingSystem = DefaultNativePlatform.getCurrentOperatingSystem()
val brotliVersion = "1.17.0"
val operatingSystem = DefaultNativePlatform.getCurrentOperatingSystem()
val currentArchitecture = DefaultNativePlatform.getCurrentArchitecture().name

repositories {
mavenCentral()
}

dependencies {
implementation("com.aayushatharva.brotli4j:brotli4j:$brotliVersion")
implementation("com.aayushatharva.brotli4j:brotli4j:${brotliVersion}")
runtimeOnly(
"com.aayushatharva.brotli4j:native-" +
if (operatingSystem.isWindows) {
if (DefaultNativePlatform.getCurrentArchitecture().isArm()) {
"windows-aarch64"
} else {
"windows-x86_64"
}
} else if (operatingSystem.isMacOsX) {
if (DefaultNativePlatform.getCurrentArchitecture().isArm()) {
"osx-aarch64"
} else {
"osx-x86_64"
}
} else if (operatingSystem.isLinux) {
if (Architectures.ARM_V7.isAlias(DefaultNativePlatform.getCurrentArchitecture().name)) {
"linux-armv7"
} else if (Architectures.AARCH64.isAlias(DefaultNativePlatform.getCurrentArchitecture().name)) {
"linux-aarch64"
} else if (Architectures.X86_64.isAlias(DefaultNativePlatform.getCurrentArchitecture().name)) {
"linux-x86_64"
} else if (Architectures.S390X.isAlias(DefaultNativePlatform.getCurrentArchitecture().name)) {
"linux-s390x"
} else if (Architectures.RISCV_64.isAlias(DefaultNativePlatform.getCurrentArchitecture().name)) {
"linux-riscv64"
} else if (Architectures.PPC64LE.isAlias(DefaultNativePlatform.getCurrentArchitecture().name)) {
"linux-ppc64le"
} else {
throw IllegalStateException("Unsupported architecture: ${DefaultNativePlatform.getCurrentArchitecture().name}")
}
if (operatingSystem.isWindows()) {
if (Architectures.X86_64.isAlias(currentArchitecture)) "windows-x86_64"
else if (Architectures.X86.isAlias(currentArchitecture)) "windows-x86"
else if (Architectures.AARCH64.isAlias(currentArchitecture)) "windows-aarch64"
else if (Architectures.ARM_V7.isAlias(currentArchitecture)) "windows-armv7"
else throw new IllegalStateException ("Unsupported architecture: $currentArchitecture")
} else if (operatingSystem.isMacOsX()) {
if (Architectures.X86_64.isAlias(currentArchitecture)) "osx-x86_64"
else if (Architectures.AARCH64.isAlias(currentArchitecture)) "osx-aarch64"
else throw new IllegalStateException ("Unsupported architecture: $currentArchitecture")
} else if (operatingSystem.isLinux()) {
if (Architectures.X86_64.isAlias(currentArchitecture)) "linux-x86_64"
else if (Architectures.X86.isAlias(currentArchitecture)) "linux-x86"
else if (Architectures.AARCH64.isAlias(currentArchitecture)) "linux-aarch64"
else if (Architectures.ARM_V7.isAlias(currentArchitecture)) "linux-armv7"
else if ("ppc64le".equals(currentArchitecture, true)) "linux-ppc64le"
else if ("s390x".equals(currentArchitecture, true)) "linux-s390x"
else if ("riscv64".equals(currentArchitecture, true)) "linux-riscv64"
else throw new IllegalStateException ("Unsupported architecture: $currentArchitecture")
} else {
throw IllegalStateException("Unsupported operating system: $operatingSystem")
throw new IllegalStateException("Unsupported operating system: $operatingSystem")
} + ":$brotliVersion"
)
}
Expand All @@ -100,9 +96,9 @@ dependencies {
import org.gradle.nativeplatform.platform.internal.Architectures
import org.gradle.nativeplatform.platform.internal.DefaultNativePlatform

def brotliVersion = "1.16.0"
def brotliVersion = "1.17.0"
def operatingSystem = DefaultNativePlatform.getCurrentOperatingSystem()
def currentArchitecture = DefaultNativePlatform.getCurrentArchitecture()
def currentArchitecture = DefaultNativePlatform.getCurrentArchitecture().name

repositories {
mavenCentral()
Expand All @@ -112,24 +108,25 @@ dependencies {
implementation "com.aayushatharva.brotli4j:brotli4j:$brotliVersion"
runtimeOnly("""com.aayushatharva.brotli4j:native-${
if (operatingSystem.isWindows())
if (currentArchitecture.isX86_64()) "windows-x86_64"
else if (currentArchitecture.isArm()) "windows-aarch64"
else
throw new IllegalStateException("Unsupported architecture: ${currentArchitecture.getName()}");
if (Architectures.X86_64.isAlias(currentArchitecture)) "windows-x86_64"
else if (Architectures.X86.isAlias(currentArchitecture)) "windows-x86"
else if (Architectures.AARCH64.isAlias(currentArchitecture)) "windows-aarch64"
else if (Architectures.ARM_V7.isAlias(currentArchitecture)) "windows-armv7"
else throw new IllegalStateException("Unsupported architecture: $currentArchitecture")
else if (operatingSystem.isMacOsX())
if (currentArchitecture.isArm()) "osx-aarch64"
else "osx-x86_64"
if (Architectures.X86_64.isAlias(currentArchitecture)) "osx-x86_64"
else if (Architectures.AARCH64.isAlias(currentArchitecture)) "osx-aarch64"
else throw new IllegalStateException("Unsupported architecture: $currentArchitecture")
else if (operatingSystem.isLinux())
if (currentArchitecture.isAARCH64()) "linux-aarch64"
else if (currentArchitecture.isX86_64()) "linux-x86_64"
else if (currentArchitecture.isARM_V7()) "linux-armv7"
else if (currentArchitecture.isPPC64LE()) "linux-ppc64le"
else if (currentArchitecture.isS390X()) "linux-s390x"
else if (currentArchitecture.isRISCV64()) "linux-riscv64"
else
throw new IllegalStateException("Unsupported architecture: ${currentArchitecture.getName()}");
else
throw new IllegalStateException("Unsupported operating system: $operatingSystem");
if (Architectures.X86_64.isAlias(currentArchitecture)) "linux-x86_64"
else if (Architectures.X86.isAlias(currentArchitecture)) "linux-x86"
else if (Architectures.AARCH64.isAlias(currentArchitecture)) "linux-aarch64"
else if (Architectures.ARM_V7.isAlias(currentArchitecture)) "linux-armv7"
else if ("ppc64le".equalsIgnoreCase(currentArchitecture)) "linux-ppc64le"
else if ("s390x".equalsIgnoreCase(currentArchitecture)) "linux-s390x"
else if ("riscv64".equalsIgnoreCase(currentArchitecture)) "linux-riscv64"
else throw new IllegalStateException("Unsupported architecture: $currentArchitecture")
else throw new IllegalStateException("Unsupported operating system: $operatingSystem")
}:$brotliVersion""")
}
```
Expand All @@ -140,7 +137,7 @@ dependencies {

Call `Brotli4jLoader.ensureAvailability()` in your application once before using Brotli4j. This will load
Brotli4j native library automatically using automatic dependency resolution.
However, its possible to load native library manually from custom path by specifying System Property `"brotli4j.library.path"`.
However, it's possible to load native library manually from custom path by specifying System Property `"brotli4j.library.path"`.

### Direct API

Expand Down Expand Up @@ -219,17 +216,6 @@ 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.
__________________________________________________________________

## Projects that use Brotli4j

- [Netty](https://github.com/netty/netty)
Expand All @@ -252,4 +238,4 @@ performance bottlenecks, pin down memory leaks and understand threading issues.

<a href="https://www.ej-technologies.com/products/jprofiler/overview.html" target="_blank" title="File Management">
<img src="https://www.ej-technologies.com/images/product_banners/jprofiler_large.png" alt="File Management">
</a>
</a>
Loading
Loading