Skip to content

Commit

Permalink
crossProject, %%% (#392)
Browse files Browse the repository at this point in the history
  • Loading branch information
MasseGuillaume authored and densh committed Nov 25, 2016
1 parent 8ab0a15 commit bad85d1
Show file tree
Hide file tree
Showing 27 changed files with 298 additions and 121 deletions.
6 changes: 2 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ matrix:
- brew install bdw-gc
- brew link bdw-gc
- brew install jq

cache:
directories:
- $HOME/.ivy2/cache
Expand Down Expand Up @@ -54,6 +53,5 @@ before_script:
fi;
script:
- java -version
- bin/scalafmt --test
- sbt 'cleanCache' 'cleanLocal' 'nscplugin/publishLocal' 'nativelib/publishLocal' 'publishLocal' 'sandbox/run' 'demoNative/run' 'tests/run' 'tools/test' 'benchmarks/run' 'scripted' 'publishSnapshot'

- bin/scalafmt --test && sbt 'cleanCache' 'cleanLocal' 'nscplugin/publishLocal' 'nativelib/publishLocal' 'publishLocal' 'sandbox/run' 'demoNative/run' 'tests/run' 'tools/test' 'benchmarks/run' 'scripted' 'publishSnapshot'

12 changes: 0 additions & 12 deletions bin/clang.nix

This file was deleted.

2 changes: 1 addition & 1 deletion bin/nix-run
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
#!/usr/bin/env bash

nix-shell bin/clang.nix -A clangEnv
nix-shell bin/scala-native.nix -A clangEnv
22 changes: 22 additions & 0 deletions bin/scala-native.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
let
pkgs = import <nixpkgs> {};
stdenv = pkgs.stdenv;
sbtOracle = pkgs.sbt.override {
jre = pkgs.oraclejdk8.jre;
};
in rec {
clangEnv = stdenv.mkDerivation rec {
name = "clang-env";
shellHook = ''
alias cls=clear
'';
CLANG_PATH = pkgs.clang + "/bin/clang";
CLANGPP_PATH = pkgs.clang + "/bin/clang++";
buildInputs = with pkgs; [
stdenv
sbtOracle
boehmgc
clang
];
};
}
73 changes: 46 additions & 27 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ lazy val publishSettings = Seq(
publishArtifact in Compile := true,
publishArtifact in Test := false,
publishMavenStyle := true,
publishTo <<= version { v: String =>
publishTo := {
val nexus = "https://oss.sonatype.org/"
if (v.trim.endsWith("SNAPSHOT"))
if (version.value.trim.endsWith("SNAPSHOT"))
Some("snapshots" at nexus + "content/repositories/snapshots")
else
Some("releases" at nexus + "service/local/staging/deploy/maven2")
Expand Down Expand Up @@ -139,7 +139,12 @@ lazy val tools =
compilerPlugin(
"org.scalamacros" % "paradise" % "2.0.1" cross CrossVersion.full),
"org.scalatest" %% "scalatest" % "3.0.0" % "test"
))
),
publishLocal := publishLocal
.dependsOn(publishLocal in nir)
.dependsOn(publishLocal in util)
.value
)
.dependsOn(nir, util)

lazy val nscplugin =
Expand All @@ -161,30 +166,38 @@ lazy val nscplugin =
publishArtifact in (Compile, packageDoc) := false
)

lazy val sbtplugin =
lazy val sbtPluginSettings =
toolSettings ++
publishSettings ++
ScriptedPlugin.scriptedSettings ++
Seq(
sbtPlugin := true,
scriptedLaunchOpts ++=
Seq("-Xmx1024M",
"-XX:MaxPermSize=256M",
"-Dplugin.version=" + version.value)
)

