mirror of https://github.com/sbt/sbt.git
Merge pull request #16 from sbt/wip/scala-native
Add Scala Native support
This commit is contained in:
commit
4fb332a3a5
12
.travis.yml
12
.travis.yml
|
|
@ -1,8 +1,18 @@
|
|||
dist: trusty
|
||||
group: stable
|
||||
sudo: required
|
||||
|
||||
env:
|
||||
- SCALANATIVE_GC=boehm
|
||||
|
||||
language: scala
|
||||
jdk: oraclejdk8
|
||||
matrix:
|
||||
include:
|
||||
- jdk: openjdk8
|
||||
# - jdk: openjdk11
|
||||
|
||||
before_install:
|
||||
- bash scripts/travis_setup.sh
|
||||
|
||||
before_script:
|
||||
- export JVM_OPTS="-Dfile.encoding=UTF-8 -Xmx1G -Xms1G -server -XX:ReservedCodeCacheSize=128M"
|
||||
|
|
|
|||
|
|
@ -74,7 +74,7 @@ This is an example where `core` builds against Scala 2.11 and 2.12, but app only
|
|||
|
||||
### Scala.js support
|
||||
|
||||
Scala.js support was added in sbt-projectmatrix 0.2.0.
|
||||
[Scala.js](http://scala-js.org/) support was added in sbt-projectmatrix 0.2.0.
|
||||
To use this, you need to setup sbt-scalajs as well:
|
||||
|
||||
```scala
|
||||
|
|
@ -87,6 +87,22 @@ lazy val core = (projectMatrix in file("core"))
|
|||
|
||||
This will create subprojects `coreJS2_11` and `coreJS2_12`.
|
||||
|
||||
### Scala Native support
|
||||
|
||||
[Scala Native](http://scala-native.org) support will be added in upcoming release.
|
||||
To use this, you need to setup sbt-scala-native` as well:
|
||||
|
||||
```scala
|
||||
lazy val core = (projectMatrix in file("core"))
|
||||
.settings(
|
||||
name := "core"
|
||||
)
|
||||
.nativePlatform(scalaVersions = Seq("2.12.8", "2.11.12"))
|
||||
```
|
||||
|
||||
This will create subprojects `coreJS2_11` and `coreJS2_12`.
|
||||
|
||||
|
||||
### parallel cross-library building
|
||||
|
||||
The rows can also be used for parallel cross-library building.
|
||||
|
|
|
|||
|
|
@ -0,0 +1,74 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Format C/C++ code using clang-format.
|
||||
#
|
||||
# To ensure reproducible formatting the script checks that clang-format
|
||||
# is from the most recent version of LLVM supported by Scala Native.
|
||||
#
|
||||
# Usage: $0 [--test]
|
||||
#
|
||||
# Set CLANG_FORMAT_PATH to configure path to clang-format.
|
||||
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
# The required version of clang-format.
|
||||
CLANG_FORMAT_VERSION=5.0
|
||||
CLANG_FORMAT_VERSION_STRING="clang-format version $CLANG_FORMAT_VERSION"
|
||||
|
||||
die() {
|
||||
while [ "$#" -gt 0 ]; do
|
||||
echo >&2 "$1"; shift
|
||||
done
|
||||
exit 1
|
||||
}
|
||||
|
||||
check_clang_format_version() {
|
||||
cmd="$1"
|
||||
[ -e "$(type -P "$cmd")" ] && \
|
||||
"$cmd" --version 2> /dev/null | grep -q "$CLANG_FORMAT_VERSION_STRING"
|
||||
}
|
||||
|
||||
clang_format=
|
||||
|
||||
if [ -n "${CLANG_FORMAT_PATH:-}" ]; then
|
||||
check_clang_format_version "$CLANG_FORMAT_PATH" || \
|
||||
die "CLANG_FORMAT_PATH does not have required version $CLANG_FORMAT_VERSION" \
|
||||
"CLANG_FORMAT_PATH points to $CLANG_FORMAT_PATH"
|
||||
clang_format="$CLANG_FORMAT_PATH"
|
||||
else
|
||||
for cmd in "clang-format-$CLANG_FORMAT_VERSION" clang-format; do
|
||||
if check_clang_format_version "$cmd"; then
|
||||
clang_format="$cmd"
|
||||
break
|
||||
fi
|
||||
done
|
||||
fi
|
||||
|
||||
if [ -z "$clang_format" ]; then
|
||||
die "clang-format version $CLANG_FORMAT_VERSION not found" \
|
||||
"Install LLVM version $CLANG_FORMAT_VERSION and rerun."
|
||||
fi
|
||||
|
||||
test_mode=
|
||||
|
||||
while [ "$#" -gt 0 ]; do
|
||||
arg="$1"
|
||||
case "$arg" in
|
||||
--test) test_mode=true; shift ;;
|
||||
--*) die "Unknown argument: $arg" "Usage: $0 [--test]" ;;
|
||||
*) break ;;
|
||||
esac
|
||||
done
|
||||
|
||||
if [ "$#" -gt 0 ]; then
|
||||
"$clang_format" --style=file -i "$@"
|
||||
else
|
||||
find . -name "*.[ch]" -or -name "*.cpp" | xargs "$clang_format" --style=file -i
|
||||
fi
|
||||
|
||||
if [ "$test_mode" = true ]; then
|
||||
git diff --quiet --exit-code || \
|
||||
die "C/C++ code formatting changes detected" \
|
||||
"Run \`$0\` to reformat."
|
||||
fi
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,22 @@
|
|||
"""
|
||||
Utility that lists all non-implementation specific classes in javalib.
|
||||
|
||||
It must be run from the root of the Scala Native checkout.
|
||||
"""
|
||||
|
||||
import subprocess,os
|
||||
|
||||
cwd = os.getcwd()
|
||||
|
||||
target = cwd + "/javalib/target/scala-2.11/classes/"
|
||||
|
||||
paths = subprocess.check_output(["find", target, "-name", "*.nir"])
|
||||
|
||||
classes = sorted(list(set(
|
||||
line.replace(target, "").replace(".nir", "").lstrip("/").rstrip("$").replace("/", ".")
|
||||
for line in paths.split("\n")
|
||||
if "$$anon" not in line and "java/" in line
|
||||
)))
|
||||
|
||||
for cls in classes:
|
||||
print("* ``{}``".format(cls))
|
||||
|
|
@ -0,0 +1,5 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
HERE="`dirname $0`"
|
||||
|
||||
nix-shell $HERE/scala-native.nix -A clangEnv
|
||||
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -ex
|
||||
|
||||
sbt rebuild test-all
|
||||
sbt "tools/mimaReportBinaryIssues"
|
||||
sbt publishSigned
|
||||
sbt "project nscplugin" ++2.11.12 publishSigned
|
||||
sbt "project nscplugin" ++2.11.11 publishSigned
|
||||
sbt "project nscplugin" ++2.11.8 publishSigned
|
||||
sbt ^^1.0.4 sbtScalaNative/publishSigned nir/publishSigned tools/publishSigned util/publishSigned testRunner/publishSigned
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
let
|
||||
pkgs = import <nixpkgs> {};
|
||||
stdenv = pkgs.stdenv;
|
||||
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
|
||||
sbt
|
||||
openjdk
|
||||
boehmgc
|
||||
libunwind
|
||||
re2
|
||||
clang
|
||||
zlib
|
||||
];
|
||||
};
|
||||
}
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# set -x
|
||||
|
||||
HERE="`dirname $0`"
|
||||
VERSION="1.2.0"
|
||||
COURSIER="$HERE/.coursier"
|
||||
SCALAFMT="$HERE/.scalafmt-$VERSION"
|
||||
|
||||
if [ ! -f $COURSIER ]; then
|
||||
curl -L -o $COURSIER https://git.io/vgvpD
|
||||
chmod +x $COURSIER
|
||||
fi
|
||||
|
||||
if [ ! -f $SCALAFMT ]; then
|
||||
$COURSIER bootstrap com.geirsson:scalafmt-cli_2.11:$VERSION --main org.scalafmt.cli.Cli -o $SCALAFMT
|
||||
chmod +x $SCALAFMT
|
||||
fi
|
||||
|
||||
$SCALAFMT "$@"
|
||||
|
|
@ -0,0 +1,42 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
# Enable strict mode and fail the script on non-zero exit code,
|
||||
# unresolved variable or pipe failure.
|
||||
set -euo pipefail
|
||||
IFS=$'\n\t'
|
||||
|
||||
if [ "$(uname)" == "Darwin" ]; then
|
||||
|
||||
brew update
|
||||
brew install sbt
|
||||
brew install bdw-gc
|
||||
brew link bdw-gc
|
||||
brew install jq
|
||||
brew install re2
|
||||
brew install llvm@4
|
||||
export PATH="/usr/local/opt/llvm@4/bin:$PATH"
|
||||
|
||||
else
|
||||
|
||||
sudo apt-get update
|
||||
|
||||
# Remove pre-bundled libunwind
|
||||
sudo find /usr -name "*libunwind*" -delete
|
||||
|
||||
# Use pre-bundled clang
|
||||
export PATH=/usr/local/clang-5.0.0/bin:$PATH
|
||||
export CXX=clang++
|
||||
|
||||
# Install Boehm GC and libunwind
|
||||
sudo apt-get install libgc-dev libunwind8-dev
|
||||
|
||||
# Build and install re2 from source
|
||||
git clone https://code.googlesource.com/re2
|
||||
pushd re2
|
||||
git checkout 2017-03-01
|
||||
make -j4 test
|
||||
sudo make install prefix=/usr
|
||||
make testinstall prefix=/usr
|
||||
popd
|
||||
|
||||
fi
|
||||
|
|
@ -69,6 +69,10 @@ sealed trait ProjectMatrix extends CompositeProject {
|
|||
def jsPlatform(scalaVersions: Seq[String], settings: Seq[Setting[_]]): ProjectMatrix
|
||||
def js: ProjectFinder
|
||||
|
||||
def nativePlatform(scalaVersions: Seq[String]): ProjectMatrix
|
||||
def nativePlatform(scalaVersions: Seq[String], settings: Seq[Setting[_]]): ProjectMatrix
|
||||
def native: ProjectFinder
|
||||
|
||||
def crossLibrary(scalaVersions: Seq[String], suffix: String, settings: Seq[Setting[_]]): ProjectMatrix
|
||||
def crossLib(suffix: String): ProjectFinder
|
||||
|
||||
|
|
@ -93,6 +97,8 @@ object ProjectMatrix {
|
|||
val jvmDirectorySuffix: String = "-jvm"
|
||||
val jsIdSuffix: String = "JS"
|
||||
val jsDirectorySuffix: String = "-js"
|
||||
val nativeIdSuffix: String = "Native"
|
||||
val nativeDirectorySuffix: String = "-native"
|
||||
|
||||
/** A row in the project matrix, typically representing a platform.
|
||||
*/
|
||||
|
|
@ -209,7 +215,7 @@ object ProjectMatrix {
|
|||
|
||||
override def jsPlatform(scalaVersions: Seq[String]): ProjectMatrix =
|
||||
jsPlatform(scalaVersions, Nil)
|
||||
|
||||
|
||||
override def jsPlatform(scalaVersions: Seq[String], settings: Seq[Setting[_]]): ProjectMatrix =
|
||||
custom(jsIdSuffix, jsDirectorySuffix, scalaVersions,
|
||||
{ _
|
||||
|
|
@ -228,6 +234,29 @@ object ProjectMatrix {
|
|||
}
|
||||
}
|
||||
|
||||
override def native: ProjectFinder = new SuffixBaseProjectFinder(nativeIdSuffix)
|
||||
|
||||
override def nativePlatform(scalaVersions: Seq[String]): ProjectMatrix =
|
||||
nativePlatform(scalaVersions, Nil)
|
||||
|
||||
override def nativePlatform(scalaVersions: Seq[String], settings: Seq[Setting[_]]): ProjectMatrix =
|
||||
custom(nativeIdSuffix, nativeDirectorySuffix, scalaVersions,
|
||||
{ _
|
||||
.enablePlugins(nativePlugin(this.getClass.getClassLoader).getOrElse(
|
||||
sys.error("""Scala Native plugin was not found. Add the sbt-scala-native plugin into project/plugins.sbt:
|
||||
| addSbtPlugin("org.scala-native" % "sbt-scala-natiev" % "x.y.z")
|
||||
|""".stripMargin)
|
||||
))
|
||||
.settings(settings)
|
||||
})
|
||||
|
||||
def nativePlugin(classLoader: ClassLoader): Try[AutoPlugin] = {
|
||||
import sbtprojectmatrix.ReflectionUtil._
|
||||
withContextClassloader(classLoader) { loader =>
|
||||
getSingletonObject[AutoPlugin](loader, "scala.scalanative.sbtplugin.ScalaNativePlugin$")
|
||||
}
|
||||
}
|
||||
|
||||
override def js: ProjectFinder = new SuffixBaseProjectFinder(jsIdSuffix)
|
||||
|
||||
override def crossLibrary(scalaVersions: Seq[String], suffix: String, settings: Seq[Setting[_]]): ProjectMatrix =
|
||||
|
|
|
|||
|
|
@ -0,0 +1,8 @@
|
|||
package a
|
||||
|
||||
object App {
|
||||
def main(args: Array[String]): Unit = {
|
||||
val a = new Core
|
||||
println(s"Hello, world! ${a}")
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,19 @@
|
|||
// lazy val root = (project in file("."))
|
||||
// .aggregate(core.projectRefs ++ app.projectRefs: _*)
|
||||
// .settings(
|
||||
// )
|
||||
|
||||
lazy val core = (projectMatrix in file("core"))
|
||||
.settings(
|
||||
name := "core",
|
||||
mainClass in (Compile, run) := Some("a.CoreMain")
|
||||
)
|
||||
.nativePlatform(scalaVersions = Seq("2.11.12"))
|
||||
|
||||
lazy val app = (projectMatrix in file("app"))
|
||||
.dependsOn(core)
|
||||
.settings(
|
||||
name := "app",
|
||||
mainClass in (Compile, run) := Some("a.App")
|
||||
)
|
||||
.nativePlatform(scalaVersions = Seq("2.11.12"))
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package a
|
||||
|
||||
class Core {
|
||||
}
|
||||
|
||||
object Core extends Core
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
package a
|
||||
|
||||
object CoreMain {
|
||||
def main(args: Array[String]): Unit = {
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
sys.props.get("plugin.version") match {
|
||||
case Some(x) => addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % x)
|
||||
case _ => sys.error("""|The system property 'plugin.version' is not defined.
|
||||
|Specify this property using the scriptedLaunchOpts -D.""".stripMargin)
|
||||
}
|
||||
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.9")
|
||||
|
|
@ -0,0 +1,4 @@
|
|||
> nativeLink
|
||||
|
||||
$ exists app/target/native-2.11/app-out
|
||||
$ exists core/target/native-2.11/core-out
|
||||
Loading…
Reference in New Issue