11/*
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- */
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+ @file:Suppress(" unused" )
17+
1618plugins {
1719 pklAllProjects
1820 pklGraalVm
1921 pklJavaLibrary
20- pklJavaExecutable
2122 pklNativeLifecycle
2223}
2324
24- // assumes that `pklJavaExecutable` is also applied
25- val executableSpec = project.extensions.getByType<ExecutableSpec >()
26-
2725val stagedMacAmd64NativeLibrary: Configuration by configurations.creating
2826val stagedMacAarch64NativeLibrary: Configuration by configurations.creating
2927val stagedLinuxAmd64NativeLibrary: Configuration by configurations.creating
@@ -57,18 +55,6 @@ dependencies {
5755 stagedWindowsAmd64NativeLibrary(sharedLibrary(" windows-amd64.exe" ))
5856}
5957
60- executable {
61- name = " libpkl_internal"
62-
63- // TODO(kushal): Why is all of this necessary now? Can it be stripped back?
64- javaName = " libpkl"
65- documentationName = " Pkl Native Library"
66- publicationName = " libpkl"
67- javaPublicationName = " libpkl"
68- mainClass = " org.pkl.libpkl.LibPkl"
69- website = " TODO"
70- }
71-
7258private fun extension (osAndArch : String ) =
7359 when (osAndArch.split(" -" ).dropWhile { it == " alpine" }.first()) {
7460 " linux" -> " so"
@@ -85,7 +71,7 @@ private fun extension(osAndArch: String) =
8571private fun nativeLibraryOutputFiles (osAndArch : String ) =
8672 project.layout.buildDirectory.dir(" libs/$osAndArch " ).map { outputDir ->
8773 // TODO(kushal): dashes/underscores for library files? C convention assumes underscores.
88- val libraryName = executableSpec.name
74+ val libraryName = " libpkl_internal "
8975 val libraryOutputFiles =
9076 listOf (
9177 " lib${libraryName} .${extension(osAndArch)} " ,
@@ -125,8 +111,8 @@ private fun NativeImageBuild.setClasspath() {
125111val macNativeLibraryAmd64 by
126112 tasks.registering(NativeImageBuild ::class ) {
127113 outputDir = project.layout.buildDirectory.dir(" libs/macos-amd64" )
128- imageName = executableSpec.name
129- mainClass = executableSpec.mainClass
114+ imageName = " libpkl_internal "
115+ mainClass = " org.pkl.libpkl.LibPkl "
130116 amd64()
131117 setClasspath()
132118 extraNativeImageArgs = listOf (" --shared" )
@@ -137,8 +123,8 @@ val macNativeLibraryAmd64 by
137123val macNativeLibraryAarch64 by
138124 tasks.registering(NativeImageBuild ::class ) {
139125 outputDir = project.layout.buildDirectory.dir(" libs/macos-aarch64" )
140- imageName = executableSpec.name
141- mainClass = executableSpec.mainClass
126+ imageName = " libpkl_internal "
127+ mainClass = " org.pkl.libpkl.LibPkl "
142128 aarch64()
143129 setClasspath()
144130 extraNativeImageArgs = listOf (" --shared" )
@@ -149,8 +135,8 @@ val macNativeLibraryAarch64 by
149135val linuxNativeLibraryAmd64 by
150136 tasks.registering(NativeImageBuild ::class ) {
151137 outputDir = project.layout.buildDirectory.dir(" libs/linux-amd64" )
152- imageName = executableSpec.name
153- mainClass = executableSpec.mainClass
138+ imageName = " libpkl_internal "
139+ mainClass = " org.pkl.libpkl.LibPkl "
154140 amd64()
155141 setClasspath()
156142 extraNativeImageArgs = listOf (" --shared" )
@@ -161,8 +147,8 @@ val linuxNativeLibraryAmd64 by
161147val linuxNativeLibraryAarch64 by
162148 tasks.registering(NativeImageBuild ::class ) {
163149 outputDir = project.layout.buildDirectory.dir(" libs/linux-aarch64" )
164- imageName = executableSpec.name
165- mainClass = executableSpec.mainClass
150+ imageName = " libpkl_internal "
151+ mainClass = " org.pkl.libpkl.LibPkl "
166152 aarch64()
167153 setClasspath()
168154
@@ -180,8 +166,8 @@ val linuxNativeLibraryAarch64 by
180166val alpineNativeLibraryAmd64 by
181167 tasks.registering(NativeImageBuild ::class ) {
182168 outputDir = project.layout.buildDirectory.dir(" libs/alpine-linux-amd64" )
183- imageName = executableSpec.name
184- mainClass = executableSpec.mainClass
169+ imageName = " libpkl_internal "
170+ mainClass = " org.pkl.libpkl.LibPkl "
185171 amd64()
186172 setClasspath()
187173
@@ -198,8 +184,8 @@ val alpineNativeLibraryAmd64 by
198184val windowsNativeLibraryAmd64 by
199185 tasks.registering(NativeImageBuild ::class ) {
200186 outputDir = project.layout.buildDirectory.dir(" libs/windows-amd64" )
201- imageName = executableSpec.name
202- mainClass = executableSpec.mainClass
187+ imageName = " libpkl_internal "
188+ mainClass = " org.pkl.libpkl.LibPkl "
203189 amd64()
204190 setClasspath()
205191 extraNativeImageArgs = listOf (" --shared" , " -Dfile.encoding=UTF-8" )
@@ -317,3 +303,14 @@ tasks.withType<Test> {
317303
318304 useJUnitPlatform()
319305}
306+
307+ private val licenseHeaderFile by lazy {
308+ rootProject.file(" buildSrc/src/main/resources/license-header.star-block.txt" )
309+ }
310+
311+ spotless {
312+ cpp {
313+ licenseHeaderFile(licenseHeaderFile, " // " )
314+ target(" src/main/c/*.c" , " src/main/c/*.h" )
315+ }
316+ }
0 commit comments