Skip to content

Commit a36b65c

Browse files
Merge pull request #310 from davenverse/updatedBuild
ScalaJS, Scala 3, davenverse
2 parents d0f8365 + 2234a06 commit a36b65c

File tree

11 files changed

+153
-239
lines changed

11 files changed

+153
-239
lines changed

.github/workflows/ci.yml

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ name: Continuous Integration
99

1010
on:
1111
pull_request:
12-
branches: ['*']
12+
branches: ['**']
1313
push:
14-
branches: ['*']
14+
branches: ['**']
1515
tags: [v*]
1616

1717
env:
@@ -23,8 +23,8 @@ jobs:
2323
strategy:
2424
matrix:
2525
os: [ubuntu-latest]
26-
scala: [2.12.13, 2.13.5]
27-
java: [adopt@1.8]
26+
scala: [2.12.13, 2.13.6, 3.0.1]
27+
java: [adopt@1.8, adopt@1.11]
2828
runs-on: ${{ matrix.os }}
2929
steps:
3030
- name: Checkout current branch (full)
@@ -33,7 +33,7 @@ jobs:
3333
fetch-depth: 0
3434

3535
- name: Setup Java and Scala
36-
uses: olafurpg/setup-scala@v10
36+
uses: olafurpg/setup-scala@v12
3737
with:
3838
java-version: ${{ matrix.java }}
3939

@@ -50,18 +50,18 @@ jobs:
5050
key: ${{ runner.os }}-sbt-cache-v2-${{ hashFiles('**/*.sbt') }}-${{ hashFiles('project/build.properties') }}
5151

5252
- name: Check that workflows are up to date
53-
run: sbt ++${{ matrix.scala }} githubWorkflowCheck
53+
run: sbt --client '++${{ matrix.scala }}; githubWorkflowCheck'
5454

55-
- run: sbt ++${{ matrix.scala }} test mimaReportBinaryIssues
55+
- run: sbt --client '++${{ matrix.scala }}; test; mimaReportBinaryIssues'
5656

5757
publish:
5858
name: Publish Artifacts
5959
needs: [build]
60-
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v'))
60+
if: github.event_name != 'pull_request' && (startsWith(github.ref, 'refs/tags/v') || github.ref == 'refs/heads/main')
6161
strategy:
6262
matrix:
6363
os: [ubuntu-latest]
64-
scala: [2.12.12]
64+
scala: [3.0.1]
6565
java: [adopt@1.8]
6666
runs-on: ${{ matrix.os }}
6767
steps:
@@ -71,7 +71,7 @@ jobs:
7171
fetch-depth: 0
7272

7373
- name: Setup Java and Scala
74-
uses: olafurpg/setup-scala@v10
74+
uses: olafurpg/setup-scala@v12
7575
with:
7676
java-version: ${{ matrix.java }}
7777

@@ -95,4 +95,4 @@ jobs:
9595
PGP_SECRET: ${{ secrets.PGP_SECRET }}
9696
SONATYPE_PASSWORD: ${{ secrets.SONATYPE_PASSWORD }}
9797
SONATYPE_USERNAME: ${{ secrets.SONATYPE_USERNAME }}
98-
run: sbt ++${{ matrix.scala }} ci-release
98+
run: sbt --client '++${{ matrix.scala }}; ci-release'

.gitignore

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ tags
88

99
.bloop
1010
.metals
11-
project/metals.sbt
11+
metals.sbt
1212
.bsp/
1313

1414
# gtags
1515
GPATH
1616
GRTAGS
17-
GTAGS
17+
GTAGS
18+
.vscode

.jvmopts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
-Dfile.encoding=UTF8
2+
-Xms1G
3+
-Xmx6G
4+
-XX:ReservedCodeCacheSize=250M
5+
-XX:+TieredCompilation
6+
-XX:+UseG1GC

build.sbt

Lines changed: 46 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -1,125 +1,79 @@
1-
val Scala213 = "2.13.5"
1+
ThisBuild / crossScalaVersions := Seq("2.12.13", "2.13.6", "3.0.1")
22

3-
ThisBuild / crossScalaVersions := Seq("2.12.13", Scala213)
4-
ThisBuild / scalaVersion := crossScalaVersions.value.last
3+
ThisBuild / testFrameworks += new TestFramework("munit.Framework")
54

