diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d2d4df5..c26504b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,7 +30,7 @@ jobs: matrix: os: [ubuntu-latest, macos-13, macos-latest] scala: [3, 2.13, 2.12] - java: [temurin@8] + java: [temurin@17] project: [rootJS, rootJVM, rootNative] exclude: - project: rootJS @@ -53,17 +53,17 @@ 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: Install libyaml (ubuntu) @@ -87,7 +87,7 @@ jobs: 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 @@ -102,11 +102,11 @@ jobs: 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 @@ -131,7 +131,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - java: [temurin@8] + java: [temurin@17] runs-on: ${{ matrix.os }} steps: - name: Install sbt @@ -143,17 +143,17 @@ 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: Install libyaml (ubuntu) @@ -292,7 +292,7 @@ jobs: strategy: matrix: os: [ubuntu-latest] - java: [temurin@8] + java: [temurin@17] runs-on: ${{ matrix.os }} steps: - name: Install sbt @@ -304,17 +304,17 @@ 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: Install libyaml (ubuntu) @@ -336,7 +336,7 @@ jobs: - name: Submit Dependencies uses: scalacenter/sbt-dependency-submission@v2 with: - modules-ignore: rootjs_3 rootjs_2.13 rootjs_2.12 docs_3 docs_2.13 docs_2.12 yaml4s-tests_sjs1_3 yaml4s-tests_sjs1_2.13 yaml4s-tests_sjs1_2.12 rootjvm_3 rootjvm_2.13 rootjvm_2.12 rootnative_3 rootnative_2.13 rootnative_2.12 yaml4s-tests_3 yaml4s-tests_2.13 yaml4s-tests_2.12 yaml4s-tests_native0.4_3 yaml4s-tests_native0.4_2.13 yaml4s-tests_native0.4_2.12 + modules-ignore: rootjs_3 rootjs_2.13 rootjs_2.12 docs_3 docs_2.13 docs_2.12 yaml4s-tests_sjs1_3 yaml4s-tests_sjs1_2.13 yaml4s-tests_sjs1_2.12 rootjvm_3 rootjvm_2.13 rootjvm_2.12 rootnative_3 rootnative_2.13 rootnative_2.12 yaml4s-tests_3 yaml4s-tests_2.13 yaml4s-tests_2.12 yaml4s-tests_native0.5_3 yaml4s-tests_native0.5_2.13 yaml4s-tests_native0.5_2.12 configs-ignore: test scala-tool scala-doc-tool test-internal post-build: @@ -367,17 +367,17 @@ 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: Install libyaml (ubuntu) @@ -396,19 +396,6 @@ jobs: vcpkg integrate install vcpkg install --triplet x64-windows libyaml - - 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: 17 - cache: sbt - - - name: sbt update - if: matrix.java == 'temurin@17' && steps.setup-java-temurin-17.outputs.cache-hit == 'false' - run: sbt +update - - name: Generate site run: sbt docs/tlSite diff --git a/build.sbt b/build.sbt index 58f6dc7..35ccb00 100644 --- a/build.sbt +++ b/build.sbt @@ -1,7 +1,7 @@ import laika.ast.Image import sbtcrossproject.CrossProject -ThisBuild / tlBaseVersion := "0.2" +ThisBuild / tlBaseVersion := "0.3" ThisBuild / organization := "dev.hnaderi" ThisBuild / organizationName := "Hossein Naderi" @@ -95,7 +95,7 @@ lazy val tests = module("tests") { .settings( libraryDependencies ++= Seq( "org.scalameta" %%% "munit" % "1.0.0", - "org.scalameta" %%% "munit-scalacheck" % "1.0.0-M11" + "org.scalameta" %%% "munit-scalacheck" % "1.0.0" ) ) } @@ -113,7 +113,7 @@ lazy val circe = module("circe") { .dependsOn(core) .settings( description := "yaml4s integration with circe", - libraryDependencies += "io.circe" %%% "circe-core" % "0.14.8" + libraryDependencies += "io.circe" %%% "circe-core" % "0.14.9" ) } diff --git a/flake.nix b/flake.nix index 2ebcd98..fa52fdc 100644 --- a/flake.nix +++ b/flake.nix @@ -10,7 +10,7 @@ let pkgs = import nixpkgs { inherit system; - overlays = [ typelevel-nix.overlay ]; + overlays = [ typelevel-nix.overlays.default ]; }; in { devShell = pkgs.devshell.mkShell { diff --git a/modules/libyaml/src/main/scala/LibYamlDocument.scala b/modules/libyaml/src/main/scala/LibYamlDocument.scala index e185e60..bef0702 100644 --- a/modules/libyaml/src/main/scala/LibYamlDocument.scala +++ b/modules/libyaml/src/main/scala/LibYamlDocument.scala @@ -18,7 +18,7 @@ package dev.hnaderi.yaml4s package binding import scala.collection.mutable -import scala.scalanative.runtime.libc +import scala.scalanative.libc import scala.scalanative.unsafe._ import scala.scalanative.unsigned._ @@ -32,11 +32,12 @@ private final class LibYamlDocument(private val document: Ptr[yaml_document_t]) def clean(): Unit = yaml_document_delete(document) - def visit[T](implicit w: Writer[T]): Option[T] = Zone { implicit zone => - val root = yaml_document_get_root_node(document) + def visit[T](implicit w: Writer[T]): Option[T] = Zone.acquire { + implicit zone: Zone => + val root = yaml_document_get_root_node(document) - if (root == null) None - else Some(visitNode(document, root)) + if (root == null) None + else Some(visitNode(document, root)) } private def visitNode[T]( @@ -58,7 +59,7 @@ private final class LibYamlDocument(private val document: Ptr[yaml_document_t]) private def stringValue(node: Ptr[struct_scalar_node]): String = { val bytes = new Array[Byte](node.length.toInt) val value = node.value.asInstanceOf[CString] - libc.memcpy(bytes.at(0), value, node.length.toULong) + libc.string.memcpy(bytes.at(0), value, node.length.toUSize) new String(bytes) } diff --git a/modules/libyaml/src/main/scala/LibyamlParser.scala b/modules/libyaml/src/main/scala/LibyamlParser.scala index 0468e01..014f2a7 100644 --- a/modules/libyaml/src/main/scala/LibyamlParser.scala +++ b/modules/libyaml/src/main/scala/LibyamlParser.scala @@ -26,8 +26,8 @@ import others._ private[yaml4s] trait LibyamlParser extends Parser { - override def parse[T: Writer](input: String): Either[Throwable, T] = Zone { - implicit zone => + override def parse[T: Writer](input: String): Either[Throwable, T] = + Zone.acquire { implicit zone: Zone => val input_c = toCString(input).asInstanceOf[Ptr[CUnsignedChar]] val parser = struct_yaml_parser_s() @@ -48,14 +48,14 @@ private[yaml4s] trait LibyamlParser extends Parser { yaml_parser_delete(parser) result } - } + } private def handle(result: CInt, err: => Throwable) = Either.cond(result != 0, (), err) override def parseDocuments[T: Writer]( input: String - ): Either[Throwable, Iterable[T]] = Zone { implicit zone => + ): Either[Throwable, Iterable[T]] = Zone.acquire { implicit zone: Zone => val input_c = toCString(input).asInstanceOf[Ptr[CUnsignedChar]] val parser = struct_yaml_parser_s() diff --git a/modules/libyaml/src/main/scala/LibyamlPrinter.scala b/modules/libyaml/src/main/scala/LibyamlPrinter.scala index 49e6480..07337c8 100644 --- a/modules/libyaml/src/main/scala/LibyamlPrinter.scala +++ b/modules/libyaml/src/main/scala/LibyamlPrinter.scala @@ -17,36 +17,42 @@ package dev.hnaderi.yaml4s package binding +import scala.scalanative.libc import scala.scalanative.runtime -import scala.scalanative.unsafe._ -import scala.scalanative.unsigned._ +import scala.scalanative.unsafe.* +import scala.scalanative.unsigned.* -import libyaml._ -import others._ -import definitions._ -import LibyamlPrinter._ +import libyaml.* +import others.* +import definitions.* +import LibyamlPrinter.* private[yaml4s] trait LibyamlPrinter extends Printer { - override def print[T: Visitable](t: T): String = Zone { implicit z => - val emitter = struct_yaml_emitter_s() + override def print[T: Visitable](t: T): String = Zone.acquire { + implicit z: Zone => + val emitter = struct_yaml_emitter_s() - yaml_emitter_initialize(emitter) + yaml_emitter_initialize(emitter) - val stringBuilder = new java.lang.StringBuilder() - yaml_emitter_set_output(emitter, handler(_, _, _), toPtr(stringBuilder)) + val stringBuilder = new java.lang.StringBuilder() + yaml_emitter_set_output( + emitter, + handler(_, _, _), + LibyamlPrinter.toPtr(stringBuilder) + ) - val doc = struct_yaml_document_s() - yaml_document_initialize(doc, null, null, null, 1, 1) - build(doc, t) + val doc = struct_yaml_document_s() + yaml_document_initialize(doc, null, null, null, 1, 1) + build(doc, t) - yaml_emitter_dump(emitter, doc) + yaml_emitter_dump(emitter, doc) - yaml_emitter_flush(emitter) - yaml_emitter_close(emitter) - yaml_emitter_delete(emitter) + yaml_emitter_flush(emitter) + yaml_emitter_close(emitter) + yaml_emitter_delete(emitter) - stringBuilder.toString() + stringBuilder.toString() } } @@ -69,7 +75,7 @@ private object LibyamlPrinter { val bytes = new Array[Byte](size.toInt) val value = buf.asInstanceOf[CString] - runtime.libc.memcpy(bytes.at(0), value, size.toULong) + libc.string.memcpy(bytes.at(0), value, size.toUSize) builder.append(new String(bytes)) diff --git a/project/plugins.sbt b/project/plugins.sbt index a3d6c0d..74e8065 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -1,7 +1,7 @@ addSbtPlugin("org.typelevel" % "sbt-typelevel" % "0.6.7") addSbtPlugin("org.typelevel" % "sbt-typelevel-site" % "0.6.7") addSbtPlugin("org.scalameta" % "sbt-mdoc" % "2.5.3") -addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.17") +addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.5.4") addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.3.2") addSbtPlugin("org.scala-js" % "sbt-scalajs" % "1.16.0") addSbtPlugin("ch.epfl.scala" % "sbt-scalajs-bundler" % "0.21.1") diff --git a/workflows.sbt b/workflows.sbt index fe3e520..10c4ae4 100644 --- a/workflows.sbt +++ b/workflows.sbt @@ -1,6 +1,8 @@ // This is a huge build matrix! so it's better to find problems rather than failing prematurely. +val LTSJava = JavaSpec.temurin("17") +ThisBuild / githubWorkflowJavaVersions := Seq(LTSJava) ThisBuild / githubWorkflowBuildMatrixFailFast := Some(false) -ThisBuild / tlSiteJavaVersion := JavaSpec.temurin("17") +ThisBuild / tlSiteJavaVersion := LTSJava ThisBuild / githubWorkflowOSes := Seq( "ubuntu-latest", // "windows-2022", // disable for now, there is some linking problem