Skip to content

Commit a4a5d48

Browse files
authored
feat: add riscv64 binaries
1 parent 0035ec4 commit a4a5d48

6 files changed

Lines changed: 297 additions & 2 deletions

File tree

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,10 @@ jobs:
106106
- arch: ppc64le
107107
distro: ubuntu_latest
108108
java: 21
109+
# RISC-V 64
110+
- arch: riscv64
111+
distro: ubuntu_latest
112+
java: 21
109113
runs-on: ubuntu-latest
110114
steps:
111115
- uses: actions/checkout@v4

Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ NATIVE_TARGET_DIR:=$(TARGET)/classes/org/sqlite/native/$(OS_NAME)/$(OS_ARCH)
121121
NATIVE_DLL:=$(NATIVE_DIR)/$(LIBNAME)
122122

123123
# For cross-compilation, install docker. See also https://github.com/dockcross/dockcross
124-
native-all: native win32 win64 win-armv7 win-arm64 mac64-signed mac-arm64-signed linux32 linux64 freebsd32 freebsd64 freebsd-arm64 linux-arm linux-armv6 linux-armv7 linux-arm64 linux-android-arm linux-android-arm64 linux-android-x86 linux-android-x64 linux-ppc64 linux-musl32 linux-musl64 linux-musl-arm64
124+
native-all: native win32 win64 win-armv7 win-arm64 mac64-signed mac-arm64-signed linux32 linux64 freebsd32 freebsd64 freebsd-arm64 linux-arm linux-armv6 linux-armv7 linux-arm64 linux-android-arm linux-android-arm64 linux-android-x86 linux-android-x64 linux-ppc64 linux-musl32 linux-musl64 linux-musl-arm64 linux-riscv64
125125

126126
native: $(NATIVE_DLL)
127127

@@ -194,6 +194,9 @@ linux-android-x64: $(SQLITE_UNPACKED) jni-header
194194
linux-ppc64: $(SQLITE_UNPACKED) jni-header
195195
./docker/dockcross-ppc64 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=powerpc64le-unknown-linux-gnu- OS_NAME=Linux OS_ARCH=ppc64'
196196

197+
linux-riscv64: $(SQLITE_UNPACKED) jni-header
198+
./docker/dockcross-riscv64 -a $(DOCKER_RUN_OPTS) bash -c 'make clean-native native CROSS_PREFIX=riscv64-unknown-linux-gnu- OS_NAME=Linux OS_ARCH=riscv64'
199+
197200
mac64: $(SQLITE_UNPACKED) jni-header
198201
docker run $(DOCKER_RUN_OPTS) -v $$PWD:/workdir -e CROSS_TRIPLE=x86_64-apple-darwin multiarch/crossbuild make clean-native native OS_NAME=Mac OS_ARCH=x86_64
199202

Makefile.common

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ endif
5252

5353
# os=Default is meant to be generic unix/linux
5454

55-
known_targets := Linux-x86 Linux-x86_64 Linux-arm Linux-armv6 Linux-armv7 Linux-Android-arm Linux-Android-aarch64 Linux-Android-x86 Linux-Android-x86_64 Linux-ppc64 Mac-x86 Mac-x86_64 Mac-aarch64 DragonFly-x86_64 FreeBSD-x86 FreeBSD-x86_64 FreeBSD-aarch64 OpenBSD-x86_64 Windows-x86 Windows-x86_64 Windows-armv7 Windows-aarch64 SunOS-sparcv9 HPUX-ia64_32
55+
known_targets := Linux-x86 Linux-x86_64 Linux-arm Linux-armv6 Linux-armv7 Linux-Android-arm Linux-Android-aarch64 Linux-Android-x86 Linux-Android-x86_64 Linux-ppc64 Linux-riscv64 Mac-x86 Mac-x86_64 Mac-aarch64 DragonFly-x86_64 FreeBSD-x86 FreeBSD-x86_64 FreeBSD-aarch64 OpenBSD-x86_64 Windows-x86 Windows-x86_64 Windows-armv7 Windows-aarch64 SunOS-sparcv9 HPUX-ia64_32
5656
target := $(OS_NAME)-$(OS_ARCH)
5757

