Skip to content

Conversation

lovasoa
Copy link
Collaborator

@lovasoa lovasoa commented Sep 29, 2025

Statically link unixODBC and configure rpath to simplify distribution and enable placing ODBC drivers in a sqlpage/ subdirectory.

This change embeds the unixODBC driver manager directly into the SQLPage binary, removing the need for separate installation on target systems. The updated rpath allows database-specific ODBC drivers to be placed alongside the SQLPage executable in a sqlpage/ directory, streamlining self-contained application packaging.


Open in Cursor Open in Web

Copy link

cursor bot commented Sep 29, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@lovasoa
Copy link
Collaborator Author

lovasoa commented Sep 29, 2025

@cursoragent

#15 121.7    Compiling darling v0.21.3
#15 123.0    Compiling dirs v6.0.0
#15 123.0 error: could not find native static library `odbc`, perhaps an -L flag is missing?
#15 123.0 
#15 123.0 error: could not compile `odbc-sys` (lib) due to 1 previous error
#15 123.0 warning: build failed, waiting for other jobs to finish...
#15 ERROR: process "/bin/sh -c BINDGEN_EXTRA_CLANG_ARGS=$(cat BINDGEN_EXTRA_CLANG_ARGS || true)     RS_ODBC_LINK_SEARCH=$(cat ODBC_LIBDIR)     PKG_CONFIG_ALL_STATIC=1     cargo build      --target $(cat TARGET)      --config target.$(cat TARGET).linker='\"'$(cat LINKER)'\"'      --profile superoptimized" did not complete successfully: exit code: 101
------
 > [builder 5/7] RUN BINDGEN_EXTRA_CLANG_ARGS=$(cat BINDGEN_EXTRA_CLANG_ARGS || true)     RS_ODBC_LINK_SEARCH=$(cat ODBC_LIBDIR)     PKG_CONFIG_ALL_STATIC=1     cargo build      --target $(cat TARGET)      --config target.$(cat TARGET).linker='"'$(cat LINKER)'"'      --profile superoptimized:
120.0    Compiling actix-server v2.6.0
120.5    Compiling ecdsa v0.16.9
121.3    Compiling dlv-list v0.5.2
 sqlx-rt-oldapi v0.6.49-beta.4
121.7    Compiling darling v0.21.3
 dirs v6.0.0
123.0 error: could not find native static library `odbc`, perhaps an -L flag is missing?
123.0 
123.0 error: could not compile `odbc-sys` (lib) due to 1 previous error
123.0 warning: build failed, waiting for other jobs to finish...
------
WARNING: No output specified with docker-container driver. Build result will only remain in the build cache. To push result image into registry use --push or to load image into docker use --load
Dockerfile:42
--------------------
  41 |     COPY Cargo.toml Cargo.lock ./
  42 | >>> 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 \
  45 | >>>     cargo build \
  46 | >>>      --target $(cat TARGET) \
  47 | >>>      --config target.$(cat TARGET).linker='"'$(cat LINKER)'"' \
  48 | >>>      --profile superoptimized
  49 |     
--------------------
ERROR: failed to build: failed to solve: process "/bin/sh -c BINDGEN_EXTRA_CLANG_ARGS=$(cat BINDGEN_EXTRA_CLANG_ARGS || true)     RS_ODBC_LINK_SEARCH=$(cat ODBC_LIBDIR)     PKG_CONFIG_ALL_STATIC=1     cargo build      --target $(cat TARGET)      --config target.$(cat TARGET).linker='\"'$(cat LINKER)'\"'      --profile superoptimized" did not complete successfully: exit code: 101
buildx failed with: ERROR: failed to build: failed to solve: process "/bin/sh -c BINDGEN_EXTRA_CLANG_ARGS=$(cat BINDGEN_EXTRA_CLANG_ARGS || true)     RS_ODBC_LINK_SEARCH=$(cat ODBC_LIBDIR)     PKG_CONFIG_ALL_STATIC=1     cargo build      --target $(cat TARGET)      --config target.$(cat TARGET).linker='\"'$(cat LINKER)'\"'      --profile superoptimized" did not complete successfully: exit code: 101

