feat: add support to x64 systems using musl (#632)

* fix: add snappy support

* fix: update alpine image

* fix: update files

* fix: dockerfile building

* feat: adding alpine architecture

* feat: adding alpine architecture

* feat: reset files

* fix: remove code not used

* docs: update build.md

* fix: dockerfile name

* feat: rename osname and image arch

* feat: rename osname and image arch

* feat: add try catch block

* feat: better error message

* feat: address review comments

* Update src/main/java/org/xerial/snappy/OSInfo.java

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>

* fix: use standard OSGi processor value for musl variant

Changed processor=x86-64-musl to processor=x86-64 in Bundle-NativeCode
as x86-64-musl is not a valid OSGi processor value. The OSGi spec only
recognizes x86-64 (and aliases: amd64, em64t, x86_64) for 64-bit x86.

Also fixed osname=Linux to osname=linux for consistency with other entries.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

* fix: correct indentation in OSInfo.java catch block

Fixed improper indentation of catch statement at line 237

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>

---------

Co-authored-by: Taro L. Saito <leo@xerial.org>
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Samuel Fernandes 2025-07-19 20:52:26 +01:00 committed by GitHub
parent a317643ef9
commit ded9f16e05
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 74 additions and 3 deletions

View File

@ -116,4 +116,9 @@ If you are using Mac and openjdk7 (or higher), use the following option:
$ make native LIBNAME=libsnappyjava.dylib
## Building with Alpine
This project supports Alpine-based container images, which use the musl libc implementation. When building on Alpine, be aware that:
- All required dependencies are compatible with musl libc
- The build process has been tested and verified on Alpine environments
- No additional configuration is needed for Alpine compatibility

View File

@ -151,7 +151,7 @@ native: jni-header snappy-header $(NATIVE_DLL)
native-nocmake: jni-header $(NATIVE_DLL)
snappy: native $(TARGET)/$(snappy-jar-version).jar
native-all: native native-arm clean-docker mac64 win32 win64 linux32 linux64 linux-ppc64le linux-riscv64 linux-s390x
native-all: native native-arm clean-docker mac64 win32 win64 linux32 linux64 linux-ppc64le linux-riscv64 linux-s390x musl-image musl
ifdef CI
# Clean docker images within CI to avoid no space left error
@ -199,6 +199,12 @@ linux32: jni-header
linux64: jni-header
docker run $(DOCKER_RUN_OPTS) -i -v $$PWD:/work xerial/centos5-linux-x86_64-pic bash -c 'make clean-native native-nocmake OS_NAME=Linux OS_ARCH=x86_64'
musl-image:
docker build -f docker/Dockerfile.linux-x86_64-musl -t snappy-java-musl .
musl: jni-header
docker run $(DOCKER_RUN_OPTS) -i -v $$PWD:/work snappy-java-musl bash -c 'make clean-native native-nocmake OS_NAME=Linux OS_ARCH=x86_64-musl'
freebsd64:
$(MAKE) native OS_NAME=FreeBSD OS_ARCH=x86_64

View File

@ -6,7 +6,6 @@ ifndef JAVA_HOME
$(warning Set JAVA_HOME environment variable)
endif
JAVA := "$$JAVA_HOME/bin/java"
JAVAC := "$$JAVA_HOME/bin/javac"
JAVAH := "$$JAVA_HOME/bin/javah"
@ -51,7 +50,7 @@ endif
# os=Default is meant to be generic unix/linux
# To support new CPU architecture, add a new target name here
known_os_archs := Linux-x86 Linux-x86_64 Linux-arm Linux-armv6 Linux-armv7 Linux-android-arm Linux-android-aarch64 Linux-aarch64 Linux-ppc Linux-ppc64 Linux-ppc64le Linux-s390 Linux-s390x Mac-x86 Mac-x86_64 Mac-aarch64 FreeBSD-x86_64 Windows-x86 Windows-x86_64 Windows-aarch64 SunOS-x86 SunOS-sparc SunOS-x86_64 AIX-ppc AIX-ppc64 Linux-riscv Linux-riscv64 Linux-loongarch Linux-loongarch64
known_os_archs := Linux-x86_64-musl Linux-x86 Linux-x86_64 Linux-arm Linux-armv6 Linux-armv7 Linux-android-arm Linux-android-aarch64 Linux-aarch64 Linux-ppc Linux-ppc64 Linux-ppc64le Linux-s390 Linux-s390x Mac-x86 Mac-x86_64 Mac-aarch64 FreeBSD-x86_64 Windows-x86 Windows-x86_64 Windows-aarch64 SunOS-x86 SunOS-sparc SunOS-x86_64 AIX-ppc AIX-ppc64 Linux-riscv Linux-riscv64 Linux-loongarch Linux-loongarch64
os_arch := $(OS_NAME)-$(OS_ARCH)
IBM_JDK_7 := $(findstring IBM, $(shell $(JAVA) -version 2>&1 | grep IBM | grep "JRE 1.7"))
@ -103,6 +102,17 @@ Linux-x86_64_LINKFLAGS := -shared -static-libgcc -static-libstdc++
Linux-x86_64_LIBNAME := libsnappyjava.so
Linux-x86_64_SNAPPY_FLAGS :=
Linux-x86_64-musl_CXX := $(CROSS_PREFIX)g++
Linux-x86_64-musl_STRIP := $(CROSS_PREFIX)strip
ifeq ($(IBM_JDK_7),)
Linux-x86_64-musl_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -m64 -std=c++11
else
Linux-x86_64-musl_CXXFLAGS := -include $(IBM_JDK_LIB)/jni_md.h -include $(IBM_JDK_LIB)/jniport.h -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -m64 -std=c++11
endif
Linux-x86_64-musl_LINKFLAGS := -shared -static-libgcc -static-libstdc++
Linux-x86_64-musl_LIBNAME := libsnappyjava.so
Linux-x86_64-musl_SNAPPY_FLAGS :=
Linux-ppc_CXX := g++
Linux-ppc_STRIP := strip
ifeq ($(IBM_JDK_7),)

View File

@ -114,6 +114,7 @@ OsgiKeys.additionalHeaders := Map(
"org/xerial/snappy/native/Linux/ppc64/libsnappyjava.so;osname=linux;processor=ppc64le",
"org/xerial/snappy/native/Linux/s390x/libsnappyjava.so;osname=linux;processor=s390x",
"org/xerial/snappy/native/Linux/loongarch64/libsnappyjava.so;osname=linux;processor=loongarch64",
"org/xerial/snappy/native/Linux/x86_64-musl/libsnappyjava.so;osname=linux;processor=x86-64",
"org/xerial/snappy/native/AIX/ppc/libsnappyjava.a;osname=aix;processor=ppc",
"org/xerial/snappy/native/AIX/ppc64/libsnappyjava.a;osname=aix;processor=ppc64",
"org/xerial/snappy/native/SunOS/x86/libsnappyjava.so;osname=sunos;processor=x86",

View File

@ -0,0 +1,36 @@
FROM alpine:3.18
# Set workspace directory
WORKDIR /work
# Copy the project to the container
COPY . .
# Install build dependencies
RUN apk add --no-cache \
openjdk8 \
cmake \
make \
gcc \
g++ \
musl-dev \
linux-headers \
git \
util-linux \
bash \
curl
# Install SBT
RUN curl -L "https://github.com/sbt/sbt/releases/download/v1.9.7/sbt-1.9.7.tgz" | tar xz -C /usr/local
ENV PATH="/usr/local/sbt/bin:${PATH}"
# Install python/pip
ENV PYTHONUNBUFFERED=1
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
RUN python3 -m ensurepip
RUN pip3 install --no-cache --upgrade pip setuptools
# Set Env Vars
ENV CC=gcc CXX=g++
ENV JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk
ENV PATH="${JAVA_HOME}/bin:${PATH}"

View File

@ -25,6 +25,7 @@
package org.xerial.snappy;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
@ -219,6 +220,10 @@ public class OSInfo {
return "android-arm";
}
if (isX64Musl()) {
return "x86_64-musl";
}
if(osArch.startsWith("arm")) {
osArch = resolveArmArchType();
}
@ -230,6 +235,14 @@ public class OSInfo {
return translateArchNameToFolderName(osArch);
}
private static boolean isX64Musl() {
try {
return new File("/lib/ld-musl-x86_64.so.1").exists();
} catch (SecurityException e) {
return false;
}
}
static String translateOSNameToFolderName(String osName) {
if(osName.contains("Windows")) {
return "Windows";