Skip to content

Commit 83efc1a

Browse files
cursoragentlovasoa
andcommitted
Checkpoint before follow-up message
Co-authored-by: contact <contact@ophir.dev>
1 parent d4dd9c2 commit 83efc1a

5 files changed

Lines changed: 22 additions & 10 deletions

File tree

.cargo/config.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,6 @@
55
# set by the user, and this is a good thing. If the user already set some
66
# LIBSQLITE3_FLAGS, he probably knows what he is doing.
77
LIBSQLITE3_FLAGS = "-DSQLITE_ENABLE_MATH_FUNCTIONS"
8+
9+
[build]
10+
rustflags = ["-C", "link-arg=-Wl,-rpath=$ORIGIN/lib"]

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ sqlparser = { version = "0.59.0", default-features = false, features = [
4949
"std",
5050
"visitor",
5151
] }
52+
odbc-sys = { version = "0.27", features = ["static"] }
5253
async-stream = "0.3"
5354
async-trait = "0.1.61"
5455
async-recursion = "1.0.0"

Dockerfile

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,22 @@ RUN apt-get update && \
77
if [ "$TARGETARCH" = "$BUILDARCH" ]; then \
88
rustup target list --installed > TARGET && \
99
echo gcc > LINKER && \
10-
apt-get install -y gcc libgcc-s1 cmake unixodbc-dev libodbc2 libltdl7 && \
11-
LIBDIR="/lib/*"; \
12-
USRLIBDIR="/usr/lib/*"; \
10+
apt-get install -y gcc libgcc-s1 cmake unixodbc-dev libltdl-dev pkg-config && \
11+
LIBMULTIARCH=$(gcc -print-multiarch); \
12+
LIBDIR="/lib/$LIBMULTIARCH"; \
13+
USRLIBDIR="/usr/lib/$LIBMULTIARCH"; \
1314
elif [ "$TARGETARCH" = "arm64" ]; then \
1415
echo aarch64-unknown-linux-gnu > TARGET && \
1516
echo aarch64-linux-gnu-gcc > LINKER && \
1617
dpkg --add-architecture arm64 && apt-get update && \
17-
apt-get install -y gcc-aarch64-linux-gnu libgcc-s1-arm64-cross unixodbc-dev:arm64 libodbc2:arm64 libltdl7:arm64 && \
18+
apt-get install -y gcc-aarch64-linux-gnu libgcc-s1-arm64-cross unixodbc-dev:arm64 libltdl-dev:arm64 && \
1819
LIBDIR="/lib/aarch64-linux-gnu"; \
1920
USRLIBDIR="/usr/lib/aarch64-linux-gnu"; \
2021
elif [ "$TARGETARCH" = "arm" ]; then \
2122
echo armv7-unknown-linux-gnueabihf > TARGET && \
2223
echo arm-linux-gnueabihf-gcc > LINKER && \
2324
dpkg --add-architecture armhf && apt-get update && \
24-
apt-get install -y gcc-arm-linux-gnueabihf libgcc-s1-armhf-cross cmake libclang1 clang unixodbc-dev:armhf libodbc2:armhf libltdl7:armhf && \
25+
apt-get install -y gcc-arm-linux-gnueabihf libgcc-s1-armhf-cross cmake libclang1 clang unixodbc-dev:armhf libltdl-dev:armhf && \
2526
cargo install --force --locked bindgen-cli && \
2627
SYSROOT=$(arm-linux-gnueabihf-gcc -print-sysroot); \
2728
echo "--sysroot=$SYSROOT -I$SYSROOT/usr/include -I$SYSROOT/usr/include/arm-linux-gnueabihf" > BINDGEN_EXTRA_CLANG_ARGS; \
@@ -31,13 +32,16 @@ RUN apt-get update && \
3132
echo "Unsupported cross compilation target: $TARGETARCH"; \
3233
exit 1; \
3334
fi && \
34-
cp $LIBDIR/libgcc_s.so.1 $USRLIBDIR/libodbc.so.2 $USRLIBDIR/libltdl.so.7 /opt/sqlpage-libs/ && \
35+
echo $USRLIBDIR > ODBC_LIBDIR && \
36+
cp $LIBDIR/libgcc_s.so.1 /opt/sqlpage-libs/ && \
3537
rustup target add $(cat TARGET) && \
3638
cargo init .
3739