Make sure to run all ci tests locally before pushing changes

Copy link

cursor bot commented Sep 29, 2025

Working on it! I'll start making changes in this branch.

Open in Cursor Open in Web

@lovasoa
Copy link
Collaborator Author

lovasoa commented Sep 29, 2025

@cursoragent

error: failed to run custom build command for `odbc-sys v0.27.0`
note: To improve backtraces for build dependencies, set the CARGO_PROFILE_TEST_BUILD_OVERRIDE_DEBUG=true environment variable to enable debug information generation.

Caused by:
  process didn't exit successfully: `D:\a\SQLPage\SQLPage\target\debug\build\odbc-sys-1d67932078962fc9\build-script-build` (exit code: 101)
  --- stderr

  thread 'main' panicked at C:\Users\runneradmin\.cargo\registry\src\index.crates.io-1949cf8c6b5b557f\odbc-sys-0.27.0\build.rs:6:13:
  odbc-sys does not currently support static linking on windows
  stack backtrace:
     0: std::panicking::begin_panic_handler
               at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library\std\src\panicking.rs:697
     1: core::panicking::panic_fmt
               at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library\core\src\panicking.rs:75
     2: std::rt::lang_start
     3: std::rt::lang_start
     4: std::rt::lang_start
     5: std::rt::lang_start
     6: std::rt::lang_start_internal::closure$0
               at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library\std\src\rt.rs:175
     7: std::panicking::catch_unwind::do_call
               at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library\std\src\panicking.rs:589
     8: std::panicking::catch_unwind
               at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library\std\src\panicking.rs:552
     9: std::panic::catch_unwind
               at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library\std\src\panic.rs:359
    10: std::rt::lang_start_internal
               at /rustc/29483883eed69d5fb4db01964cdf2af4d86e9cb2/library\std\src\rt.rs:171
    11: std::rt::lang_start
    12: main
    13: invoke_main
               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:78
    14: __scrt_common_main_seh
               at D:\a\_work\1\s\src\vctools\crt\vcstartup\src\startup\exe_common.inl:288
    15: BaseThreadInitThunk
    16: RtlUserThreadStart
  note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
warning: build failed, waiting for other jobs to finish...
Process completed with exit code 1.

Copy link

cursor bot commented Sep 29, 2025

I refactored the build process to statically link unixODBC from source, enhancing portability and reducing runtime dependencies. This involved modifying the Dockerfile to build unixODBC and updating Cargo.toml to conditionally enable static linking for odbc-sys on Unix-like systems. Additionally, I configured RPATHs in .cargo/config.toml for better dependency discovery.

  • I implemented a custom build of unixODBC (version 2.3.12) from source within the Dockerfile. This build is configured for static linking (--disable-shared --enable-static) and installed to /opt/unixodbc.
    • I removed unixodbc-dev and libltdl-dev from apt-get install as they are no longer needed, and added make, autoconf, automake, libtool, curl, and ca-certificates as build dependencies.
    • I updated ODBC_LIBDIR to point to /opt/unixodbc/lib and removed the PKG_CONFIG_ALL_STATIC=1 environment variable.
  • In Cargo.toml, I refactored the odbc-sys dependency to use target-specific configurations.
    • I moved odbc-sys = { version = "0.27", features = ["static"] } into a [target.'cfg(all(unix, not(target_os = "macos")))'.dependencies] section to enable static linking only for Linux/Unix targets.
    • I added odbc-sys = { version = "0.27" } to a [target.'cfg(any(target_os = "windows", target_os = "macos"))'.dependencies] section for dynamic linking on Windows and macOS.
  • In .cargo/config.toml, I added rustflags for specific Linux targets (x86_64-unknown-linux-gnu, aarch64-unknown-linux-gnu, armv7-unknown-linux-gnueabihf).
    • These flags set the runtime library search path (-Wl,-rpath=$ORIGIN/sqlpage:$ORIGIN/lib) to ensure the application can locate its shared libraries at runtime.

Open in Cursor Open in Web

Learn more about Cursor Agents

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants