forked from disneystreaming/smithy4s
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sbt
1029 lines (951 loc) · 33.9 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
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import sbt.internal.IvyConsole
import org.scalajs.jsenv.nodejs.NodeJSEnv
import java.io.File
import sys.process._
ThisBuild / commands ++= createBuildCommands(allModules)
ThisBuild / scalafixDependencies += "com.github.liancheng" %% "organize-imports" % "0.5.0"
ThisBuild / dynverSeparator := "-"
ThisBuild / versionScheme := Some("early-semver")
ThisBuild / mimaBaseVersion := "0.16.1"
ThisBuild / testFrameworks += new TestFramework("weaver.framework.CatsEffect")
Global / onChangedBuildSource := ReloadOnSourceChanges
import Smithy4sPlugin._
val latest2ScalaVersions = List(Scala213, Scala3)
val allJvmScalaVersions = List(Scala212, Scala213, Scala3)
val allJsScalaVersions = latest2ScalaVersions
val allNativeScalaVersions = List(Scala3)
val jvmScala2Versions = List(Scala212, Scala213)
val buildtimejvmScala2Versions = List(Scala212, Scala213)
Global / organizationName := "Disney Streaming"
Global / startYear := Some(2021)
Global / licenses := Seq(
"TOST-1.0" -> new URL("https://disneystreaming.github.io/TOST-1.0.txt")
)
sonatypeCredentialHost := "s01.oss.sonatype.org"
ThisBuild / version := {
if (!sys.env.contains("CI")) "dev-SNAPSHOT"
else (ThisBuild / version).value
}
lazy val root = project
.in(file("."))
.aggregate(allModules: _*)
// .disablePlugins(Smithy4sPlugin)
.enablePlugins(ScalafixPlugin)
.settings(Smithy4sPlugin.doNotPublishArtifact)
.settings(
pushRemoteCache := {},
pullRemoteCache := {},
Compile / packageCache / moduleName := "smithy4s-root"
)
lazy val allModules = Seq(
core,
codegen,
millCodegenPlugin,
json,
example,
tests,
http4s,
`http4s-swagger`,
decline,
codegenPlugin,
benchmark,
protocol,
protocolTests,
openapi,
`aws-kernel`,
aws,
`aws-http4s`,
`codegen-cli`,
dynamic,
testUtils,
guides,
complianceTests
).flatMap(_.projectRefs)
lazy val docs =
projectMatrix
.in(file("modules/docs"))
.enablePlugins(MdocPlugin, DocusaurusPlugin)
.jvmPlatform(List(Scala213))
.dependsOn(
`codegen-cli`,
http4s,
`http4s-swagger`,
decline,
`aws-http4s` % "compile -> compile,test",
complianceTests % "compile -> compile,test"
)
.settings(
mdocIn := (ThisBuild / baseDirectory).value / "modules" / "docs" / "src",
mdocVariables := Map(
"VERSION" -> (if (isSnapshot.value)
previousStableVersion.value.getOrElse(
throw new Exception(
"No previous version found from dynver"
)
)
else version.value),
"SCALA_VERSION" -> scalaVersion.value,
"HTTP4S_VERSION" -> Dependencies.Http4s.http4sVersion.value
),
mdocExtraArguments := Seq("--check-link-hygiene"),
isCE3 := true,
libraryDependencies ++= Seq(
Dependencies.Http4s.emberClient.value,
Dependencies.Http4s.emberServer.value,
Dependencies.Decline.effect.value
),
Compile / sourceGenerators := Seq(genSmithyScala(Compile).taskValue),
Compile / smithySpecs := Seq(
(ThisBuild / baseDirectory).value / "sampleSpecs" / "hello.smithy"
)
)
.settings(Smithy4sPlugin.doNotPublishArtifact)
val munitDeps = Def.setting {
if (virtualAxes.value.contains(VirtualAxis.native)) {
Seq(
Dependencies.MunitMilestone.core.value % Test,
Dependencies.MunitMilestone.scalacheck.value % Test
)
} else {
Seq(
Dependencies.Munit.core.value % Test,
Dependencies.Munit.scalacheck.value % Test
)
}
}
/**
* Protocol-agnostic, dependency-free core module, containing
* only interfaces and other polymorphic constructs, allowing for the
* traversal of models and services.
*
* These interfaces are implemented by the generated code, and leveraged
* by protocol-specific interpreters.
*
* This module also contains a Scala representation of smithy's Standard Library
* (under the smithy.api namespace), which cointains a number of types and traits
* (hints in smithy4s) that are commonly used (such as http-specific traits, etc)
*
* In most cases, it this module the only dependency required to compile the generated
* code.
*/
lazy val core = projectMatrix
.in(file("modules/core"))
.settings(
Test / fork := virtualAxes.value.contains(VirtualAxis.jvm),
isMimaEnabled := true,
allowedNamespaces := Seq(
"smithy.api",
"smithy.waiters",
"smithy4s.api"
),
genDiscoverModels := true,
Compile / sourceGenerators := Seq(genSmithyScala(Compile).taskValue),
Compile / sourceGenerators += sourceDirectory
.map(Boilerplate.gen(_, Boilerplate.BoilerplateModule.Core))
.taskValue,
libraryDependencies ++= Seq(
Dependencies.collectionsCompat.value,
Dependencies.Cats.core.value % Test
),
libraryDependencies ++= munitDeps.value,
Test / allowedNamespaces := Seq(
"smithy4s.example",
"smithy4s.example.collision"
),
Test / smithySpecs := Seq(
(ThisBuild / baseDirectory).value / "sampleSpecs" / "metadata.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "recursive.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "bodies.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "misc.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "product.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "weather.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "discriminated.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "untagged.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "packedInputs.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "errors.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "example.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "adtMember.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "namecollision.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "reservednames.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "enums.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "defaults.smithy"
),
(Test / sourceGenerators) := Seq(genSmithyScala(Test).taskValue),
Compile / packageSrc / mappings ++= {
val base = (Compile / sourceManaged).value
val files = (Compile / managedSources).value
files
.map(f => (f, f.relativeTo(base)))
// this excludes modules/core/src/generated/PartiallyAppliedStruct.scala
.collect { case (f, Some(relF)) => f -> relF.getPath() }
}
)
.jvmPlatform(allJvmScalaVersions, jvmDimSettings)
.jsPlatform(allJsScalaVersions, jsDimSettings)
.nativePlatform(allNativeScalaVersions, nativeDimSettings)
/**
* Smithy4s specific scalacheck integration.
*/
lazy val scalacheck = projectMatrix
.in(file("modules/scalacheck"))
.dependsOn(core)
.settings(
libraryDependencies ++= Seq(
Dependencies.collectionsCompat.value,
Dependencies.Scalacheck.scalacheck.value
),
libraryDependencies ++= munitDeps.value,
testFrameworks += new TestFramework("weaver.framework.CatsEffect")
)
.jvmPlatform(allJvmScalaVersions, jvmDimSettings)
.jsPlatform(allJsScalaVersions, jsDimSettings)
.nativePlatform(allNativeScalaVersions, nativeDimSettings)
/**
* The aws-specific core a library. Contains the generated code for AWS specific
* traits, the instances of which contain metadata required to run the AWS signing
* algorithm.
*
* Also contains basic data types and functionality.
*/
lazy val `aws-kernel` = projectMatrix
.in(file("modules/aws-kernel"))
.dependsOn(core)
.settings(
isCE3 := true,
libraryDependencies ++= Seq(
Dependencies.Weaver.cats.value % Test,
Dependencies.Weaver.scalacheck.value % Test
),
genDiscoverModels := true,
Compile / allowedNamespaces := Seq(
"aws.api",
"aws.auth",
"aws.customizations",
"aws.protocols"
),
Compile / sourceGenerators := Seq(genSmithyScala(Compile).taskValue),
Test / fork := true,
Test / envVars ++= Map("TEST_VAR" -> "hello")
)
.jvmPlatform(latest2ScalaVersions, jvmDimSettings)
.jsPlatform(
latest2ScalaVersions,
jsDimSettings ++ Seq(
Test / jsEnv := new NodeJSEnv(
NodeJSEnv.Config().withEnv(Map("TEST_VAR" -> "hello"))
)
)
)
.nativePlatform(allNativeScalaVersions, nativeDimSettings)
/**
* cats-effect specific abstractions of AWS protocol interpreters and constructs
*/
lazy val aws = projectMatrix
.in(file("modules/aws"))
.dependsOn(`aws-kernel`, json)
.settings(
isCE3 := true,
libraryDependencies ++= {
// Only building this module against CE3
Seq(
Dependencies.Fs2.core.value,
Dependencies.Weaver.cats.value % Test,
Dependencies.Weaver.scalacheck.value % Test
)
},
Test / fork := true
)
.jvmPlatform(latest2ScalaVersions, jvmDimSettings)
.jsPlatform(latest2ScalaVersions, jsDimSettings)
.nativePlatform(allNativeScalaVersions, nativeDimSettings)
/**
* http4s-specific implementation of aws protocols. This module exposes generic methods
* to acquire instances of AWS clients.
*
* This module does not contain the service-specific instances (ie, it does not contain
* DynamoDB or Kinesis specific constructs). It works against the types generated in the
* `aws` module to provide interpreters that can "run" AWS requests.
*/
lazy val `aws-http4s` = projectMatrix
.in(file("modules/aws-http4s"))
.dependsOn(aws)
.settings(
isCE3 := true,
Test / genDiscoverModels := true,
libraryDependencies ++= {
Seq(
Dependencies.Http4s.client.value,
Dependencies.Http4s.emberClient.value % Test
)
},
Test / allowedNamespaces := Seq(),
Test / sourceGenerators := Seq(genSmithyScala(Test).taskValue)
)
.jvmPlatform(
latest2ScalaVersions,
jvmDimSettings ++ Seq(
Test / smithySpecs ++= Seq(
(ThisBuild / baseDirectory).value / "sampleSpecs" / "dynamodb.2012-08-10.json",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "lambda.json"
)
)
)
.jsPlatform(latest2ScalaVersions, jsDimSettings)
.nativePlatform(allNativeScalaVersions, nativeDimSettings)
/**
* This module contains the logic used at build time for reading smithy
* models and rendering Scala (or openapi) code.
*/
lazy val codegen = projectMatrix
.in(file("modules/codegen"))
.enablePlugins(BuildInfoPlugin)
.dependsOn(openapi)
.jvmPlatform(buildtimejvmScala2Versions, jvmDimSettings)
.settings(
buildInfoKeys := Seq[BuildInfoKey](
version,
scalaBinaryVersion,
"smithyVersion" -> Dependencies.Smithy.smithyVersion
),
buildInfoPackage := "smithy4s.codegen",
libraryDependencies ++= Seq(
Dependencies.Cats.core.value,
Dependencies.Smithy.model,
Dependencies.Smithy.build,
Dependencies.Smithy.awsTraits,
Dependencies.Smithy.testTraits,
Dependencies.Smithy.waiters,
"com.lihaoyi" %% "os-lib" % "0.8.1",
"org.scala-lang.modules" %% "scala-collection-compat" % "2.2.0",
"org.scala-lang" % "scala-reflect" % scalaVersion.value,
"io.get-coursier" %% "coursier" % "2.0.16"
),
libraryDependencies ++= munitDeps.value,
scalacOptions := scalacOptions.value
.filterNot(Seq("-Ywarn-value-discard", "-Wvalue-discard").contains)
)
/**
* This module is the command-line-interface to the codegen module, that
* can be used independently of build tools (or that build tools can choose
* to delegate to in order to implement plugins)
*/
lazy val `codegen-cli` = projectMatrix
.in(file("modules/codegen-cli"))
.dependsOn(codegen)
.jvmPlatform(List(Scala213), jvmDimSettings)
.settings(
isCE3 := true,
libraryDependencies ++= Seq(
Dependencies.Decline.core.value,
Dependencies.Weaver.cats.value % Test
)
)
/**
* SBT plugin wrapping calls to the functions provided by the codegen module.
*/
lazy val codegenPlugin = (projectMatrix in file("modules/codegen-plugin"))
.enablePlugins(SbtPlugin)
.dependsOn(codegen)
.jvmPlatform(
scalaVersions = List(Scala212),
jvmDimSettings
)
.settings(
name := "sbt-codegen",
sbtPlugin := true,
scriptedLaunchOpts := {
scriptedLaunchOpts.value ++
Seq("-Xmx1024M", "-Dplugin.version=" + version.value)
},
Compile / unmanagedSources / excludeFilter := { f =>
Glob("**/sbt-test/**").matches(f.toPath)
},
publishLocal := {
// make sure that core and codegen are published before the
// plugin is published
// this allows running `scripted` alone
val _ = List(
// for the code being built
(core.jvm(Scala213) / publishLocal).value,
(dynamic.jvm(Scala213) / publishLocal).value,
(codegen.jvm(Scala213) / publishLocal).value,
// dependency of codegen
(openapi.jvm(Scala213) / publishLocal).value,
// for sbt
(codegen.jvm(Scala212) / publishLocal).value,
(openapi.jvm(Scala212) / publishLocal).value,
(protocol.jvm(autoScalaLibrary = false) / publishLocal).value
)
publishLocal.value
},
scriptedBufferLog := false
)
/**
* Mill plugin to run codegen
*/
lazy val millCodegenPlugin = projectMatrix
.in(file("modules/mill-codegen-plugin"))
.enablePlugins(BuildInfoPlugin)
.jvmPlatform(
scalaVersions = List(Scala213),
simpleJVMLayout
)
.settings(
name := "mill-codegen-plugin",
crossVersion := CrossVersion
.binaryWith(s"mill${millPlatform(Dependencies.Mill.millVersion)}_", ""),
buildInfoKeys := Seq[BuildInfoKey](version),
buildInfoPackage := "smithy4s.codegen.mill",
libraryDependencies ++= Seq(
Dependencies.Mill.main,
Dependencies.Mill.mainApi,
Dependencies.Mill.scalalib,
Dependencies.Mill.mainTestkit
),
publishLocal := {
// make sure that core and codegen are published before the
// plugin is published
// this allows running `scripted` alone
val _ = List(
// for the code being built
(core.jvm(Scala213) / publishLocal).value,
(dynamic.jvm(Scala213) / publishLocal).value,
(codegen.jvm(Scala213) / publishLocal).value,
// dependency of codegen
(openapi.jvm(Scala213) / publishLocal).value,
// for mill
(protocol.jvm(autoScalaLibrary = false) / publishLocal).value
)
publishLocal.value
},
Test / test := (Test / test).dependsOn(publishLocal).value,
libraryDependencies ++= munitDeps.value
)
.dependsOn(codegen)
lazy val decline = (projectMatrix in file("modules/decline"))
.settings(
name := "decline",
isCE3 := true,
libraryDependencies ++= List(
Dependencies.Cats.core.value,
Dependencies.CatsEffect3.value,
Dependencies.Decline.core.value,
Dependencies.Weaver.cats.value % Test
)
)
.dependsOn(json)
.jvmPlatform(allJvmScalaVersions, jvmDimSettings)
.jsPlatform(allJsScalaVersions, jsDimSettings)
.nativePlatform(allNativeScalaVersions, nativeDimSettings)
/**
* This module contains the smithy specification of a bunch of types
* that are not provided by the smithy standard library, but are useful
* nonetheless and pretty common (such as UUID).
*
* It also contains the definition of a custom protocol implemented in this
* library, which is a pretty basic REST-JSON protocol. smithy4s provides
* server and client side bindings for this protocol.
*/
lazy val protocol = projectMatrix
.in(file("modules/protocol"))
.jvmPlatform(
autoScalaLibrary = false,
scalaVersions = Seq.empty,
settings = jvmDimSettings
)
.settings(
Compile / packageSrc / mappings := (Compile / packageSrc / mappings).value
.filterNot { case (file, path) =>
path.equalsIgnoreCase("META-INF/smithy/manifest")
},
resolvers += Resolver.mavenLocal,
libraryDependencies += Dependencies.Smithy.model,
javacOptions ++= Seq("--release", "8")
)
lazy val protocolTests = projectMatrix
.in(file("modules/protocol-tests"))
.jvmPlatform(Seq(Scala213), jvmDimSettings)
.dependsOn(protocol)
.settings(
isCE3 := true,
libraryDependencies ++= Seq(
Dependencies.Weaver.cats.value % Test,
Dependencies.Weaver.scalacheck.value % Test
),
Test / fork := true
)
.settings(Smithy4sPlugin.doNotPublishArtifact)
/**
* This modules contains utilities to dynamically instantiate
* the interfaces provide by smithy4s, based on data from dynamic
* Model instances.
*/
lazy val dynamic = projectMatrix
.in(file("modules/dynamic"))
.dependsOn(core % "test->test;compile->compile", testUtils % "test->compile")
.settings(
libraryDependencies ++= Seq(
"org.scala-lang.modules" %%% "scala-collection-compat" % "2.8.1",
Dependencies.Cats.core.value
),
libraryDependencies ++= munitDeps.value,
Compile / allowedNamespaces := Seq("smithy4s.dynamic.model"),
Compile / smithySpecs := Seq(
(ThisBuild / baseDirectory).value / "modules" / "dynamic" / "smithy" / "dynamic.smithy"
),
Compile / sourceGenerators := Seq(genSmithyScala(Compile).taskValue),
Test / allowedNamespaces := Seq("smithy4s.example"),
Test / smithySpecs := Seq(
(ThisBuild / baseDirectory).value / "sampleSpecs" / "kvstore.smithy"
),
(Test / sourceGenerators) := Seq(genSmithyScala(Test).taskValue)
)
.jvmPlatform(
allJvmScalaVersions,
jvmDimSettings ++ Seq(
Test / fork := true,
// Forwarding cwd to tests
Test / javaOptions += s"-Duser.dir=${sys.props("user.dir")}",
libraryDependencies += Dependencies.Smithy.model
)
)
.jsPlatform(allJsScalaVersions, jsDimSettings)
.nativePlatform(allNativeScalaVersions, nativeDimSettings)
/**
* Module that contains the logic for generating "openapi views" of the
* services that abide by some custom protocols provided by this library.
*/
lazy val openapi = projectMatrix
.in(file("modules/openapi"))
.jvmPlatform(buildtimejvmScala2Versions, jvmDimSettings)
.dependsOn(protocol)
.settings(
isCE3 := true,
libraryDependencies ++= Seq(
Dependencies.Cats.core.value,
Dependencies.Smithy.openapi,
"org.scala-lang.modules" %% "scala-collection-compat" % "2.8.1",
Dependencies.Weaver.cats.value % Test
)
)
/**
* Module that contains jsoniter-based encoders/decoders for the generated
* types.
*/
lazy val json = projectMatrix
.in(file("modules/json"))
.dependsOn(
core % "test->test;compile->compile",
scalacheck % "test -> compile"
)
.settings(
isMimaEnabled := true,
libraryDependencies ++= Seq(
Dependencies.Jsoniter.value
),
libraryDependencies ++= munitDeps.value,
Test / fork := virtualAxes.value.contains(VirtualAxis.jvm)
)
.jvmPlatform(allJvmScalaVersions, jvmDimSettings)
.jsPlatform(allJsScalaVersions, jsDimSettings)
.nativePlatform(allNativeScalaVersions, nativeDimSettings)
/**
* Module that contains http4s-specific client/server bindings for the
* custom protocols provided by smithy4s.
*/
lazy val http4s = projectMatrix
.in(file("modules/http4s"))
.dependsOn(
core,
json,
dynamic % "test->compile",
tests % "test->compile",
testUtils % "test->compile"
)
.settings(
isCE3 := virtualAxes.value.contains(CatsEffect3Axis),
isMimaEnabled := true,
libraryDependencies ++= {
val ce3 =
if (isCE3.value) Seq(Dependencies.CatsEffect3.value)
else Seq.empty
ce3 ++ Seq(
Dependencies.Http4s.core.value,
Dependencies.Http4s.dsl.value,
Dependencies.Http4s.client.value,
Dependencies.Http4s.circe.value % Test,
Dependencies.Weaver.cats.value % Test
)
},
moduleName := {
if (virtualAxes.value.contains(CatsEffect2Axis))
moduleName.value + "-ce2"
else moduleName.value
}
)
.http4sPlatform(allJvmScalaVersions, jvmDimSettings)
/**
* Module that contains a function to derive a documentation endpoint
*/
lazy val `http4s-swagger` = projectMatrix
.in(file("modules/http4s-swagger"))
.dependsOn(http4s)
.settings(
isCE3 := virtualAxes.value.contains(CatsEffect3Axis),
libraryDependencies ++= {
Seq(
Dependencies.Weaver.cats.value % Test,
Dependencies.Webjars.swaggerUi,
Dependencies.Webjars.webjarsLocator
)
},
moduleName := {
if (virtualAxes.value.contains(CatsEffect2Axis))
moduleName.value + "-ce2"
else moduleName.value
}
)
.http4sJvmPlatform(allJvmScalaVersions, jvmDimSettings)
lazy val testUtils = projectMatrix
.in(file("modules/test-utils"))
.dependsOn(core)
.settings(Smithy4sPlugin.doNotPublishArtifact)
.settings(
libraryDependencies += Dependencies.Cats.core.value
)
.jvmPlatform(allJvmScalaVersions, jvmDimSettings)
.jsPlatform(allJsScalaVersions, jsDimSettings)
.nativePlatform(allNativeScalaVersions, nativeDimSettings)
/**
* Generic tests aimed at testing the implementations of the custom protocols
* provided by smithy4s.
*/
lazy val tests = projectMatrix
.in(file("modules/tests"))
.dependsOn(core)
.settings(
isCE3 := virtualAxes.value.contains(CatsEffect3Axis),
libraryDependencies ++= {
val ce3 =
if (isCE3.value) Seq(Dependencies.CatsEffect3.value)
else Seq.empty
ce3 ++ Seq(
Dependencies.Http4s.core.value,
Dependencies.Http4s.dsl.value,
Dependencies.Http4s.client.value,
Dependencies.Http4s.circe.value,
Dependencies.Weaver.cats.value
)
},
Compile / smithySpecs := Seq(
(ThisBuild / baseDirectory).value / "sampleSpecs" / "pizza.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "weather.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "recursiveInput.smithy"
),
moduleName := {
if (virtualAxes.value.contains(CatsEffect2Axis))
moduleName.value + "-ce2"
else moduleName.value
},
(Compile / sourceGenerators) := Seq(genSmithyScala(Compile).taskValue)
)
.http4sPlatform(allJvmScalaVersions, jvmDimSettings)
lazy val complianceTests = projectMatrix
.in(file("modules/compliance-tests"))
.dependsOn(core, http4s % "test->compile", testUtils)
.settings(
name := "compliance-tests",
Compile / allowedNamespaces := Seq("smithy.test", "smithy4s.example"),
genDiscoverModels := true,
(Compile / sourceGenerators) := Seq(genSmithyScala(Compile).taskValue),
isCE3 := virtualAxes.value.contains(CatsEffect3Axis),
libraryDependencies ++= {
val ce3 =
if (isCE3.value) Seq(Dependencies.CatsEffect3.value)
else Seq.empty
ce3 ++ Seq(
Dependencies.Http4s.circe.value,
Dependencies.Http4s.client.value,
Dependencies.Weaver.cats.value % Test
)
},
testFrameworks += new TestFramework("weaver.framework.CatsEffect"),
Test / smithySpecs := Seq(
(ThisBuild / baseDirectory).value / "sampleSpecs" / "test.smithy"
),
Test / genDiscoverModels := true,
Test / sourceGenerators := Seq(genSmithyScala(Test).taskValue)
)
.http4sPlatform(allJvmScalaVersions, jvmDimSettings)
/**
* Example application using the custom REST-JSON protocol provided by
* smithy4s.
*/
lazy val example = projectMatrix
.in(file("modules/example"))
.dependsOn(`http4s-swagger`)
.disablePlugins(ScalafixPlugin)
.disablePlugins(HeaderPlugin)
.settings(
Compile / allowedNamespaces := Seq(
"smithy4s.example",
"smithy4s.example.import_test",
"smithy4s.example.imp",
"smithy4s.example.error",
"smithy4s.example.common",
"smithy4s.example.collision"
),
smithySpecs := Seq(
(ThisBuild / baseDirectory).value / "sampleSpecs" / "example.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "errors.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "streaming.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "operation.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "import.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "importerror.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "adtMember.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "brands.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "brandscommon.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "refined.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "enums.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "reservednames.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "namecollision.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "mixins.smithy",
(ThisBuild / baseDirectory).value / "sampleSpecs" / "defaults.smithy"
),
Compile / resourceDirectory := (ThisBuild / baseDirectory).value / "modules" / "example" / "resources",
isCE3 := true,
libraryDependencies += Dependencies.Http4s.emberServer.value,
(Compile / sourceGenerators) := Seq(genSmithyScala(Compile).taskValue),
(Compile / resourceGenerators) := Seq(
genSmithyResources(Compile).taskValue
),
genSmithyOutput := ((ThisBuild / baseDirectory).value / "modules" / "example" / "src"),
genSmithyResourcesOutput := (Compile / resourceDirectory).value,
smithy4sSkip := List("resource")
)
.jvmPlatform(List(Scala213), jvmDimSettings)
.settings(Smithy4sPlugin.doNotPublishArtifact)
lazy val guides = projectMatrix
.in(file("modules/guides"))
.dependsOn(http4s)
.settings(
Compile / allowedNamespaces := Seq("smithy4s.guides.hello"),
smithySpecs := Seq(
(ThisBuild / baseDirectory).value / "modules" / "guides" / "smithy" / "hello.smithy"
),
(Compile / sourceGenerators) := Seq(genSmithyScala(Compile).taskValue),
isCE3 := true,
libraryDependencies ++= Seq(
Dependencies.Http4s.emberServer.value,
Dependencies.Weaver.cats.value % Test
)
)
.jvmPlatform(Seq(Scala3), jvmDimSettings)
.settings(Smithy4sPlugin.doNotPublishArtifact)
/**
* Pretty primitive benchmarks to test that we're not doing anything drastically
* slow.
*/
lazy val benchmark = projectMatrix
.in(file("modules/benchmark"))
.enablePlugins(JmhPlugin)
.dependsOn(
http4s % "compile -> compile,test",
`scalacheck`
)
.settings(
libraryDependencies ++= Seq(
Dependencies.Circe.generic.value
),
smithySpecs := Seq(
(ThisBuild / baseDirectory).value / "sampleSpecs" / "benchmark.smithy"
),
(Compile / sourceGenerators) := Seq(genSmithyScala(Compile).taskValue)
)
.jvmPlatform(List(Scala213), jvmDimSettings)
.settings(Smithy4sPlugin.doNotPublishArtifact)
val isCE3 = settingKey[Boolean]("Is the current build using CE3?")
lazy val Dependencies = new {
val collectionsCompat =
Def.setting(
"org.scala-lang.modules" %%% "scala-collection-compat" % "2.8.1"
)
val Jsoniter =
Def.setting(
"com.github.plokhotnyuk.jsoniter-scala" %%% "jsoniter-scala-core" % "2.17.5"
)
val Smithy = new {
val smithyVersion = "1.25.1"
val model = "software.amazon.smithy" % "smithy-model" % smithyVersion
val testTraits =
"software.amazon.smithy" % "smithy-protocol-test-traits" % smithyVersion
val build = "software.amazon.smithy" % "smithy-build" % smithyVersion
val awsTraits =
"software.amazon.smithy" % "smithy-aws-traits" % smithyVersion
val openapi = "software.amazon.smithy" % "smithy-openapi" % smithyVersion
val waiters = "software.amazon.smithy" % "smithy-waiters" % smithyVersion
}
val Cats = new {
val core: Def.Initialize[ModuleID] =
Def.setting("org.typelevel" %%% "cats-core" % "2.8.0")
}
object Decline {
val declineVersion = "2.3.1"
val core = Def.setting("com.monovore" %%% "decline" % declineVersion)
val effect =
Def.setting("com.monovore" %%% "decline-effect" % declineVersion)
}
object Fs2 {
val core: Def.Initialize[ModuleID] =
Def.setting("co.fs2" %%% "fs2-core" % "3.3.0")
}
object Mill {
val millVersion = "0.10.7"
val scalalib = "com.lihaoyi" %% "mill-scalalib" % millVersion
val main = "com.lihaoyi" %% "mill-main" % millVersion
val mainApi = "com.lihaoyi" %% "mill-main-api" % millVersion
val mainTestkit = "com.lihaoyi" %% "mill-main-testkit" % millVersion % Test
}
val Circe = new {
val generic: Def.Initialize[ModuleID] =
Def.setting("io.circe" %%% "circe-generic" % "0.14.3")
}
/*
* we override the version to use the fix included in
* https://github.com/typelevel/cats-effect/pull/2945
* it allows us to use UUIDGen instead of calling
* UUID.randomUUID manually
*
* we also provide a 2.12 shim under:
* modules/tests/src-ce2/UUIDGen.scala
*/
val CatsEffect3: Def.Initialize[ModuleID] =
Def.setting("org.typelevel" %%% "cats-effect" % "3.3.14")
object Http4s {
val http4sVersion = Def.setting(if (isCE3.value) "0.23.16" else "0.22.14")
val emberServer: Def.Initialize[ModuleID] =
Def.setting("org.http4s" %%% "http4s-ember-server" % http4sVersion.value)
val emberClient: Def.Initialize[ModuleID] =
Def.setting("org.http4s" %%% "http4s-ember-client" % http4sVersion.value)
val circe: Def.Initialize[ModuleID] =
Def.setting("org.http4s" %%% "http4s-circe" % http4sVersion.value)
val core: Def.Initialize[ModuleID] =
Def.setting("org.http4s" %%% "http4s-core" % http4sVersion.value)
val dsl: Def.Initialize[ModuleID] =
Def.setting("org.http4s" %%% "http4s-dsl" % http4sVersion.value)
val client: Def.Initialize[ModuleID] =
Def.setting("org.http4s" %%% "http4s-client" % http4sVersion.value)
}
object Weaver {
val weaverVersion = Def.setting(if (isCE3.value) "0.8.0" else "0.6.15")
val cats: Def.Initialize[ModuleID] =
Def.setting("com.disneystreaming" %%% "weaver-cats" % weaverVersion.value)
val scalacheck: Def.Initialize[ModuleID] =
Def.setting(
"com.disneystreaming" %%% "weaver-scalacheck" % weaverVersion.value
)
}
class MunitCross(munitVersion: String) {
val core: Def.Initialize[ModuleID] =
Def.setting("org.scalameta" %%% "munit" % munitVersion)
val scalacheck: Def.Initialize[ModuleID] =
Def.setting("org.scalameta" %%% "munit-scalacheck" % munitVersion)
}
object Munit extends MunitCross("0.7.29")
object MunitMilestone extends MunitCross("1.0.0-M6")
val Scalacheck = new {
val version = "1.16.0"
val scalacheck =
Def.setting("org.scalacheck" %%% "scalacheck" % version)
}
object Webjars {
val swaggerUi: ModuleID = "org.webjars.npm" % "swagger-ui-dist" % "4.14.0"
val webjarsLocator: ModuleID = "org.webjars" % "webjars-locator" % "0.42"
}
}
lazy val smithySpecs = SettingKey[Seq[File]]("smithySpecs")
lazy val genSmithyOutput = SettingKey[File]("genSmithyOutput")
lazy val genSmithyResourcesOutput = SettingKey[File]("genSmithyResourcesOutput")
lazy val allowedNamespaces = SettingKey[Seq[String]]("allowedNamespaces")
lazy val genSmithyDependencies =
SettingKey[Seq[String]]("genSmithyDependencies")
lazy val genDiscoverModels = SettingKey[Boolean]("genDiscoverModels")
lazy val smithy4sSkip = SettingKey[Seq[String]]("smithy4sSkip")
(ThisBuild / smithySpecs) := Seq.empty
def genSmithyScala(config: Configuration) = genSmithyImpl(config).map(_._1)
def genSmithyResources(config: Configuration) = genSmithyImpl(config).map(_._2)
/**
* Dogfooding task that calls the codegen module, to generate smithy standard
* library code, aws-specific code.
*/
def genSmithyImpl(config: Configuration) = Def.task {
val inputFiles = (config / smithySpecs).value
val outputDir = (config / genSmithyOutput).?.value
.getOrElse((config / sourceManaged).value)
.getAbsolutePath()
val resourceOutputDir =
(config / genSmithyResourcesOutput).?.value
.getOrElse((config / resourceManaged).value)
.getAbsolutePath()
val allowedNS = (config / allowedNamespaces).?.value.filterNot(_.isEmpty)
val discoverModels =
(config / genDiscoverModels).?.value.getOrElse(false)
val skip = (config / smithy4sSkip).?.value.getOrElse(Seq.empty)
val codegenCp =
(`codegen-cli`.jvm(Smithy4sPlugin.Scala213) / Compile / fullClasspath).value
.map(_.data)
val mc = "smithy4s.codegen.cli.Main"
val s = (config / streams).value
def untupled[A, B, C](f: ((A, B)) => C): (A, B) => C = (a, b) => f((a, b))
val cached =
Tracked.inputChanged[FilesInfo[HashFileInfo], Seq[File]](
s.cacheStoreFactory.make("input")
) {
untupled {
Tracked
.lastOutput[(Boolean, FilesInfo[HashFileInfo]), Seq[File]](
s.cacheStoreFactory.make("output")
) { case ((changed, files), outputs) =>
if (changed || outputs.isEmpty) {
val inputs = inputFiles.map(_.getAbsolutePath()).toList
val args =
List("--output", outputDir) ++
List("--resource-output", resourceOutputDir) ++
(if (discoverModels) List("--discover-models") else Nil) ++
(if (allowedNS.isDefined)
List("--allowed-ns", allowedNS.get.mkString(","))
else Nil) ++
inputs ++
skip.flatMap(s => List("--skip", s))
val cp = codegenCp
.map(_.getAbsolutePath())
.mkString(":")
val res =
("java" :: "-cp" :: cp :: mc :: "generate" :: args).lineStream.toList
res.map(new File(_))
} else outputs.getOrElse(Seq.empty)
}
}