6-
ThisBuild / githubWorkflowArtifactUpload := false
7-
8-
ThisBuild / githubWorkflowBuild := Seq(
9-
WorkflowStep.Sbt(List("test", "mimaReportBinaryIssues")),
10-
)
11-
12-
ThisBuild / githubWorkflowTargetTags ++= Seq("v*")
13-
14-
// currently only publishing tags
15-
ThisBuild / githubWorkflowPublishTargetBranches :=
16-
Seq(RefPredicate.StartsWith(Ref.Tag("v")))
17-
18-
ThisBuild / githubWorkflowPublishPreamble +=
19-
WorkflowStep.Use(UseRef.Public("olafurpg", "setup-gpg", "v3"))
5+
val catsV = "2.6.1"
6+
val catsEffectV = "3.2.2"
7+
val catsCollectionV = "0.9.3"
208

21-
ThisBuild / githubWorkflowPublish := Seq(
22-
WorkflowStep.Sbt(
23-
List("ci-release"),
24-
name = Some("Publish artifacts to Sonatype"),
25-
env = Map(
26-
"PGP_PASSPHRASE" -> "${{ secrets.PGP_PASSPHRASE }}",
27-
"PGP_SECRET" -> "${{ secrets.PGP_SECRET }}",
28-
"SONATYPE_PASSWORD" -> "${{ secrets.SONATYPE_PASSWORD }}",
29-
"SONATYPE_USERNAME" -> "${{ secrets.SONATYPE_USERNAME }}"
30-
)
31-
),
32-
)
9+
val munitV = "0.7.25"
10+
val munitCEV = "1.0.5"
3311

3412
lazy val mules = project.in(file("."))
3513
.disablePlugins(MimaPlugin)
36-
.settings(skip in publish := true)
37-
.settings(commonSettings)
38-
.aggregate(core, caffeine, reload, noop, bench)
14+
.enablePlugins(NoPublishPlugin)
15+
.aggregate(core.jvm, core.js, caffeine, reload.jvm, reload.js, noop.jvm, noop.js, bench)
3916

4017
lazy val bench = project.in(file("modules/bench"))
41-
.disablePlugins(MimaPlugin)
4218
.enablePlugins(JmhPlugin)
43-
.settings(skip in publish := true)
44-
.settings(commonSettings)
45-
.dependsOn(core, caffeine)
19+
.disablePlugins(MimaPlugin)
20+
.enablePlugins(NoPublishPlugin)
21+
.dependsOn(core.jvm, caffeine)
4622

47-
lazy val core = project.in(file("modules/core"))
48-
.settings(commonSettings)
23+
lazy val core = crossProject(JSPlatform, JVMPlatform)
24+
.crossType(CrossType.Pure)
25+
.in(file("modules/core"))
4926
.settings(
50-
name := "mules"
27+
name := "mules",
28+
libraryDependencies ++= Seq(
29+
"org.typelevel" %%% "cats-core" % catsV,
30+
"org.typelevel" %%% "cats-effect" % catsEffectV,
31+
"io.chrisdavenport" %%% "mapref" % "0.2.0",
32+
),
33+
).settings(testDeps)
34+
.jsSettings(
35+
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule)},
5136
)
5237

5338
lazy val caffeine = project.in(file("modules/caffeine"))
54-
.settings(commonSettings)
55-
.dependsOn(core)
39+
.dependsOn(core.jvm)
5640
.settings(
5741
name := "mules-caffeine",
5842
libraryDependencies ++= Seq(
5943
"com.github.ben-manes.caffeine" % "caffeine" % "2.9.2"
60-
)
61-
)
44+
),
45+
).settings(testDeps)
6246

63-
lazy val noop = project.in(file("modules/noop"))
64-
.settings(commonSettings)
47+
lazy val noop = crossProject(JSPlatform, JVMPlatform)
48+
.crossType(CrossType.Pure)
49+
.in(file("modules/noop"))
6550
.dependsOn(core)
6651
.settings(
6752
name := "mules-noop"
53+
).settings(testDeps)
54+
.jsSettings(
55+
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule)},
6856
)
6957

