-
Notifications
You must be signed in to change notification settings - Fork 343
Expand file tree
/
Copy pathbuild.sbt
More file actions
6636 lines (6413 loc) · 265 KB
/
build.sbt
File metadata and controls
6636 lines (6413 loc) · 265 KB
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 org.enso.build.BenchTasks.*
import org.enso.build.WithDebugCommand
import org.apache.commons.io.FileUtils
import sbt.Keys.{libraryDependencies, scalacOptions}
import sbt.addCompilerPlugin
import sbt.complete.DefaultParsers.*
import sbt.complete.Parser
import sbt.nio.file.FileTreeView
import sbt.internal.util.ManagedLogger
import src.main.scala.licenses.{
DistributionDescription,
SBTDistributionComponent
}
import scala.sys.process.*
import Dependencies.*
import JarExtractor.{
CopyToOutputJar,
LinuxAMD64,
MacOSArm64,
PolyglotLib,
WindowsAMD64
}
import java.nio.file.{Files, StandardCopyOption}
// This import is unnecessary, but bit adds a proper code completion features
// to IntelliJ.
import JPMSPlugin.autoImport._
import PackageListPlugin.autoImport._
import BazelSupport.autoImport._
import JarExtractPlugin.autoImport._
import java.io.File
// ============================================================================
// === Global Configuration ===================================================
// ============================================================================
// Inspired by https://www.scala-sbt.org/1.x/docs/Howto-Startup.html#How+to+take+an+action+on+startup
lazy val startupStateTransition: State => State = { s: State =>
GraalVM.versionCheck(
graalVersion,
graalMavenPackagesVersion,
javaVersion,
s
)
}
Global / onLoad := {
val old = (Global / onLoad).value
startupStateTransition compose old
}
ThisBuild / organization := "org.enso"
ThisBuild / scalaVersion := scalacVersion
ThisBuild / publish / skip := true
ThisBuild / assembly / logLevel := Level.Warn
/* Tag limiting the concurrent access to tools/simple-library-server in tests.
*/
val simpleLibraryServerTag = Tags.Tag("simple-library-server")
Global / concurrentRestrictions += Tags.limit(simpleLibraryServerTag, 1)
/** Tag limiting the concurrent spawning of `native-image` subprocess.
*/
val nativeImageBuildTag = NativeImage.nativeImageBuildTag
Global / concurrentRestrictions += Tags.limit(nativeImageBuildTag, 1)
lazy val gatherLicenses =
taskKey[Unit](
"Gathers licensing information for relevant dependencies of all distributions"
)
gatherLicenses := {
val _ = GatherLicenses.run.toTask("").value
}
lazy val verifyLicensePackages =
taskKey[Unit](
"Verifies if the license package has been generated, " +
"has no warnings and is up-to-date with dependencies."
)
verifyLicensePackages := GatherLicenses.verifyReports.value
lazy val verifyGeneratedPackage =
inputKey[Unit](
"Verifies if the license package in a generated distribution is " +
"up-to-date with the one from the report."
)
verifyGeneratedPackage := GatherLicenses.verifyGeneratedPackage.evaluated
def makeStdLibDistribution(
name: String,
components: Seq[SBTDistributionComponent]
): DistributionDescription =
Distribution(
name,
file(s"distribution/lib/Standard/$name/$stdLibVersion/THIRD-PARTY"),
components
)
GatherLicenses.distributions := Seq(
Distribution(
"launcher",
file("distribution/launcher/THIRD-PARTY"),
Distribution.sbtProjects(launcher)
),
Distribution(
"engine",
file("distribution/engine/THIRD-PARTY"),
Distribution.sbtProjects(
`runtime-and-langs`,
`engine-runner`,
`language-server`
)
),
makeStdLibDistribution("Base", Distribution.sbtProjects(`std-base`)),
makeStdLibDistribution(
"Generic_JDBC",
Distribution.sbtProjects(`std-generic-jdbc`)
),
makeStdLibDistribution(
"Google",
Distribution.sbtProjects(`std-google`)
),
makeStdLibDistribution("Table", Distribution.sbtProjects(`std-table`)),
makeStdLibDistribution("Database", Distribution.sbtProjects(`std-database`)),
makeStdLibDistribution("Image", Distribution.sbtProjects(`std-image`)),
makeStdLibDistribution("AWS", Distribution.sbtProjects(`std-aws`)),
makeStdLibDistribution(
"Snowflake",
Distribution.sbtProjects(`std-snowflake`)
),
makeStdLibDistribution(
"Microsoft",
Distribution.sbtProjects(`std-microsoft`)
),
makeStdLibDistribution(
"Tableau",
Distribution.sbtProjects(`std-tableau`, `jna-wrapper`)
),
makeStdLibDistribution(
"Saas",
Distribution.sbtProjects(`std-saas`)
),
makeStdLibDistribution(
"DuckDB",
Distribution.sbtProjects(`std-duckdb`)
)
)
GatherLicenses.licenseConfigurations := Set("compile")
GatherLicenses.configurationRoot := file("tools/legal-review")
lazy val openLegalReviewReport =
inputKey[Unit](
"Gathers licensing information for relevant dependencies and opens the " +
"report in review mode in the browser. Specify names of distributions to process, separated by spaces. If no names are provided, all distributions are processed."
)
openLegalReviewReport := {
GatherLicenses.run.evaluated
GatherLicenses.runReportServer()
}
lazy val analyzeDependency = inputKey[Unit]("...")
analyzeDependency := GatherLicenses.analyzeDependency.evaluated
lazy val distributionArtifactRoot = SettingKey[File](
"root directory where distribution artifacts will be built."
)
distributionArtifactRoot := {
if ((Bazel / wasStartedFromBazel).value) {
(Bazel / outputDir).value.get
} else {
file("built-distribution")
}
}
lazy val packageBuilder = SettingKey[DistributionPackage.Builder](
"create package builder with correct output dir path"
)
packageBuilder := {
val artifactRoot = distributionArtifactRoot.value
new DistributionPackage.Builder(
ensoVersion = ensoVersion,
graalVersion = graalMavenPackagesVersion,
graalJavaVersion = graalVersion,
artifactRoot = artifactRoot
)
}
lazy val writeEditionConfig = taskKey[Editions.EditionTemplate](
"Writes the edition configuration yaml file."
)
writeEditionConfig := {
Editions.writeEditionConfig(
editionsRoot = file("distribution") / "editions",
editionTemplate = file("distribution") / "edition.template.yaml",
ensoVersion = ensoVersion,
editionName = currentEdition,
libraryVersion = stdLibVersion,
log = streams.value.log
)
}
lazy val librariesToUpload = taskKey[Seq[String]](
"List of libraries that will be uploaded as release assets"
)
librariesToUpload := {
val editionTemplate = writeEditionConfig.value
editionTemplate.libsToUpload()
}
lazy val checkIRCacheSizes = taskKey[Unit](
"Checks that the IR caches of all standard libraries are within the size limit."
)
checkIRCacheSizes := Def
.task {
val stdLibRoot =
engineDistributionRoot.value / "lib" / "Standard"
IRCaches.checkCacheSizes(
stdLibRoot = stdLibRoot,
ensoVersion = ensoVersion,
log = streams.value.log
)
}
.dependsOn(buildEngineDistribution)
.value
Global / onChangedBuildSource := ReloadOnSourceChanges
Global / excludeLintKeys += logManager
// ============================================================================
// === Compiler Options =======================================================
// ============================================================================
ThisBuild / javacOptions ++= Seq(
"-encoding", // Provide explicit encoding (the next line)
"UTF-8", // Specify character encoding used by Java source files
"-deprecation", // Shows a description of each use or override of a deprecated member or class
"-g", // Include debugging information
"-Xlint:unchecked", // Enable additional warnings
"-proc:full" // Annotation processing is enabled
)
ThisBuild / javaOptions ++= Seq(
// Truffle calls terminally deprecated methods from sun.misc.Unsafe in JDK24.
// This removes the warnings at runtime.
// TODO: Remove this until JDK 26
"--sun-misc-unsafe-memory-access=allow"
)
ThisBuild / scalacOptions ++= Seq(
"-deprecation", // Emit warning and location for usages of deprecated APIs.
"-encoding", // Provide explicit encoding (the next line)
"utf-8", // Specify character encoding used by Scala source files.
"-explaintypes", // Explain type errors in more detail.
"-feature", // Emit warning and location for usages of features that should be imported explicitly.
"-language:existentials", // Existential types (besides wildcard types) can be written and inferred
"-language:experimental.macros", // Allow macro definition (besides implementation and application)
"-language:higherKinds", // Allow higher-kinded types
"-language:implicitConversions", // Allow definition of implicit functions called views
"-unchecked", // Enable additional warnings where generated code depends on assumptions.
"-Vimplicits", // Prints implicit resolution chains when no implicit can be found.
"-Vtype-diffs", // Prints type errors as coloured diffs between types.
"-Xcheckinit", // Wrap field accessors to throw an exception on uninitialized access.
"-Xfatal-warnings", // Make warnings fatal so they don't make it onto main (use @nowarn for local suppression)
"-Xlint:adapted-args", // Warn if an argument list is modified to match the receiver.
"-Xlint:constant", // Evaluation of a constant arithmetic expression results in an error.
"-Xlint:delayedinit-select", // Selecting member of DelayedInit.
"-Xlint:doc-detached", // A Scaladoc comment appears to be detached from its element.
"-Xlint:inaccessible", // Warn about inaccessible types in method signatures.
"-Xlint:infer-any", // Warn when a type argument is inferred to be `Any`.
"-Xlint:missing-interpolator", // A string literal appears to be missing an interpolator id.
"-Xlint:nullary-unit", // Warn when nullary methods return Unit.
"-Xlint:option-implicit", // Option.apply used implicit view.
"-Xlint:package-object-classes", // Class or object defined in package object.
"-Xlint:poly-implicit-overload", // Parameterized overloaded implicit methods are not visible as view bounds.
"-Xlint:private-shadow", // A private field (or class parameter) shadows a superclass field.
"-Xlint:stars-align", // Pattern sequence wildcard must align with sequence component.
"-Xlint:type-parameter-shadow", // A local type parameter shadows a type already in scope.
"-Xmacro-settings:-logging@org.enso", // Disable the debug logging globally.
"-Ywarn-dead-code", // Warn when dead code is identified.
"-Ywarn-extra-implicit", // Warn when more than one implicit parameter section is defined.
"-Ywarn-numeric-widen", // Warn when numerics are widened.
"-Ywarn-unused:implicits", // Warn if an implicit parameter is unused.
"-Ywarn-unused:imports", // Warn if an import selector is not referenced.
"-Ywarn-unused:locals", // Warn if a local definition is unused.
"-Ywarn-unused:params", // Warn if a value parameter is unused.
"-Ywarn-unused:patvars", // Warn if a variable bound in a pattern is unused.
"-Ywarn-unused:privates" // Warn if a private member is unused.
)
ThisBuild / Test / testOptions ++=
Seq(
Tests.Argument(TestFrameworks.ScalaTest, "-oID"),
Tests.Argument(TestFrameworks.JUnit, "--verbosity=1")
) ++
sys.env
.get("ENSO_TEST_JUNIT_DIR")
.map { junitDir =>
Tests.Argument(TestFrameworks.ScalaTest, "-u", junitDir)
}
Compile / console / scalacOptions ~= (_ filterNot (_ == "-Xfatal-warnings"))
lazy val frgaalShouldNotLimitModules = Def.settingKey[Boolean](
"Whether --limit-modules cmd line option should be passed to the java process that runs " +
"the frgaal compiler"
)
// Native Image Generation
lazy val rebuildNativeImage = taskKey[Unit]("Force to rebuild native image")
lazy val buildNativeImage =
taskKey[Unit]("Ensure that the Native Image is built.")
lazy val checkNativeImageSize =
taskKey[Unit]("Ensures the generated Native Image has reasonable size")
// ============================================================================
// === Global Project =========================================================
// ============================================================================
lazy val enso = (project in file("."))
.settings(version := "0.1")
.aggregate(
`akka-wrapper`,
`benchmark-java-helpers`,
`benchmarks-common`,
`bench-processor`,
cli,
`common-polyglot-core-utils`,
`connected-lock-manager`,
`connected-lock-manager-server`,
`distribution-manager`,
downloader,
editions,
`edition-updater`,
`engine-common`,
`engine-runner`,
`engine-runner-common`,
`generic-jdbc-connection-spec-dependencies`,
`enso-test-java-helpers`,
`snowflake-test-java-helpers`,
`exploratory-benchmark-java-helpers`,
`fansi-wrapper`,
filewatcher,
`http-test-helper`,
`interpreter-dsl`,
`interpreter-dsl-test`,
`jna-wrapper`,
`jna-wrapper-extracted`,
`json-rpc-server`,
`jvm-channel`,
`jvm-interop`,
`language-server`,
`language-server-deps-wrapper`,
launcher,
`library-manager`,
`locking-test-helper`,
`logging-config`,
`logging-service`,
`logging-service-logback`,
`logging-service-common`,
`logging-service-opensearch`,
`logging-service-telemetry`,
`logging-truffle-connector`,
`logging-utils`,
`logging-utils-akka`,
`netty-epoll-native-wrapper`,
`netty-tc-native-wrapper`,
`netty-resolver-dns-native-macos-wrapper`,
`opencv-wrapper`,
`os-environment`,
`os-environment-lib`,
`persistance`,
`persistance-dsl`,
pkg,
`poi-wrapper`,
`polyglot-api`,
`polyglot-api-macros`,
`process-utils`,
`profiling-utils`,
`python-extract`,
`python-resource-provider`,
`refactoring-utils`,
runtime,
`runtime-and-langs`,
`runtime-benchmarks`,
`runtime-compiler`,
`runtime-compiler-dump`,
`runtime-compiler-dump-igv`,
`runtime-parser`,
`runtime-parser-dsl`,
`runtime-parser-processor`,
`runtime-parser-processor-tests`,
`runtime-language-arrow`,
`runtime-language-epb`,
`runtime-instrument-common`,
`runtime-instrument-id-execution`,
`runtime-instrument-repl-debugger`,
`runtime-instrument-runtime-server`,
`runtime-integration-tests`,
`runtime-parser`,
`runtime-suggestions`,
`runtime-version-manager`,
`runtime-test-instruments`,
`runtime-utils`,
`scala-libs-wrapper`,
`scala-yaml`,
searcher,
semver,
`std-aws`,
`std-base`,
`std-benchmarks`,
`std-database`,
`std-generic-jdbc`,
`std-google`,
`std-image`,
`std-microsoft`,
`std-snowflake`,
`std-table`,
`std-tests`,
`std-tableau`,
`std-saas`,
`std-duckdb`,
`sqlite-wrapper`,
`syntax-rust-definition`,
`tableau-wrapper`,
`task-progress-notifications`,
testkit,
`test-utils`,
`text-buffer`,
`version-output`,
`ydoc-api`,
`ydoc-polyfill`,
`ydoc-server`,
`ydoc-server-registration`,
`zio-wrapper`
)
.settings(Global / concurrentRestrictions += Tags.exclusive(Exclusive))
.settings(
commands ++= {
Seq(
packageBuilder.value.makePackages,
packageBuilder.value.makeBundles
)
}
)
.settings(
clean := Def.task {
val _ = clean.value
val filesToDelete = Seq(
engineDistributionRoot.value,
launcherDistributionRoot.value,
packageBuilder.value.artifactRoot
)
IO.delete(filesToDelete)
}.value
)
// ============================================================================
// === Utility methods =====================================================
// ============================================================================
lazy val componentModulesPaths =
taskKey[Seq[File]](
"Gathers all component modules (Jar archives that should be put on module-path" +
" as files"
)
(ThisBuild / componentModulesPaths) := {
val runnerCp = (`engine-runner` / Runtime / fullClasspath).value
val runtimeCp = (`runtime` / Runtime / fullClasspath).value
val langServerCp = (`language-server` / Runtime / fullClasspath).value
val akkaWrapperCp = (`akka-wrapper` / Compile / fullClasspath).value
val fullCp = (runnerCp ++ runtimeCp ++ langServerCp ++ akkaWrapperCp).distinct
val log = streams.value.log
val thirdPartyModIds =
GraalVM.modules ++
GraalVM.langsPkgs ++
GraalVM.toolsPkgs ++
scalaReflect ++
helidon ++
scalaLibrary ++
logbackPkg ++
jline ++
slf4jApi ++
Seq(
"org.netbeans.api" % "org-netbeans-modules-sampler" % netbeansApiVersion,
"com.google.flatbuffers" % "flatbuffers-java" % flatbuffersVersion,
"com.google.protobuf" % "protobuf-java" % googleProtobufVersion,
"commons-cli" % "commons-cli" % commonsCliVersion,
"commons-io" % "commons-io" % commonsIoVersion,
"org.yaml" % "snakeyaml" % snakeyamlVersion,
"org.eclipse.jgit" % "org.eclipse.jgit" % jgitVersion,
"com.typesafe" % "config" % typesafeConfigVersion,
"org.reactivestreams" % "reactive-streams" % reactiveStreamsVersion,
"org.apache.commons" % "commons-lang3" % commonsLangVersion,
"org.apache.commons" % "commons-compress" % commonsCompressVersion,
"org.apache.tika" % "tika-core" % tikaVersion,
"org.yaml" % "snakeyaml" % snakeyamlVersion,
"com.ibm.icu" % "icu4j" % icuVersion
)
val modsToExclude = jlineNative ++ Seq(
"org.graalvm.python" % "python-resources" % Dependencies.graalMavenPackagesVersion
)
val reducedThirdPartyModIds = thirdPartyModIds.filterNot { modId =>
modsToExclude.exists { excludedMod =>
modId.organization == excludedMod.organization &&
modId.name == excludedMod.name &&
modId.revision == excludedMod.revision
}
}
val thirdPartyMods = JPMSUtils.filterModulesFromClasspath(
fullCp,
reducedThirdPartyModIds,
log,
projName = moduleName.value,
scalaBinaryVersion.value,
shouldContainAll = true
)
val thirdPartyModFiles = thirdPartyMods.map(_.data)
val ourMods = Seq(
(`akka-wrapper` / Compile / exportedModuleBin).value,
(`cli` / Compile / exportedModuleBin).value,
(`common-polyglot-core-utils` / Compile / exportedModuleBin).value,
(`connected-lock-manager` / Compile / exportedModuleBin).value,
(`connected-lock-manager-server` / Compile / exportedModuleBin).value,
(`distribution-manager` / Compile / exportedModuleBin).value,
(`downloader` / Compile / exportedModuleBin).value,
(`editions` / Compile / exportedModuleBin).value,
(`edition-updater` / Compile / exportedModuleBin).value,
(`engine-common` / Compile / exportedModuleBin).value,
(`engine-runner` / Compile / exportedModuleBin).value,
(`engine-runner-common` / Compile / exportedModuleBin).value,
(`fansi-wrapper` / Compile / exportedModuleBin).value,
(`filewatcher` / Compile / exportedModuleBin).value,
(`json-rpc-server` / Compile / exportedModuleBin).value,
(`jvm-channel` / Compile / exportedModuleBin).value,
(`jvm-interop` / Compile / exportedModuleBin).value,
(`language-server` / Compile / exportedModuleBin).value,
(`language-server-deps-wrapper` / Compile / exportedModuleBin).value,
(`library-manager` / Compile / exportedModuleBin).value,
(`library-manager` / Compile / exportedModuleBin).value,
(`logging-config` / Compile / exportedModuleBin).value,
(`logging-service` / Compile / exportedModuleBin).value,
(`logging-service-common` / Compile / exportedModuleBin).value,
(`logging-service-logback` / Compile / exportedModuleBin).value,
(`logging-service-opensearch` / Compile / exportedModuleBin).value,
(`logging-service-telemetry` / Compile / exportedModuleBin).value,
(`logging-utils` / Compile / exportedModuleBin).value,
(`logging-utils-akka` / Compile / exportedModuleBin).value,
(`os-environment` / Compile / exportedModuleBin).value,
(`persistance` / Compile / exportedModuleBin).value,
(`pkg` / Compile / exportedModuleBin).value,
(`process-utils` / Compile / exportedModuleBin).value,
(`profiling-utils` / Compile / exportedModuleBin).value,
(`polyglot-api` / Compile / exportedModuleBin).value,
(`polyglot-api-macros` / Compile / exportedModuleBin).value,
(`python-resource-provider` / Compile / exportedModuleBin).value,
(`refactoring-utils` / Compile / exportedModuleBin).value,
(`runtime` / Compile / exportedModuleBin).value,
(`runtime-compiler` / Compile / exportedModuleBin).value,
(`runtime-compiler-dump` / Compile / exportedModuleBin).value,
(`runtime-compiler-dump-igv` / Compile / exportedModuleBin).value,
(`runtime-instrument-common` / Compile / exportedModuleBin).value,
(`runtime-instrument-id-execution` / Compile / exportedModuleBin).value,
(`runtime-instrument-repl-debugger` / Compile / exportedModuleBin).value,
(`runtime-instrument-runtime-server` / Compile / exportedModuleBin).value,
(`runtime-language-arrow` / Compile / exportedModuleBin).value,
(`runtime-language-epb` / Compile / exportedModuleBin).value,
(`runtime-parser` / Compile / exportedModuleBin).value,
(`runtime-suggestions` / Compile / exportedModuleBin).value,
(`runtime-utils` / Compile / exportedModuleBin).value,
(`runtime-version-manager` / Compile / exportedModuleBin).value,
(`scala-libs-wrapper` / Compile / exportedModuleBin).value,
(`scala-yaml` / Compile / exportedModuleBin).value,
(`searcher` / Compile / exportedModuleBin).value,
(`semver` / Compile / exportedModuleBin).value,
(`syntax-rust-definition` / Compile / exportedModuleBin).value,
(`task-progress-notifications` / Compile / exportedModuleBin).value,
(`text-buffer` / Compile / exportedModuleBin).value,
(`version-output` / Compile / exportedModuleBin).value,
(`ydoc-api` / Compile / exportedModuleBin).value,
(`ydoc-polyfill` / Compile / exportedModuleBin).value,
(`ydoc-server` / Compile / exportedModuleBin).value,
(`ydoc-server-registration` / Compile / exportedModuleBin).value,
(`zio-wrapper` / Compile / exportedModuleBin).value
)
ourMods ++ thirdPartyModFiles
}
/** Common settings for our wrappers of some *problematic* dependencies that are not
* compatible with the JPMS system, i.e., these dependencies cannot be put on module-path.
* These projects contain only single `module-info.java` source.
* Before this source is compiled, all the dependencies are gathered via the `assembly`
* task into a Jar.
* The `module-info.java` exports all the packages from these dependencies.
* Note that this is the recommended way how to handle dependencies that are not
* JPMS-friendly.
*
* `exportedModule` of these projects return path to the assembled modular Jar.
* The projects should define:
* - `moduleDependencies`
* - `patchModules`
* - `assembly / assemblyExcludedJars`
*/
lazy val modularFatJarWrapperSettings = frgaalJavaCompilerSetting ++ Seq(
Compile / forceModuleInfoCompilation := true,
Compile / exportedModuleBin := assembly
.dependsOn(Compile / compileModuleInfo)
.value,
Compile / exportedModule := (Compile / exportedModuleBin).value
)
/** Mockito agent needs to be explicitly set as `-javaagent` to the JVM.
* Note that starting agent programatically was deprecated in JDK 21 and is scheduled to be removed.
* See https://javadoc.io/doc/org.mockito/mockito-core/latest/org.mockito/org/mockito/Mockito.html#0.3
*/
lazy val mockitoAgentSettings: SettingsDefinition = Seq(
libraryDependencies ++= Seq(
"org.mockito" % "mockito-core" % mockitoJavaVersion % Test
),
Test / javaOptions += {
val logger = streams.value.log
val mockitoJar = JPMSUtils.filterModulesFromUpdate(
update.value,
Seq(
"org.mockito" % "mockito-core" % mockitoJavaVersion
),
logger,
moduleName.value,
scalaBinaryVersion.value,
shouldContainAll = true
)
if (mockitoJar.length != 1) {
logger.error(
s"Expected exactly one mockito-core jar on the classpath, found: ${mockitoJar.map(_.name).mkString(", ")}"
)
}
val mockitoJarPath = mockitoJar.head.getAbsolutePath
s"-javaagent:$mockitoJarPath"
}
)
// ============================================================================
// === Internal Libraries =====================================================
// ============================================================================
lazy val `text-buffer` = project
.in(file("lib/scala/text-buffer"))
.enablePlugins(JPMSPlugin)
.configs(Test)
.settings(
frgaalJavaCompilerSetting,
scalaModuleDependencySetting,
mixedJavaScalaProjectSetting,
annotationProcSetting,
commands += WithDebugCommand.withDebug,
javaModuleName := "org.enso.text.buffer",
libraryDependencies ++= Seq(
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
"org.scalacheck" %% "scalacheck" % scalacheckVersion % Test
)
)
lazy val rustParserTargetDirectory =
SettingKey[File]("target directory for the Rust parser")
(`syntax-rust-definition` / rustParserTargetDirectory) := {
target.value / "rust" / "parser-jni"
}
val generateRustParserLib =
TaskKey[Seq[File]]("generateRustParserLib", "Generates parser native library")
`syntax-rust-definition` / generateRustParserLib := Def.taskIf {
if ((`syntax-rust-definition` / Bazel / wasStartedFromBazel).value) {
val libName = System.mapLibraryName("enso_parser")
val libDest =
(`syntax-rust-definition` / rustParserTargetDirectory).value / libName
val libFrombazel =
(`syntax-rust-definition` / Bazel / rustParserLib).value
IO.copyFile(libFrombazel, libDest)
Seq(
libDest
)
} else {
val log = state.value.log
val profile = if (BuildInfo.isReleaseMode) "release" else "dev"
val profileDir = if (BuildInfo.isReleaseMode) "release" else "debug"
val libName = System.mapLibraryName("enso_parser")
// The library will be copied into this location. It is required in various
// other places.
val copyLibDest =
(`syntax-rust-definition` / rustParserTargetDirectory).value / libName
val libGlob =
(`syntax-rust-definition` / rustParserTargetDirectory).value.toGlob / libName
val allLibs = FileTreeView.default.list(Seq(libGlob)).map(_._1)
if (
sys.env.get("CI").isDefined ||
allLibs.isEmpty ||
(`syntax-rust-definition` / generateRustParserLib).inputFileChanges.hasChanges
) {
val os = System.getProperty("os.name")
val target = os.toLowerCase() match {
case DistributionPackage.OS.Linux.name =>
Some("x86_64-unknown-linux-musl")
case _ =>
None
}
// Destination of the native library as built by Cargo
val libDest = target match {
case Some(someTarget) =>
(`syntax-rust-definition` / rustParserTargetDirectory).value / someTarget / profileDir / libName
case None =>
(`syntax-rust-definition` / rustParserTargetDirectory).value / profileDir / libName
}
target.foreach { t =>
Cargo.rustUp(t, log)
}
val arguments = Seq(
"build",
"-p",
"enso-parser-jni",
"--profile",
profile
) ++ target.map(t => Seq("--target", t)).getOrElse(Seq()) ++
Seq(
"--target-dir",
(`syntax-rust-definition` / rustParserTargetDirectory).value.toString
)
val envVars = target
.map(_ => Seq(("RUSTFLAGS", "-C target-feature=-crt-static")))
.getOrElse(Seq())
Cargo.run(arguments, log, envVars)
if (!libDest.exists()) {
log.error(
s"Expected Rust parser library at ${libDest.toPath} but it does not exist after build."
)
}
Files.copy(
libDest.toPath,
copyLibDest.toPath,
StandardCopyOption.REPLACE_EXISTING
)
if (!Files.exists(copyLibDest.toPath)) {
log.error(
s"Failed to copy Rust parser library to ${copyLibDest.toPath}."
)
}
}
FileTreeView.default.list(Seq(libGlob)).map(_._1.toFile)
}
}.value
`syntax-rust-definition` / generateRustParserLib / fileInputs := {
if ((`syntax-rust-definition` / Bazel / wasStartedFromBazel).value) {
Seq.empty
} else {
Seq(
(`syntax-rust-definition` / baseDirectory).value.toGlob / "jni" / "src" / ** / "*.rs",
(`syntax-rust-definition` / baseDirectory).value.toGlob / "src" / ** / "*.rs"
)
}
}
val generateParserJavaSources = TaskKey[Seq[File]](
"generateParserJavaSources",
"Generates Java sources for Rust parser"
)
`syntax-rust-definition` / generateParserJavaSources := Def.taskIf {
import scala.jdk.CollectionConverters._
if ((`syntax-rust-definition` / Bazel / wasStartedFromBazel).value) {
// Copy the generated sources from Bazel directory to our directory
val srcsFromBazel =
(`syntax-rust-definition` / Bazel / rustParserJavaSources).value
val base = (`syntax-rust-definition` / Compile / sourceManaged).value
val outDir = base / "org" / "enso" / "syntax2"
if (!outDir.exists()) {
outDir.mkdirs()
srcsFromBazel.foreach { src =>
val fname = src.getName
val dest = outDir / fname
IO.copyFile(src, dest)
}
}
FileUtils.listFiles(outDir, Array("scala", "java"), true).asScala.toSeq
} else {
val base = (`syntax-rust-definition` / Compile / sourceManaged).value
val outDir = base / "org" / "enso" / "syntax2"
generateRustParser(
outDir,
(`syntax-rust-definition` / generateParserJavaSources).inputFileChanges,
state.value.log
)
}
}.value
`syntax-rust-definition` / generateParserJavaSources / fileInputs := {
if ((`syntax-rust-definition` / Bazel / wasStartedFromBazel).value) {
Seq.empty
} else {
Seq(
(`syntax-rust-definition` / baseDirectory).value.toGlob / "generate-java" / "src" / ** / "*.rs",
(`syntax-rust-definition` / baseDirectory).value.toGlob / "src" / ** / "*.rs"
)
}
}
/** Generates Java sources via `enso-parser-generate-java` binary.
* That binary must already exist - created via Rust compilation.
* @param outDir Base directory where the sources will be put.
* No package hierarchy will be created.
*/
def generateRustParser(
outDir: File,
changes: sbt.nio.FileChanges,
log: ManagedLogger
): Seq[File] = {
import scala.jdk.CollectionConverters._
if (!outDir.exists()) {
outDir.mkdirs()
}
if (changes.hasChanges) {
val args = Seq(
"run",
"-p",
"enso-parser-generate-java",
"--bin",
"enso-parser-generate-java",
outDir.toString
)
Cargo.run(args, log)
}
FileUtils.listFiles(outDir, Array("scala", "java"), true).asScala.toSeq
}
lazy val `syntax-rust-definition` = project
.in(file("lib/rust/parser"))
.enablePlugins(BazelSupport && JPMSPlugin)
.configs(Test)
.settings(
javadocSettings,
publishLocalSetting,
Compile / exportJars := true,
autoScalaLibrary := false,
crossPaths := false,
libraryDependencies ++= slf4jApi,
Compile / moduleDependencies ++= slf4jApi,
javaModuleName := "org.enso.syntax",
Compile / sourceGenerators += generateParserJavaSources,
Compile / resourceGenerators += generateRustParserLib,
Compile / javaSource := baseDirectory.value / "generate-java" / "java",
Compile / compile / javacOptions ++= Seq("-source", "11", "-target", "11"),
// Make sure the native library is not packaged in the exported `jar`.
assembly / assemblyMergeStrategy := {
case PathList(file)
if file.endsWith(".so") || file.endsWith(".dll") || file
.endsWith(".dylib") =>
MergeStrategy.discard
case _ =>
MergeStrategy.first
},
assembly / assemblyExcludedJars := {
JPMSUtils.filterModulesFromClasspath(
(Compile / fullClasspath).value,
slf4jApi,
streams.value.log,
javaModuleName.value,
scalaBinaryVersion.value,
shouldContainAll = true
)
},
Compile / exportedModule := assembly.value,
Compile / exportedModuleBin := assembly.value
)
lazy val `scala-yaml` = (project in file("lib/scala/yaml"))
.enablePlugins(JPMSPlugin)
.configs(Test)
.settings(
frgaalJavaCompilerSetting,
scalaModuleDependencySetting,
mixedJavaScalaProjectSetting,
libraryDependencies ++= Seq(
"org.yaml" % "snakeyaml" % snakeyamlVersion % "provided"
),
Compile / moduleDependencies ++= Seq(
"org.yaml" % "snakeyaml" % snakeyamlVersion
),
Compile / internalModuleDependencies := Seq(
(`scala-libs-wrapper` / Compile / exportedModule).value
)
)
.dependsOn(`scala-libs-wrapper`)
lazy val pkg = (project in file("lib/scala/pkg"))
.enablePlugins(JPMSPlugin)
.settings(
frgaalJavaCompilerSetting,
scalaModuleDependencySetting,
mixedJavaScalaProjectSetting,
annotationProcSetting,
version := "0.1",
Compile / run / mainClass := Some("org.enso.pkg.Main"),
libraryDependencies ++= Seq(
"org.graalvm.sdk" % "nativeimage" % graalMavenPackagesVersion % "provided",
"io.circe" %% "circe-core" % circeVersion % "provided",
"org.yaml" % "snakeyaml" % snakeyamlVersion % "provided",
"org.scalatest" %% "scalatest" % scalatestVersion % Test,
"org.apache.commons" % "commons-compress" % commonsCompressVersion
),
Compile / moduleDependencies ++= Seq(
"org.graalvm.sdk" % "word" % graalMavenPackagesVersion,
"org.graalvm.sdk" % "nativeimage" % graalMavenPackagesVersion,
"org.apache.commons" % "commons-compress" % commonsCompressVersion,
"org.yaml" % "snakeyaml" % snakeyamlVersion
),
Compile / internalModuleDependencies := Seq(
(`editions` / Compile / exportedModule).value,
(`scala-libs-wrapper` / Compile / exportedModule).value,
(`scala-yaml` / Compile / exportedModule).value,
(`semver` / Compile / exportedModule).value,
(`version-output` / Compile / exportedModule).value
)
)
.dependsOn(editions)
lazy val extractPythonResources = taskKey[Seq[File]](
"Extract python resources from the python-resource.jar"
)
// Project that extracts python-resources during build time.
lazy val `python-extract` = project
.in(file("lib/java/python-extract"))
.settings(
frgaalJavaCompilerSetting,
libraryDependencies ++= Seq(
"org.graalvm.python" % "python-language" % graalMavenPackagesVersion,
"org.graalvm.python" % "python-resources" % graalMavenPackagesVersion
),
Compile / run / mainClass := Some("org.enso.pyextract.PythonExtract"),
Compile / run / javaOptions ++= Seq("--enable-native-access=ALL-UNNAMED"),
Compile / run / fork := true,
extractPythonResources := Def.taskIf {
if ((Bazel / wasStartedFromBazel).value) {
val resDir = (Bazel / extractedPythonResourceDir).value
val glob = resDir.toGlob / ** / *
FileTreeView.default.list(Seq(glob)).map(_._1.toFile)
} else {
val outDir = target.value / "python-resources"
val pyResourcesGlob = target.value.toGlob / "python-resources" / ** / *
val logger = streams.value.log
val outs = FileTreeView.default.list(Seq(pyResourcesGlob)).map(_._1)
val main = (Compile / run / mainClass).value
val classPath = (Compile / fullClasspath).value
val args = Seq(
outDir.getPath
)
val javaRunner = (Compile / run / runner).value
if (outs.isEmpty) {
javaRunner.run(
main.get,
classPath.files,
args,
logger
)
}
FileTreeView.default.list(Seq(pyResourcesGlob)).map(_._1.toFile)
}
}.value,
clean := {
val _ = clean.value
val outDir = target.value / "python-resources"
IO.delete(outDir)
}
)
lazy val `python-resource-provider` = project
.in(file("engine/python-resource-provider"))
.enablePlugins(JPMSPlugin)
.settings(
frgaalJavaCompilerSetting,
libraryDependencies ++= Seq(
"org.graalvm.truffle" % "truffle-api" % graalMavenPackagesVersion
),
Compile / moduleDependencies ++= Seq(
"org.graalvm.truffle" % "truffle-api" % graalMavenPackagesVersion,
"org.graalvm.sdk" % "word" % graalMavenPackagesVersion
)
)
lazy val `profiling-utils` = project
.in(file("lib/scala/profiling-utils"))
.enablePlugins(JPMSPlugin)
.configs(Test)
.settings(
customFrgaalJavaCompilerSettings(targetJdk = "21"),
compileOrder := CompileOrder.JavaThenScala,
javaModuleName := "org.enso.profiling",
Compile / exportJars := true,
version := "0.1",