Skip to content

fix(rust): unit tests load DuckDB under Cargo 1.100's build-dir layout (#529) - #534

Merged
HananKavitzAmat merged 1 commit into
chunkhound:mainfrom
fstrasz:fix/529-duckdb-loader-path
Nov 17, 2026
Merged

HananKavitzAmat merged 1 commit into
chunkhound:mainfrom
fstrasz:fix/529-duckdb-loader-path

Conversation

@fstrasz

@fstrasz fstrasz commented Nov 16, 2026

Copy link
Copy Markdown
Contributor

Fixes #529.

Manifest change beyond the approved design: this PR adds a direct dependency, libduckdb-sys = "=1.10504.0", next to the duckdb pin. Cargo passes links metadata (DEP_DUCKDB_INCLUDE) only to immediate dependents (build scripts reference, "The links Manifest Key"), and chunkhound_native reached libduckdb-sys only through duckdb, so without it build.rs would never see the library directory. Its version has to match duckdb's; a mismatch fails to resolve, because only one package may declare links = "duckdb". The comment on the dependency says so.

Opened at the maintainers' request on #529 ("Go ahead and open the PR", comment), which is why it does not wait in the usual queue.

What changes

  • build.rs (new): implements the design agreed on rust-checks: make the unit test binary load DuckDB on Cargo 1.100 and later #529, in the order ofriw gave (comment). It reads DEP_DUCKDB_INCLUDE, removes any stale file of the library's name from OUT_DIR, hard-links the library there (or copies it if the link fails), and emits cargo:rustc-link-search=native=$OUT_DIR. Cargo then puts OUT_DIR on PATH / LD_LIBRARY_PATH / DYLD_FALLBACK_LIBRARY_PATH when it runs the test binary. It uses no symlinks. One comment at the top says why it exists, naming the Cargo 1.100 layout change and Cargo's "discouraged" caveat.
  • Cargo.toml: the direct libduckdb-sys dependency above, and one sentence in the duckdb note pointing cargo test lookup at build.rs.
  • Cargo.lock: records that dependency (no version changes).

When build.rs acts. It reads the env vars the same way libduckdb-sys does.

Configuration What build.rs does
Download mode (DUCKDB_DOWNLOAD_LIB 1/true, no DUCKDB_LIB_DIR, not static) Links or copies the library. If DEP_DUCKDB_INCLUDE or the library is missing, the build fails with a message naming what is missing.
Static (DUCKDB_STATIC set and not 0), including the air-gapped DUCKDB_LIB_DIR + DUCKDB_STATIC=1 path Nothing; no library is loaded at run time.
DUCKDB_LIB_DIR, dynamic, library in the published dir Links or copies it.
System / pkg-config / vcpkg DuckDB (the published include dir holds no library) Nothing; the system loader finds it.

Download mode always publishes the directory with the library in it, so a miss there is a wiring failure. In the last row the include dir legitimately holds no library, so a missing library is no error there; that is why "variable set, no library" fails only in download mode.

