-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathbuild.sbt
439 lines (387 loc) · 15.4 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
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
import sbtcrossproject.{crossProject, CrossType}
val scalaVer = "2.13.4"
val scalatestVer = "3.1.1"
lazy val commonSettings = Seq(
version := "0.0.1",
organization := "com.regblanc.sgl",
scalaVersion := scalaVer,
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
)
// Android cannot run on Java8 so we stick with 2.11 and Java7. We
// need to build core separately for the right version.
val commonAndroidSettings = Seq(
scalaVersion := "2.11.12",
scalacOptions += "-target:jvm-1.7",
javacOptions ++= Seq("-source", "1.7", "-target", "1.7"),
exportJars := true
)
lazy val core = (crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossType.Pure) in file("./core"))
.settings(commonSettings: _*)
.settings(
name := "sgl-core",
)
.jvmSettings(
libraryDependencies += "org.scalatest" %%% "scalatest" % scalatestVer % "test"
)
.jsSettings(
libraryDependencies += "org.scalatest" %%% "scalatest" % scalatestVer % "test"
)
.nativeSettings(scalaVersion := scalaVer)
lazy val coreJVM = core.jvm
lazy val coreJS = core.js
lazy val coreNative = core.native
// We need to build the core classes for a different JVM version for Android.
lazy val coreAndroid = (project in file("./core"))
.settings(commonSettings: _*)
.settings(commonAndroidSettings: _*)
.settings(
name := "sgl-core-android",
target := baseDirectory.value / ".android" / "target",
libraryDependencies += "org.scalatest" %%% "scalatest" % scalatestVer % "test"
)
lazy val jvmShared = (project in file("./jvm-shared"))
.settings(commonSettings: _*)
.settings(
name := "sgl-jvmshared",
libraryDependencies += "org.scalatest" %%% "scalatest" % scalatestVer % "test"
)
.dependsOn(coreJVM % "test->test;compile->compile")
lazy val jvmSharedAndroid = (project in file("./jvm-shared"))
.settings(commonSettings: _*)
.settings(commonAndroidSettings: _*)
.settings(
name := "sgl-jvmshared-android",
target := baseDirectory.value / ".android" / "target"
)
.dependsOn(coreAndroid)
lazy val desktopAWT = (project in file("./desktop-awt"))
.settings(commonSettings: _*)
.settings(
name := "sgl-desktop-awt",
// Add .ogg support by using jorbis (transitive dependency) as a service provider
libraryDependencies += "com.googlecode.soundlibs" % "vorbisspi" % "1.0.3-2",
// Additional audio format can be added in the game build config, with a standard spi for java sound API.
libraryDependencies += "net.liftweb" %% "lift-json" % "3.4.3",
libraryDependencies += "org.scalatest" %% "scalatest" % scalatestVer % "test"
)
.dependsOn(coreJVM % "test->test;compile->compile", jvmShared)
lazy val desktopNative = (project in file("./desktop-native"))
.enablePlugins(ScalaNativePlugin)
.settings(commonSettings: _*)
.settings(scalaVersion := scalaVer)
.settings(
name := "sgl-desktop-native",
libraryDependencies += "com.regblanc" %%% "native-sdl2" % "0.2",
libraryDependencies += "com.regblanc" %%% "native-sdl2-image" % "0.2",
libraryDependencies += "com.regblanc" %%% "native-opengl" % "0.2"
)
.dependsOn(coreNative)
val scalaJSDomVer = "1.0.0"
lazy val html5 = (project in file("./html5"))
.enablePlugins(ScalaJSPlugin)
.settings(commonSettings: _*)
.settings(
name := "sgl-html5",
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % scalaJSDomVer,
libraryDependencies += "org.scalatest" %%% "scalatest" % scalatestVer % "test"
)
.dependsOn(coreJS % "test->test;compile->compile")
lazy val html5Firebase = (project in file("./html5/firebase"))
.enablePlugins(ScalaJSPlugin)
.settings(commonSettings: _*)
.settings(
name := "sgl-html5-firebase",
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % scalaJSDomVer,
libraryDependencies += "org.scalatest" %%% "scalatest" % scalatestVer % "test"
)
.dependsOn(coreJS % "test->test;compile->compile")
lazy val html5Cordova = (project in file("./html5/cordova"))
.enablePlugins(ScalaJSPlugin)
.settings(commonSettings: _*)
.settings(
name := "sgl-html5-cordova",
libraryDependencies += "org.scala-js" %%% "scalajs-dom" % scalaJSDomVer,
libraryDependencies += "org.scalatest" %%% "scalatest" % scalatestVer % "test"
)
.dependsOn(coreJS % "test->test;compile->compile", html5)
/*
* I want to make sure that the test games are always buildable and
* their build is kept in sync with the library. The original approach used to
* define the build for each game directly in its own subfolder.
*
* Since I also wanted to directly depend on the sources (by opposition to a
* published artifact), that required also declaring a sub project/ directory
* that included the right version of sbt and every plugins. Then we could
* define the dependency to the root library (i.e.
* ProjectRef(file("../../core"))). Dependency on source is important because
* we want to be able to test modifications to the core library without having
* to publish (even locally). With the source dependency, we can edit the
* library code, and compile/run from the example game sbt console and verify
* that the new version of the library still works.
*
* The drawback is of course the need to update the sbt version (the passage
* from 0.13 to 1.0 was annoying) and the sbt plugins in the library as well
* as in all example game projects. It would also be nice to be able, in one
* command, to compile all games on all platform, to verify that changes are
* not breaking anything too obvious. We can achieve this by defining the
* projects at the top level, along with the core library definitions. We
* use a set of settings (noPublishSettings) to avoid publishing the game
* projects.
*/
lazy val noPublishSettings = Seq(
publishArtifact := false,
packagedArtifacts := Map.empty,
publish := {},
publishLocal := {}
)
lazy val helloCommonSettings = Seq(
version := "1.0",
scalaVersion := scalaVer,
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
)
lazy val helloCore = (crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossType.Pure) in file("./examples/hello/core"))
.settings(helloCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(name := "hello-core")
.jvmSettings(
exportJars := true
)
.nativeSettings(scalaVersion := scalaVer)
.jvmConfigure(_.dependsOn(coreJVM))
.jsConfigure(_.dependsOn(coreJS))
.nativeConfigure(_.dependsOn(coreNative))
lazy val helloCoreJVM = helloCore.jvm
lazy val helloCoreJS = helloCore.js
lazy val helloCoreNative = helloCore.native
lazy val helloAssets = file("./examples/hello/assets")
lazy val helloDesktopAWT = (project in file("./examples/hello/desktop-awt"))
.settings(helloCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(
name := "hello-desktop-awt",
fork in run := true,
unmanagedResourceDirectories in Compile := Seq(helloAssets)
)
.dependsOn(coreJVM, desktopAWT, helloCoreJVM)
lazy val helloHtml5 = (project in file("./examples/hello/html5"))
.enablePlugins(ScalaJSPlugin)
.settings(helloCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(
name := "hello-html5",
scalaJSUseMainModuleInitializer := true
)
.dependsOn(coreJS, html5, helloCoreJS)
lazy val helloDesktopNative = (project in file("./examples/hello/desktop-native"))
.enablePlugins(ScalaNativePlugin)
.settings(helloCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(scalaVersion := scalaVer)
.settings(
name := "hello-desktop-native",
unmanagedResourceDirectories in Compile := Seq(helloAssets),
if(isLinux(OS))
nativeLinkingOptions ++= Seq("-lGL")
else if(isMac(OS))
nativeLinkingOptions ++= Seq("-framework", "OpenGL")
else
???
)
.dependsOn(coreNative, desktopNative, helloCoreNative)
lazy val snakeCommonSettings = Seq(
version := "1.0",
scalaVersion := scalaVer,
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
)
lazy val snakeCore = (crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossType.Pure) in file("./examples/snake/core"))
.settings(snakeCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(name := "snake-core")
.nativeSettings(scalaVersion := scalaVer)
.jvmConfigure(_.dependsOn(coreJVM))
.jsConfigure(_.dependsOn(coreJS))
.nativeConfigure(_.dependsOn(coreNative))
lazy val snakeCoreJVM = snakeCore.jvm
lazy val snakeCoreJS = snakeCore.js
lazy val snakeCoreNative = snakeCore.native
lazy val snakeDesktopAWT = (project in file("./examples/snake/desktop-awt"))
.settings(snakeCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(
name := "snake-desktop-awt",
fork in run := true
)
.dependsOn(coreJVM, desktopAWT, snakeCoreJVM)
lazy val snakeHtml5 = (project in file("./examples/snake/html5"))
.enablePlugins(ScalaJSPlugin)
.settings(snakeCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(
name := "snake-html5",
scalaJSUseMainModuleInitializer := true
)
.dependsOn(coreJS, html5, snakeCoreJS)
lazy val snakeDesktopNative = (project in file("./examples/snake/desktop-native"))
.enablePlugins(ScalaNativePlugin)
.settings(snakeCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(scalaVersion := scalaVer)
.settings(
name := "snake-desktop-native",
if(isLinux(OS))
nativeLinkingOptions += "-lGL"
else if(isMac(OS))
nativeLinkingOptions ++= Seq("-framework", "OpenGL")
else
???
)
.dependsOn(coreNative, desktopNative, snakeCoreNative)
lazy val menuCommonSettings = Seq(
version := "1.0",
scalaVersion := scalaVer,
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
)
lazy val menuCore = (crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossType.Pure) in file("./examples/menu/core"))
.settings(menuCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(name := "menu-core")
.jvmSettings(
exportJars := true
)
.nativeSettings(scalaVersion := scalaVer)
.jvmConfigure(_.dependsOn(coreJVM))
.jsConfigure(_.dependsOn(coreJS))
.nativeConfigure(_.dependsOn(coreNative))
lazy val menuCoreJVM = menuCore.jvm
lazy val menuCoreJS = menuCore.js
lazy val menuCoreNative = menuCore.native
lazy val menuDesktopAWT = (project in file("./examples/menu/desktop-awt"))
.settings(menuCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(
name := "menu-desktop-awt",
fork in run := true
)
.dependsOn(coreJVM, desktopAWT, menuCoreJVM)
lazy val menuHtml5 = (project in file("./examples/menu/html5"))
.enablePlugins(ScalaJSPlugin)
.settings(menuCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(
name := "menu-html5",
scalaJSUseMainModuleInitializer := true
)
.dependsOn(coreJS, html5, menuCoreJS)
lazy val platformerCommonSettings = Seq(
version := "1.0",
scalaVersion := scalaVer,
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
)
lazy val platformerCore = (crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossType.Pure) in file("./examples/platformer/core"))
.settings(platformerCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(name := "platformer-core")
.nativeSettings(scalaVersion := scalaVer)
.jvmConfigure(_.dependsOn(coreJVM))
.jsConfigure(_.dependsOn(coreJS))
.nativeConfigure(_.dependsOn(coreNative))
lazy val platformerCoreJVM = platformerCore.jvm
lazy val platformerCoreJS = platformerCore.js
lazy val platformerCoreNative = platformerCore.native
lazy val platformerAssets = file("./examples/platformer/assets")
lazy val platformerDesktopAWT = (project in file("./examples/platformer/desktop-awt"))
.settings(platformerCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(
name := "platformer-desktop-awt",
unmanagedResourceDirectories in Compile := Seq(platformerAssets),
fork in run := true
)
.dependsOn(coreJVM, desktopAWT, platformerCoreJVM)
lazy val platformerDesktopNative = (project in file("./examples/platformer/desktop-native"))
.enablePlugins(ScalaNativePlugin)
.settings(platformerCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(scalaVersion := scalaVer)
.settings(
name := "platformer-desktop-native",
if(isLinux(OS))
nativeLinkingOptions += "-lGL"
else if(isMac(OS))
nativeLinkingOptions ++= Seq("-framework", "OpenGL")
else
???
)
.dependsOn(coreNative, desktopNative, platformerCoreNative)
lazy val boardCommonSettings = Seq(
version := "1.0",
scalaVersion := scalaVer,
scalacOptions ++= Seq("-unchecked", "-deprecation", "-feature")
)
lazy val boardCore = (crossProject(JSPlatform, JVMPlatform, NativePlatform).crossType(CrossType.Pure) in file("./examples/board/core"))
.settings(boardCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(name := "board-core")
.jvmSettings(
exportJars := true
)
.nativeSettings(scalaVersion := scalaVer)
.jvmConfigure(_.dependsOn(coreJVM))
.jsConfigure(_.dependsOn(coreJS))
.nativeConfigure(_.dependsOn(coreNative))
lazy val boardCoreJVM = boardCore.jvm
lazy val boardCoreJS = boardCore.js
lazy val boardCoreNative = boardCore.native
lazy val boardDesktopAWT = (project in file("./examples/board/desktop-awt"))
.settings(boardCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(
name := "board-desktop-awt",
fork in run := true
)
.dependsOn(coreJVM, desktopAWT, boardCoreJVM)
lazy val boardHtml5 = (project in file("./examples/board/html5"))
.enablePlugins(ScalaJSPlugin)
.settings(boardCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(
name := "board-html5",
scalaJSUseMainModuleInitializer := true
)
.dependsOn(coreJS, html5, boardCoreJS)
lazy val boardDesktopNative = (project in file("./examples/board/desktop-native"))
.enablePlugins(ScalaNativePlugin)
.settings(boardCommonSettings: _*)
.settings(noPublishSettings: _*)
.settings(scalaVersion := scalaVer)
.settings(
name := "board-desktop-native",
if(isLinux(OS))
nativeLinkingOptions ++= Seq("-lGL")
else if(isMac(OS))
nativeLinkingOptions ++= Seq("-framework", "OpenGL")
else
???
)
.dependsOn(coreNative, desktopNative, boardCoreNative)
lazy val OS = sys.props("os.name").toLowerCase
lazy val LinuxName = "Linux"
lazy val MacName = "Mac OS X"
def isLinux(name: String): Boolean = name.startsWith(LinuxName.toLowerCase)
def isMac(name: String): Boolean = name.startsWith(MacName.toLowerCase)
/** Currently, the native projects are not compiling due to binary incompatibility
* with scalatest. Once this issue is resolved, we can revert back to the CI
* command being `sbt test`. For now, this hackily ensures that we don't regress
* being on everything else.
*
* Missing projects from this command: coreNative, jvmSharedAndroid, platformerDesktopNative.
*/
lazy val verifyCiCommand = List(
"coreJVM","desktopAWT","desktopNative","helloCoreJS","helloCoreJVM","helloCoreNative",
"helloDesktopAWT","helloDesktopNative","helloHtml5","html5","html5Firebase","jvmShared",
"menuCoreJS","menuCoreJVM","menuCoreNative","menuDesktopAWT",
"platformerCoreJS","platformerCoreJVM","platformerCoreNative","platformerDesktopAWT",
"snakeCoreJS","snakeCoreJVM","snakeCoreNative","snakeDesktopAWT","snakeDesktopNative","snakeHtml5",
"boardCoreJS","boardCoreJVM","boardCoreNative","boardDesktopAWT","boardDesktopNative","boardHtml5"
).map(_ + "/test").mkString("; ")
addCommandAlias("verifyCI", s"; $verifyCiCommand")