Skip to content

Commit

Permalink
Shuffle build for custom runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
armanbilge committed Sep 25, 2022
1 parent 7ea939b commit 26b1622
Show file tree
Hide file tree
Showing 34 changed files with 128 additions and 21 deletions.
42 changes: 39 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,16 @@ jobs:
os: [ubuntu-latest]
scala: [2.12.17, 3.1.3, 2.13.9]
java: [corretto@8, corretto@11]
project: [rootJS, rootJVM]
project: [rootJS, rootJVM, rootNative]
exclude:
- scala: 2.12.17
java: corretto@11
- scala: 3.1.3
java: corretto@11
- project: rootJS
java: corretto@11
- project: rootNative
java: corretto@11
- project: rootJS
scala: 2.12.17
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -108,6 +110,10 @@ jobs:
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
if: matrix.scala != '2.12.17'
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' test
Expand All @@ -126,11 +132,11 @@ jobs:

- name: Make target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
run: mkdir -p target lambda-cloudformation-custom-resource/.js/target lambda-http4s/.jvm/target unidocs/target .js/target core/.js/target examples/.js/target lambda-http4s/.js/target core/.jvm/target .jvm/target lambda/js/target .native/target examples/.jvm/target lambda/jvm/target sbt-lambda/target lambda-cloudformation-custom-resource/.jvm/target project/target
run: mkdir -p lambda-kernel/.jvm/target target lambda-cloudformation-custom-resource/.js/target lambda-http4s/.jvm/target unidocs/target .js/target core/.js/target examples/.js/target lambda-http4s/.js/target core/.jvm/target .jvm/target lambda/js/target lambda-kernel/.js/target .native/target lambda-kernel/.native/target examples/.jvm/target lambda/jvm/target feral-lambda-runtime/.jvm/target sbt-lambda/target feral-lambda-runtime/.native/target lambda-cloudformation-custom-resource/.jvm/target feral-lambda-runtime/.js/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 target lambda-cloudformation-custom-resource/.js/target lambda-http4s/.jvm/target unidocs/target .js/target core/.js/target examples/.js/target lambda-http4s/.js/target core/.jvm/target .jvm/target lambda/js/target .native/target examples/.jvm/target lambda/jvm/target sbt-lambda/target lambda-cloudformation-custom-resource/.jvm/target project/target
run: tar cf targets.tar lambda-kernel/.jvm/target target lambda-cloudformation-custom-resource/.js/target lambda-http4s/.jvm/target unidocs/target .js/target core/.js/target examples/.js/target lambda-http4s/.js/target core/.jvm/target .jvm/target lambda/js/target lambda-kernel/.js/target .native/target lambda-kernel/.native/target examples/.jvm/target lambda/jvm/target feral-lambda-runtime/.jvm/target sbt-lambda/target feral-lambda-runtime/.native/target lambda-cloudformation-custom-resource/.jvm/target feral-lambda-runtime/.js/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 Down Expand Up @@ -209,6 +215,16 @@ jobs:
tar xf targets.tar
rm targets.tar
- name: Download target directories (2.12.17, rootNative)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.17-rootNative

- name: Inflate target directories (2.12.17, rootNative)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.1.3, rootJS)
uses: actions/download-artifact@v2
with:
Expand All @@ -229,6 +245,16 @@ jobs:
tar xf targets.tar
rm targets.tar
- name: Download target directories (3.1.3, rootNative)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-3.1.3-rootNative

- name: Inflate target directories (3.1.3, rootNative)
run: |
tar xf targets.tar
rm targets.tar
- name: Download target directories (2.13.9, rootJS)
uses: actions/download-artifact@v2
with:
Expand All @@ -249,6 +275,16 @@ jobs:
tar xf targets.tar
rm targets.tar
- name: Download target directories (2.13.9, rootNative)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.9-rootNative

- name: Inflate target directories (2.13.9, rootNative)
run: |
tar xf targets.tar
rm targets.tar
- name: Import signing key
if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE == ''
run: echo $PGP_SECRET | base64 -di | gpg --import
Expand Down
60 changes: 47 additions & 13 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,11 @@ val circeVersion = "0.14.3"
val fs2Version = "3.3.0"
val http4sVersion = "0.23.16"
val natchezVersion = "0.1.6"
val munitVersion = "0.7.29"
val munitCEVersion = "1.0.7"
val scalacheckEffectVersion = "1.0.4"
val munitVersion = "1.0.0-M6"
val munitCEVersion = "2.0.0-M3"
val scalacheckEffectVersion = "2.0.0-M2"

ThisBuild / resolvers ++= Resolver.sonatypeOssRepos("snapshots")

lazy val commonSettings = Seq(
crossScalaVersions := Seq(Scala3, Scala213)
Expand All @@ -72,6 +74,8 @@ lazy val commonSettings = Seq(
lazy val root =
tlCrossRootProject.aggregate(
core,
lambdaKernel,
lambdaRuntime,
lambda,
sbtLambda,
lambdaHttp4s,
Expand All @@ -91,25 +95,55 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
)
.settings(commonSettings)

lazy val lambda = crossProject(JSPlatform, JVMPlatform)
.in(file("lambda"))
lazy val lambdaKernel = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("lambda-kernel"))
.settings(
name := "feral-lambda",
name := "feral-lambda-kernel",
libraryDependencies ++= Seq(
"org.tpolecat" %%% "natchez-core" % natchezVersion,
"org.typelevel" %%% "cats-effect-kernel" % catsEffectVersion,
"com.armanbilge" %%% "natchez-core" % "0.1.6-SNAPSHOT",
"io.circe" %%% "circe-scodec" % circeVersion,
"io.circe" %%% "circe-jawn" % circeVersion,
"org.scodec" %%% "scodec-bits" % "1.1.34",
"org.scalameta" %%% "munit-scalacheck" % munitVersion % Test,
"org.typelevel" %%% "munit-cats-effect-3" % munitCEVersion % Test,
"org.typelevel" %%% "munit-cats-effect" % munitCEVersion % Test,
"io.circe" %%% "circe-literal" % circeVersion % Test
)
)
.platformsSettings(JSPlatform, NativePlatform)(
libraryDependencies ++= Seq(
"io.github.cquiroz" %%% "scala-java-time" % "2.4.0"
)
)

lazy val lambdaRuntime = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("feral-lambda-runtime"))
.settings(
name := "feral-lambda-kernel",
libraryDependencies ++= Seq(
"io.circe" %%% "circe-jawn" % circeVersion,
"org.http4s" %%% "http4s-client" % http4sVersion,
"org.http4s" %%% "http4s-circe" % http4sVersion
)
)
.dependsOn(lambdaKernel)

