go2nix-nix-plugin: build Rust core as cdylib alongside staticlib#131
Merged
Conversation
The extern "C" surface (resolve_go_packages_json, go2nix_free_string,
go2nix_api_level) is the entire plugin contract. Building as a
standalone libgo2nix_nix_plugin.so — no nix-expr/nix-store linkage —
lets non-cppnix evaluators dlopen it directly and skip the C++ shim.
The cppnix build path is unchanged: the C++ MODULE keeps linking
the staticlib. The cdylib is purely additive output.
Verify:
cargo build -p go2nix-nix-plugin
nm -D target/debug/libgo2nix_nix_plugin.so \
| grep -E ' T (resolve_go_packages_json|go2nix_free_string|go2nix_api_level)$'
All three symbols should appear with type T (exported text).
The Rust crate now emits both staticlib and cdylib. An unqualified `-lgo2nix_nix_plugin` lets the linker pick the .so, which isn't on the Nix plugin's runtime loader path — the eval-test failed with "libgo2nix_nix_plugin.so: cannot open shared object file". Pin the staticlib path explicitly so the C++ MODULE keeps statically embedding the Rust core regardless of cdylib presence.
ee88ff7 to
c234888
Compare
Benchmark Regression Check
Baseline: |
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.
Summary
cdylibto the Rust core'scrate-typeso the build emitslibgo2nix_nix_plugin.sonext to the existinglibgo2nix_nix_plugin.a.resolve_go_packages_json,go2nix_free_string,go2nix_api_level) and skip the C++ shim.Test plan
nix build .#go2nix-nix-pluginstill succeeds (cppnix MODULE links the staticlib unchanged).libgo2nix_nix_plugin.aandlibgo2nix_nix_plugin.soare produced.nm -D libgo2nix_nix_plugin.soshows all three exported symbols with typeT: