Skip to content

Commit 5746c66

Browse files
authored
rust bindings (#10)
1 parent 63d2060 commit 5746c66

8 files changed

Lines changed: 721 additions & 9 deletions

File tree

.github/workflows/build.yml

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ jobs:
1212
runs-on: ubuntu-20.04
1313
steps:
1414
- uses: actions/checkout@v2
15+
with:
16+
fetch-depth: 0
1517
- name: deps
1618
run: |
1719
sudo apt-get install -y clang-format cppcheck python3-pip
@@ -20,6 +22,17 @@ jobs:
2022
run: pre-commit run --all-files
2123
- name: mvn spotless:check
2224
run: mvn spotless:check -B -f bindings/jdbc/genomicsqlite-jdbc/pom.xml
25+
- name: rust toolchain
26+
uses: actions-rs/toolchain@v1
27+
with:
28+
components: rustfmt, clippy
29+
toolchain: stable
30+
default: true
31+
- name: rust lint
32+
run: |
33+
cd bindings/rust
34+
./cargo check --no-default-features
35+
./cargo fmt -- --check
2336
2437
test:
2538
runs-on: ubuntu-20.04
@@ -28,10 +41,17 @@ jobs:
2841
BUILD_TYPE: [Debug, Release]
2942
steps:
3043
- uses: actions/checkout@v2
44+
with:
45+
fetch-depth: 0
3146
- name: deps
3247
run: |
3348
sudo apt-get install -y $APT_DEPS
3449
sudo pip3 install --system $PIP_DEPS
50+
- name: rust toolchain
51+
uses: actions-rs/toolchain@v1
52+
with:
53+
toolchain: stable
54+
default: true
3555
- name: build
3656
run: cmake -DCMAKE_BUILD_TYPE=${{ matrix.BUILD_TYPE }} -B build . && cmake --build build -j $(nproc)
3757
- name: test
@@ -41,6 +61,8 @@ jobs:
4161
runs-on: ubuntu-20.04
4262
steps:
4363
- uses: actions/checkout@v2
64+
with:
65+
fetch-depth: 0
4466
- name: build loaders
4567
run: |
4668
sudo apt-get install -y $APT_DEPS
@@ -55,8 +77,19 @@ jobs:
5577
docker run genomicsqlite ldd -v -r build/libgenomicsqlite.so
5678
echo "----"
5779
ldd -v -r build/libgenomicsqlite.so
80+
- name: rust toolchain
81+
uses: actions-rs/toolchain@v1
82+
with:
83+
toolchain: stable
84+
default: true
5885
- name: test portable .so
5986
run: env -C build ctest -V
87+
- name: test rust crate
88+
run: |
89+
set -e
90+
cp build/libgenomicsqlite.so bindings/rust
91+
bindings/rust/cargo test --release
92+
bindings/rust/cargo package --list | grep libgenomicsqlite.so
6093
- name: prepare artifacts
6194
run: cp build/libgenomicsqlite.so include/genomicsqlite.h .
6295
- uses: actions/upload-artifact@v2
@@ -68,30 +101,48 @@ jobs:
68101
runs-on: macOS-10.15
69102
steps:
70103
- uses: actions/checkout@v2
104+
with:
105+
fetch-depth: 0
71106
- name: dependencies
72107
run: |
73108
brew update
74109
brew upgrade
75110
brew install $BREW_DEPS
76111
/usr/local/bin/pip3 install $PIP_DEPS
112+
- name: rust toolchain
113+
uses: actions-rs/toolchain@v1
114+
with:
115+
toolchain: stable
116+
default: true
117+
- name: build environment
118+
run: |
119+
echo "PREFIX=$(brew --prefix)" >> $GITHUB_ENV
120+
echo "PATH=${PREFIX}/opt/python/libexec/bin:${PREFIX}/opt/sqlite/bin:${PATH}" >> $GITHUB_ENV
121+
echo "CFLAGS=-I$(brew --prefix)/include -I$(brew --prefix)/opt/sqlite/include -march=sandybridge" >> $GITHUB_ENV
122+
echo "CXXFLAGS=-I$(brew --prefix)/include -march=sandybridge" >> $GITHUB_ENV
123+
echo "LDFLAGS=-L$(brew --prefix)/lib -L$(brew --prefix)/opt/sqlite/lib" >> $GITHUB_ENV
124+
# used by rusqlite:
125+
echo "SQLITE3_INCLUDE_DIR=$(brew --prefix)/opt/sqlite/include" >> $GITHUB_ENV
126+
echo "SQLITE3_LIB_DIR=$(brew --prefix)/opt/sqlite/lib" >> $GITHUB_ENV
77127
- name: build
78128
run: |
79-
CFLAGS="-I$(brew --prefix)/include -I$(brew --prefix)/opt/sqlite/include -march=sandybridge" \
80-
CXXFLAGS="-I$(brew --prefix)/include -march=sandybridge" \
81-
LDFLAGS="-L$(brew --prefix)/lib -L$(brew --prefix)/opt/sqlite/lib" \
82-
cmake -DCMAKE_BUILD_TYPE=Release \
83-
-DCMAKE_PREFIX_PATH=$(brew --prefix)/opt/sqlite \
84-
-B build .
129+
cmake -DCMAKE_BUILD_TYPE=Release \
130+
-DCMAKE_PREFIX_PATH=$(brew --prefix)/opt/sqlite \
131+
-B build .
85132
cmake --build build -j 4
86133
- name: otool
87134
run: otool -L build/libgenomicsqlite.dylib
88135
- name: ctest
89136
run: |
90-
export PREFIX=$(brew --prefix)
91-
export PATH=${PREFIX}/opt/python/libexec/bin:${PREFIX}/opt/sqlite/bin:$PATH
92137
cd build
93138
otool -L test/capi_smoke_test
94139
ctest -V
140+
- name: test rust crate
141+
run: |
142+
set -e
143+
cp build/libgenomicsqlite.dylib bindings/rust
144+
bindings/rust/cargo test --release
145+
bindings/rust/cargo package --list | grep libgenomicsqlite.dylib
95146
- name: prepare artifacts
96147
run: cp build/libgenomicsqlite.dylib include/genomicsqlite.h .
97148
- uses: actions/upload-artifact@v2
@@ -115,7 +166,6 @@ jobs:
115166
- name: detect GIT_REVISION
116167
run: |
117168
cp include/genomicsqlite.h .
118-
git fetch origin --tags
119169
echo "GIT_REVISION=$(git describe --tags --always)" >> $GITHUB_ENV
120170
- uses: actions/upload-artifact@v2
121171
with:

CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,6 @@ if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
5858
add_test(NAME smoke_test COMMAND ${GENOMICSQLITE_TEST_ENV} python3 ${CMAKE_CURRENT_SOURCE_DIR}/test/genomicsqlite_smoke_test.py)
5959
add_test(NAME capi_smoke_test COMMAND ${GENOMICSQLITE_TEST_ENV} ${CMAKE_BINARY_DIR}/test/capi_smoke_test)
6060
add_test(NAME JdbcTests COMMAND ${GENOMICSQLITE_TEST_ENV} mvn test -B -f ${CMAKE_CURRENT_SOURCE_DIR}/bindings/jdbc/genomicsqlite-jdbc/pom.xml)
61+
add_test(NAME cargo_test COMMAND ${GENOMICSQLITE_TEST_ENV} ${CMAKE_CURRENT_SOURCE_DIR}/bindings/rust/cargo test --no-default-features)
6162
add_test(NAME pytest COMMAND ${GENOMICSQLITE_TEST_ENV} python3 -m pytest -xv -n 4 --tb=short ${CMAKE_CURRENT_SOURCE_DIR}/test)
6263
endif()

bindings/rust/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# Generated by Cargo
2+
# will have compiled files and executables
3+
debug/
4+
target/
5+
6+
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
7+
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
8+
Cargo.lock
9+
10+
# These are backup files generated by rustfmt
11+
**/*.rs.bk
12+
13+
# Cargo.toml is generated from Cargo.toml.in by ./cargo
14+
Cargo.toml
15+
libgenomicsqlite.*

bindings/rust/Cargo.toml.in

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
[package]
2+
name = "genomicsqlite"
3+
version = "{{GENOMICSQLITE_VERSION}}"
4+
authors = ["Mike Lin <dna@mlin.net>"]
5+
edition = "2018"
6+
license = "Apache"
7+
repository = "https://github.com/mlin/GenomicSQLite"
8+
documentation = "https://mlin.github.io/GenomicSQLite"
9+
include = ["src/**/*", "Cargo.toml", "libgenomicsqlite.*"]
10+
11+
[features]
12+
# Use default-features=false to prevent bundling a platform-specific libgenomicsqlite into your
13+
# compilation unit. Then at runtime, you must either set env LIBGENOMICSQLITE to the library path,
14+
# or place it somewhere it'll be found by dlopen("libgenomicsqlite").
15+
default = ["bundle_libgenomicsqlite"]
16+
bundle_libgenomicsqlite = []
17+
18+
[dependencies]
19+
json = "^0"
20+
tempfile = "^3"
21+
22+
[dependencies.rusqlite]
23+
version = "^0"
24+
features = ["load_extension", "vtab"]
25+
26+
[dev-dependencies.uuid]
27+
version = "^0"
28+
features = ["v4"]
29+
30+
# TODO:
31+
# update Programming Guide

bindings/rust/cargo

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#!/bin/bash
2+
# wrapper for cargo that generates Cargo.toml from Cargo.toml.in, filling in git revision as
3+
# crate version
4+
set -e
5+
cd `dirname $0`
6+
7+
revision="$(git describe --tags --dirty)"
8+
revision="${revision#v}" # strip 'v' prefix
9+
>&2 echo "$revision"
10+
11+
sed "s/{{GENOMICSQLITE_VERSION}}/${revision}/" Cargo.toml.in > Cargo.toml
12+
cargo "$@"

0 commit comments

Comments
 (0)