lazy val lambda = crossProject(JSPlatform, JVMPlatform)
.in(file("lambda"))
.settings(
name := "feral-lambda",
libraryDependencies ++= Seq(
"org.scalameta" %%% "munit-scalacheck" % munitVersion % Test,
"org.typelevel" %%% "munit-cats-effect" % munitCEVersion % Test,
"io.circe" %%% "circe-literal" % circeVersion % Test
)
)
.settings(commonSettings)
.jsSettings(
libraryDependencies ++= Seq(
"io.circe" %%% "circe-scalajs" % circeVersion,
"io.github.cquiroz" %%% "scala-java-time" % "2.4.0"
"io.circe" %%% "circe-scalajs" % circeVersion
)
)
.jvmSettings(
Expand All @@ -119,7 +153,7 @@ lazy val lambda = crossProject(JSPlatform, JVMPlatform)
"io.circe" %%% "circe-fs2" % "0.14.0"
)
)
.dependsOn(core)
.dependsOn(core, lambdaKernel)

lazy val sbtLambda = project
.in(file("sbt-lambda"))
Expand Down Expand Up @@ -147,7 +181,7 @@ lazy val lambdaHttp4s = crossProject(JSPlatform, JVMPlatform)
)
)
.settings(commonSettings)
.dependsOn(lambda % "compile->compile;test->test")
.dependsOn(lambda, lambdaKernel % "compile->compile;test->test")

lazy val lambdaCloudFormationCustomResource = crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
Expand All @@ -164,7 +198,7 @@ lazy val lambdaCloudFormationCustomResource = crossProject(JSPlatform, JVMPlatfo
"org.http4s" %%% "http4s-circe" % http4sVersion,
"org.http4s" %%% "http4s-dsl" % http4sVersion % Test,
"org.scalameta" %%% "munit-scalacheck" % munitVersion % Test,
"org.typelevel" %%% "munit-cats-effect-3" % munitCEVersion % Test,
"org.typelevel" %%% "munit-cats-effect" % munitCEVersion % Test,
"org.typelevel" %%% "scalacheck-effect" % scalacheckEffectVersion % Test,
"org.typelevel" %%% "scalacheck-effect-munit" % scalacheckEffectVersion % Test,
"com.eed3si9n.expecty" %%% "expecty" % "0.16.0" % Test,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* Copyright 2021 Typelevel
*
* 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
*
* http://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 feral.lambda
package runtime

import cats.effect.kernel.Concurrent
import cats.effect.kernel.Resource
import io.circe.Json
import org.http4s.client.Client

object FeralLambdaRuntime {

def apply[F[_]](client: Client[F])(handler: (Json, Context[F]) => F[Json])(
implicit F: Concurrent[F]
): Resource[F, Unit] =
// TODO implement a runtime here
// it should retrieve incoming events and handle them with the handler
// it will run on a background fiber, whose lifecycle is controlled by the resource
???

}
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ final class Context[F[_]] private[lambda] (
f(remainingTime))
}

object Context extends ContextCompanionPlatform
object Context

final class CognitoIdentity(
val identityId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import io.circe.scalajs._

import scala.concurrent.duration._

private[lambda] trait ContextCompanionPlatform {
private[lambda] object ContextPlatform {

private[lambda] def fromJS[F[_]: Sync](context: facade.Context): Context[F] =
new Context(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ private[lambda] trait IOLambdaPlatform[Event, Result] {
(for {
lambda <- setupMemo
event <- IO.fromEither(decodeJs[Event](event))
result <- lambda(event, Context.fromJS(context))
result <- lambda(event, ContextPlatform.fromJS(context))
} yield result.map(_.asJsAny).orUndefined).unsafeToPromise()(runtime)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import io.circe.jawn.parse
import scala.concurrent.duration._
import scala.jdk.CollectionConverters._

private[lambda] trait ContextCompanionPlatform {
private[lambda] object ContextPlatform {

private[lambda] def fromJava[F[_]: Sync](context: runtime.Context): Context[F] =
new Context(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ private[lambda] abstract class IOLambdaPlatform[Event, Result]
.head
.compile
.lastOrError
context <- IO(Context.fromJava[IO](context))
context <- IO(ContextPlatform.fromJava[IO](context))
_ <- OptionT(lambda(event, context)).foreachF { result =>
Resource.fromAutoCloseable(IO(new OutputStreamWriter(output))).use { writer =>
IO.blocking(Printer.noSpaces.unsafePrintToAppendable(result.asJson, writer))
Expand Down
2 changes: 2 additions & 0 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.4.15")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.10.1")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.7")
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.2.0")

0 comments on commit 26b1622

Please sign in to comment.