mirror of
https://github.com/xerial/snappy-java.git
synced 2025-07-27 07:54:17 +02:00
fix: add snappy support
This commit is contained in:
parent
ec23d7c611
commit
fab9375a35
48
docker/Dockerfile.alpine
Normal file
48
docker/Dockerfile.alpine
Normal file
@ -0,0 +1,48 @@
|
||||
FROM alpine:3.18
|
||||
|
||||
# Install build dependencies
|
||||
RUN apk add --no-cache \
|
||||
openjdk11 \
|
||||
cmake \
|
||||
make \
|
||||
gcc \
|
||||
g++ \
|
||||
musl-dev \
|
||||
linux-headers
|
||||
|
||||
# Set workspace directory
|
||||
WORKDIR /workspace
|
||||
|
||||
# Copy the source code
|
||||
COPY . .
|
||||
|
||||
# Build the project
|
||||
ENV CC=gcc CXX=g++ TARGET_OS=Linux-musl
|
||||
|
||||
# Install Maven
|
||||
RUN apk add --no-cache maven
|
||||
|
||||
# Build with Maven
|
||||
RUN mvn package -Dlibrary.name=libsnappyjava.so -DskipTests -DskipJavadoc=true
|
||||
|
||||
# Install snappy dependencies
|
||||
RUN apk add --no-cache snappy-dev
|
||||
|
||||
# Compile and link statically
|
||||
RUN cd target/native/Linux-musl/x86_64 && \
|
||||
${CXX} -std=c++11 -O2 -fPIC -DPIC -D_GNU_SOURCE \
|
||||
-I../../../../src/main/java/org/xerial/snappy/ \
|
||||
-I/usr/include \
|
||||
-shared -static-libstdc++ -static-libgcc \
|
||||
../../../../src/main/java/org/xerial/snappy/SnappyNative.cpp \
|
||||
-L/usr/lib -lsnappy \
|
||||
-o libsnappyjava.so
|
||||
|
||||
# Create necessary directories
|
||||
RUN mkdir -p src/main/resources/org/xerial/snappy/native/Linux-musl/x86_64/
|
||||
|
||||
# Copy the built library
|
||||
RUN cp target/native/Linux-musl/x86_64/libsnappyjava.so src/main/resources/org/xerial/snappy/native/Linux-musl/x86_64/
|
||||
|
||||
# Set the entry point
|
||||
ENTRYPOINT ["java"]
|
22
docker/README-musl.md
Normal file
22
docker/README-musl.md
Normal file
@ -0,0 +1,22 @@
|
||||
# Building with musl libc
|
||||
|
||||
This project now supports building with musl libc, which is commonly used in Alpine Linux. To build using musl:
|
||||
|
||||
1. Use the provided Alpine-based Dockerfile:
|
||||
```bash
|
||||
docker build -f docker/Dockerfile.alpine -t snappy-java-alpine .
|
||||
```
|
||||
|
||||
2. The build process will:
|
||||
- Use musl libc instead of glibc
|
||||
- Statically link required libraries
|
||||
- Create a native library compatible with Alpine/musl systems
|
||||
|
||||
The resulting library will be placed in:
|
||||
`src/main/resources/org/xerial/snappy/native/Linux-musl/x86_64/libsnappyjava.so`
|
||||
|
||||
## Testing
|
||||
To test the musl build:
|
||||
```bash
|
||||
docker run --rm snappy-java-alpine -cp target/snappy-java-*.jar org.xerial.snappy.SnappyLoader
|
||||
```
|
20
docker/Toolchain-musl.cmake
Normal file
20
docker/Toolchain-musl.cmake
Normal file
@ -0,0 +1,20 @@
|
||||
set(CMAKE_SYSTEM_NAME Linux)
|
||||
set(CMAKE_SYSTEM_VERSION 1)
|
||||
|
||||
# Specify the cross compilers
|
||||
set(CMAKE_C_COMPILER gcc)
|
||||
set(CMAKE_CXX_COMPILER g++)
|
||||
|
||||
# Set target environment path
|
||||
set(CMAKE_FIND_ROOT_PATH /usr)
|
||||
|
||||
# Search for programs in the host environment
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
|
||||
|
||||
# Search for libraries and headers in the target environment
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
|
||||
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
|
||||
|
||||
# Set compiler flags for musl
|
||||
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static")
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static")
|
@ -327,7 +327,20 @@ public class SnappyLoader
|
||||
}
|
||||
|
||||
// Load an OS-dependent native library inside a jar file
|
||||
snappyNativeLibraryPath = "/org/xerial/snappy/native/" + OSInfo.getNativeLibFolderPathForCurrentOS();
|
||||
String osName = OSInfo.getOSName();
|
||||
// Check for musl by looking at the output of ldd --version
|
||||
try {
|
||||
Process p = Runtime.getRuntime().exec(new String[]{"ldd", "--version"});
|
||||
try (BufferedReader br = new BufferedReader(new InputStreamReader(p.getErrorStream()))) {
|
||||
String line = br.readLine();
|
||||
if (line != null && line.toLowerCase().contains("musl")) {
|
||||
osName = "Linux-musl";
|
||||
}
|
||||
}
|
||||
} catch (Exception e) {
|
||||
// Ignore errors - default to normal Linux detection
|
||||
}
|
||||
snappyNativeLibraryPath = "/org/xerial/snappy/native/" + osName + "/" + OSInfo.getArchName();
|
||||
boolean hasNativeLib = hasResource(snappyNativeLibraryPath + "/" + snappyNativeLibraryName);
|
||||
if (!hasNativeLib) {
|
||||
if (OSInfo.getOSName().equals("Mac")) {
|
||||
|
@ -0,0 +1 @@
|
||||
This directory contains native libraries for Linux-musl x86_64 platform
|
Loading…
x
Reference in New Issue
Block a user