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

Add example nativeImageOption to second native image example in all 3 JVM languages #4407

Merged
merged 4 commits into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ object Deps {
ivy"org.apache.maven.resolver:maven-resolver-transport-http:$mavenResolverVersion"
val mavenResolverTransportWagon =
ivy"org.apache.maven.resolver:maven-resolver-transport-wagon:$mavenResolverVersion"
val coursierJvmIndexVersion = "0.0.4-70-51469f"
val coursierJvmIndexVersion = "0.0.4-84-f852c6"
val gradleApi = ivy"dev.gradleplugins:gradle-api:8.11.1"

object RuntimeDeps {
Expand Down
8 changes: 5 additions & 3 deletions example/javalib/publishing/8-native-image-libs/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,19 @@ object foo extends JavaModule with NativeImageModule {

def nativeImageOptions = Seq(
"--no-fallback",
"-H:IncludeResourceBundles=net.sourceforge.argparse4j.internal.ArgumentParserImpl"
"-H:IncludeResourceBundles=net.sourceforge.argparse4j.internal.ArgumentParserImpl",
"-Os"
)
}

object ZincWorkerGraalvm extends ZincWorkerModule {
def jvmId = "graalvm-community:17.0.9"
def jvmId = "graalvm-community:23.0.1"
}

// This example shows how to generate native images for projects using third-party
// libraries, in this case ArgParse4J and Thymeleaf. ArgParse4J does use some dynamic
// resource loading and reflection, and so we need to pass the `-H:IncludeResourceBundles`
// flag to `nativeImageOptions` in order to be compatible.
// flag to `nativeImageOptions` in order to be compatible. We also demonstrate setting
// `nativeImageOptions`, in this case using `-Os` to optimize for the smallest binary size.

//// SNIPPET:END
13 changes: 11 additions & 2 deletions example/kotlinlib/publishing/8-native-image-libs/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ object foo extends KotlinModule with NativeImageModule {

def mainClass = Some("foo.FooKt")

def nativeImageOptions = Seq(
"--no-fallback",
"-Os",
"--initialize-at-build-time=com.github.ajalt.mordant.internal.nativeimage.NativeImagePosixMppImpls"
)

def ivyDeps = Agg(
ivy"com.github.ajalt.clikt:clikt-jvm:4.4.0",
ivy"org.jetbrains.kotlinx:kotlinx-html-jvm:0.11.0"
Expand All @@ -17,10 +23,13 @@ object foo extends KotlinModule with NativeImageModule {
}

object ZincWorkerGraalvm extends ZincWorkerModule {
def jvmId = "graalvm-community:17.0.7"
def jvmId = "graalvm-community:23.0.2"
}

// This example shows how to generate native images for projects using third-party
// libraries, in this case Clikt and KotlinX-HTML.
// libraries, in this case Clikt and KotlinX-HTML. We also demonstrate setting
// `nativeImageOptions`, in this case using `-Os` to optimize for the smallest binary size,
// and the `--initialize-at-build-time` flag seems to be necessary for this particular set
// of libraries and flags.

//// SNIPPET:END
12 changes: 9 additions & 3 deletions example/scalalib/publishing/8-native-image-libs/build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import mill.define.ModuleRef
object foo extends ScalaModule with NativeImageModule {
def scalaVersion = "2.13.11"

def nativeImageOptions = Seq("--no-fallback")
def nativeImageOptions = Seq("--no-fallback", "-Os")

def ivyDeps = Agg(
ivy"com.lihaoyi::scalatags:0.13.1",
Expand All @@ -17,13 +17,19 @@ object foo extends ScalaModule with NativeImageModule {
}

object ZincWorkerGraalvm extends ZincWorkerModule {
def jvmId = "graalvm-community:17.0.7"
def jvmId = "graalvm-community:23.0.1"
}

// This example shows how to generate native images for projects using third-party
// libraries, in this case Scalatags and Mainargs.
// libraries, in this case Scalatags and Mainargs. We also demonstrate setting
//// `nativeImageOptions`, in this case using `-Os` to optimize for the smallest binary size.

//// SNIPPET:END

// You can see the Graal documentation to see what flags are available:
//
// * https://www.graalvm.org/21.3/reference-manual/native-image/Options/

/** Usage

> ./mill show foo.nativeImage
Expand Down
Loading