Skip to content

go2nix-nix-plugin: build Rust core as cdylib alongside staticlib#131

Merged
zimbatm merged 2 commits into
mainfrom
zimbatm/cdylib-output
May 7, 2026
Merged

go2nix-nix-plugin: build Rust core as cdylib alongside staticlib#131
zimbatm merged 2 commits into
mainfrom
zimbatm/cdylib-output

Conversation

@zimbatm

@zimbatm zimbatm commented May 7, 2026

Copy link
Copy Markdown
Member

Summary

  • Adds cdylib to the Rust core's crate-type so the build emits libgo2nix_nix_plugin.so next to the existing libgo2nix_nix_plugin.a.
  • The cppnix path is unchanged: the C++ MODULE keeps linking the staticlib. The cdylib is purely additive.
  • Lets non-cppnix evaluators dlopen the resolver directly (its entire surface is the prefixed extern "C" trio: resolve_go_packages_json, go2nix_free_string, go2nix_api_level) and skip the C++ shim.

Test plan

  • nix build .#go2nix-nix-plugin still succeeds (cppnix MODULE links the staticlib unchanged).
  • Built the core derivation in isolation; both libgo2nix_nix_plugin.a and libgo2nix_nix_plugin.so are produced.
  • nm -D libgo2nix_nix_plugin.so shows all three exported symbols with type T:
    T go2nix_api_level
    T go2nix_free_string
    T resolve_go_packages_json
    

zimbatm added 2 commits May 7, 2026 13:39
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.
@zimbatm zimbatm force-pushed the zimbatm/cdylib-output branch from ee88ff7 to c234888 Compare May 7, 2026 11:40
@github-actions

github-actions Bot commented May 7, 2026

Copy link
Copy Markdown

Benchmark Regression Check

Scenario Tool Base (s) Current (s) Change Drvs (base) Drvs (curr) Status
no_change nix-ca-nocgo 0.67 0.68 +1.9% 0 0 ok
no_change nix-nocgo 0.67 0.68 +1.5% 0 0 ok
leaf-private nix-ca-nocgo 1.78 1.78 +0.0% 2 2 ok
leaf-private nix-nocgo 1.40 1.47 +4.5% 2 2 ok
mid-private nix-ca-nocgo 1.88 1.83 -2.7% 2 2 ok
mid-private nix-nocgo 1.49 1.52 +2.0% 4 4 ok
deep-private nix-ca-nocgo 2.12 2.04 -3.5% 3 3 ok
deep-private nix-nocgo 1.80 1.72 -4.2% 8 8 ok

Baseline: main | Current: 3f9d13b0cb603a0b5441c6d4271cd38940e76e1f

@zimbatm zimbatm added this pull request to the merge queue May 7, 2026
Merged via the queue into main with commit 6c2df42 May 7, 2026
3 checks passed
@zimbatm zimbatm deleted the zimbatm/cdylib-output branch May 7, 2026 12:22
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.

1 participant