Skip to content

Commit e5ee473

Browse files
author
reidspencer
committed
Support build target for scala native
1 parent d8adcb1 commit e5ee473

3 files changed

Lines changed: 38 additions & 4 deletions

File tree

src/main/scala/com/ossuminc/sbt/OssumIncPlugin.scala

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,25 @@ object OssumIncPlugin extends AutoPlugin {
177177
}
178178

179179
def native(
180-
targetTriple: String = "arm64-apple-darwin20.6.0",
180+
buildTarget: String = "static",
181+
targetTriple: String = "arm64-apple-macosx11.0.0",
181182
gc: String = "commix",
182183
debug: Boolean = true,
183184
noLTO: Boolean = false,
184-
debugLog: Boolean = false
185+
debugLog: Boolean = false,
186+
verbose: Boolean = false,
187+
ld64Path: String = "/opt/homebrew/opt/llvm/bin/ld64.lld"
185188
)(project: Project): Project = {
186-
helpers.Native.configure(targetTriple, gc, debug, noLTO, debugLog)(project)
189+
helpers.Native.configure(
190+
buildTarget,
191+
targetTriple,
192+
gc,
193+
debug,
194+
noLTO,
195+
debugLog,
196+
verbose,
197+
ld64Path
198+
)(project)
187199
}
188200

189201
def plugin(project: Project): Project = {

src/main/scala/com/ossuminc/sbt/helpers/Native.scala

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ object Native extends AutoPluginHelper {
2121
}
2222

2323
def configure(
24+
buildTarget : String = "static",
2425
targetTriple: String = "arm64-apple-macosx11.0.0",
2526
gc: String = "commix",
2627
debug: Boolean = true,
@@ -45,14 +46,35 @@ object Native extends AutoPluginHelper {
4546
val lto = if (noLTO) LTO.none else LTO.thin
4647
val compileOptions = if (verbose) { Seq("-v") } else {Seq.empty}
4748
val linkOptions = Seq(s"-fuse-ld=$ld64Path")
49+
val bTarget = buildTarget match {
50+
case "application" => BuildTarget.application
51+
case "dynamic" => BuildTarget.libraryDynamic
52+
case "static" => BuildTarget.libraryStatic
53+
case _ => BuildTarget.libraryStatic
54+
}
4855
c.withLTO(lto)
4956
.withMode(mode)
5057
.withGC(GC(gc))
5158
.withTargetTriple(targetTriple)
59+
.withBuildTarget(bTarget)
5260
.withCompileOptions(c.compileOptions ++ compileOptions)
5361
.withLinkingOptions(c.linkingOptions ++ linkOptions)
5462
}
5563
}
5664
)
5765
}
5866
}
67+
68+
69+
// nativeConfig ~= { _.withBuildTarget(BuildTarget.libraryDynamic) }
70+
//application (default)
71+
//
72+
//Results in creating ready to use executable program.
73+
//
74+
//libraryDynamic
75+
//
76+
//Results in dynamic library being built based on entry point methods annotated with @exported, for details see Native code interoperability.
77+
//
78+
//libraryStatic
79+
//
80+
//Results in building static library using the same semantincs as in the libraryDynamic. Exported methods should handle exceptions, as they might not be able to be catched in the program that is using a produced static library.

src/sbt-test/sbt-ossuminc/native/build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import sbt.url
44
enablePlugins(OssumIncPlugin)
55

66
lazy val root = Root("native-test", startYr=2024)
7-
.configure(With.basic,With.native(debug=false))
7+
.configure(With.basic,With.native(buildTarget="application",debug=true,verbose=true))
88
.settings(
99
maxErrors := 50
1010
)

0 commit comments

Comments
 (0)