Skip to content

Commit

Permalink
Merge branch 'main' into pre-v1.13.0
Browse files Browse the repository at this point in the history
  • Loading branch information
hyperxpro authored Nov 1, 2023
2 parents 085ab55 + e37f6a9 commit 3ea7c66
Show file tree
Hide file tree
Showing 18 changed files with 850 additions and 45 deletions.
313 changes: 294 additions & 19 deletions .github/workflows/maven.yml

Large diffs are not rendered by default.

70 changes: 46 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,17 @@ 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 |
| Linux (CentOS 6) | x64 | JDK 1.8, JDK 11, JDK 17 |
| Linux (Ubuntu 18.04) | Aarch64 | JDK 1.8, JDK 11, JDK 17 |
| Linux (Ubuntu 18.04) | ARMv7 | JDK 1.8, JDK 11 |
| Linux (Ubuntu 18.04) | s390x | JDK 1.8, JDK 11 |
| macOS (Catalina) | x64 | JDK 1.8, JDK 11, JDK 17 |
| macOS (Catalina) | Aarch64 | JDK 1.8, JDK 11, JDK 17 |
| Module | Architecture | Tested On |
|:------------------------------|:------------:|--------------------------------:|
| Windows (Windows Server 2022) | x64 | JDK 1.8, JDK 11, JDK 17 |
| Linux (CentOS 6) | x64 | JDK 1.8, JDK 11, JDK 17 |
| Linux (Ubuntu 18.04) | Aarch64 | JDK 1.8, JDK 11, JDK 17 |
| Linux (Ubuntu 18.04) | ARMv7 | JDK 1.8, JDK 11 |
| 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 |
| macOS (Catalina) | Aarch64 | JDK 1.8, JDK 11, JDK 17 |

#### *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 Down Expand Up @@ -43,6 +45,7 @@ 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.13.0"
val operatingSystem: OperatingSystem = DefaultNativePlatform.getCurrentOperatingSystem()
Expand All @@ -54,20 +57,32 @@ repositories {
dependencies {
implementation("com.aayushatharva.brotli4j:brotli4j:$brotliVersion")
runtimeOnly(
"com.aayushatharva.brotli4j:native-${
if (operatingSystem.isWindows) "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
throw IllegalStateException("Unsupported architecture: ${DefaultNativePlatform.getCurrentArchitecture().name}")
else
throw IllegalStateException("Unsupported operating system: $operatingSystem")
}:$brotliVersion"
"com.aayushatharva.brotli4j:native-" +
if (operatingSystem.isWindows) {
"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 {
throw IllegalStateException("Unsupported architecture: ${DefaultNativePlatform.getCurrentArchitecture().name}")
}
} else {
throw IllegalStateException("Unsupported operating system: $operatingSystem")
} + ":$brotliVersion"
)
}
```
Expand Down Expand Up @@ -96,9 +111,11 @@ dependencies {
if (Architectures.ARM_V7.isAlias(DefaultNativePlatform.getCurrentArchitecture().getName())) "linux-armv7"
else if (Architectures.AARCH64.isAlias(DefaultNativePlatform.getCurrentArchitecture().getName())) "linux-aarch64"
else if (Architectures.X86_64.isAlias(DefaultNativePlatform.getCurrentArchitecture().getName())) "linux-x86_64"
else if (Architectures.S390X.isAlias(DefaultNativePlatform.getCurrentArchitecture().getName())) "linux-s390x"
else if (Architectures.RISCV_64.isAlias(DefaultNativePlatform.getCurrentArchitecture().getName())) "linux-riscv64"
else
throw new IllegalStateException("Unsupported architecture: ${DefaultNativePlatform.getCurrentArchitecture().getName()}");
else
else
throw new IllegalStateException("Unsupported operating system: $operatingSystem");
}:$brotliVersion""")
}
Expand Down Expand Up @@ -189,6 +206,11 @@ public class Example {
}
```

### Additional Notes

* 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.
__________________________________________________________________

## Sponsors
Expand Down
10 changes: 10 additions & 0 deletions all/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@
<artifactId>native-linux-s390x</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>native-linux-ppc64le</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>native-linux-riscv64</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>com.aayushatharva.brotli4j</groupId>
<artifactId>native-osx-aarch64</artifactId>
Expand Down
34 changes: 34 additions & 0 deletions brotli4j/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,23 @@
</dependencies>
</profile>

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

<profile>
<id>linux-aarch64</id>
<activation>
Expand Down Expand Up @@ -110,6 +127,23 @@
</dependencies>
</profile>

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

