Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cross-build for Native #613

Merged
merged 5 commits into from
Oct 1, 2022
Merged
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
48 changes: 41 additions & 7 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
os: [ubuntu-latest]
scala: [2.12.16, 2.13.8, 3.1.3]
java: [temurin@8]
project: [rootJS, rootJVM]
project: [rootJS, rootJVM, rootNative]
runs-on: ${{ matrix.os }}
steps:
- name: Checkout current branch (full)
Expand Down Expand Up @@ -77,6 +77,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
run: sbt 'project ${{ matrix.project }}' '++${{ matrix.scala }}' test

Expand All @@ -89,15 +93,15 @@ jobs:
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/lightstep-grpc/target modules/log/jvm/target modules/noop/jvm/target modules/mock/target modules/examples/target target .js/target modules/docs/target modules/lightstep-http/target modules/datadog/target modules/xray/jvm/target modules/opentracing/target modules/xray/js/target modules/core/js/target modules/noop/js/target modules/core/jvm/target .jvm/target modules/jaeger/target .native/target modules/opencensus/target modules/honeycomb/target modules/log/js/target modules/mtl/js/target modules/newrelic/target modules/mtl/jvm/target modules/lightstep/target project/target
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/series/0.1')
run: mkdir -p modules/mtl/native/target modules/lightstep-grpc/target modules/log/jvm/target modules/noop/jvm/target modules/mock/target modules/examples/target target modules/log/native/target .js/target modules/core/native/target modules/docs/target modules/lightstep-http/target modules/datadog/target modules/xray/jvm/target modules/opentracing/target modules/noop/native/target modules/xray/js/target modules/core/js/target modules/noop/js/target modules/core/jvm/target .jvm/target modules/jaeger/target .native/target modules/opencensus/target modules/honeycomb/target modules/log/js/target modules/mtl/js/target modules/newrelic/target modules/mtl/jvm/target modules/lightstep/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/lightstep-grpc/target modules/log/jvm/target modules/noop/jvm/target modules/mock/target modules/examples/target target .js/target modules/docs/target modules/lightstep-http/target modules/datadog/target modules/xray/jvm/target modules/opentracing/target modules/xray/js/target modules/core/js/target modules/noop/js/target modules/core/jvm/target .jvm/target modules/jaeger/target .native/target modules/opencensus/target modules/honeycomb/target modules/log/js/target modules/mtl/js/target modules/newrelic/target modules/mtl/jvm/target modules/lightstep/target project/target
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/series/0.1')
run: tar cf targets.tar modules/mtl/native/target modules/lightstep-grpc/target modules/log/jvm/target modules/noop/jvm/target modules/mock/target modules/examples/target target modules/log/native/target .js/target modules/core/native/target modules/docs/target modules/lightstep-http/target modules/datadog/target modules/xray/jvm/target modules/opentracing/target modules/noop/native/target modules/xray/js/target modules/core/js/target modules/noop/js/target modules/core/jvm/target .jvm/target modules/jaeger/target .native/target modules/opencensus/target modules/honeycomb/target modules/log/js/target modules/mtl/js/target modules/newrelic/target modules/mtl/jvm/target modules/lightstep/target project/target

- name: Upload target directories
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/series/0.1')
uses: actions/upload-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-${{ matrix.scala }}-${{ matrix.project }}
Expand All @@ -106,7 +110,7 @@ jobs:
publish:
name: Publish Artifacts
needs: [build]
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main' || github.ref == 'refs/heads/series/0.1')
strategy:
matrix:
os: [ubuntu-latest]
Expand Down Expand Up @@ -167,6 +171,16 @@ jobs:
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.12.16, rootNative)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.12.16-rootNative

- name: Inflate target directories (2.12.16, rootNative)
run: |
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.13.8, rootJS)
uses: actions/download-artifact@v2
with:
Expand All @@ -187,6 +201,16 @@ jobs:
tar xf targets.tar
rm targets.tar

- name: Download target directories (2.13.8, rootNative)
uses: actions/download-artifact@v2
with:
name: target-${{ matrix.os }}-${{ matrix.java }}-2.13.8-rootNative