5858
ifeq (,$(findstring $(strip $(target)),$(known_targets)))
@@ -141,6 +141,13 @@ Linux-ppc64_LINKFLAGS := $(Default_LINKFLAGS)
141141
Linux-ppc64_LIBNAME := libsqlitejdbc.so
142142
Linux-ppc64_SQLITE_FLAGS :=
143143

144+
Linux-riscv64_CC := $(CROSS_PREFIX)gcc
145+
Linux-riscv64_STRIP := $(CROSS_PREFIX)strip
146+
Linux-riscv64_CCFLAGS := -I$(JAVA_HOME)/include -Ilib/inc_linux -Os -fPIC -fvisibility=hidden
147+
Linux-riscv64_LINKFLAGS := $(Default_LINKFLAGS)
148+
Linux-riscv64_LIBNAME := libsqlitejdbc.so
149+
Linux-riscv64_SQLITE_FLAGS :=
150+
144151
DragonFly-x86_64_CC := $(CROSS_PREFIX)cc
145152
DragonFly-x86_64_STRIP := $(CROSS_PREFIX)strip
146153
DragonFly-x86_64_CCFLAGS := -I$(JAVA_HOME)/include -Ilib/inc_linux -O2 -fPIC -fvisibility=hidden

docker/dockcross-riscv64

