-
Notifications
You must be signed in to change notification settings - Fork 8
/
build.sbt
executable file
·243 lines (223 loc) · 8.97 KB
/
build.sbt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
import org.scalajs.linker.interface.ModuleSplitStyle
import scala.sys.process.Process
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}
//val dottyVersion = dottyLatestNightlyBuild.get
val dottyVersion = "3.6.1"
val spireVersion = "0.18.0"
val scalaTestVersion = "3.2.19"
scalaVersion := dottyVersion
lazy val commonSettings = Seq(
organization := "org.emergentorder.onnx",
version := "0.18.0",
scalaVersion := dottyVersion,
resolvers += Resolver.mavenLocal,
resolvers += "Sonatype OSS Snapshots" at "https://s01.oss.sonatype.org/content/repositories/snapshots",
updateOptions := updateOptions.value.withLatestSnapshots(false),
libraryDependencies += "com.google.protobuf" % "protobuf-java" % "4.28.2",
libraryDependencies += "org.scala-lang" % "scala3-compiler_3" % scalaVersion.value exclude (
"org.scala-sbt",
"compiler-interface"
),
scalacOptions ++= Seq(
"-explain",
"-explain-types",
"-feature",
// "-Xfatal-warnings",
"-unchecked",
"-deprecation",
// "-release:21",
"-rewrite",
"-source:3.4-migration"
),
versionPolicyIntention := Compatibility.BinaryCompatible, // As long as we are pre 1.0.0, BinaryCompatible for a patch version bump and None for a minor version bump
versionScheme := Some("early-semver"),
mimaPreviousArtifacts := Set("org.emergent-order" %%% "onnx-scala-common" % "0.17.0"),
autoCompilerPlugins := true
) ++ sonatypeSettings
lazy val common = (crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Pure) in file("common"))
.settings(
commonSettings,
name := "onnx-scala-common",
crossScalaVersions := Seq(
dottyVersion
)
)
.jsSettings(
scalaJSStage := FullOptStage
)
lazy val proto = (crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Pure) in file("proto"))
.settings(
commonSettings,
name := "onnx-scala-proto",
mimaPreviousArtifacts := Set("org.emergent-order" %%% "onnx-scala-proto" % "0.17.0"),
crossScalaVersions := Seq(
dottyVersion
),
Compile / PB.targets := Seq(
scalapb.gen() -> (Compile / sourceManaged).value / "scalapb"
),
// The trick is in this line:
Compile / PB.protoSources := Seq(file("proto/src/main/protobuf"))
)
.jsSettings(
scalaJSStage := FullOptStage
)
val copyIndexTs = taskKey[Unit]("Copy ts types file to target directory")
val copyPackageNoExports = taskKey[Unit]("Copy package file without exports to target directory")
lazy val backends = (crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure) in file("backends"))
.dependsOn(core)
.settings(
commonSettings,
name := "onnx-scala-backends",
mimaPreviousArtifacts := Set("org.emergent-order" %%% "onnx-scala-backends" % "0.17.0"),
libraryDependencies ++= Seq(
"com.microsoft.onnxruntime" % "onnxruntime" % "1.19.2",
"com.microsoft.onnxruntime" % "onnxruntime-extensions" % "0.12.4"
),
libraryDependencies += ("org.scalatest" %%% "scalatest" % scalaTestVersion) % Test,
crossScalaVersions := Seq(dottyVersion)
)
.jvmSettings(
libraryDependencies += "org.typelevel" %%% "cats-effect-testing-scalatest" % "1.5.0" % Test
)
.jsSettings(
scalaJSUseMainModuleInitializer := true, // , //Testing
// stuck on web/node 1.15.1 due to this issue: https://github.com/microsoft/onnxruntime/issues/17979
scalaJSLinkerConfig ~= {
_.withModuleKind(ModuleKind.ESModule)
.withModuleSplitStyle(
ModuleSplitStyle.SmallModulesFor(List("onnx-scala")))
},
// Compile / npmDependencies += "onnxruntime-web" -> "1.15.1",
// ORT web and node are interchangeable, given minor package name changes, and node offers a significant speed-up (at the cost of working on the web)
// Compile / npmDependencies += "onnxruntime-node" -> "1.19.0",
// Compile / npmDependencies += "onnxruntime-common" -> "1.19.0",
// Compile / npmDependencies += "typescript" -> "5.5.4",
copyIndexTs := {
import Path._
val src = new File(".")
// get the files we want to copy
val htmlFiles: Seq[File] = Seq(new File("index.d.ts"))
// use Path.rebase to pair source files with target destination in crossTarget
val pairs = htmlFiles pair rebase(
src,
(baseDirectory).value / "node_modules/onnxruntime-node/dist/"
)
// Copy files to source files to target
IO.copy(
pairs,
CopyOptions
.apply(overwrite = true, preserveLastModified = true, preserveExecutable = false)
)
},
copyPackageNoExports := {
import Path._
val src = new File(".")
// get the files we want to copy
val htmlFiles: Seq[File] = Seq(new File("package.json"))
// use Path.rebase to pair source files with target destination in crossTarget
val pairs = htmlFiles pair rebase(
src,
(baseDirectory).value / "node_modules/onnxruntime-common/"
)
// Copy files to source files to target
IO.copy(
pairs,
CopyOptions
.apply(overwrite = true, preserveLastModified = true, preserveExecutable = false)
)
},
Compile / compile := (Compile / compile dependsOn (copyIndexTs, copyPackageNoExports)).value,
// Test / test := (Test / test dependsOn (copyPackageNoExports)).value,
libraryDependencies += "org.typelevel" %%% "cats-effect-testing-scalatest" % "1.5.0" % Test,
stOutputPackage := "org.emergentorder.onnx",
stShortModuleNames := true,
Compile / packageDoc / publishArtifact := false, // This is inordinately slow, only publish doc on release
scalaJSStage := FullOptStage,
scalaJSLinkerConfig ~= (_.withESFeatures(
_.withESVersion(org.scalajs.linker.interface.ESVersion.ES2021)
)),
externalNpm := {
Process("npm install", baseDirectory.value).!
Process("npm run", baseDirectory.value).!
baseDirectory.value
}
// scalaJSLinkerConfig ~= { _.withESFeatures(_.withESVersion(scala.scalajs.LinkingInfo.ESVersion.ES2021)) }
)
// For distribution as a library, using ScalablyTypedConverterGenSourcePlugin (vs ScalablyTypedConverterPlugin) is required
// which slows down the build (particularly the doc build, for publishing) considerably
// TODO: minimize to reduce build time and size of js output
.jsConfigure { project => project.enablePlugins(ScalablyTypedConverterExternalNpmPlugin) }
lazy val core = (crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure) in file("core"))
.dependsOn(common)
.dependsOn(proto)
.settings(
commonSettings,
name := "onnx-scala",
mimaPreviousArtifacts := Set("org.emergent-order" %%% "onnx-scala" % "0.17.0"),
crossScalaVersions := Seq(
dottyVersion
),
libraryDependencies ++= (CrossVersion
.partialVersion(scalaVersion.value) match {
case _ =>
Seq(
("org.typelevel" %%% "spire" % spireVersion),
("org.typelevel" %%% "cats-effect" % "3.6-623178c")
)
})
)
.jsSettings(
scalaJSStage in Global := FullOptStage
)
/*
lazy val docs = (crossProject(JVMPlatform)
.crossType(CrossType.Pure) in file("core-docs")) // new documentation project
.settings(
commonSettings,
mdocVariables := Map(
"VERSION" -> version.value
)
)
.dependsOn(backends)
.enablePlugins(MdocPlugin)
.jvmSettings(
crossScalaVersions := Seq(scala213Version)
)
*/
publish / skip := true
lazy val sonatypeSettings = Seq(
sonatypeProfileName := "org.emergent-order",
sonatypeCredentialHost := "s01.oss.sonatype.org",
sonatypeRepository := "https://s01.oss.sonatype.org/service/local",
ThisBuild / sonatypeCredentialHost := "s01.oss.sonatype.org",
organization := "org.emergent-order",
homepage := Some(url("https://github.com/EmergentOrder/onnx-scala")),
scmInfo := Some(
ScmInfo(
url("https://github.com/EmergentOrder/onnx-scala"),
"[email protected]:EmergentOrder/onnx-scala.git"
)
),
developers := List(
Developer(
"EmergentOrder",
"Alex Merritt",
url("https://github.com/EmergentOrder")
)
),
licenses += ("AGPL-3.0", url("https://www.gnu.org/licenses/agpl-3.0.html")),
publishMavenStyle := true,
publishConfiguration := publishConfiguration.value.withOverwrite(true),
publishLocalConfiguration := publishLocalConfiguration.value.withOverwrite(true),
publishTo := {
val nexus = "https://s01.oss.sonatype.org/"
if (isSnapshot.value) Some("snapshots" at nexus + "content/repositories/snapshots")
else Some("releases" at nexus + "service/local/staging/deploy/maven2")
}
)