Skip to content

feat(mkLogosModule): auto-stage external_libraries in dev shell#98

Open
danisharora099 wants to merge 1 commit into
logos-co:masterfrom
danisharora099:feat/devshell-stage-external-libs
Open

feat(mkLogosModule): auto-stage external_libraries in dev shell#98
danisharora099 wants to merge 1 commit into
logos-co:masterfrom
danisharora099:feat/devshell-stage-external-libs

Conversation

@danisharora099
Copy link
Copy Markdown

@danisharora099 danisharora099 commented May 20, 2026

Closes #97.

What

When the consumer passes a non-empty externalLibInputs, mkLogosModule's dev shell now:

  1. Builds the external libraries (reusing the same resolveExtInput + mkExternalLib.buildExternalLibs path the package outputs already use).
  2. Symlinks each one's lib/* and include/*.h into ./lib so the module's existing CMakeLists.txt (find_library(... PATHS lib NO_DEFAULT_PATH)) resolves it outside the Nix sandbox.
  3. Exports DYLD_LIBRARY_PATH (Darwin) / LD_LIBRARY_PATH (Linux) + CMAKE_LIBRARY_PATH + CMAKE_INCLUDE_PATH.
  4. Exports CMAKE_EXPORT_COMPILE_COMMANDS=ON for clangd.

Why

Every universal C++ module wrapping a Rust cdylib (or any external lib declared in metadata.json#nix.external_libraries) currently writes the same dev-shell override to make nix develop work with clangd / IDEs / plain cmake. The most recent example is eth-lez-atomic-swaps PR #26. After this lands, that ~40-line block disappears downstream.

Full rationale + design questions in #97.

Backward compatibility

  • Modules without external_libraries: zero change (the new behaviour is gated on the list being non-empty).
  • Modules that already override devShells.<system>.default: keep working.
  • nix build derivations: untouched. Only nix develop is affected.

Verification

  • nix flake check passes on aarch64-darwin (all 4 checks, including devShells.aarch64-darwin.default).
  • One file changed, +62 / −2.

Notes for review

A few small calls in here I'd like a second opinion on (also in #97):

  • Symlink vs copy when staging into ./lib. Using symlinks here so a cdylib rebuild is picked up on the next shell entry; the in-sandbox copyExternalLibsToLib uses cp. Worth surfacing.
  • Header glob is *.h only — happy to extend to *.hpp / extension-less outputs if anyone needs it.
  • "Auto whenever externalLibInputs is non-empty" vs an explicit autoStageExternalLibs toggle. I went with implicit.
  • resolveExtInput is duplicated locally inside devShells rather than hoisted, to keep the blast radius small. Happy to lift it as a follow-up if reviewers prefer.

When the consumer passes non-empty externalLibInputs, resolve them
the same way the package outputs do (via resolveExtInput +
mkExternalLib.buildExternalLibs) and emit a shellHook that:

- symlinks each resolved cdylib + headers into ./lib so the module's
  CMakeLists.txt find_library(... PATHS lib NO_DEFAULT_PATH) resolves
  outside the Nix sandbox (clangd, IDEs, raw cmake)
- exports DYLD_LIBRARY_PATH / LD_LIBRARY_PATH / CMAKE_LIBRARY_PATH /
  CMAKE_INCLUDE_PATH for runtime + cmake search
- exports CMAKE_EXPORT_COMPILE_COMMANDS=ON so editor tooling Just Works

Gated on extLibValues != [] so modules without external_libraries see
no change. Removes the need for downstream modules to hand-roll a
devShells.<system>.default override.

Verified: nix flake check passes on aarch64-darwin.
Amp-Thread-ID: https://ampcode.com/threads/T-019e45fb-5eb1-74ea-8e25-612703031f87
Co-authored-by: Amp <amp@ampcode.com>
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.

Auto-stage external_libraries in mkLogosModule's dev shell

1 participant