11import org .scalajs .linker .interface .{CheckedBehavior , ESVersion }
2- import sbt ._
3- import scala .sys .process ._
2+ import sbt .*
3+
4+ import scala .collection .Seq
5+ import scala .scalanative .build .{GC , LTO , Mode }
6+ import scala .sys .process .*
47
58lazy val oldVersion = " git describe --abbrev=0" .!! .trim.replaceAll(" ^v" , " " )
69
@@ -58,6 +61,49 @@ lazy val commonSettings = Seq(
5861 pomIncludeRepository := { _ => false }
5962)
6063
64+ lazy val jsSettings = Seq (
65+ scalacOptions ++= {
66+ val localSourcesPath = (LocalRootProject / baseDirectory).value.toURI
67+ val remoteSourcesPath = s " https://raw.githubusercontent.com/plokhotnyuk/rtree2d/ ${git.gitHeadCommit.value.get}/ "
68+ CrossVersion .partialVersion(scalaVersion.value) match {
69+ case Some ((2 , _)) => Seq (
70+ s " -P:scalajs:mapSourceURI: $localSourcesPath-> $remoteSourcesPath" ,
71+ " -P:scalajs:genStaticForwardersForNonTopLevelObjects"
72+ )
73+ case _ => Seq (
74+ s " -scalajs-mapSourceURI: $localSourcesPath-> $remoteSourcesPath" ,
75+ " -scalajs-genStaticForwardersForNonTopLevelObjects"
76+ )
77+ }
78+ },
79+ scalaJSLinkerConfig ~= {
80+ _.withSemantics({
81+ _.optimized
82+ .withProductionMode(true )
83+ .withAsInstanceOfs(CheckedBehavior .Unchecked )
84+ .withStringIndexOutOfBounds(CheckedBehavior .Unchecked )
85+ .withArrayIndexOutOfBounds(CheckedBehavior .Unchecked )
86+ .withArrayStores(CheckedBehavior .Unchecked )
87+ .withNegativeArraySizes(CheckedBehavior .Unchecked )
88+ .withNullPointers(CheckedBehavior .Unchecked )
89+ }).withClosureCompiler(true )
90+ .withESFeatures(_.withESVersion(ESVersion .ES2015 ))
91+ .withModuleKind(ModuleKind .CommonJSModule )
92+ },
93+ coverageEnabled := false // FIXME: Unexpected crash of scalac
94+ )
95+
96+ lazy val nativeSettings = Seq (
97+ scalacOptions ++= Seq (" -P:scalanative:genStaticForwardersForNonTopLevelObjects" ),
98+ nativeConfig ~= {
99+ _.withMode(Mode .releaseFast) // TODO: test with `Mode.releaseSize` and `Mode.releaseFull`
100+ .withLTO(LTO .none)
101+ .withGC(GC .immix)
102+ },
103+ mimaPreviousArtifacts := Set (), // FIXME: remove after the first release for Scala Native 0.5
104+ coverageEnabled := false // FIXME: Unexpected linking error
105+ )
106+
61107lazy val noPublishSettings = Seq (
62108 publish / skip := true ,
63109 mimaPreviousArtifacts := Set ()
@@ -88,7 +134,7 @@ lazy val publishSettings = Seq(
88134)
89135
90136lazy val rtree2d = project.in(file(" ." ))
91- .aggregate((if (isWindows) winProjects else unixProjects):_ * )
137+ .aggregate((if (isWindows) winProjects else unixProjects)* )
92138 .settings(commonSettings)
93139 .settings(noPublishSettings)
94140
@@ -103,8 +149,8 @@ lazy val `rtree2d-core` = crossProject(JVMPlatform, JSPlatform, NativePlatform)
103149 .settings(
104150 crossScalaVersions := Seq (" 3.3.3" , " 2.13.14" , " 2.12.19" ),
105151 libraryDependencies ++= Seq (
106- " org.scalatest " %%% " scalatest " % " 3.2.18 " % Test ,
107- " org.scalatestplus " %%% " scalacheck-1-16 " % " 3.2.14.0 " % Test
152+ " org.scalatestplus " %%% " scalacheck-1-18 " % " 3.2.19.0 " % Test ,
153+ " org.scalatest " %%% " scalatest " % " 3.2.19 " % Test
108154 )
109155 )
110156 .jsSettings(
@@ -129,8 +175,10 @@ lazy val `rtree2d-core` = crossProject(JVMPlatform, JSPlatform, NativePlatform)
129175lazy val `rtree2d-coreJVM` = `rtree2d-core`.jvm
130176
131177lazy val `rtree2d-coreJS` = `rtree2d-core`.js
178+ .settings(jsSettings)
132179
133180lazy val `rtree2d-coreNative` = `rtree2d-core`.native
181+ .settings(nativeSettings)
134182
135183lazy val `rtree2d-benchmark` = project
136184 .enablePlugins(JmhPlugin )
@@ -143,7 +191,7 @@ lazy val `rtree2d-benchmark` = project
143191 " org.locationtech.jts" % " jts-core" % " 1.19.0" ,
144192 " com.github.davidmoten" % " rtree2" % " 0.9.3" ,
145193 " org.spire-math" %% " archery" % " 0.6.0" ,
146- " org.scalatest" %% " scalatest" % " 3.2.18 " % Test
194+ " org.scalatest" %%% " scalatest" % " 3.2.19 " % Test
147195 ),
148196 charts := Def .inputTaskDyn {
149197 val jmhParams = Def .spaceDelimited().parsed
0 commit comments