From 9d1cd57430417c8923b9727542608ac34008fa27 Mon Sep 17 00:00:00 2001 From: Jakob Odersky Date: Wed, 15 Jan 2014 19:26:00 +0100 Subject: implement fat jar generation --- .gitignore | 2 +- project/FlowBuild.scala | 23 ++++++++++++++--------- project/nativefat.scala | 43 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 58 insertions(+), 10 deletions(-) create mode 100644 project/nativefat.scala diff --git a/.gitignore b/.gitignore index 03cf618..5575b91 100644 --- a/.gitignore +++ b/.gitignore @@ -20,4 +20,4 @@ project/plugins/project/ # Native *.o *.so -!/flow-binaries/*.so +*.jnilib diff --git a/project/FlowBuild.scala b/project/FlowBuild.scala index fcf4d10..9ef9dd1 100644 --- a/project/FlowBuild.scala +++ b/project/FlowBuild.scala @@ -37,12 +37,14 @@ object FlowBuild extends Build { publishLocal := () ) ) + lazy val flow: Project = ( Project("flow", file("flow")) settings (commonSettings: _*) settings (JniDefaults.settings: _*) settings (NativeDefaults.settings: _*) + settings (NativeFatDefaults.settings: _*) settings (selectHost().settings: _*) settings( nativeIncludeDirectories += (sourceDirectory in Compile).value / "native" / "include", @@ -56,14 +58,6 @@ object FlowBuild extends Build { Dependencies.ioFile) ) ) - - lazy val samplesTerminal = ( - Project("flow-samples-terminal", file("flow-samples") / "flow-samples-terminal") - settings(commonSettings: _*) - settings(runSettings: _*) - dependsOn(flow) - ) - //the current operating system used to run the native compile trait Host{ def settings: Seq[Setting[_]] } @@ -73,6 +67,7 @@ object FlowBuild extends Build { val compiler = "gcc" val linker = compiler val cFlags = Seq("-O2", "-fPIC") + val linkerFlags = Seq("-shared", s"-Wl,-soname,libflow.so.${NativeMajorVersion}") val binary = s"libflow.so" @@ -130,5 +125,15 @@ object FlowBuild extends Build { nativeLink := osError ) } - } + } + + + lazy val samplesTerminal = ( + Project("flow-samples-terminal", file("flow-samples") / "flow-samples-terminal") + settings(commonSettings: _*) + settings(runSettings: _*) + dependsOn(flow) + ) + + } diff --git a/project/nativefat.scala b/project/nativefat.scala new file mode 100644 index 0000000..0cdf636 --- /dev/null +++ b/project/nativefat.scala @@ -0,0 +1,43 @@ +import sbt._ +import Keys._ +import NativeKeys._ +import java.io.File +import scala.collection.mutable.HashSet + +object NativeFatKeys { + val packageFat = taskKey[File]("Create a fat jar containing native binaries.") + val packageFatSuffix = settingKey[String]("Suffix to add to name of fat jar.") + val packageFatUnmanaged = settingKey[File]("Directory containing any pre-compiled native binaries.") +} + +object NativeFatDefaults { + import NativeFatKeys._ + + val mappingsImpl = Def.task { + val links = nativeLink.value + val unamanagedDir = packageFatUnmanaged.value + + val managed: Seq[(File, String)] = for ( (build, binary) <- links.toSeq) yield { + binary -> ("native/" + build.name + "/" + binary.name) + } + + val unmanaged: Seq[(File, String)] = for (file <- (unamanagedDir ** "*").get; if file.isFile) yield { + file -> ("native/" + (file relativeTo unamanagedDir).get.getPath) + } + + managed ++ unmanaged + } + + def settings = sbt.Defaults.packageTaskSettings(packageFat, sbt.Defaults.packageBinMappings) ++ + Seq( + packageFatSuffix := "-fat", + packageFatUnmanaged := baseDirectory.value / "lib_native", + products in packageFat := (products in Compile).value, + artifact in packageFat := { + val prev = (artifact in packageBin).value + prev.copy(name = prev.name + packageFatSuffix.value) + }, + mappings in packageFat ++= mappingsImpl.value + ) + +} \ No newline at end of file -- cgit v1.2.3