Skip to content

Commit ded9f16

Browse files
samyuhxerialgemini-code-assist[bot]claude
authored
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 <[email protected]> * 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 <[email protected]> --------- Co-authored-by: Taro L. Saito <[email protected]> Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> Co-authored-by: Claude <[email protected]>
1 parent a317643 commit ded9f16

File tree

7 files changed

+74
-3
lines changed

7 files changed

+74
-3
lines changed

BUILD.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,4 +116,9 @@ If you are using Mac and openjdk7 (or higher), use the following option:
116116

117117
$ make native LIBNAME=libsnappyjava.dylib
118118

119+
## Building with Alpine
120+
This project supports Alpine-based container images, which use the musl libc implementation. When building on Alpine, be aware that:
119121

122+
- All required dependencies are compatible with musl libc
123+
- The build process has been tested and verified on Alpine environments
124+
- No additional configuration is needed for Alpine compatibility

Makefile

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ native: jni-header snappy-header $(NATIVE_DLL)
151151
native-nocmake: jni-header $(NATIVE_DLL)
152152
snappy: native $(TARGET)/$(snappy-jar-version).jar
153153

154-
native-all: native native-arm clean-docker mac64 win32 win64 linux32 linux64 linux-ppc64le linux-riscv64 linux-s390x
154+
native-all: native native-arm clean-docker mac64 win32 win64 linux32 linux64 linux-ppc64le linux-riscv64 linux-s390x musl-image musl
155155

156156
ifdef CI
157157
# Clean docker images within CI to avoid no space left error
@@ -199,6 +199,12 @@ linux32: jni-header
199199
linux64: jni-header
200200
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'
201201

202+
musl-image:
203+
docker build -f docker/Dockerfile.linux-x86_64-musl -t snappy-java-musl .
204+
205+
musl: jni-header
206+
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'
207+
202208
freebsd64:
203209
$(MAKE) native OS_NAME=FreeBSD OS_ARCH=x86_64
204210

Makefile.common

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ ifndef JAVA_HOME
66
$(warning Set JAVA_HOME environment variable)
77
endif
88

9-
109
JAVA := "$$JAVA_HOME/bin/java"
1110
JAVAC := "$$JAVA_HOME/bin/javac"
1211
JAVAH := "$$JAVA_HOME/bin/javah"
@@ -51,7 +50,7 @@ endif
5150
# os=Default is meant to be generic unix/linux
5251

5352
# To support new CPU architecture, add a new target name here
54-
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
53+
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
5554
os_arch := $(OS_NAME)-$(OS_ARCH)
5655
IBM_JDK_7 := $(findstring IBM, $(shell $(JAVA) -version 2>&1 | grep IBM | grep "JRE 1.7"))
5756

@@ -103,6 +102,17 @@ Linux-x86_64_LINKFLAGS := -shared -static-libgcc -static-libstdc++
103102
Linux-x86_64_LIBNAME := libsnappyjava.so
104103
Linux-x86_64_SNAPPY_FLAGS :=
105104

105+
Linux-x86_64-musl_CXX := $(CROSS_PREFIX)g++
106+
Linux-x86_64-musl_STRIP := $(CROSS_PREFIX)strip
107+
ifeq ($(IBM_JDK_7),)
108+
Linux-x86_64-musl_CXXFLAGS := -Ilib/inc_linux -I$(JAVA_HOME)/include -O2 -fPIC -fvisibility=hidden -m64 -std=c++11
109+
else
110+
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
111+
endif
112+
Linux-x86_64-musl_LINKFLAGS := -shared -static-libgcc -static-libstdc++
113+
Linux-x86_64-musl_LIBNAME := libsnappyjava.so
114+
Linux-x86_64-musl_SNAPPY_FLAGS :=
115+
106116
Linux-ppc_CXX := g++
107117
Linux-ppc_STRIP := strip
108118
ifeq ($(IBM_JDK_7),)

build.sbt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ OsgiKeys.additionalHeaders := Map(
114114
"org/xerial/snappy/native/Linux/ppc64/libsnappyjava.so;osname=linux;processor=ppc64le",
115115
"org/xerial/snappy/native/Linux/s390x/libsnappyjava.so;osname=linux;processor=s390x",
116116
"org/xerial/snappy/native/Linux/loongarch64/libsnappyjava.so;osname=linux;processor=loongarch64",
117+
"org/xerial/snappy/native/Linux/x86_64-musl/libsnappyjava.so;osname=linux;processor=x86-64",
117118
"org/xerial/snappy/native/AIX/ppc/libsnappyjava.a;osname=aix;processor=ppc",
118119
"org/xerial/snappy/native/AIX/ppc64/libsnappyjava.a;osname=aix;processor=ppc64",
119120
"org/xerial/snappy/native/SunOS/x86/libsnappyjava.so;osname=sunos;processor=x86",

docker/Dockerfile.linux-x86_64-musl

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
FROM alpine:3.18
2+
3+
# Set workspace directory
4+
WORKDIR /work
5+
6+
# Copy the project to the container
7+
COPY . .
8+
9+
# Install build dependencies
10+
RUN apk add --no-cache \
11+
openjdk8 \
12+
cmake \
13+
make \
14+
gcc \
15+
g++ \
16+
musl-dev \
17+
linux-headers \
18+
git \
19+
util-linux \
20+
bash \
21+
curl
22+
23+
# Install SBT
24+
RUN curl -L "https://github.com/sbt/sbt/releases/download/v1.9.7/sbt-1.9.7.tgz" | tar xz -C /usr/local
25+
ENV PATH="/usr/local/sbt/bin:${PATH}"
26+
27+
# Install python/pip
28+
ENV PYTHONUNBUFFERED=1
29+
RUN apk add --update --no-cache python3 && ln -sf python3 /usr/bin/python
30+
RUN python3 -m ensurepip
31+
RUN pip3 install --no-cache --upgrade pip setuptools
32+
33+
# Set Env Vars
34+
ENV CC=gcc CXX=g++
35+
ENV JAVA_HOME=/usr/lib/jvm/java-1.8-openjdk
36+
ENV PATH="${JAVA_HOME}/bin:${PATH}"

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
package org.xerial.snappy;
2626

2727
import java.io.ByteArrayOutputStream;
28+
import java.io.File;
2829
import java.io.IOException;
2930
import java.io.InputStream;
3031
import java.util.HashMap;
@@ -219,6 +220,10 @@ public static String getArchName() {
219220
return "android-arm";
220221
}
221222

223+
if (isX64Musl()) {
224+
return "x86_64-musl";
225+
}
226+
222227
if(osArch.startsWith("arm")) {
223228
osArch = resolveArmArchType();
224229
}
@@ -230,6 +235,14 @@ public static String getArchName() {
230235
return translateArchNameToFolderName(osArch);
231236
}
232237

238+
private static boolean isX64Musl() {
239+
try {
240+
return new File("/lib/ld-musl-x86_64.so.1").exists();
241+
} catch (SecurityException e) {
242+
return false;
243+
}
244+
}
245+
233246
static String translateOSNameToFolderName(String osName) {
234247
if(osName.contains("Windows")) {
235248
return "Windows";
Binary file not shown.

0 commit comments

Comments
 (0)