Skip to content

Commit 18fa4d0

Browse files
authored
Rework bundled-library packaging (#37)
Rework libgenomicsqlite packaging to add aarch64 Linux and keep all the flavors nicely organized.
1 parent fd868f5 commit 18fa4d0

18 files changed

Lines changed: 474 additions & 211 deletions

File tree

‎.github/workflows/build.yml‎

Lines changed: 65 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,21 @@ jobs:
7272
- name: test
7373
run: env -C build SQLITE_WEB_LOG=99 ctest -V
7474

75-
linux-x86-64-so:
76-
runs-on: ubuntu-24.04
75+
linux-so:
76+
runs-on: ${{ matrix.runs-on }}
77+
strategy:
78+
matrix:
79+
include:
80+
- target: x86_64-linux-gnu
81+
runs-on: ubuntu-24.04
82+
cpu_arch: ivybridge
83+
artifact: libgenomicsqlite.so-x86_64
84+
sqlite_artifact: libsqlite3.so.0-x86_64
85+
- target: aarch64-linux-gnu
86+
runs-on: ubuntu-24.04-arm
87+
cpu_arch: armv8-a
88+
artifact: libgenomicsqlite.so-aarch64
89+
sqlite_artifact: libsqlite3.so.0-aarch64
7790
steps:
7891
- uses: actions/checkout@v7
7992
with:
@@ -106,10 +119,11 @@ jobs:
106119
run: |
107120
# BuildKit builds only the stages the final target depends on, so the
108121
# two minimum-runtime smoke-test stages -- which nothing depends on --
109-
# must be built explicitly, or they are silently skipped.
110-
docker build --target alma-smoke-test .
111-
docker build --target rust-smoke-test .
112-
docker build -t genomicsqlite . && docker run -v $(pwd):/mnt --rm genomicsqlite cp /usr/local/lib/{libgenomicsqlite.so,libsqlite3.so.0} /usr/local/bin/sqlite3 /mnt/build/
122+
# must be built explicitly, or they are silently skipped. CPU_ARCH
123+
# selects the Dockerfile's -march baseline for this leg's CPU.
124+
docker build --build-arg CPU_ARCH=${{ matrix.cpu_arch }} --target alma-smoke-test .
125+
docker build --build-arg CPU_ARCH=${{ matrix.cpu_arch }} --target rust-smoke-test .
126+
docker build --build-arg CPU_ARCH=${{ matrix.cpu_arch }} -t genomicsqlite . && docker run -v $(pwd):/mnt --rm genomicsqlite cp /usr/local/lib/{libgenomicsqlite.so,libsqlite3.so.0} /usr/local/bin/sqlite3 /mnt/build/
113127
- name: symbols & digests
114128
run: |
115129
readelf -d build/libgenomicsqlite.so
@@ -135,31 +149,37 @@ jobs:
135149
- name: test rust crate
136150
run: |
137151
set -e
138-
cp build/libgenomicsqlite.so bindings/rust/libgenomicsqlite-linux-x86_64.so
152+
mkdir -p bindings/rust/lib/${{ matrix.target }}
153+
cp build/libgenomicsqlite.so bindings/rust/lib/${{ matrix.target }}/
139154
ln -sf libsqlite3.so.0 build/libsqlite3.so # linker name, scoped to build/ like the Dockerfile rust stage
140155
env LD_LIBRARY_PATH="$(pwd)/build" LIBRARY_PATH="$(pwd)/build" SQLITE_WEB_LOG=99 bindings/rust/cargo test --release
141-
bindings/rust/cargo package --list | grep libgenomicsqlite-linux-x86_64.so
156+
bindings/rust/cargo package --list | grep lib/${{ matrix.target }}/libgenomicsqlite.so
142157
- name: installed-package smoke test
143158
run: |
144159
python3 -m pip install -q setuptools wheel
145-
bash test/pkg_smoke.sh python3 bindings/python build/libgenomicsqlite.so libgenomicsqlite-linux-x86_64.so "$(pwd)/build"
160+
bash test/pkg_smoke.sh python3 bindings/python build/libgenomicsqlite.so lib/${{ matrix.target }} "$(pwd)/build"
146161
- name: prepare artifacts
147-
run: cp build/{libgenomicsqlite.so,libsqlite3.so.0} .
162+
run: cp build/libgenomicsqlite.so .
163+
- name: prepare sqlite artifact
164+
run: cp build/libsqlite3.so.0 .
148165
- uses: actions/upload-artifact@v7
149166
with:
150-
name: libgenomicsqlite.so
167+
name: ${{ matrix.artifact }}
151168
path: libgenomicsqlite.so
152169
- uses: actions/upload-artifact@v7
153170
with:
154-
name: libsqlite3.so.0
171+
name: ${{ matrix.sqlite_artifact }}
155172
path: libsqlite3.so.0
156173

157-
macOS-arm64-dylib:
174+
macOS-aarch64-dylib:
158175
runs-on: macos-15
159176
steps:
160177
- uses: actions/checkout@v7
161178
with:
162179
fetch-depth: 0
180+
# The brew passes below report "Skipping <formula>: most recent version
181+
# not installed" for the runner image's own outdated formulae; GitHub
182+
# renders them as job annotations. Expected, and not our dependencies.
163183
- name: dependencies
164184
run: |
165185
rm -f $(brew --prefix)/bin/2to3 # https://github.com/pypa/pipenv/issues/3831
@@ -215,37 +235,48 @@ jobs:
215235
- name: test rust crate
216236
run: |
217237
set -e
218-
cp build/libgenomicsqlite.dylib bindings/rust/libgenomicsqlite-macos-aarch64.dylib
238+
mkdir -p bindings/rust/lib/aarch64-darwin
239+
cp build/libgenomicsqlite.dylib bindings/rust/lib/aarch64-darwin/
219240
SQLITE_WEB_LOG=99 bindings/rust/cargo test --release
220-
bindings/rust/cargo package --list | grep libgenomicsqlite-macos-aarch64.dylib
241+
bindings/rust/cargo package --list | grep lib/aarch64-darwin/libgenomicsqlite.dylib
221242
- name: installed-package smoke test
222243
run: |
223244
python3 -m pip install -q setuptools wheel
224-
bash test/pkg_smoke.sh python3 bindings/python build/libgenomicsqlite.dylib libgenomicsqlite-macos-aarch64.dylib "$(brew --prefix)/opt/sqlite/bin"
245+
bash test/pkg_smoke.sh python3 bindings/python build/libgenomicsqlite.dylib lib/aarch64-darwin "$(brew --prefix)/opt/sqlite/bin"
225246
- name: prepare artifacts
226-
run: cp build/libgenomicsqlite.dylib libgenomicsqlite-macos-aarch64.dylib && cp include/genomicsqlite.h .
247+
run: cp build/libgenomicsqlite.dylib . && cp include/genomicsqlite.h .
227248
- uses: actions/upload-artifact@v7
228249
with:
229-
name: libgenomicsqlite-macos-aarch64.dylib
230-
path: libgenomicsqlite-macos-aarch64.dylib
250+
name: libgenomicsqlite.dylib
251+
path: libgenomicsqlite.dylib
231252

232253
artifacts:
233254
runs-on: ubuntu-24.04
234-
needs: [linux-x86-64-so, macOS-arm64-dylib]
255+
needs: [linux-so, macOS-aarch64-dylib]
235256
steps:
236257
- uses: actions/checkout@v7
237-
- name: fetch libgenomicsqlite.so
258+
# Each library downloads directly into its per-target directory under
259+
# lib/ (the shipped layout, docs/bindings.md): plain file names, target
260+
# variation in the directory. Artifact names are transport labels only.
261+
- name: fetch libgenomicsqlite.so (x86_64)
262+
uses: actions/download-artifact@v8
263+
with:
264+
name: libgenomicsqlite.so-x86_64
265+
path: lib/x86_64-linux-gnu
266+
- name: fetch libsqlite3.so.0 (x86_64)
238267
uses: actions/download-artifact@v8
239268
with:
240-
name: libgenomicsqlite.so
241-
- name: fetch libsqlite3.so.0
269+
name: libsqlite3.so.0-x86_64
270+
- name: fetch libgenomicsqlite.so (aarch64)
242271
uses: actions/download-artifact@v8
243272
with:
244-
name: libsqlite3.so.0
273+
name: libgenomicsqlite.so-aarch64
274+
path: lib/aarch64-linux-gnu
245275
- name: fetch libgenomicsqlite.dylib
246276
uses: actions/download-artifact@v8
247277
with:
248-
name: libgenomicsqlite-macos-aarch64.dylib
278+
name: libgenomicsqlite.dylib
279+
path: lib/aarch64-darwin
249280
- name: detect GIT_REVISION
250281
run: |
251282
cp include/genomicsqlite.h .
@@ -256,17 +287,21 @@ jobs:
256287
path: |
257288
LICENSE
258289
genomicsqlite.h
259-
libgenomicsqlite.so
260-
libgenomicsqlite-macos-aarch64.dylib
290+
lib/x86_64-linux-gnu/libgenomicsqlite.so
291+
lib/aarch64-linux-gnu/libgenomicsqlite.so
292+
lib/aarch64-darwin/libgenomicsqlite.dylib
261293
- name: build jar
262294
run: |
263-
cp libgenomicsqlite.so bindings/jdbc/genomicsqlite-jdbc/src/main/resources/libgenomicsqlite-linux-x86_64.so
264-
cp libgenomicsqlite-macos-aarch64.dylib bindings/jdbc/genomicsqlite-jdbc/src/main/resources/libgenomicsqlite-macos-aarch64.dylib
295+
RES=bindings/jdbc/genomicsqlite-jdbc/src/main/resources
296+
mkdir -p $RES/lib/x86_64-linux-gnu $RES/lib/aarch64-linux-gnu $RES/lib/aarch64-darwin
297+
cp lib/x86_64-linux-gnu/libgenomicsqlite.so $RES/lib/x86_64-linux-gnu/
298+
cp lib/aarch64-linux-gnu/libgenomicsqlite.so $RES/lib/aarch64-linux-gnu/
299+
cp lib/aarch64-darwin/libgenomicsqlite.dylib $RES/lib/aarch64-darwin/
265300
mvn deploy -Drevision=${{ env.GIT_REVISION }} -B -f bindings/jdbc/genomicsqlite-jdbc/pom.xml
266301
- name: JDBC smoke test
267302
run: bash test/jdbc_smoke_test.sh bindings/jdbc/genomicsqlite-jdbc
268303
- name: digests
269-
run: sha256sum *genomicsqlite* bindings/jdbc/genomicsqlite-jdbc/target/genomicsqlite*.jar libsqlite3.so.0
304+
run: sha256sum lib/x86_64-linux-gnu/libgenomicsqlite.so lib/aarch64-linux-gnu/libgenomicsqlite.so lib/aarch64-darwin/libgenomicsqlite.dylib bindings/jdbc/genomicsqlite-jdbc/target/genomicsqlite*.jar libsqlite3.so.0
270305
- uses: actions/upload-artifact@v7
271306
with:
272307
name: genomicsqlite-jdbc-${{ env.GIT_REVISION }}

‎Dockerfile‎

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
# Builds libgenomicsqlite.so in AlmaLinux 8 (glibc 2.28, the manylinux_2_28 baseline) to
2-
# maximize compatibility. Bakes in Zstandard, and also builds a compatible libsqlite3.so.0
3-
# for users unable/unwilling to upgrade their host's.
1+
# Build against AlmaLinux 8 (glibc 2.28) for the manylinux_2_28 baseline.
2+
# Link Zstandard statically and provide a compatible SQLite library for older hosts.
43
FROM almalinux:8 as builder
54

6-
ARG CMAKE_VERSION=3.17.3
75
ARG SQLITE_VERSION=3540100
86
ARG ZSTD_VERSION=1.5.5
7+
# x86_64 defaults to ivybridge; pass --build-arg CPU_ARCH=armv8-a on aarch64.
98
ARG CPU_ARCH=ivybridge
109
ENV CFLAGS="-march=${CPU_ARCH} -O3"
1110
ENV CXXFLAGS=${CFLAGS}
@@ -28,7 +27,12 @@ ENV SQLITE_CFLAGS="\
2827
-DSQLITE_ENABLE_SESSION \
2928
"
3029

31-
RUN dnf install -y -q wget unzip rsync git libcurl-devel gcc gcc-c++ make
30+
# cmake comes from the distro: arch-native on both x86_64 and aarch64,
31+
# and new enough for the project's CMake floor.
32+
RUN dnf install -y -q wget unzip git libcurl-devel gcc gcc-c++ make cmake
33+
# fail fast, before the expensive builds, if CPU_ARCH doesn't fit this CPU
34+
RUN echo 'int main(void){return 0;}' | gcc ${CFLAGS} -x c - -o /dev/null \
35+
|| { echo "error: CPU_ARCH=${CPU_ARCH} is not a valid -march for $(uname -m); pass --build-arg CPU_ARCH=armv8-a on aarch64" >&2; exit 1; }
3236

3337
RUN mkdir -p /work/GenomicSQLite
3438

@@ -48,12 +52,6 @@ RUN wget -nv -O - https://github.com/facebook/zstd/releases/download/v${ZSTD_VER
4852
WORKDIR /work/zstd-${ZSTD_VERSION}
4953
RUN CFLAGS="${CFLAGS} -fPIC" make install -j $(nproc)
5054

51-
# CMake
52-
WORKDIR /work
53-
RUN wget -nv https://github.com/Kitware/CMake/releases/download/v${CMAKE_VERSION}/cmake-${CMAKE_VERSION}-Linux-x86_64.sh
54-
RUN yes | sh cmake-${CMAKE_VERSION}-Linux-x86_64.sh
55-
RUN rsync -a cmake-${CMAKE_VERSION}-Linux-x86_64/ /usr/local/
56-
5755
RUN ldconfig
5856

5957
# libgenomicsqlite.so
@@ -119,7 +117,9 @@ COPY --from=builder /usr/local/lib/libsqlite3.so.0 ./lib/
119117
RUN ln -s libsqlite3.so.0 lib/libsqlite3.so
120118
ADD ./.git ./.git
121119
ADD ./bindings/rust ./rust
122-
COPY --from=builder /work/GenomicSQLite/build/libgenomicsqlite.so ./rust/libgenomicsqlite-linux-x86_64.so
120+
COPY --from=builder /work/GenomicSQLite/build/libgenomicsqlite.so ./libgenomicsqlite.so
121+
# plant the library in the crate's per-target directory for this build's CPU
122+
RUN mkdir -p ./rust/lib/$(uname -m)-linux-gnu && cp ./libgenomicsqlite.so ./rust/lib/$(uname -m)-linux-gnu/
123123
# git in the cargo wrapper must accept the context's .git even if the build
124124
# host checked it out under a different uid than root
125125
RUN git config --global --add safe.directory /work

‎bindings/jdbc/genomicsqlite-jdbc/src/main/java/net/mlin/genomicsqlite/JdbcDriver.java‎

Lines changed: 46 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
public class JdbcDriver extends org.sqlite.JDBC {
3232
public static final String PREFIX = "jdbc:genomicsqlite:";
3333
private static Connection memoryDb = null;
34+
// how getLibraryFilename() obtained the library, for load-failure messages
35+
private static String librarySource = "the system library search path";
3436

3537
static {
3638
try {
@@ -98,7 +100,6 @@ public static SQLiteConnection createConnection(String url, Properties prop) thr
98100
String config_json = prop.getProperty("genomicsqlite.config_json", "{}");
99101

100102
ensureExtension();
101-
// generate connection URI
102103
PreparedStatement stmt;
103104
ResultSet row;
104105
synchronized (memoryDb) {
@@ -110,14 +111,12 @@ public static SQLiteConnection createConnection(String url, Properties prop) thr
110111
url = row.getString(1);
111112
}
112113

113-
// connect via sqlite-jdbc
114114
if (prop.getProperty("open_mode") == null
115115
&& (url.indexOf("&mode=ro") > -1 || url.indexOf("&immutable=1") > -1)) {
116116
prop.setProperty("open_mode", "65"); // SQLITE_OPEN_READONLY|SQLITE_OPEN_URI
117117
}
118118
SQLiteConnection conn = org.sqlite.JDBC.createConnection("jdbc:sqlite:" + url, prop);
119119

120-
// generate & apply tuning script
121120
stmt = conn.prepareStatement("SELECT genomicsqlite_tuning_sql(?)");
122121
stmt.setString(1, config_json);
123122
row = stmt.executeQuery();
@@ -127,7 +126,6 @@ public static SQLiteConnection createConnection(String url, Properties prop) thr
127126
}
128127

129128
static synchronized void ensureExtension() throws SQLException {
130-
// Load the extension library if we haven't already
131129
if (memoryDb == null) {
132130
String libraryFilename = getLibraryFilename();
133131

@@ -137,33 +135,47 @@ static synchronized void ensureExtension() throws SQLException {
137135
Properties memProp = new Properties();
138136
memProp.setProperty("enable_load_extension", "true");
139137
Connection db = DriverManager.getConnection("jdbc:sqlite::memory:", memProp);
138+
String loadName = libraryFilename != null ? libraryFilename : "libgenomicsqlite";
140139
PreparedStatement stmt = db.prepareStatement("SELECT load_extension(?)");
141-
stmt.setString(1, libraryFilename != null ? libraryFilename : "libgenomicsqlite");
142-
stmt.execute();
140+
stmt.setString(1, loadName);
141+
try {
142+
stmt.execute();
143+
} catch (SQLException exc) {
144+
throw new SQLException(
145+
"genomicsqlite: could not load "
146+
+ loadName
147+
+ " (from "
148+
+ librarySource
149+
+ "): "
150+
+ exc.getMessage()
151+
+ "; set LIBGENOMICSQLITE to the library file, or install libgenomicsqlite"
152+
+ " where the system loader finds it",
153+
exc);
154+
}
143155
memoryDb = db;
144156
}
145157
}
146158

147159
static String getLibraryFilename() {
148-
// extract platform-appropriate extension library file from resources and return its temp
149-
// filename, which will be deleted on exit. sources:
150-
// https://stackoverflow.com/questions/228477/how-do-i-programmatically-determine-operating-system-in-java
151-
// https://github.com/xerial/sqlite-jdbc/blob/master/src/main/java/org/sqlite/SQLiteJDBCLoader.java
152-
String override = System.getenv("LIBGENOMICSQLITE");
153-
if (override != null && override.trim().length() > 0) return override;
160+
// Return an override or extracted bundle path; null requests system-loader search.
161+
librarySource = "the system library search path";
162+
String override = trimmedOverride(System.getenv("LIBGENOMICSQLITE"));
163+
if (override != null) {
164+
librarySource = "the LIBGENOMICSQLITE environment variable";
165+
return override;
166+
}
154167
String ans = null;
155-
String basename = getLibraryBasename();
156-
if (basename != null) {
168+
String resourcePath = getLibraryResourcePath();
169+
if (resourcePath != null) {
157170
try {
158-
InputStream reader = JdbcDriver.class.getClassLoader().getResourceAsStream(basename);
171+
InputStream reader = JdbcDriver.class.getClassLoader().getResourceAsStream(resourcePath);
159172
if (reader != null) {
160173
String tempDirpath =
161174
Files.createTempDirectory("genomicsqlite-jdbc-").toAbsolutePath().toString();
162175
(new File(tempDirpath)).deleteOnExit();
163-
// Extract under the resource's own architecture-qualified name: the
164-
// bundled binaries export the standard sqlite3_extension_init entry
165-
// point, which SQLite tries before guessing one from the file name.
166-
File extracted = new File(tempDirpath, basename);
176+
// Extract under the plain filename; target variation belongs in resource paths.
177+
File extracted =
178+
new File(tempDirpath, resourcePath.substring(resourcePath.lastIndexOf('/') + 1));
167179
FileOutputStream writer = new FileOutputStream(extracted.getAbsolutePath());
168180
extracted.deleteOnExit();
169181
byte[] buffer = new byte[65536];
@@ -174,20 +186,26 @@ static String getLibraryFilename() {
174186
extracted.setReadable(true);
175187
extracted.setExecutable(true);
176188
ans = extracted.getAbsolutePath();
189+
librarySource = "the copy bundled in this JAR";
177190
}
178191
} catch (IOException exc) {
179192
}
180193
}
181194
return ans;
182195
}
183196

184-
static String getLibraryBasename() {
185-
// Resource name of the bundled library for this OS + CPU, in the
186-
// architecture-qualified form the release pipeline packs into the JAR (the
187-
// same naming the Rust crate uses). Matching is exact: an Intel JVM never
188-
// selects the ARM build, nor vice versa. If the JAR carries no resource
189-
// under the returned name (a platform the release doesn't bundle), the
190-
// caller falls back to the system library search.
197+
static String trimmedOverride(String override) {
198+
// String.trim() does not cover Unicode whitespace; whitespace-only means unset.
199+
if (override == null) {
200+
return null;
201+
}
202+
String trimmed = override.replaceAll("(?U)^\\s+|\\s+$", "");
203+
return trimmed.length() > 0 ? trimmed : null;
204+
}
205+
206+
static String getLibraryResourcePath() {
207+
// Return the canonical resource path, or null for an unrecognized OS or CPU.
208+
// Missing resources fall back to system search.
191209
String arch = System.getProperty("os.arch", "unknown").toLowerCase(Locale.ENGLISH);
192210
String archTok = null;
193211
if (arch.equals("amd64") || arch.equals("x86_64")) {
@@ -200,9 +218,9 @@ static String getLibraryBasename() {
200218
}
201219
String os = System.getProperty("os.name", "unknown").toLowerCase(Locale.ENGLISH);
202220
if (os.indexOf("mac") >= 0 || os.indexOf("darwin") >= 0) {
203-
return "libgenomicsqlite-macos-" + archTok + ".dylib";
221+
return "lib/" + archTok + "-darwin/libgenomicsqlite.dylib";
204222
} else if (os.indexOf("nux") >= 0) {
205-
return "libgenomicsqlite-linux-" + archTok + ".so";
223+
return "lib/" + archTok + "-linux-gnu/libgenomicsqlite.so";
206224
}
207225
return null;
208226
}

‎bindings/jdbc/genomicsqlite-jdbc/src/test/java/net/mlin/genomicsqlite/JdbcTests.java‎

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,19 @@
1212
import org.junit.Test;
1313

1414
public class JdbcTests {
15+
@Test
16+
public void trimmedOverrideTest() {
17+
// LIBGENOMICSQLITE: unset, empty, and whitespace-only all mean no
18+
// override; a nonempty value wins, trimmed (docs/bindings.md).
19+
assertNull(JdbcDriver.trimmedOverride(null));
20+
assertNull(JdbcDriver.trimmedOverride(""));
21+
assertNull(JdbcDriver.trimmedOverride(" \t "));
22+
assertNull(JdbcDriver.trimmedOverride("\u2003")); // EM SPACE only
23+
assertEquals("/x/libgenomicsqlite.so", JdbcDriver.trimmedOverride(" /x/libgenomicsqlite.so "));
24+
assertEquals(
25+
"/x/libgenomicsqlite.so", JdbcDriver.trimmedOverride("\u2003/x/libgenomicsqlite.so\u2003"));
26+
}
27+
1528
@Test
1629
public void smokeTest() throws SQLException {
1730
// create temp database

‎bindings/python/MANIFEST.in‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include RELEASE-VERSION version.py genomicsqlite/libgenomicsqlite-*
1+
include RELEASE-VERSION version.py genomicsqlite/lib/*/libgenomicsqlite.so genomicsqlite/lib/*/libgenomicsqlite.dylib

0 commit comments

Comments
 (0)