forked from scalapy/scalapy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.sbt
148 lines (132 loc) · 5.25 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
import sbtcrossproject.CrossPlugin.autoImport.{crossProject, CrossType}
import scala.sys.process._
organization in ThisBuild := "me.shadaj"
lazy val scala211Version = "2.11.12"
lazy val scala212Version = "2.12.8"
lazy val scala213Version = "2.13.1"
lazy val supportedScalaVersions = List(scala212Version, scala213Version)
scalaVersion in ThisBuild := scala213Version
lazy val scalapy = project.in(file(".")).aggregate(
macrosJVM, macrosNative,
coreJVM, coreNative,
).settings(
publish := {},
publishLocal := {}
)
addCommandAlias(
"publishSignedAll",
(scalapy: ProjectDefinition[ProjectReference])
.aggregate
.map(p => s"+ ${p.asInstanceOf[LocalProject].project}/publishSigned")
.mkString(";", ";", "")
)
lazy val macros = crossProject(JVMPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("coreMacros"))
.settings(
name := "scalapy-macros",
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value
).jvmSettings(
crossScalaVersions := supportedScalaVersions,
).nativeSettings(
scalaVersion := scala211Version
)
lazy val macrosJVM = macros.jvm
lazy val macrosNative = macros.native
lazy val core = crossProject(JVMPlatform, NativePlatform)
.in(file("core"))
.dependsOn(macros)
.settings(
name := "scalapy-core",
sourceGenerators in Compile += Def.task {
val fileToWrite = (sourceManaged in Compile).value / "TupleReaders.scala"
val methods = (2 to 22).map { n =>
val tupleElements = (1 to n).map(t => s"r$t.read(orArr(${t - 1}))")
.mkString(", ")
s"""implicit def tuple${n}Reader[${(1 to n).map(t => s"T$t").mkString(", ")}](implicit ${(1 to n).map(t => s"r$t: Reader[T$t]").mkString(", ")}): Reader[(${(1 to n).map(t => s"T$t").mkString(", ")})] = {
| new Reader[(${(1 to n).map(t => s"T$t").mkString(", ")})] {
| override def read(or: PyValue) = {
| val orArr = or.getTuple
| ($tupleElements)
| }
| }
|}"""
}
val toWrite =
s"""package me.shadaj.scalapy.py
|trait TupleReaders {
|${methods.mkString("\n")}
|}""".stripMargin
IO.write(fileToWrite, toWrite)
Seq(fileToWrite)
},
sourceGenerators in Compile += Def.task {
val fileToWrite = (sourceManaged in Compile).value / "TupleWriters.scala"
val methods = (2 to 22).map { n =>
val seqArgs = (1 to n).map(t => s"r$t.write(v._" + t + ")").mkString(", ")
s"""implicit def tuple${n}Writer[${(1 to n).map(t => s"T$t").mkString(", ")}](implicit ${(1 to n).map(t => s"r$t: Writer[T$t]").mkString(", ")}): Writer[(${(1 to n).map(t => s"T$t").mkString(", ")})] = {
| new Writer[(${(1 to n).map(t => s"T$t").mkString(", ")})] {
| override def write(v: (${(1 to n).map(t => s"T$t").mkString(", ")})): PyValue = {
| CPythonInterpreter.createTuple(Seq(${seqArgs}))
| }
| }
|}"""
}
val toWrite =
s"""package me.shadaj.scalapy.py
|trait TupleWriters {
|${methods.mkString("\n")}
|}""".stripMargin
IO.write(fileToWrite, toWrite)
Seq(fileToWrite)
}
).settings(
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value,
unmanagedSourceDirectories in Compile += {
val sharedSourceDir = (baseDirectory in ThisBuild).value / "core/shared/src/main"
if (scalaVersion.value.startsWith("2.13.")) sharedSourceDir / "scala-2.13"
else sharedSourceDir / "scala-2.11_2.12"
}
).jvmSettings(
crossScalaVersions := supportedScalaVersions,
libraryDependencies += "net.java.dev.jna" % "jna" % "5.5.0",
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.1.2" % Test,
libraryDependencies += "org.scalacheck" %% "scalacheck" % "1.14.3" % Test,
fork in Test := true,
javaOptions in Test += s"-Djna.library.path=${"python3-config --prefix".!!.trim}/lib"
).nativeSettings(
scalaVersion := scala211Version,
libraryDependencies += "org.scalatest" %%% "scalatest" % "3.1.0-RC3" % Test,
libraryDependencies += "com.github.lolgab" %%% "scalacheck" % "1.14.1" % Test,
nativeLinkStubs := true,
nativeLinkingOptions ++= "python3-config --ldflags".!!.split(' ').map(_.trim).filter(_.nonEmpty).toSeq
)
lazy val coreJVM = core.jvm
lazy val coreNative = core.native
lazy val docs = project
.in(file("built-docs"))
.settings(
moduleName := "built-docs",
)
.enablePlugins(MdocPlugin, DocusaurusPlugin)
.dependsOn(coreJVM)
.settings(
fork := true,
connectInput := true,
javaOptions += s"-Djna.library.path=${"python3-config --prefix".!!.trim}/lib"
)
lazy val bench = crossProject(JVMPlatform, NativePlatform)
.crossType(CrossType.Pure)
.in(file("bench"))
.settings(
name := "scalapy-bench"
).jvmSettings(
fork := true,
crossScalaVersions := supportedScalaVersions,
javaOptions += s"-Djna.library.path=${"python3-config --prefix".!!.trim}/lib"
).nativeSettings(
scalaVersion := scala211Version,
nativeLinkingOptions ++= "python3-config --ldflags".!!.split(' ').map(_.trim).filter(_.nonEmpty).toSeq
).dependsOn(core)
lazy val benchJVM = bench.jvm
lazy val benchNative = bench.native