70-
lazy val reload = project.in(file("modules/reload"))
71-
.settings(commonSettings)
58+
lazy val reload = crossProject(JSPlatform, JVMPlatform)
59+
.crossType(CrossType.Pure)
60+
.in(file("modules/reload"))
7261
.dependsOn(core)
7362
.settings(
7463
name := "mules-reload",
7564
libraryDependencies ++= Seq(
76-
"org.typelevel" %% "cats-collections-core" % catsCollectionV
77-
)
65+
"org.typelevel" %%% "cats-collections-core" % catsCollectionV
66+
),
67+
).settings(testDeps)
68+
.jsSettings(
69+
scalaJSLinkerConfig ~= { _.withModuleKind(ModuleKind.CommonJSModule)},
7870
)
7971

80-
val catsV = "2.6.1"
81-
val catsEffectV = "3.1.0"
82-
val catsCollectionV = "0.9.2"
83-
84-
val munitV = "0.7.25"
85-
val munitCEV = "1.0.5"
86-
87-
lazy val commonSettings = Seq(
88-
scalaVersion := "2.13.5",
89-
crossScalaVersions := Seq(scalaVersion.value, "2.12.12"),
90-
91-
addCompilerPlugin("org.typelevel" %% "kind-projector" % "0.13.0" cross CrossVersion.full),
92-
addCompilerPlugin("com.olegpy" %% "better-monadic-for" % "0.3.1"),
93-
94-
testFrameworks += new TestFramework("munit.Framework"),
95-
72+
lazy val testDeps = Seq(
9673
libraryDependencies ++= Seq(
97-
"org.typelevel" %% "cats-core" % catsV,
98-
"org.typelevel" %% "cats-effect" % catsEffectV,
99-
"io.chrisdavenport" %% "mapref" % "0.2.0-M2",
100-
101-
"org.typelevel" %% "cats-effect-laws" % catsEffectV % Test,
102-
"org.scalameta" %% "munit" % munitV % Test,
103-
"org.scalameta" %% "munit-scalacheck" % munitV % Test,
104-
"org.typelevel" %% "munit-cats-effect-3" % munitCEV % Test,
74+
"org.typelevel" %%% "cats-effect-laws" % catsEffectV % Test,
75+
"org.scalameta" %%% "munit" % munitV % Test,
76+
"org.scalameta" %%% "munit-scalacheck" % munitV % Test,
77+
"org.typelevel" %%% "munit-cats-effect-3" % munitCEV % Test,
10578
)
10679
)
107-
108-
inThisBuild(List(
109-
organization := "io.chrisdavenport",
110-
homepage := Some(url("https://github.com/ChristopherDavenport/mules")),
111-
licenses += ("MIT", url("http://opensource.org/licenses/MIT")),
112-
developers := List(
113-
Developer(
114-
"ChristopherDavenport",
115-
"Christopher Davenport",
116-
"chris@christopherdavenport.tech",
117-
url("https://github.com/ChristopherDavenport")
118-
)
119-
),
120-
scalacOptions in (Compile, doc) ++= Seq(
121-
"-groups",
122-
"-sourcepath", (baseDirectory in LocalRootProject).value.getAbsolutePath,
123-
"-doc-source-url", "https://github.com/ChristopherDavenport/mules/blob/v" + version.value + "€{FILE_PATH}.scala"
124-
),
125-
))

modules/bench/src/main/scala/io/chrisdavenport/mules/LookupBench.scala

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ import cats.effect._
88
import cats.effect.unsafe.IORuntime
99
import io.chrisdavenport.mules.caffeine.CaffeineCache
1010

11-
1211
@BenchmarkMode(Array(Mode.Throughput))
1312
// @OutputTimeUnit(TimeUnit.MILLISECONDS)
1413
class LookUpBench {
@@ -81,11 +80,11 @@ object LookUpBench {
8180
var memoryCache: MemoryCache[IO, Int, String] = _
8281
val writeList: List[Int] = (1 to 100).toList
8382
val readList : List[Int] = (1 to 100).toList
84-
implicit val R = IORuntime.global
83+
implicit val R: IORuntime = IORuntime.global
8584

8685
@Setup(Level.Trial)
8786
def setup(): Unit = {
88-
memoryCache = MemoryCache.ofSingleImmutableMap[IO, Int, String](None).unsafeRunSync()
87+
memoryCache = MemoryCache.ofSingleImmutableMap[IO, Int, String](None).unsafeRunSync()(R)
8988
}
9089

9190
}
@@ -94,27 +93,28 @@ object LookUpBench {
9493
var memoryCache: MemoryCache[IO, Int, String] = _
9594
val writeList: List[Int] = (1 to 100).toList
9695
val readList : List[Int] = (1 to 100).toList
97-
implicit val R = IORuntime.global
96+
implicit val R: IORuntime = IORuntime.global
9897

9998
@Setup(Level.Trial)
10099
def setup(): Unit = {
101-
memoryCache = MemoryCache.ofConcurrentHashMap[IO, Int, String](None).unsafeRunSync()
102-
memoryCache.insert(1, "yellow").unsafeRunSync()
100+
memoryCache = MemoryCache.ofConcurrentHashMap[IO, Int, String](None).unsafeRunSync()(R)
101+
memoryCache.insert(1, "yellow").unsafeRunSync()(R)
103102
}
104103

105104
}
106105

107106
@State(Scope.Benchmark)
108107
class BenchStateCaffeine {
108+
109109
var cache: Cache[IO, Int, String] = _
110110
val writeList: List[Int] = (1 to 100).toList
111111
val readList : List[Int] = (1 to 100).toList
112-
implicit val R = IORuntime.global
112+
implicit val R: IORuntime = IORuntime.global
113113

114114
@Setup(Level.Trial)
115115
def setup(): Unit = {
116-
cache = CaffeineCache.build[IO, Int, String](None, None, None).unsafeRunSync()
117-
cache.insert(1, "yellow").unsafeRunSync()
116+
cache = CaffeineCache.build[IO, Int, String](None, None, None).unsafeRunSync()(R)
117+
cache.insert(1, "yellow").unsafeRunSync()(R)
118118
}
119119
}
120120
}

modules/core/src/main/scala/io/chrisdavenport/mules/DispatchOneCache.scala

Lines changed: 4 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,23 +17,8 @@ final class DispatchOneCache[F[_], K, V] private[DispatchOneCache] (
1717
import DispatchOneCache.DispatchOneCacheItem
1818
import DispatchOneCache.CancelationDuringDispatchOneCacheInsertProcessing
1919

20-
private def purgeExpiredEntriesDefault(now: Long): F[List[K]] = {
21-
mapRef.keys.flatMap(l =>
22-
l.flatTraverse(k =>
23-
mapRef(k).modify(optItem =>
24-
optItem.map(item =>
25-
if (DispatchOneCache.isExpired(now, item))
26-
(None, List(k))
27-
else
28-
(optItem, List.empty)
29-
).getOrElse((optItem, List.empty))
30-
)
31-
)
32-
)
33-
}
34-
3520
private val purgeExpiredEntries: Long => F[List[K]] =
36-
purgeExpiredEntriesOpt.getOrElse(purgeExpiredEntriesDefault)
21+
purgeExpiredEntriesOpt.getOrElse({(_: Long) => List.empty[K].pure[F]})
3722

3823
private val emptyFV = F.pure(Option.empty[Deferred[F, Either[Throwable, V]]])
3924

@@ -214,11 +199,11 @@ final class DispatchOneCache[F[_], K, V] private[DispatchOneCache] (
214199
}
215200

216201
object DispatchOneCache {
217-
private case class DispatchOneCacheItem[F[_], A](
202+
case class DispatchOneCacheItem[F[_], A](
218203
item: Deferred[F, Either[Throwable, A]],
219204
itemExpiration: Option[TimeSpec]
220205
)
221-
private case object CancelationDuringDispatchOneCacheInsertProcessing extends scala.util.control.NoStackTrace
206+
case object CancelationDuringDispatchOneCacheInsertProcessing extends scala.util.control.NoStackTrace
222207

223208
/**
224209
*
@@ -252,7 +237,7 @@ object DispatchOneCache {
252237
Ref.of[F, Map[K, DispatchOneCacheItem[F, V]]](Map.empty[K, DispatchOneCacheItem[F, V]])
253238
.map(ref => new DispatchOneCache[F, K, V](
254239
MapRef.fromSingleImmutableMapRef(ref),
255-
{l: Long => SingleRef.purgeExpiredEntries(ref)(l)}.some,
240+
{(l: Long) => SingleRef.purgeExpiredEntries(ref)(l)}.some,
256241
defaultExpiration
257242
))
258243

0 commit comments

Comments
 (0)