lazy val sbtScalaNative =
project
.in(file("sbtplugin"))
.settings(toolSettings)
.settings(publishSettings)
.in(file("sbt-scala-native"))
.settings(sbtPluginSettings)
.settings(
sbtPlugin := true,
// Support for scripted tests
ScriptedPlugin.scriptedSettings,
scriptedLaunchOpts := {
scriptedLaunchOpts.value ++
Seq("-Xmx1024M",
"-XX:MaxPermSize=256M",
"-Dplugin.version=" + version.value)
},
resolvers += Resolver.sonatypeRepo("snapshots"),
addSbtPlugin("org.scala-native" % "sbt-cross" % "0.1.0-SNAPSHOT"),
moduleName := "sbt-scala-native",
sbtTestDirectory := (baseDirectory in ThisBuild).value / "scripted-tests",
// publish the other projects before running scripted tests.
scripted <<= scripted.dependsOn(publishLocal in util,
publishLocal in nir,
publishLocal in tools,
publishLocal in nscplugin,
publishLocal in nativelib,
publishLocal in javalib,
publishLocal in scalalib)
scripted := scripted
.dependsOn(publishLocal in util,
publishLocal in nir,
publishLocal in tools,
publishLocal in nscplugin,
publishLocal in nativelib,
publishLocal in javalib,
publishLocal in scalalib)
.evaluated,
publishLocal := publishLocal.dependsOn(publishLocal in tools).value
)
.dependsOn(tools)

Expand All @@ -201,12 +214,12 @@ lazy val nativelib =
IO.withTemporaryDirectory { tmp =>
IO.copyDirectory(baseDirectory.value, tmp)
scala.scalanative.sbtplugin.ScalaNativePluginInternal
.compileCSources(clang, clangpp, tmp)
.compileCSources(clang, clangpp, tmp, streams.value.log)
}
if (compileSuccess) {
(compile in Compile).value
} else {
error("Compilation failed")
sys.error("Compilation failed")
}
})

Expand Down Expand Up @@ -260,8 +273,10 @@ lazy val scalalib =
file("scalalib/src/main/scala/scala"),
overwrite = true)
},
compile in Compile <<= (compile in Compile) dependsOn assembleScalaLibrary,
publishLocal <<= publishLocal dependsOn assembleScalaLibrary
compile in Compile := (compile in Compile)
.dependsOn(assembleScalaLibrary)
.value,
publishLocal := publishLocal.dependsOn(assembleScalaLibrary).value
)
.dependsOn(nativelib, javalib)

Expand All @@ -279,6 +294,7 @@ lazy val demoNative =
.in(file("demo/native"))
.settings(projectSettings)
.settings(noPublishSettings)
.enablePlugins(ScalaNativePlugin)

lazy val tests =
project
Expand Down Expand Up @@ -307,12 +323,14 @@ lazy val tests =
Seq(file)
}.taskValue
)
.enablePlugins(ScalaNativePlugin)

lazy val sandbox =
project
.in(file("sandbox"))
.settings(projectSettings)
.settings(noPublishSettings)
.enablePlugins(ScalaNativePlugin)

lazy val benchmarks =
project
Expand Down Expand Up @@ -342,3 +360,4 @@ lazy val benchmarks =
Seq(file)
}.taskValue
)
.enablePlugins(ScalaNativePlugin)
2 changes: 1 addition & 1 deletion docs/contrib/contributing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ In order for a Pull Request to be considered, it has to meet these requirements:

1. Live up to the current code standard:

- Be formatted with `./bin/scalafmt`_.
- Be formatted with `./bin/scalafmt --version 0.4.7`_.
- Not violate `DRY`_.
- `Boy Scout Rule`_ should be applied.

Expand Down
4 changes: 2 additions & 2 deletions docs/user/sbt.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ Start within a new folder, and create a file ``project/plugins.sbt`` as follows:

resolvers += Resolver.sonatypeRepo("snapshots")

addSbtPlugin("org.scala-native" % "sbtplugin" % "0.1-SNAPSHOT")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.1.0-SNAPSHOT")

Create a file ``project/build.properties`` to define the sbt version as follows::

sbt.version=0.13.12
sbt.version=0.13.13
define a new ``build.sbt``::

Expand Down
24 changes: 5 additions & 19 deletions docs/user/setup.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,25 +34,11 @@ FreeBSD::

$ pkg install llvm38 boehm-gc

nixOS::

$ nix-env -i clang-wrapper-3.7.1 boehm-gc-7.2f

