Skip to content

Commit

Permalink
Merge pull request #139 from hnaderi/update/scala-native
Browse files Browse the repository at this point in the history
Updated Scala native and other stuff
  • Loading branch information
mergify[bot] authored Aug 16, 2024
2 parents d188009 + f15e820 commit e2f07ea
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 76 deletions.
67 changes: 27 additions & 40 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -131,7 +131,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
java: [temurin@8]
java: [temurin@17]
runs-on: ${{ matrix.os }}
steps:
- name: Install sbt
Expand All @@ -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)
Expand Down Expand Up @@ -292,7 +292,7 @@ jobs:
strategy:
matrix:
os: [ubuntu-latest]
java: [temurin@8]
java: [temurin@17]
runs-on: ${{ matrix.os }}
steps:
- name: Install sbt
Expand All @@ -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)
Expand All @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand Down
6 changes: 3 additions & 3 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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"
)
)
}
Expand All @@ -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"
)
}

Expand Down
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
let
pkgs = import nixpkgs {
inherit system;
overlays = [ typelevel-nix.overlay ];
overlays = [ typelevel-nix.overlays.default ];
};
in {
devShell = pkgs.devshell.mkShell {
Expand Down
13 changes: 7 additions & 6 deletions modules/libyaml/src/main/scala/LibYamlDocument.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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._

Expand All @@ -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](
Expand All @@ -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)
}
Expand Down
8 changes: 4 additions & 4 deletions modules/libyaml/src/main/scala/LibyamlParser.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand Down
46 changes: 26 additions & 20 deletions modules/libyaml/src/main/scala/LibyamlPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

}
Expand All @@ -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))

Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -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")
4 changes: 3 additions & 1 deletion workflows.sbt
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit e2f07ea

Please sign in to comment.