3840
# Build dependencies (creates a layer that avoids recompiling dependencies on every build)
3941
COPY Cargo.toml Cargo.lock ./
4042
RUN BINDGEN_EXTRA_CLANG_ARGS=$(cat BINDGEN_EXTRA_CLANG_ARGS || true) \
43+
RS_ODBC_LINK_SEARCH=$(cat ODBC_LIBDIR) \
44+
PKG_CONFIG_ALL_STATIC=1 \
4145
cargo build \
4246
--target $(cat TARGET) \
4347
--config target.$(cat TARGET).linker='"'$(cat LINKER)'"' \
@@ -46,6 +50,8 @@ RUN BINDGEN_EXTRA_CLANG_ARGS=$(cat BINDGEN_EXTRA_CLANG_ARGS || true) \
4650
# Build the project
4751
COPY . .
4852
RUN touch src/main.rs && \
53+
RS_ODBC_LINK_SEARCH=$(cat ODBC_LIBDIR) \
54+
PKG_CONFIG_ALL_STATIC=1 \
4955
cargo build \
5056
--target $(cat TARGET) \
5157
--config target.$(cat TARGET).linker='"'$(cat LINKER)'"' \
@@ -62,7 +68,9 @@ ENV SQLPAGE_WEB_ROOT=/var/www
6268
ENV SQLPAGE_CONFIGURATION_DIRECTORY=/etc/sqlpage
6369
WORKDIR /var/www
6470
COPY --from=builder /usr/src/sqlpage/sqlpage.bin /usr/local/bin/sqlpage
65-
COPY --from=builder /opt/sqlpage-libs/* /lib/
71+
# Provide runtime helper libs next to the binary for rpath=$ORIGIN/lib
72+
RUN mkdir -p /usr/local/bin/lib
73+
COPY --from=builder /opt/sqlpage-libs/* /usr/local/bin/lib/
6674
USER sqlpage
6775
COPY --from=builder --chown=sqlpage:sqlpage /usr/src/sqlpage/sqlpage/sqlpage.db sqlpage/sqlpage.db
6876
EXPOSE 8080

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,12 @@ You can skip this section if you want to use one of the built-in database driver
190190
191191
SQLPage supports ODBC connections to connect to databases that don't have native drivers, such as Oracle, Snowflake, BigQuery, IBM DB2, and many others.
192192

193-
ODBC support requires an ODBC driver manager and appropriate database drivers to be installed on your system.
193+
On Linux, the SQLPage binary and Docker image now statically link against the `unixODBC` driver manager, so you generally do not need to install `unixodbc` on the host anymore. You still need to install the database-specific ODBC driver for the database you want to connect to.
194194

195195
#### Install ODBC
196196

197197
- On windows, it's installed by default.
198-
- On linux: `sudo apt-get install -y unixodbc odbcinst unixodbc-common libodbcinst2`
198+
- On linux, the driver manager is bundled with SQLPage; install only your database driver's package.
199199
- On mac: `brew install unixodbc`
200200

201201

configuration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ DATABASE_URL="Driver={Oracle ODBC Driver};Server=localhost:1521/XE;UID=hr;PWD=pa
105105
DATABASE_URL="Driver={SnowflakeDSIIDriver};Server=account.snowflakecomputing.com;Database=mydb;UID=user;PWD=password"
106106
```
107107

108-
ODBC drivers must be installed and configured on your system. On Linux, you typically need `unixodbc` and the appropriate database-specific ODBC driver.
108+
ODBC drivers must be installed and configured on your system. On Linux, the `unixODBC` driver manager is statically linked into the SQLPage binary, so you usually only need to install and configure the database-specific ODBC driver for your target database (for example Snowflake, Oracle, DuckDB...).
109109

110110
If the `database_password` configuration parameter is set, it will override any password specified in the `database_url`.
111111
It does not need to be percent-encoded.

0 commit comments

Comments
 (0)