Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for Scala Native #118

Merged
merged 10 commits into from
Jul 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
language: scala

dist: trusty

sudo: required

addons:
apt:
packages:
Expand All @@ -11,6 +15,7 @@ before_install:
- sed -e "s/^\\(127\\.0\\.0\\.1.*\\)/\\1 $(hostname | cut -c1-63)/" /etc/hosts > /tmp/hosts
- sudo mv /tmp/hosts /etc/hosts
- cat /etc/hosts # optionally check the content *after*
- admin/setup_travis.sh

env:
global:
Expand Down
22 changes: 22 additions & 0 deletions admin/setup_travis.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
#!/bin/bash

set -e

sudo add-apt-repository --yes ppa:ubuntu-toolchain-r/test
sudo apt-get -qq update
sudo apt-get install -y -qq \
clang++-3.8 \
libgc-dev \
libunwind8-dev

# Install re2
# Starting from Ubuntu 16.04 LTS, it'll be available as http://packages.ubuntu.com/xenial/libre2-dev
sudo apt-get install -y make
export CXX=clang++-3.8
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
25 changes: 21 additions & 4 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import ScalaModulePlugin._
import sbtcrossproject.{crossProject, CrossType}

scalaVersionsByJvm in ThisBuild := {
val v211 = "2.11.11"
Expand All @@ -14,12 +15,11 @@ scalaVersionsByJvm in ThisBuild := {
}

lazy val root = project.in(file("."))
.aggregate(`scala-parser-combinatorsJS`, `scala-parser-combinatorsJVM`)
.aggregate(`scala-parser-combinatorsJS`, `scala-parser-combinatorsJVM`, `scala-parser-combinatorsNative`)
.settings(disablePublishing)

lazy val `scala-parser-combinators` = crossProject.in(file(".")).
lazy val `scala-parser-combinators` = crossProject(JSPlatform, JVMPlatform, NativePlatform).in(file(".")).
settings(scalaModuleSettings: _*).
jvmSettings(scalaModuleSettingsJVM).
settings(
name := "scala-parser-combinators",
version := "1.0.7-SNAPSHOT",
Expand All @@ -40,16 +40,33 @@ lazy val `scala-parser-combinators` = crossProject.in(file(".")).
version.value
)
).
jvmSettings(scalaModuleSettingsJVM).
jvmSettings(
// Mima uses the name of the jvm project in the artifactId
// when resolving previous versions (so no "-jvm" project)
name := "scala-parser-combinators",
OsgiKeys.exportPackage := Seq(s"scala.util.parsing.*;version=${version.value}"),
libraryDependencies += "junit" % "junit" % "4.12" % "test",
libraryDependencies += "com.novocode" % "junit-interface" % "0.11" % "test"
).
jsSettings(
name := "scala-parser-combinators-js",
// Scala.js cannot run forked tests
fork in Test := false
).
jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin))
jsConfigure(_.enablePlugins(ScalaJSJUnitPlugin)).
nativeSettings(
name := "scala-parser-combinators-native",
scalaVersion := "2.11.11",
skip in compile := System.getProperty("java.version").startsWith("1.6"),
test := {},
libraryDependencies := {
if (!scalaVersion.value.startsWith("2.11"))
libraryDependencies.value.filterNot(_.organization == "org.scala-native")
else libraryDependencies.value
}
)

lazy val `scala-parser-combinatorsJVM` = `scala-parser-combinators`.jvm
lazy val `scala-parser-combinatorsJS` = `scala-parser-combinators`.js
lazy val `scala-parser-combinatorsNative` = `scala-parser-combinators`.native
14 changes: 14 additions & 0 deletions native/src/main/scala/scala/util/parsing/input/PositionCache.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package scala.util.parsing.input

import java.lang.CharSequence
import java.util.{AbstractMap, Collections}

private[input] trait PositionCache {
private[input] lazy val indexCache: java.util.Map[CharSequence,Array[Int]] = new AbstractMap[CharSequence, Array[Int]] {

override def entrySet() = Collections.emptySet()

// the /dev/null of Maps
override def put(ch: CharSequence, a: Array[Int]) = null
}
}
5 changes: 4 additions & 1 deletion project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "1.0.12")

addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.18")
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.18")
addSbtPlugin("org.scala-native" % "sbt-crossproject" % "0.2.0")
addSbtPlugin("org.scala-native" % "sbt-scalajs-crossproject" % "0.2.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.1")