Skip to content

Commit

Permalink
Merge pull request #5 from neandertech/add-native
Browse files Browse the repository at this point in the history
Add Scala Native support to core and examples
  • Loading branch information
Baccata authored Jul 16, 2024
2 parents f251fde + 948349d commit dc554b4
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 32 deletions.
73 changes: 48 additions & 25 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ jobs:
matrix:
os: [ubuntu-latest]
scala: [3]
java: [temurin@8]
project: [rootJS, rootJVM]
java: [temurin@17]
project: [rootJS, rootJVM, rootNative]
runs-on: ${{ matrix.os }}
timeout-minutes: 60
steps:
Expand All @@ -39,48 +39,61 @@ jobs:
with:
fetch-depth: 0

- name: Setup Java (temurin@8)
id: setup-java-temurin-8
if: matrix.java == 'temurin@8'
- name: Setup Java (temurin@17)
id: setup-java-temurin-17
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 8
java-version: 17
cache: sbt

- name: sbt update
if: matrix.java == 'temurin@8' && steps.setup-java-temurin-8.outputs.cache-hit == 'false'
if: matrix.java == 'temurin@17' && steps.setup-java-temurin-17.outputs.cache-hit == 'false'
run: sbt +update

- name: Cache vcpkg
uses: actions/cache@v4
with:
key: ${{ runner.os }}-sbt-vcpkg
path: |
~/Library/Caches/sbt-vcpkg/vcpkg-install
~/.cache/sbt-vcpkg/vcpkg-install
~/.cache/sbt-vcpkg/vcpkg
- name: Check that workflows are up to date
run: sbt githubWorkflowCheck

- name: Check headers and formatting
if: matrix.java == 'temurin@8' && matrix.os == 'ubuntu-latest'
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' headerCheckAll scalafmtCheckAll 'project /' scalafmtSbtCheck

- name: scalaJSLink
if: matrix.project == 'rootJS'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' Test/scalaJSLinkerResult

- name: nativeLink
if: matrix.project == 'rootNative'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' Test/nativeLink

- name: Test
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' test

- name: Check binary compatibility
if: matrix.java == 'temurin@8' && matrix.os == 'ubuntu-latest'
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' mimaReportBinaryIssues

- name: Generate API documentation
if: matrix.java == 'temurin@8' && matrix.os == 'ubuntu-latest'
if: matrix.java == 'temurin@17' && matrix.os == 'ubuntu-latest'
run: sbt 'project ${{ matrix.project }}' '++ ${{ matrix.scala }}' doc

- name: Make target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: mkdir -p modules/compiler-plugin/target modules/core/js/target modules/core/jvm/target modules/bundle/target project/target
run: mkdir -p modules/compiler-plugin/target modules/core/native/target modules/core/js/target modules/core/jvm/target modules/bundle/target project/target

- name: Compress target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: tar cf targets.tar modules/compiler-plugin/target modules/core/js/target modules/core/jvm/target modules/bundle/target project/target
run: tar cf targets.tar modules/compiler-plugin/target modules/core/native/target modules/core/js/target modules/core/jvm/target modules/bundle/target project/target

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
Expand All @@ -96,25 +109,25 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
java: [temurin@8]
java: [temurin@17]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (temurin@8)
id: setup-java-temurin-8
if: matrix.java == 'temurin@8'
- name: Setup Java (temurin@17)
id: setup-java-temurin-17
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 8
java-version: 17
cache: sbt

- name: sbt update
if: matrix.java == 'temurin@8' && steps.setup-java-temurin-8.outputs.cache-hit == 'false'
if: matrix.java == 'temurin@17' && steps.setup-java-temurin-17.outputs.cache-hit == 'false'
run: sbt +update

- name: Download target directories (3, rootJS)
Expand All @@ -137,6 +150,16 @@ jobs:
tar xf targets.tar
rm targets.tar
- name: Download target directories (3, rootNative)
uses: actions/download-artifact@v4
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3-rootNative

- name: Inflate target directories (3, rootNative)
run: |
tar xf targets.tar
rm targets.tar
- name: Import signing key
if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE == ''
env:
Expand Down Expand Up @@ -167,29 +190,29 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
java: [temurin@8]
java: [temurin@17]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Setup Java (temurin@8)
id: setup-java-temurin-8
if: matrix.java == 'temurin@8'
- name: Setup Java (temurin@17)
id: setup-java-temurin-17
if: matrix.java == 'temurin@17'
uses: actions/setup-java@v4
with:
distribution: temurin
java-version: 8
java-version: 17
cache: sbt