# clang.nix
let
pkgs = import <nixpkgs> {};
stdenv = pkgs.stdenv;
in rec {
clangEnv = stdenv.mkDerivation rec {
name = "clang-env";
buildInputs = [
stdenv
pkgs.boehmgc
];
};
}

$ nix-shell clang.nix -A clangEnv
nix/nixOS::

$ wget https://github.com/scala-native/scala-native/blob/master/bin/scala-native.nix

$ nix-shell scala-native.nix -A clangEnv

Continue to :ref:`sbt`.

Expand Down
2 changes: 1 addition & 1 deletion nir/src/main/scala/scala/scalanative/nir/Versions.scala
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,5 @@ object Versions {
final val revision: Int = 8

/* Current public release version of Scala Native. */
final val current: String = "0.1-SNAPSHOT"
final val current: String = "0.1.0-SNAPSHOT"
}
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.13.11
sbt.version = 0.13.13
42 changes: 25 additions & 17 deletions project/build.sbt
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@
resolvers += Resolver.sonatypeRepo("snapshots")

unmanagedSourceDirectories in Compile ++= {
val root = baseDirectory.value.getParentFile

Seq(
root / "util/src/main/scala",
root / "nir/src/main/scala",
root / "tools/src/main/scala",
root / "sbtplugin/src/main/scala"
)
"util",
"nir",
"tools",
"sbt-scala-native"
).map(dir => root / s"$dir/src/main/scala")
}

libraryDependencies += "org.eclipse.jgit" % "org.eclipse.jgit.pgm" % "3.2.0.201312181205-r"

libraryDependencies += "com.lihaoyi" %% "fastparse" % "0.4.2"
libraryDependencies ++= Seq(
"org.scala-sbt" % "scripted-plugin" % sbtVersion.value,
"org.eclipse.jgit" % "org.eclipse.jgit.pgm" % "3.2.0.201312181205-r",
"com.lihaoyi" %% "fastparse" % "0.4.2",
"com.lihaoyi" %% "scalaparse" % "0.4.2",
compilerPlugin(
"org.scalamacros" % "paradise" % "2.0.1" cross CrossVersion.full)
)

libraryDependencies += "com.lihaoyi" %% "scalaparse" % "0.4.2"
addSbtPlugin("org.scala-native" % "sbt-cross" % "0.1.0-SNAPSHOT")
addSbtPlugin("com.eed3si9n" % "sbt-dirty-money" % "0.1.0")

libraryDependencies += compilerPlugin(
"org.scalamacros" % "paradise" % "2.0.1" cross CrossVersion.full)

addSbtPlugin("com.eed3si9n" % "sbt-dirty-money" % "0.1.0")

libraryDependencies <+= (sbtVersion) { sv =>
"org.scala-sbt" % "scripted-plugin" % sv
}
scalacOptions ++= Seq(
"-deprecation",
"-unchecked",
"-feature",
"-encoding",
"utf8"
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package scala.scalanative
package sbtplugin

import sbt._
import sbtcross._

import scala.language.implicitConversions

trait NativeCross {
val NativePlatform = sbtplugin.NativePlatform

implicit def NativeCrossProjectBuilderOps(
builder: CrossProject.Builder): NativeCrossProjectOps =
new NativeCrossProjectOps(builder.crossType(CrossType.Full))

implicit class NativeCrossProjectOps(project: CrossProject) {
def native: Project = project.projects(NativePlatform)

def nativeSettings(ss: Def.SettingsDefinition*): CrossProject =
nativeConfigure(_.settings(ss: _*))

def nativeConfigure(transformer: Project => Project): CrossProject =
project.configurePlatform(NativePlatform)(transformer)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package scala.scalanative
package sbtplugin

import sbt._
import sbtcross._

case object NativePlatform extends Platform {
def identifier: String = "native"
def sbtSuffix: String = "Native"
def enable(project: Project): Project =
project.enablePlugins(ScalaNativePlugin)
val crossBinary: CrossVersion = ScalaNativeCrossVersion.binary
val crossFull: CrossVersion = ScalaNativeCrossVersion.full
}

0 comments on commit bad85d1

Please sign in to comment.