Skip to content

Commit

Permalink
Update cli-bot to use 'org.graalvm.buildtools.native' plugin
Browse files Browse the repository at this point in the history
Graal builds have moved to a new location:
https://github.com/graalvm/graalvm-ce-builds/releases

At the same time, palantir/gradle-graal plugin does not support this
(see palantir/gradle-graal#654)

There seems to be a gradle plugin provided by graalvm,
so trying to see if that can be used instead.

Locally I also did the following:

- install a different graal distribution via `sdk install java 17.0.9-graalce`
  - version 17 since I'm using java 17 locally mostly, though
    kotlin-faker is built with java 8 of course, but seems like that
    works fine
- make sure the native-image for the new distribution is installed:
  - `gu install native-image`
  - note that `gu` is NOT available for 21.0.2-graalce version for some reason

Note that 'reflect-config.json' was updated using the 17.0.9-graalce distribution.
  • Loading branch information
serpro69 committed Mar 10, 2024
1 parent 8c50ea8 commit 7e1da53
Show file tree
Hide file tree
Showing 8 changed files with 397 additions and 1,638 deletions.
8 changes: 3 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,13 @@ jobs:
- name: Grant execute permission for gradlew
run: chmod +x gradlew
- name: Build with Gradle
run: ./gradlew clean test integrationTest build nativeImage
run: ./gradlew clean test integrationTest build nativeCompile
- name: Test native image
run: |
_app_path=$(find ./cli-bot/build/graal -type f -name faker-bot\* -not -name \*.txt)
mv "$_app_path" ./faker-bot
# run several iterations to test various pathways when generating data
for i in {0..10}; do
./faker-bot list --verbose >/dev/null || false
./faker-bot lookup a --verbose >/dev/null || false
./cli-bot/build/native/nativeCompile/faker-bot list --verbose >/dev/null || false
./cli-bot/build/native/nativeCompile/faker-bot lookup a --verbose >/dev/null || false
done
12 changes: 9 additions & 3 deletions CONTRIBUTING.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,13 @@ class Name internal constructor(fakerService: FakerService) : YamlFakeDataProvid

* the entry point for all data generation is the link:core/src/main/kotlin/io/github/serpro69/kfaker/Faker.kt[`Faker`] class, so a new property needs to be added there that calls the data provider class

==== Update cli-bot fakers

* cli-bot/src/main/kotlin/io/github/serpro69/kfaker/app/Constants.kt[`Constants.kt`] is used to provide all faker implementations to the faker command line application. If a new faker implementation is added, this needs to be updated

==== Update native-image link:cli-bot/src/main/resources/META-INF/native-image/io.github.serpro69/cli-bot/reflect-config.json[`reflect-config.json`]

* this is used when building the native-image of the `faker-bot` CLI application and thus needs to be updated, otherwise the `nativeImage` gradle task will fail
* this is used when building the native-image of the `faker-bot` CLI application and thus needs to be updated, otherwise the `nativeCompile` gradle task will fail
* it is easy to auto-update the configuration by using `native-image-agent` (requires the `native-image` binary to be installed):
** first create the jar of the app with `./gradlew clean shadowJar`
** then run each of the cli commands (include the verbose mode since that requires additional calls):
Expand All @@ -160,9 +164,11 @@ class Name internal constructor(fakerService: FakerService) : YamlFakeDataProvid
** the link:cli-bot/src/test/kotlin/io/github/serpro69/kfaker/app/cli/IntrospectorTest.kt[`IntrospectorTest`] needs to be updated in the `cli-bot` module
** the link:core/src/test/kotlin/io/github/serpro69/kfaker/TestConstants.kt[`TestConstants`] need to be updated as well

==== Example commit
==== Examples

* In addition to the above instructions, you can also take a look at https://github.com/serpro69/kotlin-faker/commit/0b34d19d77aa728ed87382444908c90a63cc5f52[`0b34d1`] commit, which can be used as an MVP example of all of the above steps.

In addition to the above instructions, you can also take a look at https://github.com/serpro69/kotlin-faker/commit/0b34d19d77aa728ed87382444908c90a63cc5f52[`0b34d1`] commit, which can be used as an MVP example of all of the above steps.
* Also see https://github.com/serpro69/kotlin-faker/pull/222[#222] for an example of adding a completely new faker implementation module

==== Which Faker implementation to use?

Expand Down
26 changes: 13 additions & 13 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ deploy-docs: ## deploys documentation with orchid
_snapshot-in-pre-release: ## (DEPRECATED) publishes next snapshot in current pre-release version
./gradlew clean test integrationTest \
printVersion \
nativeImage \
nativeCompile \
publishToSonatype \
-PpromoteToRelease \
--info
Expand All @@ -44,7 +44,7 @@ _snapshot-in-pre-release: ## (DEPRECATED) publishes next snapshot in current pre
_snapshot-major: ## (DEPRECATED) publishes next snapshot with a major version bump
./gradlew clean test integrationTest \
printVersion \
nativeImage \
nativeCompile \
publishToSonatype \
-PbumpComponent=major \
--info
Expand All @@ -54,14 +54,14 @@ snapshot-minor: check_java ## publishes next snapshot with a minor version bump
@:$(call check_defined, VERSION, semantic version string - 'X.Y.Z(-rc.\d+)?')

./gradlew clean test integrationTest -Pversion='$(VERSION)-SNAPSHOT'
./gradlew nativeImage -Pversion='$(VERSION)-SNAPSHOT' --info
./gradlew nativeCompile -Pversion='$(VERSION)-SNAPSHOT' --info
./gradlew publishToSonatype -Pversion='$(VERSION)-SNAPSHOT' --info

.PHONY: snapshot-patch
_snapshot-patch: ## (DEPRECATED) publishes next snapshot with a patch version bump
./gradlew clean test integrationTest \
printVersion \
nativeImage \
nativeCompile \
publishToSonatype \
-PbumpComponent=patch \
--info
Expand All @@ -70,7 +70,7 @@ _snapshot-patch: ## (DEPRECATED) publishes next snapshot with a patch version bu
_pre-release-major: ## (DEPRECATED) publishes next pre-release version with a major version bump
./gradlew clean test integrationTest \
tag \
nativeImage \
nativeCompile \
publishToSonatype \
closeSonatypeStagingRepository \
-Prelease -PnewPreRelease -PbumpComponent=major \
Expand All @@ -82,7 +82,7 @@ _pre-release-major: ## (DEPRECATED) publishes next pre-release version with a ma
_pre-release-minor: ## (DEPRECATED) publishes next pre-release with a minor version bump
./gradlew clean test integrationTest \
tag \
nativeImage \
nativeCompile \
publishToSonatype \
closeSonatypeStagingRepository \
-Prelease -PnewPreRelease -PbumpComponent=minor \
Expand All @@ -94,7 +94,7 @@ _pre-release-minor: ## (DEPRECATED) publishes next pre-release with a minor vers
_pre-release-patch: ## (DEPRECATED) publishes next pre-release with a patch version bump
./gradlew clean test integrationTest \
tag \
nativeImage \
nativeCompile \
publishToSonatype \
closeSonatypeStagingRepository \
-Prelease -PnewPreRelease -PbumpComponent=patch \
Expand All @@ -106,7 +106,7 @@ _pre-release-patch: ## (DEPRECATED) publishes next pre-release with a patch vers
_next-pre-release: ## (DEPRECATED) publishes next pre-release version
./gradlew clean test integrationTest \
tag \
nativeImage \
nativeCompile \
publishToSonatype \
closeSonatypeStagingRepository \
-Prelease -PpreRelease \
Expand All @@ -118,7 +118,7 @@ _next-pre-release: ## (DEPRECATED) publishes next pre-release version
_promote-to-release: ## (DEPRECATED) publishes next release from the current pre-release version
./gradlew clean test integrationTest \
tag \
nativeImage \
nativeCompile \
publishToSonatype \
closeSonatypeStagingRepository \
-Prelease -PpromoteToRelease \
Expand All @@ -130,7 +130,7 @@ _promote-to-release: ## (DEPRECATED) publishes next release from the current pre
_release-major: ## (DEPRECATED) publishes next major release version
./gradlew clean test integrationTest \
tag \
nativeImage \
nativeCompile \
publishToSonatype \
closeSonatypeStagingRepository \
-Prelease -PbumpComponent=major \
Expand All @@ -142,7 +142,7 @@ _release-major: ## (DEPRECATED) publishes next major release version
_release-minor: ## (DEPRECATED) publishes next minor release version
./gradlew clean test integrationTest \
tag \
nativeImage \
nativeCompile \
publishToSonatype \
closeSonatypeStagingRepository \
-Prelease -PbumpComponent=minor \
Expand All @@ -154,7 +154,7 @@ _release-minor: ## (DEPRECATED) publishes next minor release version
_release-patch: ## (DEPRECATED) publishes next patch release version
./gradlew clean test integrationTest \
tag \
nativeImage \
nativeCompile \
publishToSonatype \
closeSonatypeStagingRepository \
-Prelease -PbumpComponent=patch \
Expand All @@ -169,7 +169,7 @@ release: check_java ## publishes the next release with a specified VERSION
# run tests
./gradlew clean test integrationTest -Pversion=$(VERSION)
# build and test native image
./gradlew nativeImage -Pversion=$(VERSION) --info
./gradlew nativeCompile -Pversion=$(VERSION) --info
./cli-bot/build/graal/faker-bot_$(VERSION) list --verbose >/dev/null || false
./cli-bot/build/graal/faker-bot_$(VERSION) lookup a --verbose >/dev/null || false
# publish to sonatype and close staging repo
Expand Down
19 changes: 0 additions & 19 deletions cli-bot/TODO.md

This file was deleted.

34 changes: 24 additions & 10 deletions cli-bot/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import com.adarshr.gradle.testlogger.theme.ThemeType
plugins {
application
kotlin("jvm")
id("com.palantir.graal") version "0.10.0" // 0.12.0+ requires java11+
id("org.graalvm.buildtools.native") version "0.10.1"
}

val mainFunction = "io.github.serpro69.kfaker.app.KFakerKt"
Expand Down Expand Up @@ -86,16 +86,26 @@ tasks.startScripts {
fakers.forEach { dependsOn(":faker:$it:shadowJar") }
}

graal {
graalVersion("21.2.0")
javaVersion("8")
mainClass(mainFunction)
outputName("faker-bot_${project.version}")
option("--no-fallback")
option("--no-server")
option("--report-unsupported-elements-at-runtime")
graalvmNative {
testSupport = false
toolchainDetection = true
binaries {
named("main") {
imageName = "faker-bot"
}
}
}

//graalvmNative {
// graalVersion("21.2.0")
// javaVersion("8")
// mainClass(mainFunction)
// outputName("faker-bot_${project.version}")
// option("--no-fallback")
// option("--no-server")
// option("--report-unsupported-elements-at-runtime")
//}

tasks {
compileKotlin {
// Set version for --version options
Expand All @@ -116,7 +126,11 @@ tasks {
dependsOn(":core:assemble")
}

nativeImage {
nativeCompile {
dependsOn(shadowJar)
}

generateResourcesConfigFile {
fakers.forEach { dependsOn(":faker:$it:shadowJar") }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.github.serpro69.kfaker.FakerConfig
import io.github.serpro69.kfaker.books.BooksFaker
import io.github.serpro69.kfaker.commerce.CommerceFaker
import io.github.serpro69.kfaker.creatures.CreaturesFaker
import io.github.serpro69.kfaker.databases.DatabasesFaker
import io.github.serpro69.kfaker.edu.EduFaker
import io.github.serpro69.kfaker.games.GamesFaker
import io.github.serpro69.kfaker.humor.HumorFaker
Expand All @@ -25,6 +26,7 @@ val fakers: (config: FakerConfig) -> List<AbstractFaker> = {
BooksFaker(it),
CommerceFaker(it),
CreaturesFaker(it),
DatabasesFaker(it),
EduFaker(it),
GamesFaker(it),
HumorFaker(it),
Expand Down
Loading

0 comments on commit 7e1da53

Please sign in to comment.