<profile>
<id>windows-x86_64</id>
<activation>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ private static String getPlatform() {
return "linux-armv7";
} else if ("s390x".equalsIgnoreCase(archName)) {
return "linux-s390x";
} else if ("ppc64le".equalsIgnoreCase(archName)) {
return "linux-ppc64le";
} else if ("riscv64".equalsIgnoreCase(archName)) {
return "linux-riscv64";
}
} else if (osName.startsWith("Windows")) {
if ("amd64".equalsIgnoreCase(archName)) {
Expand Down
45 changes: 45 additions & 0 deletions docker/Dockerfile21.centos6
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
FROM gatlingcorp/centos:6-gcc5

RUN rm -vf /usr/lib64/libstdc++.so.6.0.21-gdb.py

RUN yum -y install \
git

RUN export [email protected] && \
export JAVA_VERSION=$java_version && \
curl -sL https://github.com/shyiko/jabba/raw/master/install.sh | JABBA_COMMAND="install 21.0.1-custom=tgz+https://corretto.aws/downloads/resources/21.0.1.12.1/amazon-corretto-21.0.1.12.1-linux-x64.tar.gz -o /jdk" bash && \
echo 'export JAVA_HOME="/jdk"' >> ~/.bashrc && \
echo 'PATH=/jdk/bin:$PATH' >> ~/.bashrc

ENV JAVA_HOME "/jdk"
ENV PATH "/jdk/bin:$PATH"

RUN mkdir -p /workspace

RUN mkdir -p /opt && \
cd /opt && \
wget --no-verbose https://maven-central.storage-download.googleapis.com/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.tar.gz && \
tar xzf apache-maven-3.8.6-bin.tar.gz && \
ln -s apache-maven-3.8.6 maven && \
ln -s /opt/maven/bin/mvn /usr/bin/mvn

RUN cd /opt && \
wget --no-verbose https://github.com/Kitware/CMake/releases/download/v3.20.1/cmake-3.20.1-linux-x86_64.sh && \
chmod a+x cmake-3.20.1-linux-x86_64.sh && \
yes | ./cmake-3.20.1-linux-x86_64.sh

ENV MAVEN_HOME "/opt/maven"
ENV PATH "/opt/maven/bin:$PATH"
ENV PATH "/opt/cmake-3.20.1-linux-x86_64/bin:$PATH"

RUN mkdir /workspace/Brotli4j
RUN cd /workspace/Brotli4j

RUN echo "/jdk/lib/amd64" >> /etc/ld.so.conf
RUN echo "/jdk/jre/lib/amd64/" >> /etc/ld.so.conf

RUN ldconfig

RUN echo "export MAVEN_HOME=/opt/maven" >> ~/.bashrc
RUN echo "export PATH=/opt/maven/bin:\$PATH " >> ~/.bashrc
RUN echo "export PATH=/opt/cmake-3.20.1-linux-x86_64/bin:\$PATH " >> ~/.bashrc
2 changes: 1 addition & 1 deletion docker/docker-compose11.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:

build:
<<: *common
command: /bin/bash -cl "mvn -B -ntp clean package --file pom.xml"
command: /bin/bash -cl "mvn -B --show-version -ntp --file pom.xml clean package"

shell:
<<: *common
Expand Down
2 changes: 1 addition & 1 deletion docker/docker-compose17.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ services:

build:
<<: *common
command: /bin/bash -cl "mvn -B -ntp clean package --file pom.xml"
command: /bin/bash -cl "mvn -B --show-version -ntp --file pom.xml clean package"

shell:
<<: *common
Expand Down
25 changes: 25 additions & 0 deletions docker/docker-compose21.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
version: "3"

services:

runtime-setup:
image: brotli4j:default
build:
context: .
dockerfile: Dockerfile21.centos6

common: &common
image: brotli4j:default
depends_on: [ runtime-setup ]
volumes:
- ~/.m2:/root/.m2
- ..:/code
working_dir: /code

build:
<<: *common
command: /bin/bash -cl "mvn -B --show-version -ntp --file pom.xml clean package"

shell:
<<: *common
entrypoint: /bin/bash
21 changes: 21 additions & 0 deletions natives/linux-ppc64le/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/sh

CURPATH=$(pwd)
TARGET_CLASSES_PATH="target/classes/lib/linux-ppc64le"
TARGET_PATH="target"

exitWithError() {
cd ${CURPATH}
echo "*** An error occurred. Please check log messages. ***"
exit $1
}

mkdir -p "$TARGET_CLASSES_PATH"

cd "$TARGET_PATH"
cmake ../../../ || exitWithError $?
make || exitWithError $?
rm -f "$CURPATH/${TARGET_CLASSES_PATH}/libbrotli.so"
cp "./libbrotli.so" "$CURPATH/${TARGET_CLASSES_PATH}" || exitWithError $?

cd "${CURPATH}"
Loading

0 comments on commit 3ea7c66

Please sign in to comment.