- name: Inflate target directories (2.13.8, 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 @@ -207,6 +231,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: Import signing key
if: env.PGP_SECRET != '' && env.PGP_PASSPHRASE == ''
run: echo $PGP_SECRET | base64 -di | gpg --import
Expand Down
4 changes: 4 additions & 0 deletions .jvmopts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@

-Xms1G
-Xmx4G
-XX:+UseG1GC
97 changes: 39 additions & 58 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ ThisBuild / developers := List(
)
ThisBuild / tlSonatypeUseLegacyHost := false

ThisBuild / tlCiReleaseBranches += "series/0.1"

// start MiMa from here
ThisBuild / tlVersionIntroduced := List("2.12", "2.13", "3").map(_ -> "0.1.6").toMap

Expand All @@ -41,14 +43,17 @@ lazy val commonSettings = Seq(
|For more information see LICENSE or https://opensource.org/licenses/MIT
|""".stripMargin
)
),
// Testing
libraryDependencies ++= Seq(
"org.scalameta" %%% "munit" % "1.0.0-M6" % Test,
"org.scalameta" %%% "munit-scalacheck" % "1.0.0-M6" % Test,
"org.typelevel" %%% "munit-cats-effect" % "2.0.0-M3" % Test,
)
)

// Testing
ThisBuild / libraryDependencies ++= Seq(
"org.scalameta" %%% "munit" % "0.7.29" % Test,
"org.scalameta" %%% "munit-scalacheck" % "0.7.29" % Test,
"org.typelevel" %%% "munit-cats-effect-3" % "1.0.7" % Test,
lazy val commonNativeSettings = Seq(
tlVersionIntroduced := List("2.12", "2.13", "3").map(_ -> "0.1.7").toMap
)

// Compilation
Expand All @@ -71,7 +76,7 @@ lazy val root = tlCrossRootProject.aggregate(
examples
)

lazy val core = crossProject(JSPlatform, JVMPlatform)
lazy val core = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("modules/core"))
.enablePlugins(AutomateHeaderPlugin)
.settings(commonSettings)
Expand All @@ -84,18 +89,11 @@ lazy val core = crossProject(JSPlatform, JVMPlatform)
"org.typelevel" %%% "cats-effect" % catsEffectVersion,
)
)

lazy val coreJVM = core.jvm
lazy val coreJS = core.js
.settings(
Test / scalaJSStage := FastOptStage,
jsEnv := new org.scalajs.jsenv.nodejs.NodeJSEnv(),
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
)
.nativeSettings(commonNativeSettings)

lazy val jaeger = project
.in(file("modules/jaeger"))
.dependsOn(coreJVM, opentracing)
.dependsOn(core.jvm, opentracing)
.enablePlugins(AutomateHeaderPlugin)
.settings(commonSettings)
.settings(
Expand All @@ -109,7 +107,7 @@ lazy val jaeger = project

lazy val honeycomb = project
.in(file("modules/honeycomb"))
.dependsOn(coreJVM)
.dependsOn(core.jvm)
.enablePlugins(AutomateHeaderPlugin)
.settings(commonSettings)
.settings(
Expand All @@ -123,7 +121,7 @@ lazy val honeycomb = project

lazy val opencensus = project
.in(file("modules/opencensus"))
.dependsOn(coreJVM)
.dependsOn(core.jvm)
.enablePlugins(AutomateHeaderPlugin)
.settings(commonSettings)
.settings(
Expand All @@ -136,7 +134,7 @@ lazy val opencensus = project

lazy val lightstep = project
.in(file("modules/lightstep"))
.dependsOn(coreJVM, opentracing)
.dependsOn(core.jvm, opentracing)
.enablePlugins(AutomateHeaderPlugin)
.settings(commonSettings)
.settings(
Expand Down Expand Up @@ -180,7 +178,7 @@ lazy val lightstepHttp = project

lazy val opentracing = project
.in(file("modules/opentracing"))
.dependsOn(coreJVM)
.dependsOn(core.jvm)
.enablePlugins(AutomateHeaderPlugin)
.settings(commonSettings)
.settings(
Expand All @@ -196,7 +194,7 @@ lazy val opentracing = project

lazy val datadog = project
.in(file("modules/datadog"))
.dependsOn(coreJVM, opentracing)
.dependsOn(core.jvm, opentracing)
.enablePlugins(AutomateHeaderPlugin)
.settings(commonSettings)
.settings(
Expand All @@ -209,46 +207,42 @@ lazy val datadog = project
)
)

lazy val log = crossProject(JSPlatform, JVMPlatform)
lazy val log = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("modules/log"))
.dependsOn(core)
.enablePlugins(AutomateHeaderPlugin)
.settings(commonSettings)
.settings(
name := "natchez-log",
description := "Logging bindings for Natchez, using log4cats.",
libraryDependencies ++= Seq(
"io.circe" %%% "circe-core" % "0.14.2",
"org.typelevel" %%% "log4cats-core" % "2.4.0",
"io.github.cquiroz" %%% "scala-java-time" % "2.4.0" % Test
"io.circe" %%% "circe-core" % "0.14.3",
"org.typelevel" %%% "log4cats-core" % "2.5.0",
"io.github.cquiroz" %%% "scala-java-time" % "2.4.0" % Test,
)
)
lazy val logJVM = log.jvm.dependsOn(coreJVM)
lazy val logJS = log.js.dependsOn(coreJS)
.settings(
Test / scalaJSStage := FastOptStage,
jsEnv := new org.scalajs.jsenv.nodejs.NodeJSEnv(),
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
)
.nativeSettings(commonNativeSettings)

lazy val newrelic = project
.in(file("modules/newrelic"))
.dependsOn(coreJVM)
.dependsOn(core.jvm)
.enablePlugins(AutomateHeaderPlugin)
.settings(commonSettings)
.settings(
name := "newrelic",
description := "Newrelic bindings for Natchez.",
libraryDependencies ++= Seq(
"io.circe" %% "circe-core" % "0.14.2",
"io.circe" %% "circe-core" % "0.14.3",
"org.scala-lang.modules" %% "scala-collection-compat" % collectionCompatVersion,
"com.newrelic.telemetry" % "telemetry" % "0.10.0",
"com.newrelic.telemetry" % "telemetry-core" % "0.15.0",
"com.newrelic.telemetry" % "telemetry-http-okhttp" % "0.15.0"
)
)

lazy val mtl = crossProject(JSPlatform, JVMPlatform)
lazy val mtl = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("modules/mtl"))
.dependsOn(core)
.enablePlugins(AutomateHeaderPlugin)
.settings(commonSettings)
.settings(
Expand All @@ -258,16 +252,9 @@ lazy val mtl = crossProject(JSPlatform, JVMPlatform)
"org.typelevel" %%% "cats-mtl" % "1.3.0",
)
)
.nativeSettings(commonNativeSettings)

lazy val mtlJVM = mtl.jvm.dependsOn(coreJVM)
lazy val mtlJS = mtl.js.dependsOn(coreJS)
.settings(
Test / scalaJSStage := FastOptStage,
jsEnv := new org.scalajs.jsenv.nodejs.NodeJSEnv(),
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
)

lazy val noop = crossProject(JSPlatform, JVMPlatform)
lazy val noop = crossProject(JSPlatform, JVMPlatform, NativePlatform)
.in(file("modules/noop"))
.dependsOn(core)
.enablePlugins(AutomateHeaderPlugin)
Expand All @@ -277,11 +264,7 @@ lazy val noop = crossProject(JSPlatform, JVMPlatform)
description := "No-Op Open Tracing implementation",
libraryDependencies ++= Seq()
)
.jsSettings(
Test / scalaJSStage := FastOptStage,
jsEnv := new org.scalajs.jsenv.nodejs.NodeJSEnv(),
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
)
.nativeSettings(commonNativeSettings)

lazy val xray = crossProject(JSPlatform, JVMPlatform)
.in(file("modules/xray"))
Expand All @@ -292,21 +275,19 @@ lazy val xray = crossProject(JSPlatform, JVMPlatform)
name := "natchez-xray",
description := "AWS X-Ray bindings implementation",
libraryDependencies ++= Seq(
"io.circe" %%% "circe-core" % "0.14.2",
"io.circe" %%% "circe-core" % "0.14.3",
"co.fs2" %%% "fs2-io" % "3.2.14",
"com.comcast" %%% "ip4s-core" % "3.1.3",
"org.scodec" %%% "scodec-bits" % "1.1.34"
)
)
.jsSettings(
Test / scalaJSStage := FastOptStage,
jsEnv := new org.scalajs.jsenv.nodejs.NodeJSEnv(),
scalaJSLinkerConfig ~= (_.withModuleKind(ModuleKind.CommonJSModule)),
)

lazy val mock = project
.in(file("modules/mock"))
.dependsOn(coreJVM)
.dependsOn(core.jvm)
.enablePlugins(AutomateHeaderPlugin)
.settings(commonSettings)
.settings(
Expand All @@ -320,15 +301,15 @@ lazy val mock = project

lazy val examples = project
.in(file("modules/examples"))
.dependsOn(coreJVM, jaeger, honeycomb, lightstepHttp, datadog, newrelic, logJVM)
.dependsOn(core.jvm, jaeger, honeycomb, lightstepHttp, datadog, newrelic, log.jvm)
.enablePlugins(AutomateHeaderPlugin, NoPublishPlugin)
.settings(commonSettings)
.settings(
name := "natchez-examples",
description := "Example programs for Natchez.",
scalacOptions -= "-Xfatal-warnings",
libraryDependencies ++= Seq(
"org.typelevel" %% "log4cats-slf4j" % "2.4.0",
"org.typelevel" %% "log4cats-slf4j" % "2.5.0",
"org.slf4j" % "slf4j-simple" % "2.0.0",
"eu.timepit" %% "refined" % "0.9.29",
"is.cir" %% "ciris" % "2.3.3"
Expand All @@ -337,7 +318,7 @@ lazy val examples = project

// lazy val logOdin = project
// .in(file("modules/log-odin"))
// .dependsOn(coreJVM)
// .dependsOn(core.jvm)
// .enablePlugins(AutomateHeaderPlugin)
// // .settings(
// publish / skip := scalaVersion.value.startsWith("3."),
Expand All @@ -352,7 +333,7 @@ lazy val examples = project

lazy val docs = project
.in(file("modules/docs"))
.dependsOn(mtlJVM, honeycomb, datadog, jaeger, logJVM)
.dependsOn(mtl.jvm, honeycomb, datadog, jaeger, log.jvm)
.enablePlugins(AutomateHeaderPlugin)
.enablePlugins(ParadoxPlugin)
.enablePlugins(ParadoxSitePlugin)
Expand All @@ -366,10 +347,10 @@ lazy val docs = project
paradoxTheme := Some(builtinParadoxTheme("generic")),
version := version.value.takeWhile(_ != '+'), // strip off the +3-f22dca22+20191110-1520-SNAPSHOT business
paradoxProperties ++= Map(
"scala-versions" -> (coreJVM / crossScalaVersions).value.map(CrossVersion.partialVersion).flatten.distinct.map { case (a, b) => s"$a.$b"} .mkString("/"),
"scala-versions" -> (core.jvm / crossScalaVersions).value.map(CrossVersion.partialVersion).flatten.distinct.map { case (a, b) => s"$a.$b"} .mkString("/"),
"org" -> organization.value,
"scala.binary.version" -> s"2.${CrossVersion.partialVersion(scalaVersion.value).get._2}",
"core-dep" -> s"${(coreJVM / name).value}_2.${CrossVersion.partialVersion(scalaVersion.value).get._2}",
"core-dep" -> s"${(core.jvm / name).value}_2.${CrossVersion.partialVersion(scalaVersion.value).get._2}",
"version" -> version.value,
"scaladoc.natchez.base_url" -> s"https://static.javadoc.io/org.tpolecat/natchez-core_2.13/${version.value}",
),
Expand Down
3 changes: 2 additions & 1 deletion modules/log/shared/src/main/scala/LogSpan.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package natchez.log

import cats.effect.Ref
import cats.effect._
import cats.effect.std.UUIDGen
import cats.effect.Resource.ExitCase
import cats.effect.Resource.ExitCase._
import cats.syntax.all._
Expand Down Expand Up @@ -123,7 +124,7 @@ private[log] object LogSpan {
}

private def uuid[F[_]: Sync]: F[UUID] =
Sync[F].delay(UUID.randomUUID)
UUIDGen.randomUUID

private def now[F[_]: Sync]: F[Instant] =
Sync[F].delay(Instant.now)
Expand Down