Repository navigation
test(ffi): the shared library exports the header's functions and nothing else - #164
Merged
Merged
Conversation
…ing else Before 1.0 the C library's export table is part of what a client can depend on, and nothing checked it. Measured: the Linux library exports the 62 functions of emberwave.h and nothing else; the macOS one also exports four Objective-C class registration names of raw-window-metal's RawWindowMetalLayer, which no client uses and which cannot be hidden by a linker flag (ld64 refuses an unexported list beside an exported one, and rustc passes its own). The static library has no export table to restrict. tests/exports.rs builds the shared library, reads its table with nm on macOS and Linux, and fails unless it is exactly the functions of the header, with the four Objective-C names per class as the one documented exception on macOS. The header is the list, so a new C function cannot be forgotten and a stray name cannot pass. Decision D73 records the measurement and what was not done. No client-visible change. Claude-Session: https://claude.ai/code/session_019fJGoCTvP5e7n599q3ZQ42
…n exactly A review of the export test found that its nested cargo build ignored `--target-dir`, a relative `CARGO_TARGET_DIR`, `--target` and custom profiles, and failed on a read-only source tree. The test now reads the target directory, the triple and the profile from its own path and passes them on, and the macOS exception is exactly the four names of RawWindowMetalLayer, so a class of another dependency fails it until someone has looked. The doc comment, the decision's reference (D69, not D70), the README's claim about Windows, which the test does not cover, and CONTRIBUTING's list of tests are corrected. Claude-Session: https://claude.ai/code/session_019fJGoCTvP5e7n599q3ZQ42
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What changes for a client of the shared library
Nothing: no function, name or behaviour changes, and the library is built as before. This adds a test and a decision record. To revert, drop
crates/emberwave-ffi/tests/exports.rs.Purpose
Before 1.0 the C library's export table is part of what a client can depend on, and nothing checked it.
What was measured (release 0.18.1, wgpu 30.0.2)
nm -D --defined-only, Debian 12 container, current stable Rust): the 62 functions ofinclude/emberwave.hand nothing else.nm -gU): the same 62, and 4 more:___CLASS_,___DROP_FLAG_OFFSET_,___IVAR_OFFSET_and___REGISTER_CLASS_followed byRawWindowMetalLayer, the Objective-C class registration of a class that raw-window-metal declares with objc2. No client uses them.Changes
crates/emberwave-ffi/tests/exports.rs(macOS and Linux; the file is empty on Windows, which has nonm): builds the shared library throughcargo build, finds it in cargo's own report, reads its table withnmand fails unless it is exactly the functions of the header. The header is the list, so a new C function cannot be forgotten and a stray name cannot pass. One documented exception on macOS: the Objective-C class names above.-unexported_symbols_listtogether with an exported list and rustc passes its own, so a linker flag cannot remove them; there is no standard tool to remove them after linking. A version script or.deffile for Linux and Windows would fight rustc's own, which already gives exactly the functions.Testing
cargo test -p emberwave-ffipasses on macOS; the new test passes on macOS and in a Linux container.#[unsafe(no_mangle)] pub extern "C" fn stray_symbol_for_the_test()added tosrc/lib.rsit reports that name as exported but not declared (checked, then removed).-D warningspass.