From 1521833eed89b14b86f6b2e2d77847195ca23ca8 Mon Sep 17 00:00:00 2001 From: vms Date: Fri, 11 Oct 2019 02:01:25 +0300 Subject: [PATCH] project cleaning --- .circleci/config.yml | 2 +- build.sbt | 25 ++++------------ project/SbtCommons.scala | 41 ++++++++++++++++++++++++-- project/plugins.sbt | 2 ++ src/main/scala/fluence/vm/WasmVm.scala | 2 -- 5 files changed, 48 insertions(+), 24 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index c3d2c0c..2941708 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -24,7 +24,7 @@ rustup: &rustup - run: | curl https://sh.rustup.rs -sSf | sh -s -- -y --default-toolchain nightly-2019-09-23 ~/.cargo/bin/rustup toolchain install nightly-2019-09-23 # in case some other toolchain was already installed - ~/.cargo/bin/rustup target add wasm32-unknown-unknown --toolchain nightly-2019-09-23 + ~/.cargo/bin/cargo install cross version: 2 jobs: diff --git a/build.sbt b/build.sbt index 8b98e13..b6f50de 100644 --- a/build.sbt +++ b/build.sbt @@ -1,19 +1,22 @@ import SbtCommons._ -import ch.jodersky.sbt.jni.plugins.JniPackage.autoImport._ name := "frank" commons +skip in publish := false // skip the root project to be published + /* Projects */ -lazy val `vm-rust` = (project in file("src/main/rust/")) +lazy val `vm-rust` = (project in file("src/main/rust")) .settings( + skip in publish := true, compileFrankVMSettings() ) lazy val `vm-llamadb` = (project in file("src/it/resources/llamadb")) .settings( + skip in publish := true, downloadLlamadb() ) @@ -31,23 +34,7 @@ lazy val `vm-scala` = (project in file(".")) scodecCore, mockito ), - enableNativeCompilation := false, - resourceGenerators in Compile += Def.task { - val managedResource = s"${(resourceManaged in Compile).value}/native" - - val darwin_lib = new File(managedResource + "/x86_64-darwin/libfrank.dylib") - val linux_lib = new File(managedResource + "/linux_x86_64/libfrank.so") - - IO.copyFile( - new File(s"${file("").getAbsolutePath}/src/main/rust/target/release/libfrank.dylib"), - darwin_lib - ) - IO.copyFile( - new File(s"${file("").getAbsolutePath}/src/main/rust/target/x86_64-unknown-linux-gnu/release/libfrank.so"), - linux_lib - ) - Seq(darwin_lib, linux_lib) - }.taskValue, + nativeResourceSettings(), assemblyJarName in assembly := "frank.jar", assemblyMergeStrategy in assembly := SbtCommons.mergeStrategy.value, test in assembly := {}, diff --git a/project/SbtCommons.scala b/project/SbtCommons.scala index bddd8a4..f998846 100644 --- a/project/SbtCommons.scala +++ b/project/SbtCommons.scala @@ -2,9 +2,11 @@ import de.heikoseeberger.sbtheader.HeaderPlugin.autoImport.headerLicense import de.heikoseeberger.sbtheader.License import org.scalafmt.sbt.ScalafmtPlugin.autoImport.scalafmtOnCompile import sbt.Keys.{javaOptions, _} -import sbt.{Def, addCompilerPlugin, _} +import java.io.File +import sbt.{Def, IO, addCompilerPlugin, _} import sbtassembly.AssemblyPlugin.autoImport.assemblyMergeStrategy import sbtassembly.{MergeStrategy, PathList} +import bintray.BintrayKeys._ import scala.sys.process._ @@ -24,7 +26,11 @@ object SbtCommons { startYear := Some(2019), licenses += ("Apache-2.0", new URL("https://www.apache.org/licenses/LICENSE-2.0.txt")), headerLicense := Some(License.ALv2("2019", organizationName.value)), - resolvers += Resolver.bintrayRepo("fluencelabs", "releases"), + publishMavenStyle := true, + scalafmtOnCompile := true, + bintrayOrganization := Some("fluencelabs"), + bintrayRepository := "releases", + resolvers ++= Seq(Resolver.bintrayRepo("fluencelabs", "releases"), Resolver.sonatypeRepo("releases")), scalafmtOnCompile := true, // see good explanation https://gist.github.com/djspiewak/7a81a395c461fd3a09a6941d4cd040f2 scalacOptions ++= Seq("-Ypartial-unification", "-deprecation"), @@ -59,6 +65,7 @@ object SbtCommons { val projectRoot = file("").getAbsolutePath val frankFolder = s"$projectRoot/src/main/rust" val localCompileCmd = s"cargo +$rustToolchain build --manifest-path $frankFolder/Cargo.toml --release --lib" + // TODO: cross build with manifest path doesn't work - so it needs to explicitly change a directory val crossCompileCmd = s"cd $frankFolder ; cross build --target x86_64-unknown-linux-gnu --release --lib" assert((localCompileCmd !) == 0, "Frank VM native compilation failed") @@ -79,6 +86,36 @@ object SbtCommons { .value ) + def nativeResourceSettings(): Seq[Def.Setting[_]] = + Seq( + resourceGenerators in Compile += Def.task { + val managedResource = s"${(resourceManaged in Compile).value}/native" + + val darwinLib = new File(managedResource + "/x86_64-darwin/libfrank.dylib") + val linuxLib = new File(managedResource + "/linux_x86_64/libfrank.so") + + IO.copyFile( + new File(s"${file("").getAbsolutePath}/src/main/rust/target/x86_64-unknown-linux-gnu/release/libfrank.so"), + linuxLib + ) + + System.getProperty("os.name").toLowerCase match { + case os if os.contains("linux") => linuxLib :: Nil + case os if os.contains("mac") => { + IO.copyFile( + new File(s"${file("").getAbsolutePath}/src/main/rust/target/release/libfrank.dylib"), + darwinLib + ) + linuxLib :: darwinLib :: Nil + } + case os ⇒ { + new RuntimeException(s"$os is unsupported, only *nix and MacOS OS are supported now") + Nil + } + } + }.taskValue + ) + def downloadLlamadb(): Seq[Def.Setting[_]] = Seq( publishArtifact := false, diff --git a/project/plugins.sbt b/project/plugins.sbt index 56995ce..3463454 100644 --- a/project/plugins.sbt +++ b/project/plugins.sbt @@ -7,3 +7,5 @@ addSbtPlugin("net.virtual-void" % "sbt-dependency-graph" % "0.9.2") addSbtPlugin("com.eed3si9n" % "sbt-assembly" % "0.14.9") addSbtPlugin("ch.jodersky" % "sbt-jni" % "1.3.4") + +addSbtPlugin("org.foundweekends" % "sbt-bintray" % "0.5.4") diff --git a/src/main/scala/fluence/vm/WasmVm.scala b/src/main/scala/fluence/vm/WasmVm.scala index 71753ab..5b0d94c 100644 --- a/src/main/scala/fluence/vm/WasmVm.scala +++ b/src/main/scala/fluence/vm/WasmVm.scala @@ -64,8 +64,6 @@ trait WasmVm { } object WasmVm { - val javaLibPath: String = System.getProperty("java.library.path") - println(s"java.library.path = $javaLibPath") /** * Main method factory for building VM.