feat(core-runtime): configurable native library cache directory (#303) - #686
Merged
Merged
Conversation
Applications that keep config, cache and logs under a single directory can
now relocate the native library extraction path, which was hard-wired to
`%LOCALAPPDATA%\nucleus\native` / `~/.cache/nucleus/native`.
Two levers, tried in order, each falling through to the next when the
directory cannot be created or written to:
1. `-Dnucleus.native.cacheDir=<dir>`, which also works for libraries
loaded before any application code runs and bakes into the launcher
`.cfg` through the existing `jvmArgs`;
2. `NativeLibraryLoader.cacheDirectory`, for a path computed in `main()`;
3. the platform default.
The root is resolved once, at the first extraction, so every library of a
run shares it; a later assignment is ignored with a warning. The
content-addressed layout of #304 is kept under the chosen root.
Also fixes a pre-existing defect in the default: a set-but-empty or
relative `XDG_CACHE_HOME` / `LOCALAPPDATA` made the root relative, putting
native libraries under the process working directory.
Draft
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.
Closes #303.
Summary
The native library extraction path was hard-wired (
%LOCALAPPDATA%\nucleus\native,~/Library/Caches/nucleus/native,$XDG_CACHE_HOME/nucleus/native), so an application could not keep its config, cache, logs and native libraries under one user-defined directory.Two levers, tried in order, each falling through to the next when the directory cannot be created or written to:
-Dnucleus.native.cacheDir=<dir>(NativeLibraryLoader.CACHE_DIR_PROPERTY). Works for libraries loaded before any application code runs, and bakes into the launcher.cfgthrough the existingjvmArgswith no new plugin DSL.NativeLibraryLoader.cacheDirectory, for a path computed inmain().Notes:
Files.isWritable, which is advisory on Windows. The probe leaves nothing behind.<root>/<platform>/<fingerprint>/<library>) is kept under the chosen root, so two versions still never share a file.java.library.pathand extract nothing; this setting matters for fat JARs, IDE runs and distributions that bypass the plugin. Documented in the KDoc.Also fixes a pre-existing defect in the default path: a set-but-empty or relative
XDG_CACHE_HOME/LOCALAPPDATAmade the cache root relative, putting native libraries under the process working directory. Such values are now ignored, as the XDG spec requires.buildSrcapplies the same filter so its cache eviction keeps targeting the directory actually in use.Compatibility
No change for anyone who configures nothing. Verified by compiling the pre-change loader in a separate worktree and comparing both side by side against the real Rust
fs-watcherlibrary: withXDG_CACHE_HOMEunset or absolute, the resulting path, layout and timing are identical, with no extra directory creation and no probe. The only behaviour change is for the broken environments described above.Test plan
NativeLibraryLoaderTest, covering the candidate chain, malformed and relative values, the platform defaults with and without the environment variables, andcacheRootitself (configured root used and latched, unusable root falling through, default when nothing is configured)fs-watcherlibrary: resolution order, fall-through, path handling, latch-once, content-addressed layout, no probe or temp files left behind, re-run reuses the extraction without rewriting it, andjava.library.pathstill short-circuits extraction entirelyexamples:fs-watcher-smokerun through Gradle with the property set — the library extracts to the chosen directory and the watcher reports real inotify create/delete events; re-run without the property falls back to the defaultbuildNativeLinuxcache eviction still removes a stale library from the default cache:core-runtime:check(test, detekt, ktlint, apiCheck) and:buildSrc:build