Skip to content

Fix GraalVM native image baking in build-time cache directory#60

Merged
hlship merged 1 commit intohlship:mainfrom
r0man:native-image-fixes
Feb 26, 2026
Merged

Fix GraalVM native image baking in build-time cache directory#60
hlship merged 1 commit intohlship:mainfrom
r0man:native-image-fixes

Conversation

@r0man
Copy link
Contributor

@r0man r0man commented Feb 17, 2026

Summary

  • default-dispatch-options was a def, so fs/xdg-cache-home and System/getenv were evaluated at class initialization time
  • With GraalVM's InitClojureClasses feature (from clj-easy/graal-build-time), all Clojure classes are initialized during the native-image build, capturing the builder's home directory into the binary
  • On GitHub Actions this bakes /home/runner/.cache/net.lewisship.cli-tools as the cache path, causing every user to get AccessDeniedException: /home/runner at runtime

Fix

Change def to defn- so the cache directory is resolved at each dispatch call using the actual user's environment, not the build-time environment.

Reproduction

  1. Build a native image of any cli-tools based CLI on GitHub Actions (or any CI with a different home directory)
  2. Run the binary on a local machine
  3. Observe AccessDeniedException for the CI home directory

default-dispatch-options was a `def`, meaning its body—including
`fs/xdg-cache-home` and `System/getenv`—was evaluated at class
initialization time. With GraalVM's InitClojureClasses feature,
this happens during the native-image build, capturing the builder's
home directory (e.g. /home/runner on GitHub Actions) into the binary.

At runtime every user hits AccessDeniedException trying to create
the baked-in path.

Changing from `def` to `defn-` defers evaluation to each `dispatch`
call, so the cache directory is resolved using the actual user's
environment.
@r0man r0man requested a review from hlship as a code owner February 17, 2026 11:41
@hlship hlship added this to the 0.16.0 milestone Feb 25, 2026
@hlship hlship added the bug Something isn't working label Feb 25, 2026
@hlship hlship merged commit 0c4be70 into hlship:main Feb 26, 2026
1 check passed
@hlship
Copy link
Owner

hlship commented Feb 26, 2026

Thanks for the patch!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants