native-build-tools icon indicating copy to clipboard operation
native-build-tools copied to clipboard

Add an artifact that downloads GraalVM and Native Image

Open lazar-mitrovic opened this issue 3 years ago • 20 comments

It can be a bit tricky for the end users to download and configure GraalVM. We can automate this process by providing an artifact that downloads and configures GraalVM and Native Image.

This artifact would be invoked by both Gradle and Maven plugins and would be configurable trough them (by specifying version, distribution, and/or even the URL) using extensions and configuration options.

Note that Windows support for this might be a bit harder (but certainly doable).

lazar-mitrovic avatar Jul 09 '21 11:07 lazar-mitrovic

Gradle already supports the notion of tool chains which this should support imo

graemerocher avatar Jul 09 '21 12:07 graemerocher

I totally agree that we should provide a more build-tool friendly API to fetch a GraalVM build with native image preinstalled. Gradle's toolchain mechanism is two fold:

  1. it can identify JDK installations in "well-known" places: from $PATH, from OS specific paths (/usr/lib/..) or from common tools which are able to install JDKs by themselves (e.g SDKMan!).
  2. if no suitable JDK is found, it tries to download a compatible version from AdoptOpenJDKhttps://docs.gradle.org/current/userguide/toolchains.html#sec:provisioning

For both, there is a problem with GraalVM:

In 1., the problem is that even if you identify a GraalVM toolchain, there's no guarantee that the native-image tool would be installed. There should be a way to get a GraalVM SDK with the native image tool preinstalled.

For 2., the automatic provisioning is optional in Gradle. It uses the AdoptOpenJDK API to do this, but Gradle can be configured to use a different base URL for the download service. It means that GraalVM could provide an AdoptOpenJDK compatible API service to supply JDKs. It should be relatively easy to do so. Note that the API itself has nothing specific to Adopt. It can be used by any other vendor. However, again, what would be downloaded would have to come with native-image preinstalled to be build tool friendly.

melix avatar Jul 12 '21 07:07 melix

Related: https://github.com/gradle/gradle/pull/18028

melix avatar Aug 13 '21 13:08 melix

Related: https://github.com/marketplace/actions/graalvm-native-image-toolchain

sbrannen avatar Aug 27 '21 15:08 sbrannen

Related Gradle Roadmap entry: https://github.com/gradle/build-tool-roadmap/issues/29

lazar-mitrovic avatar Jun 30 '22 15:06 lazar-mitrovic

It can be a bit tricky for the end users to download and configure GraalVM. We can automate this process by providing an artifact that downloads and configures GraalVM and Native Image.

Agreed. For Gradle, that's basically the only reason why we're using https://github.com/palantir/gradle-graal in https://github.com/oss-review-toolkit/ort rather than the Gradle plugin from this repo. I'm really hoping for https://github.com/gradle/gradle/pull/18028 to land soon (it's scheduled for Gradle 7.6 currently) to address the matter generically in Gradle itself.

sschuberth avatar Jul 27 '22 10:07 sschuberth

what is the problem here i simply use

  1. download graalvm-ce and extract
  2. install native-image installs it or returns true if installed
$GRAALVM/bin/gu install native-image

so ensure installed is not a problem ??

frank-dspeed avatar Aug 02 '22 05:08 frank-dspeed

what is the problem here i simply use

  1. download graalvm-ce and extract
  2. install native-image installs it or returns true if installed
$GRAALVM/bin/gu install native-image

so ensure installed is not a problem ??

@frank-dspeed, let me re-phrase your question: "What is the point of Gradle toolchain auto provisioning?". And the answer is: convenience - you checkout a git project and it just works. No need to point people to a readme file with step-by-step instructions. It just works. That is also why we use the Gradle wrapper instead of asking everyone to install Gradle.

cvmocanu avatar Aug 12 '22 14:08 cvmocanu

BTW, the lack of auto-provisioning is why I'm also using the https://github.com/palantir/gradle-graal plugin instead of this one.

Slightly off topic: kudos to the GraalVM team (and the team behind this plugin)! It's very nice to be able to build a statically linked native Java executable.

cvmocanu avatar Aug 12 '22 14:08 cvmocanu

@cvmocanu do i understand you correct your using nativ image gradle and graal with stock JDK?

frank-dspeed avatar Aug 14 '22 07:08 frank-dspeed

@frank-dspeed: I'm using the https://github.com/palantir/gradle-graal Gradle plugin. The plugin adds a nativeImage task which compiles to native binaries. I assume the Java source->bytecode compilation is done with a stock JDK, but I'm not sure if the plugin changes the Java compiler configuration or not.

As others said, that plugin does auto-provisioning (it downloads the specified version of GraalVM community to ~/.gradle/caches/com.palantir.graal/<version>, if it's not already downloaded locally). This is really convenient.

cvmocanu avatar Aug 14 '22 11:08 cvmocanu

I would love to use the official plugin (this one) though, instead of the palantir one.

cvmocanu avatar Aug 14 '22 11:08 cvmocanu

Just wondering, could the work on this topic for the Gradle plugin already start now that Gradle 7.6 RC1 added support for Java Toolchain downloads from arbitrary repositories, despite https://github.com/gradle/gradle/pull/18028 not being merged yet?

sschuberth avatar Nov 01 '22 11:11 sschuberth

i guess this gets solved as most of the graalvm parts get moved now to stock openjdk

frank-dspeed avatar Nov 01 '22 12:11 frank-dspeed

i guess this gets solved as most of the graalvm parts get moved now to stock openjdk

I'm not sure whether it's worth waiting for that to happen in a new JDK release. Releasing a new plugin version that's able to bootstrap GraalVM with native image support now seems to be the much lower hanging fruit.

sschuberth avatar Nov 23 '22 08:11 sschuberth

@sschuberth that was exactly what i did want to say 👍🏻 simply create a bash script and call it a day much faster written then java or use kotlin and not bash.

frank-dspeed avatar Nov 23 '22 09:11 frank-dspeed

simply create a bash script and call it a day much faster written then java or use kotlin and not bash.

That, however, is not what I wanted to say 😉 : Adding a few lines of Kotlin / Java code to implement a toolchain resolver plugin is quicker than waiting for a new JDK release, and much more generic / self-contained than requiring developers to run an external script.

sschuberth avatar Nov 23 '22 09:11 sschuberth

@sschuberth i make it even more generic i am working on a https://google.github.io/blockly-samples/plugins/block-dynamic-connection/test/ graalvm build tool ok it is not related to graalvm but it can build graalvm and that is in my view the most generic as it runs generic in my browser and is able to execute it directly else where or save it to a local file.

i simply connect my input processing and output blocks click run and call it a day and even get debug output if needed and so on. As also can edit on the fly if needed.

frank-dspeed avatar Nov 23 '22 09:11 frank-dspeed

GraalVM has become more easily accessible in the last couple of months (e.g., SDKMAN!, GitHub Actions, script-friendly download URLs). It is also integrated in the Foojay API, which can be used by Gradle's toolchain detection.

Given this issue hasn't been updated for more than a year, I'm going to close it for now. In case you still see a problem or potentials for improvement, please speak up :)

fniephaus avatar Oct 16 '23 13:10 fniephaus

This should really be reopened. None of the variants listed allow for automatic management of the GraalVM SDK, or insures that all developers use same version for a particular project.

cvmocanu avatar Oct 17 '23 07:10 cvmocanu