Skip to content
Open
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
15 changes: 14 additions & 1 deletion buildSrc/src/main/kotlin/pklAllProjects.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,24 @@ dependencyLocking { lockAllConfigurations() }

configurations {
val rejectedVersionSuffix = Regex("-alpha|-beta|-eap|-m|-rc|-snapshot", RegexOption.IGNORE_CASE)
val versionSuffixRejectionExcemptions =
setOf(
// I know.
// This looks odd.
// But yes, it's transitively required by one of the relese versions of `zinc`
// https://github.com/sbt/zinc/blame/57a2df7104b3ce27b46404bb09a0126bd4013427/project/Dependencies.scala#L85
"com.eed3si9n:shaded-scalajson_2.13:1.0.0-M4"
)
configureEach {
resolutionStrategy {
componentSelection {
all {
if (rejectedVersionSuffix.containsMatchIn(candidate.version)) {
if (
rejectedVersionSuffix.containsMatchIn(candidate.version) &&
!versionSuffixRejectionExcemptions.contains(
"${candidate.group}:${candidate.module}:${candidate.version}"
)
) {
reject(
"Rejected dependency $candidate " +
"because it has a prelease version suffix matching `$rejectedVersionSuffix`."
Expand Down
8 changes: 8 additions & 0 deletions buildSrc/src/main/kotlin/pklJavaLibrary.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@ spotless {
target("src/*/java/**/*.java")
licenseHeaderFile(rootProject.file("buildSrc/src/main/resources/license-header.star-block.txt"))
}
scala {
scalafmt(libs.versions.scalafmt.get())
target("src/*/scala/**/*.scala")
licenseHeaderFile(
rootProject.file("buildSrc/src/main/resources/license-header.star-block.txt"),
"package ",
)
}
kotlin {
ktfmt(libs.versions.ktfmt.get()).googleStyle()
target("src/*/kotlin/**/*.kt")
Expand Down
49 changes: 49 additions & 0 deletions buildSrc/src/main/kotlin/pklScalaLibrary.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* 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
*
* https://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.
*/
@file:Suppress("HttpUrlsUsage", "unused")

import org.gradle.accessors.dm.LibrariesForLibs
import org.gradle.kotlin.dsl.withType

plugins {
id("pklJavaLibrary")
scala
}

// Build configuration.
val buildInfo = project.extensions.getByType<BuildInfo>()

// Version Catalog library symbols.
val libs = the<LibrariesForLibs>()

dependencies {
api(libs.scalaLibrary)
testImplementation(libs.scalaTestPlusJunit)
testImplementation(libs.scalaTest)
testImplementation(libs.diffx)
}

tasks.withType<ScalaCompile>().configureEach {
scalaCompileOptions.additionalParameters =
listOf("-Xsource:3", "-release:${buildInfo.jvmTarget}", "-target:${buildInfo.jvmTarget}")
}

tasks.test {
useJUnitPlatform {
includeEngines("scalatest")
testLogging { events("passed", "skipped", "failed") }
}
}
10 changes: 10 additions & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ assertj = "3.+"
checksumPlugin = "1.4.0"
clikt = "5.+"
commonMark = "0.+"
diffx = "0.9.0"
downloadTaskPlugin = "5.6.0"
geantyref = "1.+"
googleJavaFormat = "1.25.2"
Expand Down Expand Up @@ -43,6 +44,10 @@ msgpack = "0.9.8"
nexusPublishPlugin = "2.0.0"
nuValidator = "20.+"
paguro = "3.+"
scala = "2.13.17"
scalafmt = "3.10.0"
scalaTest = "3.2.19"
scalaTestPlusJunit = "3.2.19.0"
shadowPlugin = "9.+"
slf4j = "1.+"
snakeYaml = "2.+"
Expand All @@ -55,6 +60,7 @@ clikt = { group = "com.github.ajalt.clikt", name = "clikt", version.ref = "clikt
cliktMarkdown = { group = "com.github.ajalt.clikt", name = "clikt-markdown", version.ref = "clikt" }
commonMark = { group = "org.commonmark", name = "commonmark", version.ref = "commonMark" }
commonMarkTables = { group = "org.commonmark", name = "commonmark-ext-gfm-tables", version.ref = "commonMark" }
diffx = { group = "com.softwaremill.diffx", name = "diffx-scalatest-should_2.13", version.ref = "diffx" }
downloadTaskPlugin = { group = "de.undercouch", name = "gradle-download-task", version.ref = "downloadTaskPlugin" }
geantyref = { group = "io.leangen.geantyref", name = "geantyref", version.ref = "geantyref" }
graalCompiler = { group = "org.graalvm.compiler", name = "compiler", version.ref = "graalVm" }
Expand Down Expand Up @@ -87,6 +93,10 @@ nuValidator = { group = "nu.validator", name = "validator", version.ref = "nuVal
# to be replaced with https://github.com/usethesource/capsule or https://github.com/lacuna/bifurcan
paguro = { group = "org.organicdesign", name = "Paguro", version.ref = "paguro" }
pklConfigJavaAll025 = { group = "org.pkl-lang", name = "pkl-config-java-all", version = "0.25.0" }
scalaLibrary = { group = "org.scala-lang", name = "scala-library", version.ref = "scala" }
scalaReflect = { group = "org.scala-lang", name = "scala-reflect", version.ref = "scala" }
scalaTest = { group = "org.scalatest", name = "scalatest_2.13", version.ref = "scalaTest" }
scalaTestPlusJunit = { group = "org.scalatestplus", name = "junit-5-12_2.13", version.ref = "scalaTestPlusJunit" }
shadowPlugin = { group = "com.gradleup.shadow", name = "com.gradleup.shadow.gradle.plugin", version.ref = "shadowPlugin" }
slf4jApi = { group = "org.slf4j", name = "slf4j-api", version.ref = "slf4j" }
slf4jSimple = { group = "org.slf4j", name = "slf4j-simple", version.ref = "slf4j" }
Expand Down
44 changes: 44 additions & 0 deletions pkl-config-scala/NOTE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
# Scala bindings for PKL language

## Covered
- classes and case classes
- Scala `Option` for nullable PKL types
- Scala `Regexp` for PKL string/regexp
- Scala `Tuple2` for PKL Pair
- Scala `Duration` and `FiniteDuration` for PKL Duration
- Java `Instant` for PKL int and String (how about the rest of java.time?)
- Collections
- `immutable.Seq`
- `immutable.Vector`
- `immutable.List`
- `immutable.Set`
- `immutable.Map`
- `immutable.Stream`
- `immutable.LazyList`
- `mutable.Map`
- `mutable.Set`
- `mutable.Seq`
- `mutable.Buffer`
- `mutable.Queue`
- `mutable.Stack`
- Scala Enumeration (if annotated)
Scala 2 Enumeration is a runtime construct, we can't access it's members from Type referense.
To work around it, we introduced `@EnumOwner` annotation which you can use like below:
```
object SimpleEnum extends Enumeration {

@EnumOwner(classOf[SimpleEnum.type])
case class V() extends Val(nextId)

val Aaa = V()
val Bbb = V()
val Ccc = V()
}
```

## TODO
- more tests
- `Either` (???)
- `sealed traits`
- `object` instances
- cross-version compilation to cover scala `2.12` too
36 changes: 36 additions & 0 deletions pkl-config-scala/pkl-config-scala.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright © 2024-2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* 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
*
* https://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.
*/
plugins {
pklAllProjects
pklScalaLibrary
pklPublishLibrary
}

dependencies {
implementation(projects.pklConfigJava)
api(libs.scalaReflect)
}

publishing {
publications {
named<MavenPublication>("library") {
pom {
url.set("https://github.com/apple/pkl/tree/main/pkl-config-scala")
description.set("Scala config library based on the Pkl config language.")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Copyright © 2025 Apple Inc. and the Pkl project authors. All rights reserved.
*
* 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
*
* https://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 org.pkl.config.scala.annotation;

import java.lang.annotation.*;

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface EnumOwner {

Class<? extends scala.Enumeration> value();
}
Loading