- name: sbt update
if: matrix.java == 'temurin@8' && steps.setup-java-temurin-8.outputs.cache-hit == 'false'
if: matrix.java == 'temurin@17' && steps.setup-java-temurin-17.outputs.cache-hit == 'false'
run: sbt +update

- name: Submit Dependencies
uses: scalacenter/sbt-dependency-submission@v2
with:
modules-ignore: rootjs_3 examples_sjs1_3 rootjvm_3 rootnative_3 examples_3 tests_3
modules-ignore: examples_native0.4_3 rootjs_3 examples_sjs1_3 rootjvm_3 rootnative_3 examples_3 tests_3
configs-ignore: test scala-tool scala-doc-tool test-internal
1 change: 1 addition & 0 deletions .jvmopts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
-Xmx2G
53 changes: 46 additions & 7 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -14,22 +14,42 @@ ThisBuild / developers ++= List(
tlGitHubDev("baccata", "Olivier Mélois")
)

ThisBuild / githubWorkflowJavaVersions := Seq(JavaSpec.temurin("17"))

ThisBuild / scalacOptions ++= Seq(
"-language:implicitConversions"
)

ThisBuild / githubWorkflowBuildPreamble += {
import org.typelevel.sbt.gha.*
import WorkflowStep.*

val paths =
List(
"~/Library/Caches/sbt-vcpkg/vcpkg-install",
"~/.cache/sbt-vcpkg/vcpkg-install",
"~/.cache/sbt-vcpkg/vcpkg"
)

Use(
UseRef.Public("actions", "cache", "v4"),
name = Some("Cache vcpkg"),
params = Map("key" -> "${{ runner.os }}-sbt-vcpkg", "path" -> paths.mkString("\n"))
)
}

val Scala3 = "3.4.1"
ThisBuild / scalaVersion := Scala3 // the default Scala

testFrameworks += new TestFramework("munit.Framework")

val smithyVersion = "1.47.0"
val smithy4sVersion = "0.18.16"
val smithy4sVersion = "0.18.23"
val alloyVersion = "0.3.7"

lazy val root = tlCrossRootProject.aggregate(core, examples, plugin, pluginBundle, tests)

lazy val core = crossProject(JVMPlatform, JSPlatform)
lazy val core = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.in(file("modules/core"))
.settings(
name := "smithy4s-deriving",
Expand Down Expand Up @@ -89,16 +109,21 @@ lazy val tests = crossProject(JVMPlatform)
)
)

lazy val examples = crossProject(JVMPlatform, JSPlatform)
lazy val examples = crossProject(JVMPlatform, JSPlatform, NativePlatform)
.in(file("modules/examples"))
.dependsOn(core)
.enablePlugins(NoPublishPlugin)
.settings(
libraryDependencies ++= Seq(
"com.disneystreaming.smithy4s" %% "smithy4s-http4s" % smithy4sVersion,
"com.disneystreaming.smithy4s" %% "smithy4s-dynamic" % smithy4sVersion,
"org.http4s" %% "http4s-ember-client" % "0.23.26",
"org.http4s" %% "http4s-ember-server" % "0.23.26"
"com.disneystreaming.smithy4s" %%% "smithy4s-http4s" % smithy4sVersion,
"com.disneystreaming.smithy4s" %%% "smithy4s-dynamic" % smithy4sVersion,
"org.http4s" %%% "http4s-ember-client" % "0.23.26",
"org.http4s" %%% "http4s-ember-server" % "0.23.26",
// This particular version of fs2-io performs evictions of core CE and
// fs2 libraries so that networking with Ember works out of the box
// It still requires all necessary native dependencies (openssl, s2n, zlib)
// to be installed globally
"co.fs2" %%% "fs2-io" % "3.10-365636d"
),
autoCompilerPlugins := true,
Compile / fork := true,
Expand All @@ -113,6 +138,20 @@ lazy val examples = crossProject(JVMPlatform, JSPlatform)
"software.amazon.smithy" % "smithy-model" % smithyVersion
)
)
.nativeEnablePlugins(VcpkgNativePlugin)
.nativeSettings(
vcpkgDependencies := VcpkgDependencies(
"curl",
"s2n",
"openssl"
),
vcpkgNativeConfig ~= {
_.withRenamedLibraries(
Map("curl" -> "libcurl")
)
},
Test / fork := false
)
.jsSettings(
Test / fork := false
)
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@ addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.6.7")
// Set me up for CI release, but don't touch my scalacOptions!
addSbtPlugin("org.typelevel" % "sbt-typelevel-ci-release" % "0.6.7")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.17")
addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "2.2.0")
addSbtPlugin("com.indoorvivants.vcpkg" % "sbt-vcpkg-native" % "0.0.20")

0 comments on commit dc554b4

Please sign in to comment.