Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GraalVM native-image Maven build support #728

Closed
wants to merge 4 commits into from

Conversation

perezd
Copy link
Contributor

@perezd perezd commented Jan 24, 2022

Closes #358.

This appears to work as expected. I have a weird case I'm not really sure how to address (the need to specify -Djava.home during execution), but otherwise, this produces a fully static binary that is very fast and works.

To execute the build, you run the following command:

mvn -Pnative -DskipTests package

copybara-service bot pushed a commit that referenced this pull request Jan 27, 2022
as a concession to Android `R` classes.

DO NOT SUBMIT

FUTURE_COPYBARA_INTEGRATE_REVIEW=#728 from perezd:native-image 9b64d07
PiperOrigin-RevId: 424376371
@nhoughto
Copy link

nhoughto commented Jan 29, 2022

The simplest (only?) workaround for the java.home thing would be to add a new wrapping native-only class exposing a main(String[] args) entry method, that just does a dumb System.setProperty(..) and then calls the normal main entry method, then change the maven config to use that wrapper Main class when building the native image. Minimal change and would then work straight out of the box, it would be nice if you could specify some runtime args at native image compile time but you can't it seems. For example even heap arguments (-Xmx and friends) can't be defaulted which can be a pain.

@cushon
Copy link
Collaborator

cushon commented Jan 29, 2022

For java.home the code doesn't actually rely on the value at runtime, so we can also use --initialize-at-build-time= as a workaround to prevent the crash: oracle/graal#4254 (reply in thread)

For example even heap arguments (-Xmx and friends) can't be defaulted which can be a pain.

I just recently learned that as of 20.0 there's are flags like -R:MaxHeapSize that allow sizing the heap at image build time: https://www.graalvm.org/22.0/reference-manual/native-image/MemoryManagement/#java-heap-size

@liuchong
Copy link

Great job! 👍

@dlicois dlicois mentioned this pull request Dec 9, 2022
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.

Add native image builds
4 participants