Skip to content

Commit

Permalink
Update to official GraalVM tooling (#8613)
Browse files Browse the repository at this point in the history
  • Loading branch information
yschimke authored Dec 21, 2024
1 parent 38bab5d commit fb22f49
Show file tree
Hide file tree
Showing 27 changed files with 167 additions and 635 deletions.
27 changes: 21 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,15 @@ jobs:
distribution: 'zulu'
java-version: 17

- uses: graalvm/setup-graalvm@v1
with:
distribution: 'graalvm'
java-version: 21
github-token: ${{ secrets.GITHUB_TOKEN }}
cache: 'gradle'
native-image-job-reports: true
components: 'native-image'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

Expand Down Expand Up @@ -446,20 +455,26 @@ jobs:
distribution: 'zulu'
java-version: 17

- uses: graalvm/setup-graalvm@v1
with:
distribution: 'graalvm'
java-version: 21
github-token: ${{ secrets.GITHUB_TOKEN }}
cache: 'gradle'
native-image-job-reports: true
components: 'native-image'

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Build okcurl
run: ./gradlew okcurl:nativeImage
run: ./gradlew okcurl:nativeBuild

- name: Setup Gradle
uses: gradle/actions/setup-gradle@v4

- name: Build ConsoleLauncher
run: ./gradlew -PgraalBuild=true native-image-tests:nativeImage

- name: Run Checks
run: ./native-image-tests/build/graal/ConsoleLauncher
- name: Run native-image tests
run: ./gradlew -PgraalBuild=true native-image-tests:nativeTest

testandroid:
runs-on: ubuntu-latest
Expand Down
15 changes: 11 additions & 4 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ buildscript {
classpath(libs.gradlePlugin.kotlinSerialization)
classpath(libs.gradlePlugin.androidJunit5)
classpath(libs.gradlePlugin.android)
classpath(libs.gradlePlugin.graal)
classpath(libs.gradlePlugin.bnd)
classpath(libs.gradlePlugin.shadow)
classpath(libs.gradlePlugin.animalsniffer)
Expand All @@ -28,6 +27,7 @@ buildscript {
classpath(libs.gradlePlugin.mavenPublish)
classpath(libs.gradlePlugin.binaryCompatibilityValidator)
classpath(libs.gradlePlugin.mavenSympathy)
classpath(libs.gradlePlugin.graalvmBuildTools)
}

repositories {
Expand Down Expand Up @@ -143,9 +143,16 @@ subprojects {
signature(rootProject.libs.codehaus.signature.java18) { artifact { type = "signature" } }
}

val javaVersionSetting = when (project.name) {
"okcurl", "native-image-tests" -> "11"
else -> "1.8"
}
val projectJvmTarget = JvmTarget.fromTarget(javaVersionSetting)
val projectJavaVersion = JavaVersion.toVersion(javaVersionSetting)

tasks.withType<KotlinCompile> {
compilerOptions {
jvmTarget.set(JvmTarget.JVM_1_8)
jvmTarget.set(projectJvmTarget)
freeCompilerArgs = listOf(
"-Xjvm-default=all",
)
Expand Down Expand Up @@ -214,8 +221,8 @@ subprojects {
}

tasks.withType<JavaCompile> {
sourceCompatibility = JavaVersion.VERSION_1_8.toString()
targetCompatibility = JavaVersion.VERSION_1_8.toString()
sourceCompatibility = projectJavaVersion.toString()
targetCompatibility = projectJavaVersion.toString()
}
}

Expand Down
7 changes: 4 additions & 3 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ checkStyle = "10.20.2"
com-squareup-moshi = "1.15.2"
com-squareup-okio = "3.9.1"
de-mannodermaus-junit5 = "1.6.0"
graalvm = "22.3.2"
graalvm = "24.1.1"
kotlinx-serialization = "1.7.3"
ksp = "2.1.0-1.0.29"
mockserverClient = "5.15.0"
Expand All @@ -32,21 +32,22 @@ bouncycastle-bcprov = { module = "org.bouncycastle:bcprov-jdk15to18", version.re
bouncycastle-bctls = { module = "org.bouncycastle:bctls-jdk15to18", version.ref = "org-bouncycastle" }
brotli-dec = "org.brotli:dec:0.1.2"
checkStyle = { module = "com.puppycrawl.tools:checkstyle", version.ref = "checkStyle" }
clikt = "com.github.ajalt.clikt:clikt:4.4.0"
clikt = "com.github.ajalt.clikt:clikt:5.0.2"
codehaus-signature-java18 = "org.codehaus.mojo.signature:java18:1.0"
conscrypt-android = { module = "org.conscrypt:conscrypt-android", version.ref = "org-conscrypt" }
conscrypt-openjdk = { module = "org.conscrypt:conscrypt-openjdk-uber", version.ref = "org-conscrypt" }
converter-moshi = { module = "com.squareup.retrofit2:converter-moshi", version.ref = "retrofit" }
eclipseOsgi = "org.eclipse.platform:org.eclipse.osgi:3.22.0"
findbugs-jsr305 = "com.google.code.findbugs:jsr305:3.0.2"
graal-sdk = { module = "org.graalvm.sdk:graal-sdk", version.ref = "graalvm" }
gradlePlugin-android = "com.android.tools.build:gradle:8.7.3"
gradlePlugin-androidJunit5 = "de.mannodermaus.gradle.plugins:android-junit5:1.11.2.0"
gradlePlugin-animalsniffer = "ru.vyarus:gradle-animalsniffer-plugin:1.7.2"
gradlePlugin-binaryCompatibilityValidator = "org.jetbrains.kotlinx.binary-compatibility-validator:org.jetbrains.kotlinx.binary-compatibility-validator.gradle.plugin:0.16.3"
gradlePlugin-bnd = { module = "biz.aQute.bnd:biz.aQute.bnd.gradle", version.ref = "biz-aQute-bnd" }
gradlePlugin-dokka = "org.jetbrains.dokka:dokka-gradle-plugin:1.9.20"
gradlePlugin-errorprone = "net.ltgt.gradle:gradle-errorprone-plugin:4.1.0"
gradlePlugin-graal = "com.palantir.graal:gradle-graal:0.12.0"
gradlePlugin-graalvmBuildTools = "org.graalvm.buildtools.native:org.graalvm.buildtools.native.gradle.plugin:0.10.4"
gradlePlugin-kotlin = { module = "org.jetbrains.kotlin:kotlin-gradle-plugin", version.ref = "org-jetbrains-kotlin" }
gradlePlugin-kotlinSerialization = { module = "org.jetbrains.kotlin:kotlin-serialization", version.ref = "org-jetbrains-kotlin" }
gradlePlugin-mavenPublish = "com.vanniktech:gradle-maven-publish-plugin:0.30.0"
Expand Down
11 changes: 1 addition & 10 deletions native-image-tests/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,12 @@ Native Image Tests

This executes OkHttp's test suite inside a Graalvm image.

Build the Native Image
----------------------

Compile the classes and metadata into a Graalvm native image.

```
./gradlew --info native-image-tests:nativeImage
```

Execute
-------

The native image runs JUnit 5 tests in the project.

```
./native-image-tests/build/graal/ConsoleLauncher
./gradlew --info native-image-tests:nativeTest
```

60 changes: 33 additions & 27 deletions native-image-tests/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,10 +1,26 @@
import org.apache.tools.ant.taskdefs.condition.Os

plugins {
id("com.palantir.graal")
id("org.graalvm.buildtools.native")
kotlin("jvm")
}

animalsniffer {
isIgnoreFailures = true
}

val graal by sourceSets.creating

sourceSets {
named("graal") {}
test {
java.srcDirs(
"../okhttp-brotli/src/test/java",
"../okhttp-dnsoverhttps/src/test/java",
"../okhttp-logging-interceptor/src/test/java",
"../okhttp-sse/src/test/java",
)
}
}

dependencies {
implementation(libs.junit.jupiter.api)
implementation(libs.junit.jupiter.engine)
Expand All @@ -21,7 +37,6 @@ dependencies {
implementation(projects.mockwebserver3)
implementation(projects.mockwebserver)
implementation(projects.okhttpJavaNetCookiejar)
implementation(projects.mockwebserver3Junit4)
implementation(projects.mockwebserver3Junit5)
implementation(libs.aqute.resolve)
implementation(libs.junit.jupiter.api)
Expand All @@ -30,33 +45,24 @@ dependencies {
implementation(libs.kotlin.test.common)
implementation(libs.kotlin.test.junit)

implementation(libs.nativeImageSvm)

compileOnly(libs.findbugs.jsr305)
}

animalsniffer {
isIgnoreFailures = true
"graalCompileOnly"(libs.nativeImageSvm)
"graalCompileOnly"(libs.graal.sdk)
nativeImageTestCompileOnly(graal.output.classesDirs)
}

sourceSets {
main {
java.srcDirs(
"../okhttp-brotli/src/test/java",
"../okhttp-dnsoverhttps/src/test/java",
"../okhttp-logging-interceptor/src/test/java",
"../okhttp-sse/src/test/java",
)
}
}
graalvmNative {
testSupport = true

graal {
mainClass("okhttp3.RunTestsKt")
outputName("ConsoleLauncher")
graalVersion(libs.versions.graalvm.get())
javaVersion("11")
binaries {
named("test") {
buildArgs.add("--features=okhttp3.nativeImage.TestRegistration")
buildArgs.add("--initialize-at-build-time=org.junit.platform.engine.TestTag")
buildArgs.add("--strict-image-heap")

option("--no-fallback")
option("--report-unsupported-elements-at-runtime")
option("-H:+ReportExceptionStackTraces")
// speed up development testing
buildArgs.add("-Ob")
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright (C) 2020 Square, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package okhttp3.nativeImage

import org.graalvm.nativeimage.hosted.Feature

class TestRegistration : Feature {
override fun beforeAnalysis(access: Feature.BeforeAnalysisAccess) {
}
}
77 changes: 0 additions & 77 deletions native-image-tests/src/main/kotlin/okhttp3/DotListener.kt

This file was deleted.

56 changes: 0 additions & 56 deletions native-image-tests/src/main/kotlin/okhttp3/GenerateClassList.kt

This file was deleted.

Loading

0 comments on commit fb22f49

Please sign in to comment.