|
| 1 | +/* |
| 2 | + * Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved. |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * https://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | +import java.nio.file.Path |
| 17 | + |
| 18 | +plugins { |
| 19 | + application |
| 20 | + pklAllProjects |
| 21 | + pklKotlinLibrary |
| 22 | + pklPublishLibrary |
| 23 | + `maven-publish` |
| 24 | + alias(libs.plugins.kotlinxSerialization) |
| 25 | +} |
| 26 | + |
| 27 | +val downstreamImageClasspath: Configuration by configurations.creating |
| 28 | +val downstreamImageModulepath: Configuration by configurations.creating |
| 29 | + |
| 30 | +dependencies { |
| 31 | + api(libs.svm) |
| 32 | + implementation(libs.kotlinxSerializationJson) |
| 33 | + compileOnly(libs.truffleSvm) |
| 34 | + testImplementation(projects.pklTools) |
| 35 | + |
| 36 | + downstreamImageClasspath(libs.kotlinStdLib) |
| 37 | + downstreamImageClasspath(libs.kotlinxSerializationJson) |
| 38 | + downstreamImageClasspath(projects.pklExecutor) |
| 39 | + downstreamImageClasspath(projects.pklConfigJava) |
| 40 | + downstreamImageModulepath(libs.svm) |
| 41 | + downstreamImageModulepath(libs.truffleSvm) |
| 42 | +} |
| 43 | + |
| 44 | +val classinitConfig = layout.projectDirectory.file(Path.of("config", "classinit.jsonc").toString()) |
| 45 | + |
| 46 | +val nativeImageConfig = buildInfo.graalvmConfig(classinitConfig) |
| 47 | + |
| 48 | +tasks.processResources.configure { |
| 49 | + from(classinitConfig) { into("META-INF/native-image/org.pkl-lang/pkl-nativeimage") } |
| 50 | +} |
| 51 | + |
| 52 | +tasks.javadoc.configure { enabled = false } |
| 53 | + |
| 54 | +val buildDownstreamNativeImage by |
| 55 | + tasks.registering(Exec::class) { |
| 56 | + executable = "native-image" |
| 57 | + dependsOn(tasks.testClasses, tasks.processResources, tasks.jar) |
| 58 | + |
| 59 | + val outBin = |
| 60 | + layout.buildDirectory.file("executable-test").get().asFile.resolve("pkl-embedded").path |
| 61 | + |
| 62 | + outputs.files(outBin) |
| 63 | + argumentProviders.add( |
| 64 | + CommandLineArgumentProvider { |
| 65 | + buildList { |
| 66 | + mapOf<String, Any>( |
| 67 | + // @TODO: this should be removed once pkl supports JPMS as a true Java Module. |
| 68 | + "polyglotimpl.DisableClassPathIsolation" to true |
| 69 | + ) |
| 70 | + .forEach { add("-D${it.key}=${it.value}") } |
| 71 | + |
| 72 | + add("-o") |
| 73 | + add(outBin) |
| 74 | + |
| 75 | + add("--module-path") |
| 76 | + add( |
| 77 | + listOf(downstreamImageModulepath.asPath, tasks.jar.get().outputs.files.asPath) |
| 78 | + .joinToString(":") |
| 79 | + ) |
| 80 | + |
| 81 | + add("--class-path") |
| 82 | + add( |
| 83 | + listOf( |
| 84 | + downstreamImageClasspath.asPath, |
| 85 | + layout.buildDirectory.dir("classes/kotlin/test").get().asFile.path, |
| 86 | + layout.buildDirectory.dir("resources/main").get().asFile.path, |
| 87 | + layout.buildDirectory.dir("resources/test").get().asFile.path, |
| 88 | + ) |
| 89 | + .joinToString(":") |
| 90 | + ) |
| 91 | + |
| 92 | + add("com.sample.test.ImageSampleMainKt") |
| 93 | + } |
| 94 | + } |
| 95 | + ) |
| 96 | + } |
0 commit comments