Lines changed: 278 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,278 @@
1+
#!/usr/bin/env bash
2+
3+
DEFAULT_DOCKCROSS_IMAGE=dockcross/linux-riscv64:latest
4+
5+
#------------------------------------------------------------------------------
6+
# Helpers
7+
#
8+
err() {
9+
echo -e >&2 "ERROR: $*\n"
10+
}
11+
12+
die() {
13+
err "$*"
14+
exit 1
15+
}
16+
17+
has() {
18+
# eg. has command update
19+
local kind=$1
20+
local name=$2
21+
22+
type -t $kind:$name | grep -q function
23+
}
24+
25+
# If OCI_EXE is not already set, search for a container executor (OCI stands for "Open Container Initiative")
26+
if [ -z "$OCI_EXE" ]; then
27+
if which podman >/dev/null 2>/dev/null; then
28+
OCI_EXE=podman
29+
elif which docker >/dev/null 2>/dev/null; then
30+
OCI_EXE=docker
31+
else
32+
die "Cannot find a container executor. Search for docker and podman."
33+
fi
34+
fi
35+
36+
#------------------------------------------------------------------------------
37+
# Command handlers
38+
#
39+
command:update-image() {
40+
$OCI_EXE pull $FINAL_IMAGE
41+
}
42+
43+
help:update-image() {
44+
echo "Pull the latest $FINAL_IMAGE ."
45+
}
46+
47+
command:update-script() {
48+
if cmp -s <( $OCI_EXE run --rm $FINAL_IMAGE ) $0; then
49+
echo "$0 is up to date"
50+
else
51+
echo -n "Updating $0 ... "
52+
$OCI_EXE run --rm $FINAL_IMAGE > $0 && echo ok
53+
fi
54+
}
55+
56+
help:update-script() {
57+
echo "Update $0 from $FINAL_IMAGE ."
58+
}
59+
60+
command:update() {
61+
command:update-image
62+
command:update-script
63+
}
64+
65+
help:update() {
66+
echo "Pull the latest $FINAL_IMAGE, and then update $0 from that."
67+
}
68+
69+
command:help() {
70+
if [[ $# != 0 ]]; then
71+
if ! has command $1; then
72+
err \"$1\" is not an dockcross command
73+
command:help
74+
elif ! has help $1; then
75+
err No help found for \"$1\"
76+
else
77+
help:$1
78+
fi
79+
else
80+
cat >&2 <<ENDHELP
81+
Usage: dockcross [options] [--] command [args]
82+
83+
By default, run the given *command* in an dockcross Docker container.
84+
85+
The *options* can be one of:
86+
87+
--args|-a Extra args to the *docker run* command
88+
--image|-i Docker cross-compiler image to use
89+
--config|-c Bash script to source before running this script
90+
91+
92+
Additionally, there are special update commands:
93+
94+
update-image
95+
update-script
96+
update
97+
98+
For update command help use: $0 help <command>
99+
ENDHELP
100+
exit 1
101+
fi
102+
}
103+
104+
#------------------------------------------------------------------------------
105+
# Option processing
106+
#
107+
special_update_command=''
108+
while [[ $# != 0 ]]; do
109+
case $1 in
110+
111+
--)
112+
shift
113+
break
114+
;;
115+
116+
--args|-a)
117+
ARG_ARGS="$2"
118+
shift 2
119+
;;
120+
121+
--config|-c)
122+
ARG_CONFIG="$2"
123+
shift 2
124+
;;
125+
126+
--image|-i)
127+
ARG_IMAGE="$2"
128+
shift 2
129+
;;
130+
update|update-image|update-script)
131+
special_update_command=$1
132+
break
133+
;;
134+
-*)
135+
err Unknown option \"$1\"
136+
command:help
137+
exit
138+
;;
139+
140+
*)
141+
break
142+
;;
143+
144+
esac
145+
done
146+
147+
# The precedence for options is:
148+
# 1. command-line arguments
149+
# 2. environment variables
150+
# 3. defaults
151+
152+
# Source the config file if it exists
153+
DEFAULT_DOCKCROSS_CONFIG=~/.dockcross
154+
FINAL_CONFIG=${ARG_CONFIG-${DOCKCROSS_CONFIG-$DEFAULT_DOCKCROSS_CONFIG}}
155+
156+
[[ -f "$FINAL_CONFIG" ]] && source "$FINAL_CONFIG"
157+
158+
# Set the docker image
159+
FINAL_IMAGE=${ARG_IMAGE-${DOCKCROSS_IMAGE-$DEFAULT_DOCKCROSS_IMAGE}}
160+
161+
# Handle special update command
162+
if [ "$special_update_command" != "" ]; then
163+
case $special_update_command in
164+
165+
update)
166+
command:update
167+
exit $?
168+
;;
169+
170+
update-image)
171+
command:update-image
172+
exit $?
173+
;;
174+
175+
update-script)
176+
command:update-script
177+
exit $?
178+
;;
179+
180+
esac
181+
fi
182+
183+
# Set the docker run extra args (if any)
184+
FINAL_ARGS=${ARG_ARGS-${DOCKCROSS_ARGS}}
185+
186+
# Bash on Ubuntu on Windows
187+
UBUNTU_ON_WINDOWS=$([ -e /proc/version ] && grep -l Microsoft /proc/version || echo "")
188+
# MSYS, Git Bash, etc.
189+
MSYS=$([ -e /proc/version ] && grep -l MINGW /proc/version || echo "")
190+
# CYGWIN
191+
CYGWIN=$([ -e /proc/version ] && grep -l CYGWIN /proc/version || echo "")
192+
193+
if [ -z "$UBUNTU_ON_WINDOWS" -a -z "$MSYS" -a "$OCI_EXE" != "podman" ]; then
194+
USER_IDS=(-e BUILDER_UID="$( id -u )" -e BUILDER_GID="$( id -g )" -e BUILDER_USER="$( id -un )" -e BUILDER_GROUP="$( id -gn )")
195+
fi
196+
197+
# Change the PWD when working in Docker on Windows
198+
if [ -n "$UBUNTU_ON_WINDOWS" ]; then
199+
WSL_ROOT="/mnt/"
200+
CFG_FILE=/etc/wsl.conf
201+
if [ -f "$CFG_FILE" ]; then
202+
CFG_CONTENT=$(cat $CFG_FILE | sed -r '/[^=]+=[^=]+/!d' | sed -r 's/\s+=\s/=/g')
203+
eval "$CFG_CONTENT"
204+
if [ -n "$root" ]; then
205+
WSL_ROOT=$root
206+
fi
207+
fi
208+
HOST_PWD=`pwd -P`
209+
HOST_PWD=${HOST_PWD/$WSL_ROOT//}
210+
elif [ -n "$MSYS" ]; then
211+
HOST_PWD=$PWD
212+
HOST_PWD=${HOST_PWD/\//}
213+
HOST_PWD=${HOST_PWD/\//:\/}
214+
elif [ -n "$CYGWIN" ]; then
215+
for f in pwd readlink cygpath ; do
216+
test -n "$(type "${f}" )" || { echo >&2 "Missing functionality (${f}) (in cygwin)." ; exit 1 ; } ;
217+
done ;
218+
HOST_PWD="$( cygpath -w "$( readlink -f "$( pwd ;)" ; )" ; )" ;
219+
else
220+
HOST_PWD=$PWD
221+
[ -L $HOST_PWD ] && HOST_PWD=$(readlink $HOST_PWD)
222+
fi
223+
224+
# Mount Additional Volumes
225+
if [ -z "$SSH_DIR" ]; then
226+
SSH_DIR="$HOME/.ssh"
227+
fi
228+
229+
HOST_VOLUMES=
230+
if [ -e "$SSH_DIR" -a -z "$MSYS" ]; then
231+
if test -n "${CYGWIN}" ; then
232+
HOST_VOLUMES+="-v $(cygpath -w ${SSH_DIR} ; ):/home/$(id -un)/.ssh" ;
233+
else
234+
HOST_VOLUMES+="-v $SSH_DIR:/home/$(id -un)/.ssh" ;
235+
fi ;
236+
fi
237+
238+
#------------------------------------------------------------------------------
239+
# Now, finally, run the command in a container
240+
#
241+
TTY_ARGS=
242+
tty -s && [ -z "$MSYS" ] && TTY_ARGS=-ti
243+
CONTAINER_NAME=dockcross_$RANDOM
244+
$OCI_EXE run $TTY_ARGS --name $CONTAINER_NAME \
245+
-v "$HOST_PWD":/work \
246+
$HOST_VOLUMES \
247+
"${USER_IDS[@]}" \
248+
$FINAL_ARGS \
249+
$FINAL_IMAGE "$@"
250+
run_exit_code=$?
251+
252+
# Attempt to delete container
253+
rm_output=$($OCI_EXE rm -f $CONTAINER_NAME 2>&1)
254+
rm_exit_code=$?
255+
if [[ $rm_exit_code != 0 ]]; then
256+
if [[ "$CIRCLECI" == "true" ]] && [[ $rm_output == *"Driver btrfs failed to remove"* ]]; then
257+
: # Ignore error because of https://circleci.com/docs/docker-btrfs-error/
258+
else
259+
echo "$rm_output"
260+
exit $rm_exit_code
261+
fi
262+
fi
263+
264+
exit $run_exit_code
265+
266+
################################################################################
267+
#
268+
# This image is not intended to be run manually.
269+
#
270+
# To create a dockcross helper script for the
271+
# dockcross/linux-riscv64:latest image, run:
272+
#
273+
# docker run --rm dockcross/linux-riscv64:latest > dockcross-linux-riscv64-latest
274+
# chmod +x dockcross-linux-riscv64-latest
275+
#
276+
# You may then wish to move the dockcross script to your PATH.
277+
#
278+
################################################################################

src/main/java/org/sqlite/util/OSInfo.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ public class OSInfo {
4949
public static final String IA64 = "ia64";
5050
public static final String PPC = "ppc";
5151
public static final String PPC64 = "ppc64";
52+
public static final String RISCV64 = "riscv64";
5253

5354
static {
5455
// x86 mappings
@@ -88,6 +89,8 @@ public class OSInfo {
8889
archMapping.put("power_rs64", PPC64);
8990
archMapping.put("ppc64el", PPC64);
9091
archMapping.put("ppc64le", PPC64);
92+
93+
archMapping.put(RISCV64, RISCV64);
9194
}
9295

9396
public static void main(String[] args) {
Binary file not shown.

0 commit comments

Comments
 (0)