Skip to content

Commit af3583c

Browse files
authored
Support Scala 3 (scala-native#39)
* Support Scala 3 * Remove server which doesn't link on Scala 3 - This server is superseded by SNUnit * Add workaround for scala-native#2550
1 parent 2da4a23 commit af3583c

File tree

7 files changed

+36
-24
lines changed

7 files changed

+36
-24
lines changed

build.sbt

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
Global / onChangedBuildSource := ReloadOnSourceChanges
1+
val scala3 = "3.1.0"
2+
val scala213 = "2.13.4"
3+
val scala212 = "2.12.13"
4+
val scala211 = "2.11.12"
25

36
inThisBuild(
47
Seq(
58
organization := "com.github.lolgab",
69
version := "0.2.1-SNAPSHOT",
7-
scalaVersion := scala212
10+
scalaVersion := scala213,
11+
crossScalaVersions := Seq(scala3, scala213, scala212, scala211),
812
)
913
)
1014

@@ -40,13 +44,7 @@ val noPublishSettings = Seq(
4044
skip in publish := true
4145
)
4246

43-
val scala213 = "2.13.4"
44-
val scala212 = "2.12.13"
45-
val scala211 = "2.11.12"
46-
4747
lazy val commonSettings = Seq(
48-
scalaVersion := scala213,
49-
crossScalaVersions := Seq(scala213, scala212, scala211),
5048
scalacOptions ++= Seq(
5149
"-deprecation",
5250
"-encoding",
@@ -57,7 +55,7 @@ lazy val commonSettings = Seq(
5755
// "-Wunused:imports"
5856
),
5957
Compile / doc / sources := Seq.empty,
60-
libraryDependencies += "com.lihaoyi" %%% "utest" % "0.7.6" % Test,
58+
libraryDependencies += "com.lihaoyi" %%% "utest" % "0.7.11" % Test,
6159
testFrameworks += new TestFramework("utest.runner.Framework"),
6260
Test / nativeLinkStubs := true,
6361
)

client/curl.scala

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ object Curl {
122122
data: Ptr[Byte]
123123
) => {
124124
val serial = !(data.asInstanceOf[Ptr[Long]])
125-
val len = stackalloc[Double]
125+
val len = stackalloc[Double]()
126126
!len = 0
127127
val strData = bufferToString(ptr, size, nmemb)
128128
println(s"req $serial: got data of size ${size} x ${nmemb}")
@@ -141,7 +141,7 @@ object Curl {
141141
data: Ptr[Byte]
142142
)=> {
143143
val serial = !(data.asInstanceOf[Ptr[Long]])
144-
val len = stackalloc[Double]
144+
val len = stackalloc[Double]()
145145
!len = 0
146146
val strData = bufferToString(ptr, size, nmemb)
147147
println(s"req $serial: got header line of size ${size} x ${nmemb}")
@@ -187,10 +187,10 @@ object Curl {
187187
var actions = 0
188188
if (res.readable) actions |= 1
189189
if (res.writable) actions |= 2
190-
val running_handles = stackalloc[Int]
190+
val running_handles = stackalloc[Int]()
191191
val result =
192192
multi_socket_action(multi, socket, actions, running_handles)
193-
println("multi_socket_action", result)
193+
println(("multi_socket_action", result))
194194
}
195195
} else {
196196
println("stopping poll")
@@ -209,7 +209,7 @@ object Curl {
209209
println("starting timer")
210210
Timer.timeout(time.millis) { () =>
211211
println("in timeout callback")
212-
val running_handles = stackalloc[Int]
212+
val running_handles = stackalloc[Int]()
213213
multi_socket_action(multi, -1, 0, running_handles)
214214
println(s"on_timer fired, ${!running_handles} sockets running")
215215
}
@@ -220,8 +220,8 @@ object Curl {
220220
}
221221

222222
def cleanup_requests(): Unit = {
223-
val messages = stackalloc[Int]
224-
val privateDataPtr = stackalloc[Ptr[Long]]
223+
val messages = stackalloc[Int]()
224+
val privateDataPtr = stackalloc[Ptr[Long]]()
225225
var message: Ptr[CurlMessage] = multi_info_read(multi, messages)
226226
while (message != null) {
227227
println(

core/src/main/scala/scala/scalanative/loop/Eventloop.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,9 @@ object LibUV {
6666
type PrepareCB = CFuncPtr1[PrepareHandle, Unit]
6767
type ShutdownCB = CFuncPtr2[ShutdownReq, Int, Unit]
6868
type CloseCB = CFuncPtr1[UVHandle, Unit]
69-
type PollCB = CFuncPtr3[PollHandle, Int, Int, Unit]
69+
// Workaround for https://github.com/scala-native/scala-native/issues/2550
70+
// Use `Int` instead of `Integer` once fixed
71+
type PollCB = CFuncPtr3[PollHandle, Integer, Integer, Unit]
7072
type TimerCB = CFuncPtr1[TimerHandle, Unit]
7173
type FSCB = CFuncPtr1[FSReq, Unit]
7274

core/src/main/scala/scala/scalanative/loop/Poll.scala

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ class RWResult(val result: Int, val readable: Boolean, val writable: Boolean)
3737
}
3838

3939
object Poll {
40-
private val pollReadWriteCB: PollCB = (handle: PollHandle, status: Int, events: Int) => {
40+
private val pollReadWriteCB: PollCB = (
41+
handle: PollHandle,
42+
status: Integer,
43+
events: Integer
44+
) => {
4145
val callback =
4246
HandleUtils.getData[RWResult => Unit](handle)
4347
callback.apply(
@@ -48,11 +52,19 @@ object Poll {
4852
)
4953
)
5054
}
51-
private val pollReadCB: PollCB = (handle: PollHandle, status: Int, events: Int) => {
55+
private val pollReadCB: PollCB = (
56+
handle: PollHandle,
57+
status: Integer,
58+
events: Integer
59+
) => {
5260
val callback = HandleUtils.getData[Int => Unit](handle)
5361
if ((events & UV_READABLE) != 0) callback.apply(status)
5462
}
55-
private val pollWriteCB: PollCB = (handle: PollHandle, status: Int, events: Int) => {
63+
private val pollWriteCB: PollCB = (
64+
handle: PollHandle,
65+
status: Integer,
66+
events: Integer
67+
) => {
5668
val callback = HandleUtils.getData[Int => Unit](handle)
5769
if ((events & UV_WRITABLE) != 0) callback.apply(status)
5870
}

core/src/test/scala/scala/scalanative/loop/PollTests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ object PollTests extends LoopTestSuite {
3131
if (i != 0) {
3232
throw new Exception("Poll result != 0")
3333
}
34-
val buf = stackalloc[Byte]
34+
val buf = stackalloc[Byte]()
3535
val bytesRead = read(r, buf, 1L.toULong)
3636
assert(bytesRead == 1)
3737
assert(buf(0) == byte)
3838
promise.success(())
3939
poll.stop()
4040
}
41-
val buf = stackalloc[Byte]
41+
val buf = stackalloc[Byte]()
4242
buf(0) = byte
4343
val bytesWrote = write(w, buf, 1L.toULong)
4444
assert(bytesWrote == 1)

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=1.4.6
1+
sbt.version=1.6.1

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.0")
1+
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.3")
22
addSbtPlugin("com.eed3si9n" % "sbt-dirty-money" % "0.2.0")
33
addSbtPlugin("com.jsuereth" % "sbt-pgp" % "2.0.1")
44
addSbtPlugin("org.xerial.sbt" % "sbt-sonatype" % "3.9.4")

0 commit comments

Comments
 (0)