Known limits (accepted on #529): a test binary run directly, outside cargo test, gets no library path from Cargo; a build.build-dir moved outside the target dir puts OUT_DIR outside the paths Cargo forwards. Cargo calls relying on this behaviour discouraged; the comment in build.rs quotes that caveat and says why it is acceptable for a binary that only cargo test runs.

Acceptance criteria (#529)

Verified with rustc/cargo 1.100.0: Linux locally on a clean target/ (Docker rust:1.100), and all three OSes in a separate verification workflow on @stable (run 43900691097). That run has two legs per OS. The green legs build this branch and passed: ubuntu, macOS (cancelled on the first attempt, passed on the re-run) and Windows. The red legs build main at 84ab53d without this change and show the "Before" failures below; they end failed, which is why GitHub marks the run as a whole as failed.

Criterion Result
Clean target/, the full Rust unit test set runs: 140 ubuntu, 140 macOS, 135 Windows 140 / 140 / 135 passed. Before: Linux exit 127 (libduckdb.so: cannot open shared object file), macOS dyld: Library not loaded: @rpath/libduckdb.dylib (SIGABRT), Windows 0xc0000135 STATUS_DLL_NOT_FOUND.
No absolute build-machine path in the test binary None on any OS; output below.
Does not read the Cargo build-dir layout Only OUT_DIR and DEP_DUCKDB_INCLUDE are used. The test binary (build/chunkhound_native/2d2e2cf3…/out/) and the build script's OUT_DIR (build/chunkhound_native/98108ad4…/out/) are different directories, and the binary's location is never used.
Fresh clone, no manual step, no new required env var make rust-test on a fresh clone, with LD_LIBRARY_PATH unset.
make rust-check passes Passes (Linux); fmt and clippy --all-targets -D warnings clean on all three OSes in the verification run.
make dev and make dev-release pass tests/test_smoke.py Both build, install and pass the smoke file, 14/14 (Linux). The shipped extension keeps RPATH $ORIGIN:$ORIGIN/../chunkhound.libs and the wheel bundles the same libduckdb; maturin still resolves it from the download directory.
Air-gapped path (DUCKDB_LIB_DIR + DUCKDB_STATIC=1) build.rs emits no link-search line (cargo check -vv with an empty DUCKDB_LIB_DIR). The full static link was not run: it needs a libduckdb_static.a, which I did not have.
CI rust-checks green on @stable (1.100 or later) Green on all three OSes in the verification run; this PR's own CI runs @stable too while #527 is open.

The mechanism ran as designed (Linux, cargo test -vv): the build script printed cargo:rustc-link-search=native=…/target/debug/build/chunkhound_native/98108ad474474b3f/out, and ls -li shows its libduckdb.so and the one in target/duckdb-download/x86_64-unknown-linux-gnu/1.5.4/ sharing one inode (link count 2): a hard link, no copy.

Binary inspection (after this change)

Linux, readelf -d <test binary> | grep -E 'RPATH|RUNPATH|NEEDED' (no RPATH or RUNPATH, same as before):

 0x0000000000000001 (NEEDED)             Shared library: [libduckdb.so]
 0x0000000000000001 (NEEDED)             Shared library: [libgcc_s.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libm.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]
 0x0000000000000001 (NEEDED)             Shared library: [ld-linux-x86-64.so.2]

macOS, otool -l <test binary> | grep -A2 LC_RPATH and the DuckDB entry of otool -L:

(no LC_RPATH)
	@rpath/libduckdb.dylib (compatibility version 0.0.0, current version 0.0.0)

Windows, dumpbin /dependents <test binary>.exe:

  Image has the following dependencies:

    kernel32.dll
    bcryptprimitives.dll
    api-ms-win-core-synch-l1-2-0.dll
    ws2_32.dll
    ntdll.dll
    bcrypt.dll
    advapi32.dll
    userenv.dll
    duckdb.dll
    VCRUNTIME140.dll
    api-ms-win-crt-string-l1-1-0.dll
    api-ms-win-crt-math-l1-1-0.dll
    api-ms-win-crt-runtime-l1-1-0.dll
    api-ms-win-crt-stdio-l1-1-0.dll
    api-ms-win-crt-locale-l1-1-0.dll
    api-ms-win-crt-heap-l1-1-0.dll

Before this change, the macOS dyld search list already included another build script's OUT_DIR (target/debug/build/ring/<hash>/out/), which is the path Cargo 1.100 forwards and this change uses.

Overlap with open PRs

🤖 Generated with Claude Code, reviewed by FStrasz

chunkhound#529)

Since Cargo 1.100 the new build-dir layout is always on, and the runtime
library path Cargo sets for `cargo test` no longer includes the
<profile>/deps directory that libduckdb-sys copies the downloaded library
into. The unit-test binary failed to start on every OS (Linux exit 127,
macOS dyld abort, Windows 0xc0000135).

build.rs now reads DEP_DUCKDB_INCLUDE, hard-links the library into its own
OUT_DIR (copying where the filesystem refuses links) and declares that
directory with rustc-link-search. Cargo puts such a directory on PATH,
LD_LIBRARY_PATH or DYLD_FALLBACK_LIBRARY_PATH for every binary it runs, so
the test binary carries no build-machine path and nothing depends on the
build-dir layout. Download mode with the directory or library missing fails
the build; static builds and system DuckDB are left alone.

Cargo passes `links` metadata to immediate dependents only, so the crate
now depends on libduckdb-sys directly, pinned with duckdb.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@ofriw
ofriw self-requested a review November 17, 2026 07:21
@HananKavitzAmat

Copy link
Copy Markdown
Collaborator

Looks good to me!

@HananKavitzAmat
HananKavitzAmat self-requested a review November 17, 2026 09:19
@HananKavitzAmat
HananKavitzAmat added this pull request to the merge queue Nov 17, 2026
Merged via the queue into chunkhound:main with commit 96a604c Nov 17, 2026
25 checks passed
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 17, 2026
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 17, 2026
Brings in chunkhound#510, chunkhound#504 and chunkhound#534. No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 17, 2026
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 17, 2026
Brings in the 21 PRs merged to main since this branch was cut (chunkhound#469 through chunkhound#534). No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 17, 2026
Brings in chunkhound#534. No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 17, 2026
Brings in the 21 PRs merged to main since this branch was cut (chunkhound#469 through chunkhound#534). No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 17, 2026
munjikesh added a commit to munjikesh/chunkhound that referenced this pull request Nov 17, 2026
Picks up the rust-checks fix (chunkhound#534).

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 17, 2026
Brings in chunkhound#521, chunkhound#510, chunkhound#504 and chunkhound#534 on top of the earlier merge of main. realtime/startup.py conflicted only in its imports: chunkhound#504 adds watchdog_event_filter to the .events import and this PR adds the .inotify_overflow import; both are kept. chunkhound#504's event_filter reaches this PR's InotifyObserver through the same schedule() call.

One semantic conflict, no textual one: chunkhound#504's test_watches_are_scheduled_without_read_only_events faked _create_watchdog_observer with no arguments and unpacked _bootstrap_fs_monitor as a tuple. This PR changed both (the factory takes on_overflow and returns the observer with its overflow detection; the bootstrap returns WatchdogBootstrap), so the test now fakes and reads them that way, as this PR's own inotify tests do. Its assertions are unchanged.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 17, 2026
Brings in the 24 commits merged to main since this branch was last updated, including chunkhound#534's rust-checks fix. No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 17, 2026
Brings in the 12 commits merged to main since this branch was last updated, including chunkhound#534's rust-checks fix. No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 17, 2026
Brings in the 10 commits merged to main since this branch was last updated, including chunkhound#534's rust-checks fix. No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 17, 2026
Brings in the 36 commits merged to main since this branch was last updated, including chunkhound#534's rust-checks fix. No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 17, 2026
Brings in the 24 commits merged to main since this branch was last updated, including chunkhound#534's rust-checks fix. No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 17, 2026
Brings in the 24 commits merged to main since this branch was last updated, including chunkhound#534's rust-checks fix. No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 17, 2026
Brings in the 14 commits merged to main since this branch was last updated, including chunkhound#534's rust-checks fix. No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
fstrasz added a commit to fstrasz/chunkhound that referenced this pull request Nov 17, 2026
Brings in the 13 commits merged to main since this branch was last updated, including chunkhound#534's rust-checks fix. No conflicts.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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.

rust-checks: make the unit test binary load DuckDB on Cargo 1.100 and later

2 participants