Skip to content

Finish GraalVM native-image support#617

Open
ZacSweers wants to merge 31 commits into
facebook:mainfrom
ZacSweers:z/graalvm
Open

Finish GraalVM native-image support#617
ZacSweers wants to merge 31 commits into
facebook:mainfrom
ZacSweers:z/graalvm

Conversation

@ZacSweers

@ZacSweers ZacSweers commented May 25, 2026

Copy link
Copy Markdown
Contributor

This finishes up #584. The original commits are preserved. Closes #441.

Changes since #584

  • Rebased onto current main
  • Regenerated the reachability metadata for the current Kotlin compiler version and fixed build-time vs. runtime class initialization so the image builds and runs (was crashing on the newer kotlinc)
  • Default to the Serial GC instead of G1. G1 is unsupported by native-image on macOS and is Oracle GraalVM only; Serial fits ktfmt's short-lived runs. Opt into G1 with -Pktfmt.native.gc=G1
  • Use portable -march defaults (x86-64-v3, armv8-a). The old arm64 value was not a valid
    native-image target, and x86-64-v4 would crash on older/CI CPUs. Matches what GJF does.
  • Refactored the native-image build logic into a build-logic convention plugin
  • Rewrote the Java SVM substitution in Kotlin.
  • Dropped the unnecessary application plugin
  • A missing PGO profile now degrades to a non-PGO build instead of failing
  • Build the native image in its own CI job across linux/macOS/Windows with a smoke test that actually formats code so stale reflection metadata is caught early
  • Added a release job that builds and uploads a native binary per platform, modeled on GJF's release workflow
  • Added a README section on the native binary
  • native_smoke_test.sh and regenerate_native_metadata.sh helper scripts and a .gitattributes that marks the generated metadata so reviews collapse it
  • The cross-platform CI matrices and the release upload still need a real run to shake out, Windows-native especially.
  • PGO profiles in CI and release checksums are possible follow-ups

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label May 25, 2026
@ZacSweers

Copy link
Copy Markdown
Contributor Author

Sorry for the churn, doing a bit of leg work to make the repo build able in windows for this.

Comment thread core/build.gradle.kts
Comment thread gen_version_file.sh
@@ -1,50 +0,0 @@
#!/bin/sh

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need this file as it's used by our internal BUCK build.
I guess I could move it around so it's publicly hidden though...

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, yeah feel free to add back whatever you all need internally!

@meta-codesync

meta-codesync Bot commented May 28, 2026

Copy link
Copy Markdown

@hick209 has imported this pull request. If you are a Meta employee, you can view this in D106660271.

Comment thread core/build.gradle.kts
sgammon added a commit to sgammon/ktfmt that referenced this pull request Jun 4, 2026
Port the substantive native-image fixes from facebook#617 onto this
branch so the GraalVM binary builds and actually runs:

- Default `-march` to `compatibility` (the old `armv8.4-a+crypto+sve` is not a
  valid native-image AArch64 target and failed the build outright; `x86-64-v4`
  could also crash on older CPUs).
- Default `--gc` to `serial` and actually thread the `nativeGc` property through
  (was hardcoded to `--gc=G1`, which is unsupported by native-image on macOS and
  in GraalVM Community Edition). Opt into G1 via `-Pktfmt.native.gc=G1`.
- Align image flags with the tested set: add `--no-fallback` and
  `-H:-UseContainerSupport`; drop `--emit=build-report`, `--enable-sbom`,
  `-H:+UseCompressedReferences`, and `-H:+ReportDynamicAccess` (Oracle-EE-only or
  unnecessary), keeping the build portable to Community Edition.
- Regenerate `reachability-metadata.json` for the current Kotlin compiler and
  fold the proxy config into it, removing the now-redundant `proxy-config.json`
  (and its deprecation warning).
- Refresh `initialize-at-build-time.txt` / `initialize-at-run-time.txt` with the
  build-vs-runtime class-init fixes, and skip `#` comments when reading them.
- Add `native_smoke_test.sh` to verify the binary formats Kotlin (catches stale
  reachability metadata that a bare `--version` check would miss).

Verified: `:ktfmt:nativeCompile` + smoke test pass, and `:ktfmt:check`,
`:ktfmt:build`, `:lambda:build` are green.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: GraalVM artifacts

3 participants