Skip to content

Commit 2c4757d

Browse files
authored
Adds support for scala native (#442)
1 parent 9d71490 commit 2c4757d

File tree

6 files changed

+119
-41
lines changed

6 files changed

+119
-41
lines changed

.github/workflows/ci.yml

Lines changed: 71 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,85 @@ on:
77
tags: [v*]
88
jobs:
99
build:
10-
uses: softwaremill/github-actions-workflows/.github/workflows/build-scala.yml@main
1110
# run on 1) push, 2) external PRs, 3) softwaremill-ci PRs
1211
# do not run on internal, non-steward PRs since those will be run by push to branch
1312
if: |
14-
github.event_name == 'push' ||
13+
github.event_name == 'push' ||
1514
github.event.pull_request.head.repo.full_name != github.repository ||
1615
github.event.pull_request.user.login == 'softwaremill-ci'
17-
with:
18-
java-version: '21'
19-
compile-documentation: true
16+
runs-on: ubuntu-24.04
17+
steps:
18+
- name: Checkout
19+
uses: actions/checkout@v6
20+
- name: Set up JDK
21+
uses: actions/setup-java@v5
22+
with:
23+
distribution: 'temurin'
24+
java-version: '21'
25+
cache: 'sbt'
26+
- uses: sbt/setup-sbt@3e125ece5c3e5248e18da9ed8d2cce3d335ec8dd # v1, specifically v1.1.14
27+
- name: Install native dependencies
28+
run: |
29+
sudo apt-get update
30+
sudo apt-get install libidn2-dev libcurl3-dev
31+
- name: Check formatting
32+
run: sbt -v scalafmtCheckAll
33+
- name: Compile
34+
run: sbt -v compile
35+
- name: Compile documentation
36+
run: sbt -v compileDocumentation
37+
- name: Test
38+
run: sbt -v test
39+
- uses: actions/upload-artifact@v5 # upload test results
40+
if: success() || failure() # run this step even if previous step failed
41+
with:
42+
name: 'tests-results-java-21'
43+
path: '**/test-reports/TEST*.xml'
2044

2145
publish:
22-
uses: softwaremill/github-actions-workflows/.github/workflows/publish-release.yml@main
46+
name: Publish release
2347
needs: [build]
2448
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
25-
secrets: inherit
26-
with:
27-
java-version: '21'
28-
java-opts: "-Xmx4G"
49+
runs-on: ubuntu-24.04
50+
env:
51+
JAVA_OPTS: "-Xmx4G"
52+
steps:
53+
- name: Checkout
54+
uses: actions/checkout@v6
55+
- name: Set up JDK
56+
uses: actions/setup-java@v5
57+
with:
58+
distribution: 'temurin'
59+
java-version: '21'
60+
cache: 'sbt'
61+
- uses: sbt/setup-sbt@3e125ece5c3e5248e18da9ed8d2cce3d335ec8dd # v1, specifically v1.1.14
62+
- name: Install native dependencies
63+
run: |
64+
sudo apt-get update
65+
sudo apt-get install libidn2-dev libcurl3-dev
66+
- name: Compile
67+
run: sbt compile
68+
- name: Publish artifacts
69+
run: sbt ci-release
70+
env:
71+
PGP_PASSPHRASE: ${{ secrets.PGP_PASSPHRASE }}
72+
PGP_SECRET: ${{ secrets.PGP_SECRET }}
73+
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
74+
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
75+
- name: Extract version from tag
76+
run: |
77+
version=${GITHUB_REF/refs\/tags\/v/}
78+
echo "VERSION=$version" >> $GITHUB_ENV
79+
- name: Publish release notes
80+
uses: release-drafter/release-drafter@b1476f6e6eb133afa41ed8589daba6dc69b4d3f5 # v6, specifically v6.1.0
81+
with:
82+
config-name: release-drafter.yml
83+
publish: true
84+
name: "v${{ env.VERSION }}"
85+
tag: "v${{ env.VERSION }}"
86+
version: "v${{ env.VERSION }}"
87+
env:
88+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2989

3090
label:
3191
# only for PRs by softwaremill-ci
@@ -36,4 +96,4 @@ jobs:
3696
# only for PRs by softwaremill-ci
3797
if: github.event.pull_request.user.login == 'softwaremill-ci'
3898
needs: [ build, label ]
39-
uses: softwaremill/github-actions-workflows/.github/workflows/auto-merge.yml@main
99+
uses: softwaremill/github-actions-workflows/.github/workflows/auto-merge.yml@main

.jvmopts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
-Xms2g
2+
-Xmx6g

build.sbt

Lines changed: 25 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import Dependencies.*
22
import com.softwaremill.Publish.ossPublishSettings
33
import com.softwaremill.SbtSoftwareMillCommon.commonSmlBuildSettings
44

5-
val scala2 = List("2.13.16")
5+
val scala2 = List("2.13.18")
66
val scala3 = List("3.3.6")
77

88
def dependenciesFor(version: String)(deps: (Option[(Long, Long)] => ModuleID)*): Seq[ModuleID] =
@@ -35,24 +35,31 @@ lazy val core = (projectMatrix in file("core"))
3535
.jvmPlatform(
3636
scalaVersions = scala2 ++ scala3
3737
)
38+
.nativePlatform(
39+
scalaVersions = scala3
40+
)
3841
.settings(commonSettings: _*)
3942
.settings(
40-
libraryDependencies ++= Seq(
41-
Libraries.uPickle,
42-
Libraries.tapirApispecDocs
43-
) ++ Libraries.sttpApispec ++ Libraries.sttpClient ++ Seq(Libraries.scalaTest)
43+
libraryDependencies ++=
44+
Libraries.sttpClient.value ++ Libraries.sttpApispec.value ++ Seq(
45+
Libraries.uPickle.value,
46+
Libraries.tapirApispecDocs.value,
47+
Libraries.scalaTest.value
48+
)
4449
)
4550

4651
lazy val openai = (projectMatrix in file("openai"))
4752
.jvmPlatform(
4853
scalaVersions = scala2 ++ scala3
4954
)
55+
.nativePlatform(
56+
scalaVersions = scala3
57+
)
5058
.settings(
51-
libraryDependencies ++= Seq(
52-
Libraries.tapirApispecDocs,
53-
Libraries.uJsonCirce,
54-
Libraries.uPickle
55-
) ++ Libraries.sttpApispec ++ Libraries.sttpClient ++ Seq(Libraries.scalaTest)
59+
libraryDependencies ++=
60+
Libraries.sttpClient.value ++
61+
Seq(Libraries.uPickle.value, Libraries.tapirApispecDocs.value, Libraries.uJsonCirce.value) ++
62+
Libraries.sttpApispec.value ++ Seq(Libraries.scalaTest.value)
5663
)
5764
.settings(commonSettings: _*)
5865
.dependsOn(core % "compile->compile;test->test")
@@ -61,13 +68,15 @@ lazy val claude = (projectMatrix in file("claude"))
6168
.jvmPlatform(
6269
scalaVersions = scala3 ++ scala2 // Scala 3 first priority
6370
)
71+
.nativePlatform(
72+
scalaVersions = scala3
73+
)
6474
.settings(commonSettings: _*)
6575
.settings(
66-
libraryDependencies ++= Seq(
67-
Libraries.tapirApispecDocs,
68-
Libraries.uJsonCirce,
69-
Libraries.uPickle
70-
) ++ Libraries.sttpApispec ++ Libraries.sttpClient ++ Seq(Libraries.scalaTest)
76+
libraryDependencies ++=
77+
Seq(Libraries.tapirApispecDocs.value, Libraries.uJsonCirce.value, Libraries.uPickle.value) ++
78+
Libraries.sttpApispec.value ++
79+
Libraries.sttpClient.value ++ Seq(Libraries.scalaTest.value)
7180
)
7281
.dependsOn(core % "compile->compile;test->test")
7382

@@ -128,7 +137,7 @@ lazy val examples = (projectMatrix in file("examples"))
128137
.settings(commonSettings)
129138
.settings(
130139
libraryDependencies ++= Seq(
131-
"com.softwaremill.sttp.tapir" %% "tapir-netty-server-sync" % "1.11.46",
140+
"com.softwaremill.sttp.tapir" %% "tapir-netty-server-sync" % V.tapir,
132141
"ch.qos.logback" % "logback-classic" % "1.5.6"
133142
) ++ Libraries.sttpClientOx,
134143
publish / skip := true

openai/src/test/scala/sttp/ai/openai/openai/fixtures/ToolFixture.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ object ToolFixture {
1515
| "departureCity",
1616
| "destinationCity"
1717
| ],
18-
| "$schema": "http://json-schema.org/draft/2020-12/schema#",
18+
| "$schema": "https://json-schema.org/draft/2020-12/schema",
1919
| "$defs": {
2020
| "Passenger": {
2121
| "additionalProperties": false,
@@ -79,7 +79,7 @@ object ToolFixture {
7979
| "departureCity",
8080
| "destinationCity"
8181
| ],
82-
| "$schema": "http://json-schema.org/draft/2020-12/schema#",
82+
| "$schema": "https://json-schema.org/draft/2020-12/schema",
8383
| "$defs": {
8484
| "Passenger": {
8585
| "additionalProperties": false,

project/Dependencies.scala

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sbt.*
2+
import org.portablescala.sbtplatformdeps.PlatformDepsPlugin.autoImport.*
23

34
object Dependencies {
45

@@ -7,25 +8,29 @@ object Dependencies {
78
val scalaTestCats = "1.7.0"
89

910
val sttpApispec = "0.11.10"
10-
val sttpClient = "4.0.12"
11+
val sttpClient = "4.0.18"
1112
val pekkoStreams = "1.2.1"
1213
val akkaStreams = "2.6.20"
13-
val tapir = "1.11.46"
14+
val tapir = "1.13.8"
1415
val uPickle = "4.3.2"
1516
}
1617

1718
object Libraries {
1819

19-
val scalaTest = "org.scalatest" %% "scalatest" % V.scalaTest % Test
20+
val scalaTest = Def.setting("org.scalatest" %%% "scalatest" % V.scalaTest % Test)
2021

21-
val sttpApispec = Seq(
22-
"com.softwaremill.sttp.apispec" %% "apispec-model" % V.sttpApispec,
23-
"com.softwaremill.sttp.apispec" %% "jsonschema-circe" % V.sttpApispec
22+
val sttpApispec = Def.setting(
23+
Seq(
24+
"com.softwaremill.sttp.apispec" %%% "apispec-model" % V.sttpApispec,
25+
"com.softwaremill.sttp.apispec" %%% "jsonschema-circe" % V.sttpApispec
26+
)
2427
)
2528

26-
val sttpClient = Seq(
27-
"com.softwaremill.sttp.client4" %% "core" % V.sttpClient,
28-
"com.softwaremill.sttp.client4" %% "upickle" % V.sttpClient
29+
val sttpClient = Def.setting(
30+
Seq(
31+
"com.softwaremill.sttp.client4" %%% "core" % V.sttpClient,
32+
"com.softwaremill.sttp.client4" %%% "upickle" % V.sttpClient
33+
)
2934
)
3035

3136
val sttpClientFs2 = Seq(
@@ -49,11 +54,11 @@ object Dependencies {
4954
"com.softwaremill.sttp.client4" %% "ox" % V.sttpClient
5055
)
5156

52-
val tapirApispecDocs = "com.softwaremill.sttp.tapir" %% "tapir-apispec-docs" % V.tapir
57+
val tapirApispecDocs = Def.setting("com.softwaremill.sttp.tapir" %%% "tapir-apispec-docs" % V.tapir)
5358

54-
val uJsonCirce = "com.lihaoyi" %% "ujson-circe" % V.uPickle
59+
val uJsonCirce = Def.setting("com.lihaoyi" %%% "ujson-circe" % V.uPickle)
5560

56-
val uPickle = "com.lihaoyi" %% "upickle" % V.uPickle
61+
val uPickle = Def.setting("com.lihaoyi" %%% "upickle" % V.uPickle)
5762

5863
}
5964

project/plugins.sbt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,5 @@ addSbtPlugin("com.softwaremill.sbt-softwaremill" % "sbt-softwaremill-common" % s
33
addSbtPlugin("com.softwaremill.sbt-softwaremill" % "sbt-softwaremill-publish" % sbtSoftwareMillVersion)
44
addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.11.0")
55
addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.7.2")
6+
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.9")
7+
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.3.2")

0 commit comments

Comments
 (0)