portable-scala / sbt-crossproject Goto Github PK
View Code? Open in Web Editor NEWCross-platform compilation support for sbt.
License: BSD 3-Clause "New" or "Revised" License
Cross-platform compilation support for sbt.
License: BSD 3-Clause "New" or "Revised" License
Okay, this is a very specific and odd issue. Now, I recognize this is most likely a bug in IntelliJ's Scala plugin and not sbt-crossproject, but since it's specific to sbt-crossproject causing it, I'm hoping you all might know a solution.
On my MacBook Pro I'm experiencing this, but not on my Ubuntu desktop. I've completely cleared existing settings and wiped everything only to have the exact same issue come back.
IntelliJ warns me that Some[String]
doesn't conform to the expected type of Option[String]
. If I investigate by going to the Option
definition, I get Scala Native's implementation, but going to Some
I get see the standard Scala JVM version. IntelliJ seems to be getting confused about which jars to utilize. What's even more strange is that this is only on my MacBook Pro. This same project on Ubuntu has no problems at all.
You are more than welcome to check out the project to see it: https://github.com/outr/scribe
When converting from "plain" sbt, like
lazy val geom = project.withId("lucre-geom").in(file("geom"))
to cross-project
lazy val geom = crossProject(JSPlatform, JVMPlatform).withId("lucre-geom").in(file("geom"))
this fails with
error: value withId is not a member of sbtcrossproject.CrossProject.Builder
Is there a work-around?
The corresponding method on Project
is being removed in sbt 1.x (https://github.com/sbt/sbt/pull/3068/files#diff-de5d62c45e935f985b9d89ee74531dedL210), so we should also remove it from CrossProject
. It has already been made deprecated in Scala.js' own CrossProject
(scala-js/scala-js#2855).
I am trying to follow the example given in the README.md
and am encountering a problem with missing dependencies.
First of all, thank you for the example!
After doing a direct cut & paste, on "sbt update"
I get:
::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: org.scala-native#nativelib_native0.1.0-SNAPSHOT_2.11;0.1.0-SNAPSHOT: not found
[warn] :: org.scala-native#javalib_native0.1.0-SNAPSHOT_2.11;0.1.0-SNAPSHOT: not found
[warn] :: org.scala-native#scalalib_native0.1.0-SNAPSHOT_2.11;0.1.0-SNAPSHOT: not found
[warn] :: org.scala-native#nscplugin_2.11.8;0.1.0-SNAPSHOT: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
My sbt-native build, based on that project's example, seems to be able to fallback to a dated
variant:
[info] Resolving org.scala-native#nativelib_native0.1.0-SNAPSHOT_2.11;0.1.0-SNAP[info] Resolving org.scala-native#nativelib_native0.1.0-SNAPSHOT_2.11;0.1.0-SNAPSHOT ...
[warn] Unable to reparse org.scala-native#nativelib_native0.1.0-SNAPSHOT_2.11;0.1.0-SNAPSHOT from sonatype-snapshots, using Thu Dec 01 09:58:21 EST 2016
Looks like a glitch at the project end,
My apology if I am doing something wrong at my end.
Thank you,
Lee
I encountered this when trying to add scala-native support to a project, following the instructions in this repo's README. Then I was able to reproduce it in one of the scripted-tests sbt projects under sbt-crossproject-test
.
Steps to reproduce:
cd sbt-crossproject-test/src/sbt-test/new-api/cross-dependencies
mkdir -p project
echo "sbt.version=0.13.16" > project/build.properties
echo <<EOF > project/plugins.sbt
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.19")
addSbtPlugin("org.portable-scala" % "sbt-crossproject" % "0.3.0")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.3.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.3")
EOF
sbt
Error:
[info] Loading project definition from /Users/chris/code/sbt-crossproject/sbt-crossproject-test/src/sbt-test/new-api/cross-dependencies/project
/Users/chris/code/sbt-crossproject/sbt-crossproject-test/src/sbt-test/new-api/cross-dependencies/build.sbt:22: error: type mismatch;
found : $12b0424f132c9a6188b8.g.type (with underlying type String)
required: ?{def %%%(x$1: ? >: String): ?}
Note that implicit conversions are not applicable because they are ambiguous:
both method toPlatformDepsGroupID in object autoImport of type (groupID: String)org.portablescala.sbtplatformdeps.PlatformDepsGroupID
and method toCrossGroupID in object AutoImport of type (groupID: String)sbtcrossproject.CrossGroupID
are possible conversion functions from $12b0424f132c9a6188b8.g.type to ?{def %%%(x$1: ? >: String): ?}
libraryDependencies += g %%% a % v
^
/Users/chris/code/sbt-crossproject/sbt-crossproject-test/src/sbt-test/new-api/cross-dependencies/build.sbt:22: error: value %%% is not a member of String
libraryDependencies += g %%% a % v
If I publishLocal
the sbt plugins and then change the versions in plugins.sbt
to use those:
addSbtPlugin("org.portable-scala" % "sbt-crossproject" % "0.3.1-SNAPSHOT")
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.3.1-SNAPSHOT")
then the problem goes away. But that doesn't make any sense to me, because the only commit since the 0.3.0 release was a change to the README!
Any ideas? Am I doing something stupid?
I'm currently using ScalaJS plugin / latest sbt-crossproject plugin. I have a typical common
cross-project that publishes both a commonJVM
jar and a commonJS
SJS jar. For my project, it takes about 60 seconds to compile each project. I don't have any platform specific files in this project.
If I look at the JVM jar and the SJS jar, they are identical except:
SJS jar has JS_DEPENDENCIES file
SJS jar has NPM_DEPENDENCIES file
SJS jar has the sjsir
artifacts in addition to the class
files.
Since ScalaJS is generating class files anyway, why do I need to the commonJVM
project at all? Couldn't we have some stricter CrossType.Pure
mode where we don't actually create two different projects? Or maybe they're two different projects but we're smarter and only do compilation once and only produce one JAR? For my case, I do not care that my commonJVM
jar is going to have useless SJS artifacts. I will gladly put up with that to shave over a minute off my build.
Not sure if this is currently possible, but it would be great if sbt-crossproject could support multiple versions of scala-js and scala-native at once.
Personal use case is https://github.com/mdedetrich/scalajson, and I would like to support scala-js 0.6.18 and the new scala-js 1.0.0x (and also in general for scala-native various releases)
Again, first of all, thank you for the examples & documentation.
I hope to help improve it by reporting my experiences.
To get my feet wet with cross building, I am following the
"Cross-compiling JVM and Native" section of the README.md.
It appears to me that the section "In build.sbt:" needs to start with:
import sbtcross.{crossProject, CrossType}
val sharedSettings = Seq(scalaVersion := "2.11.8") // Scala Native only supports 2.11
not simply:
val sharedSettings = Seq(scalaVersion := "2.11.8") // Scala Native only supports 2.11
I admit to being easily lead astray, but the comment // (5) shadow sbt-scalajs' crossProject and CrossType until Scala.js 1.0.0 is released
lead me to believe that the import was only necessary when sbt-scalajs was in use. SBT soon disabused me of that notion.
Adding the import makes it easier for people to understand the intent and do a cut & paste
and have it be successful. Happy campers!
Thank you
Lee
Receiving the following error
[warn] * org.scala-js:sbt-scalajs:0.6.19 is selected over 0.6.16
[warn] +- default:scalajson-build:0.1-SNAPSHOT (scalaVersion=2.10, sbtVersion=0.13) (depends on 0.6.19)
[warn] +- org.scala-native:sbt-scalajs-crossproject:0.2.0 (scalaVersion=2.10, sbtVersion=0.13) (depends on 0.6.16)
I'd like to be able to publish for SJS 0.6 and 1.0.
My benchmark task sbt project/bench
stop working under cross project. It succeeds but does not execute any benchmark tests.
My build.sbt:
lazy val Benchmark = config("bench") extend sbt.Test
lazy val project= crossProject(JVMPlatform)
.withoutSuffixFor(JVMPlatform)
.crossType(CrossType.Pure)
.in(file("project"))
.configs(Test)
.configs(Benchmark)
.jvmSettings(
inConfig(Benchmark)(Defaults.testSettings),
bench := {
(test in Benchmark).tag(Exclusive).value
},
testFrameworks += new TestFramework("org.scalameter.ScalaMeterFramework"),
libraryDependencies += "com.storm-enroute" %% "scalameter" % "0.17" % "bench",
)
Please consider this project on github:
https://github.com/dragonfly-ai/mainclassbug
This bare bones project reproduces an error involving the main class declared with mainClass in (Compile, run) := Some("com.example.Main")
and .jsSettings(scalaJSUseMainModuleInitializer := true)
which does not express itself in the JVM context.
Specifically, although the main method finds its way to the output of fastOptJS, typing sbt run
fails with the following error message:
[error] java.lang.RuntimeException: No main class detected.
[error] at scala.sys.package$.error(package.scala:26)
[error] (Compile / bgRun) No main class detected.
Please consider having the README.md describe the run commands for
cross projects.
It has been a long while since I have used an sbt multi-project. The simple
'''sbt run'' in my mind from just having finished the
sbt-native tutorial did not work.
I was in the midst of figuring out the required commands for sbt-cross the hard way
when I came across the scalajs-cross tutorial and rejoiced. Adapting freely from that tutorial (I think I am OK with copyright/license here)
'''
sbt> barJS/run
sbt> barJVM/run
sbt> barNative/run
'''
This addition would get the README.md closer to a "Getting started: see one, do one" state.
Agreed that post-introductory work requires a deeper understanding of sbt, scala-native, &
scala-cross.
Thank you for considering this suggestion.
Lee
sbt version: 1.3.4
Sub project which is an sbt module can not be compiled on 2.13.1.
https://github.com/igorfialko/crossProjectBug
It compiles fine in 2.13.1
[error] Modules were resolved with conflicting cross-version suffixes in ProjectRef(uri("file:/fastparseIncompat/"), "projectB"):
[error] com.lihaoyi:sourcecode _2.12, _2.13
[error] com.lihaoyi:fastparse _2.13, _2.12
[error] stack trace is suppressed; run last projectB / update for the full output
[error] (projectB / update) Conflicting cross-version suffixes in: com.lihaoyi:sourcecode, com.lihaoyi:fastparse
In https://github.com/mdedetrich/scalajson, we have a situation where we want to share the shared
directory across different sbt-crossprojects. Currently the shared
directory is hardcoded in the CrossType
(see https://github.com/scala-native/sbt-crossproject/blob/f4ef45fc4a89a69d60dc438f42a8bbb40c1c1d11/sbt-crossproject/src/main/scala/sbtcrossproject/CrossType.scala#L33-L38).
Ideally there should be some "sharedSource" Setting
which you can override to make it easy to specify your own
Please pardon me if this is the wrong place to raise this issue for
consideration. On other projects, I have been turned back on
StackOverflow for attempting to discuss unreleased software.
At some point down the road, I believe that users of sbt-cross will
encounter a 2-out-of-3, more generally, m-out-of-N, problem
handling source directories, settings, etc. Examples of
solutions which do not fall into combinatorial complexity
will be useful to those users.
To get the existing sbt-cross trio project working with a
main program (1), I had to create a HelloWorld.scala
in each of bar/js/src, bar/jvm/src, and bar/native/src.
The js/src/HelloWorld.scala had to be different (until
I can figure out a better way). The bar/jvm and bar/native
files were identical, which violates DRY. To keep some
sanity, I do want to use symlinks.
Flush from success at getting the sbt-cross trio example
project working (Thank you for the example!), I tried to add
test tree code. Since it is, understandably, too soon for
scala-native to support uTest, I wanted to be prepared
and get up to speed by testing scalaJS vs scalaJVM.
Is there a better place for discussion?
This left me with a situation where I needed to enter
settings common to the scalaJS & scalaJVM sub-projects,
but not the scala-native project. Someday I may
be clever enough to figure out some elegant sbt/scala
code to do this, but for now I duplicated (and the
spirits of my mentors yelled at me, for good reason).
When I set up the testing directories, I ran into
a similar problem. I had to duplicate
the tree in js/src/test to jvm/src/test. Surely
a cause for future, self-inflicted pain.
I can also foresee situations where one would want
scalaJVM & scala-native in the mix and scalaJS out.
With time, I hope to figure out some clever way of
handling these 2-out-of-3 issues without falling into
combinatorial complexity. The sbt settings issue
is probably simpler than the duplicated tree issue.
I mention instances of this issue early on for "back of the brain'
consideration because I think other developers will
run straight into them as the try to stretch from the
well explored & experienced scalaJS/scalaJVM duo
to the nova mundi of scalaJS/scalaJVM/scala-native trio.
Thank you for any suggestions, including
"Please be patient until sbt-cross matures".
Lee
Here's what I came up with:
def zioUri = uri("git://github.com/scalaz/scalaz-zio.git#7f27e9cbc3")
lazy val zioJVM = ProjectRef(zioUri, "coreJVM")
lazy val zioJS = ProjectRef(zioUri, "coreJS")
lazy val base = crossProject(JSPlatform, JVMPlatform)
.jvmConfigure(_ dependsOn zioJVM)
.jsConfigure(_ dependsOn zioJS)
...
But with a bit of support here, I think it could look like
lazy val zio = CrossProjectRef(
uri("git://github.com/scalaz/scalaz-zio.git#7f27e9cbc3"),
Map(JSPlatform -> "coreJS", JVMPlatform -> "coreJVM")
)
lazy val base = crossProject(JSPlatform, JVMPlatform)
.dependsOn(zio)
...
Discovered while trying to use sbt-crossproject to migrate build for fastparse:
In the original Scala.js cross project they are defined in:
/cc @MasseGuillaume
I have simple sbt file: https://gitlab.com/hsn10/getopt/-/blob/ff15088ff1f327c3460cf2a7acc23b059aa64c1d/build.sbt with once dependency - scalatest
classpath for getoptJS is constructed incorrectly. It includes both JVM and JS JARs of scalatest.
In Scala.js 1.x, JSPlatform
will be defined in the package org.scalajs.sbtplugin
. In the transitioning project sbt-scalajs-crossproject
, it should therefore be defined in the same place (even if that's evil because a different .jar puts things in the same package), so that the compatibility macro can refer to _root_.org.scalajs.sbtplugin.JSPlugin
all the time, and hence be forward-compatible with Scala.js 1.x.
This is a blocker for Scala.js' master branch to migrate to sbt-crossproject.
There are a number of plugins that only make sense on a particular platform (e.g. ScalaJSBundlerPlugin). Enabling them on a cross project, makes them active on all projects. This can completely break the incompatible projects. As a workaround, I've had to make separate projects and symlink shared source code in managedSources.
I'm trying to get my code working with Scala Native and followed sbt-crossproject's README:
I rewrote my build.sbt
file and added the sbt-crossproject and sbt-scala-native plugins to project/plugins.sbt
:
addSbtPlugin("org.scala-native" % "sbt-crossproject" % "0.2.2")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.3")
I also set sbt.version=1.0.1
in project/build.properties
.
Running sbt I get:
[warn] module not found: org.scala-native#sbt-scala-native;0.3.3
[warn] ==== typesafe-ivy-releases: tried
[warn] https://repo.typesafe.com/typesafe/ivy-releases/org.scala-native/sbt-scala-native/scala_2.12/sbt_1.0//0.3.3/ivys/ivy.xml
[warn] ==== sbt-plugin-releases: tried
[warn] https://repo.scala-sbt.org/scalasbt/sbt-plugin-releases/org.scala-native/sbt-scala-native/scala_2.12/sbt_1.0//0.3.3/ivys/ivy.xml
[warn] ==== local: tried
[warn] /Users/bastian/.ivy2/local/org.scala-native/sbt-scala-native/scala_2.12/sbt_1.0//0.3.3/ivys/ivy.xml
[warn] ==== public: tried
[warn] https://repo1.maven.org/maven2/org/scala-native/sbt-scala-native_2.12_1.0/0.3.3/sbt-scala-native-0.3.3.pom
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: UNRESOLVED DEPENDENCIES ::
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn] :: org.scala-native#sbt-scala-native;0.3.3: not found
[warn] ::::::::::::::::::::::::::::::::::::::::::::::
[warn]
[warn] Note: Some unresolved dependencies have extra attributes. Check that these dependencies exist with the requested attributes.
[warn] org.scala-native:sbt-scala-native:0.3.3 (scalaVersion=2.12, sbtVersion=1.0)
[warn]
[warn] Note: Unresolved dependencies path:
[warn] org.scala-native:sbt-scala-native:0.3.3 (scalaVersion=2.12, sbtVersion=1.0) (/Users/bastian/projects/question-parser/project/plugins.sbt#L3-4)
[warn] +- default:question-parser-build:0.1-SNAPSHOT (scalaVersion=2.12, sbtVersion=1.0)
[error] sbt.librarymanagement.ResolveException: unresolved dependency: org.scala-native#sbt-scala-native;0.3.3: not found
It looks like sbt-crossproject is published for Scala 2.12 and sbt 1.0,
but sbt-scala-native is not.
lazy val bar =
crossProject(JSPlatform, JVMPlatform, NativePlatform)
.crossType(CrossType.Pure)
.settings(
scalaVersion := "2.11.11",
description := "common settings"
)
lazy val barJS = bar.js
lazy val barJVM = bar.jvm
lazy val barNative = bar.native
The name
of barJS
, barJVM
and barNative
is their respective ID, but it should be bar
for all projects, as it was in Scala.js' crossProject
.
This is important because name
makes its way to moduleName
, which decides the name of the artifact being packaged and published!
It should be possible to build a triple build for both jvm, native and JS. Is that possible without adding a dependency on the sjs cross plugin/sjs? Maybe it is better to have another cross build plugin for that case?
The original CrossProject in SJS has quite extensive documentation, notably about some common pitfalls. It should be carried over (maybe to README.md).
In my sbt project it does not resolve sbt-native:
[error] coursier.ResolutionException: Encountered 5 error(s) in dependency resolution:
[error] org.scala-native:test-interface_native0.3_2.12:0.3.6:
[error] not found:
[error] /home/antonkulaga/.ivy2/local/org.scala-native/test-interface_native0.3_2.12/0.3.6/ivys/ivy.xml
[error] https://repo1.maven.org/maven2/org/scala-native/test-interface_native0.3_2.12/0.3.6/test-interface_native0.3_2.12-0.3.6.pom
[error] org.scala-native:nativelib_native0.3_2.12:0.3.6:
[error] not found:
[error] /home/antonkulaga/.ivy2/local/org.scala-native/nativelib_native0.3_2.12/0.3.6/ivys/ivy.xml
[error] https://repo1.maven.org/maven2/org/scala-native/nativelib_native0.3_2.12/0.3.6/nativelib_native0.3_2.12-0.3.6.pom
[error] org.scala-native:auxlib_native0.3_2.12:0.3.6:
[error] not found:
[error] /home/antonkulaga/.ivy2/local/org.scala-native/auxlib_native0.3_2.12/0.3.6/ivys/ivy.xml
[error] https://repo1.maven.org/maven2/org/scala-native/auxlib_native0.3_2.12/0.3.6/auxlib_native0.3_2.12-0.3.6.pom
[error] org.scala-native:scalalib_native0.3_2.12:0.3.6:
[error] not found:
[error] /home/antonkulaga/.ivy2/local/org.scala-native/scalalib_native0.3_2.12/0.3.6/ivys/ivy.xml
[error] https://repo1.maven.org/maven2/org/scala-native/scalalib_native0.3_2.12/0.3.6/scalalib_native0.3_2.12-0.3.6.pom
[error] org.scala-native:javalib_native0.3_2.12:0.3.6:
[error] not found:
[error] /home/antonkulaga/.ivy2/local/org.scala-native/javalib_native0.3_2.12/0.3.6/ivys/ivy.xml
[error] https://repo1.maven.org/maven2/org/scala-native/javalib_native0.3_2.12/0.3.6/javalib_native0.3_2.12-0.3.6.pom
[error] (treesNative / coursierResolutions) coursier.ResolutionException: Encountered 5 error(s) in dependency resolution:
[error] org.scala-native:test-interface_native0.3_2.12:0.3.6:
[error] not found:
[error] /home/antonkulaga/.ivy2/local/org.scala-native/test-interface_native0.3_2.12/0.3.6/ivys/ivy.xml
[error] https://repo1.maven.org/maven2/org/scala-native/test-interface_native0.3_2.12/0.3.6/test-interface_native0.3_2.12-0.3.6.pom
[error] org.scala-native:nativelib_native0.3_2.12:0.3.6:
[error] not found:
[error] /home/antonkulaga/.ivy2/local/org.scala-native/nativelib_native0.3_2.12/0.3.6/ivys/ivy.xml
[error] https://repo1.maven.org/maven2/org/scala-native/nativelib_native0.3_2.12/0.3.6/nativelib_native0.3_2.12-0.3.6.pom
[error] org.scala-native:auxlib_native0.3_2.12:0.3.6:
[error] not found:
[error] /home/antonkulaga/.ivy2/local/org.scala-native/auxlib_native0.3_2.12/0.3.6/ivys/ivy.xml
[error] https://repo1.maven.org/maven2/org/scala-native/auxlib_native0.3_2.12/0.3.6/auxlib_native0.3_2.12-0.3.6.pom
[error] org.scala-native:scalalib_native0.3_2.12:0.3.6:
[error] not found:
[error] /home/antonkulaga/.ivy2/local/org.scala-native/scalalib_native0.3_2.12/0.3.6/ivys/ivy.xml
[error] https://repo1.maven.org/maven2/org/scala-native/scalalib_native0.3_2.12/0.3.6/scalalib_native0.3_2.12-0.3.6.pom
[error] org.scala-native:javalib_native0.3_2.12:0.3.6:
[error] not found:
[error] /home/antonkulaga/.ivy2/local/org.scala-native/javalib_native0.3_2.12/0.3.6/ivys/ivy.xml
[error] https://repo1.maven.org/maven2/org/scala-native/javalib_native0.3_2.12/0.3.6/javalib_native0.3_2.12-0.3.6.pom
[error] Total time: 7 s, completed Feb 18, 2018 5:12:00 PM
here is my build.sbt (sbt version 1.1.1)
val sharedSettings = Seq(scalaVersion := "2.12.4")
lazy val trees =
// (4) select supported platforms
crossProject(JVMPlatform, NativePlatform)
.settings(sharedSettings)
.jvmSettings(
libraryDependencies += "org.spire-math" %% "clouseau" % "0.1.0",
javaOptions += "-javaagent:/home/antonkulaga/Soft/clouseau_2.12-0.1.0.jar",
fork := true,
resolvers += "Sonatype OSS Snapshots" at "https://oss.sonatype.org/content/repositories/releases",
libraryDependencies += "com.storm-enroute" %% "scalameter-core" % "0.8.2"
)
lazy val treesJVM = trees.jvm
lazy val treesNative = trees.native
here are my plugins.sbt:
addSbtPlugin("org.portable-scala" % "sbt-crossproject" % "0.3.1")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.3.6")
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.2")
Note: the resolution problem is not coursier-related, without coursier I get the same problem
Running the build with this plugin enabled outputs the following log:
Project defines platforms: jvm, js
project core
discards: native
Project defines platforms: jvm, js
project core
discards: native
Project defines platforms: jvm, js
project core
discards: native
Project defines platforms: jvm, js
project core
discards: native
Project defines platforms: jvm, js
project core
discards: native
Project defines platforms: jvm, js
project core
discards: native
project state
discards: native
I think this is pretty annoying. IMO, the right way to do this is to use the sbt logger and adding a setting key to disable its output. The logic for this (println
s) is in requireDependencies
.
The fact that it is accessible through org.scalajs.sbtplugin.JSPlatform
is a remnant of the old design where JSPlatform
would be directly provided by sbt-scalajs
. The design has now changed, and it will forever be provided by sbt-scalajs-crossproject
, so it should be in the package name of the latter.
I feel like there has to be a way to get it to work, but at least right now... I cannot figure out how to get the test phase of a project to correctly use the scala-native compiler. I've tried using the utest framework, as well as just a 'main' based entry point in the test project (jsonNative/test:run) and they both yield the same result.
Looks like its missing some classes, then for the ones it does find, it runs into the 'undefined' stubs that the compiler should be able to handle. jsonNative/run works just fine.
EDIT: This is a cross-compile project with scala/scala-js/scala-native, the utest framework works just fine for scala-js and scala.
Here's the branch for my project I'm having issues with:
https://github.com/MediaMath/scala-json/tree/2.12.x
> ++2.11.8
> jsonNative/test
...
[info] scala.scalanative.runtime.UndefinedBehaviorError
[info] scala.scalanative.runtime.package$.undefined(package.scala:9)
...
[info] java.lang.NoClassDefFoundError: Could not initialize class scala.scalanative.native.Tag$
SBT 0.13.13
addSbtPlugin("org.scala-js" % "sbt-scalajs" % "0.6.14")
addSbtPlugin("org.scala-native" % "sbt-crossproject" % "0.1.0")
addSbtPlugin("org.scala-native" % "sbt-scalajs-crossproject" % "0.1.0")
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.1.0")
We need to upgrade Scala.js to sbt 1.0.0-RC2 to test it for potential critical regressions. Of course now we need sbt-crossproject to be built for 1.0.0-RC2 for that.
See also scala-js/scala-js#3065
The cats-scalatest project set up a Pure
cross project for JVM and JS platforms on several Scala versions. Dependency resolution seems to work fine throughout the matrix, except for the root project. The broken config is available for reference on the scalajs-cross-pure-broken
branch.
sbt:cats-scalatest> projects
[info] In file: ~/cats-scalatest/
[info] * cats-scalatest
[info] catsScalatestJS
[info] catsScalatestJVM
Running sbt test
or sbt compile
results in compilation failures in the root (cats-scalatest
) project that indicate missing dependencies, e.g.:
[info] Compiling 5 Scala sources to ~/cats-scalatest/target/scala-2.12/classes ...
[error] ~/cats-scalatest/src/main/scala/cats/scalatest/EitherMatchers.scala:3:12: object scalatest is not a member of package org
[error] import org.scalatest.matchers.{BeMatcher, MatchResult, Matcher}
[error] ^
Running sbt catsScalatestJS/compile
or sbt catsScalatestJVM/compile
both work fine.
I would have expected compile
or cats-scalatest/compile
to call the platform-specific projects' compile
tasks, not execute one of its own.
FWIW, I noticed that setting the Scala version using ++
excludes the core project:
sbt:cats-scalatest> ++ 2.11.12 -v
[info] Setting Scala version to 2.11.12 on 2 projects.
[info] Switching Scala version on:
[info] catsScalatestJVM (2.11.12, 2.12.10, 2.13.1)
[info] catsScalatestJS (2.11.12, 2.12.10, 2.13.1)
[info] Excluding projects:
[info] * cats-scalatest (2.12.10)
[info] Reapplying settings...
[info] Set current project to cats-scalatest (in build file:~/cats-scalatest/)
Maybe cats-scalatest
should be excluded more broadly, and it's not for some reason?
We worked around the issue by switching to a Full
cross project on the primary branch. The broken config is preserved on the scalajs-cross-pure-broken
branch. (There is no platform-specific code for this project, so ideally it will switch back to Pure
once we figure out what's going wrong.)
My cross-project is setup like this:
lazy val my_cross_project = crossProject(JSPlatform, JVMPlatform).
crossType(CrossType.Full).
in(file("web/mycrossproject")).
settings(scala_210_211 ++ commonSettings).
settings(
name := "my.crossproject"
).
jvmSettings(java7Settings ++ jvmSpecificSettings).
jsSettings(
jsDependencies += "org.webjars.npm" % "d3" % "5.4.0" / "d3.js" minified "d3.min.js",
scalaJSUseMainModuleInitializer := false,
skip in packageJSDependencies := false
)
lazy val my_cross_projectJVM = my_cross_project.jvm
lazy val my_cross_projectJS = my_cross_project.js
I get the js
and jvm
projects, but not the shared
one. What am I missing?
@densh
name class with: https://github.com/lucidsoftware/sbt-cross
[info] Compiling 5 Scala sources to /home/travis/build/xuwei-k/scalaz/project/target/scala-2.10/sbt-0.13/classes...
exception when typing scalajscrossproject.ScalaJSCrossPlugin.autoImport/class scala.reflect.internal.Trees$Select
bad symbolic reference. A signature in ScalaJSCrossPlugin.class refers to term impl
in package org.scalajs.sbtplugin which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling ScalaJSCrossPlugin.class. in file /home/travis/build/xuwei-k/scalaz/project/build.scala
scala.reflect.internal.Types$TypeError: bad symbolic reference. A signature in ScalaJSCrossPlugin.class refers to term impl
in package org.scalajs.sbtplugin which is not available.
It may be completely missing from the current classpath, or the version on
the classpath might be incompatible with the version used when compiling ScalaJSCrossPlugin.class.
at scala.reflect.internal.pickling.UnPickler$Scan.toTypeError(UnPickler.scala:847)
at scala.reflect.internal.pickling.UnPickler$Scan$LazyTypeRef.complete(UnPickler.scala:854)
at scala.reflect.internal.pickling.UnPickler$Scan$LazyTypeRef.load(UnPickler.scala:863)
at scala.reflect.internal.Symbols$Symbol.typeParams(Symbols.scala:1489)
at scala.tools.nsc.transform.SpecializeTypes$$anonfun$scala$tools$nsc$transform$SpecializeTypes$$normalizeMember$1.apply(SpecializeTypes.scala:798)
/cc @sjrd
The resource directory in the "shared" folder is not added to project resourceDirectories
. This is a problem especially for CrossType.Pure
as all resource directories for this layout are in the "hidden" .<platform>
folder.
Ideally, resource directories should be treated in the same way as source directories are.
build.sbt:
import sbtcrossproject.{crossProject, CrossType}
lazy val foo =
crossProject(JSPlatform, JVMPlatform)
.crossType(CrossType.Pure)
lazy val `foo-jvm` = foo.jvm
lazy val `foo-js` = foo.js
SBT shell:
sbt:tmp> show fooJVM/sourceDirectories
[info] * /private/tmp/foo/.jvm/src/main/scala-2.12
[info] * /private/tmp/foo/.jvm/src/main/scala
[info] * /private/tmp/foo/.jvm/src/main/java
[info] * /private/tmp/foo/src/main/scala-2.12
[info] * /private/tmp/foo/src/main/scala
[info] * /private/tmp/foo/.jvm/target/scala-2.12/src_managed/main
sbt:tmp> show fooJVM/resourceDirectories
[info] * /private/tmp/foo/.jvm/src/main/resources
[info] * /private/tmp/foo/.jvm/target/scala-2.12/resource_managed/main
I am attempting to cross-build and publish a project for all three architectures.
When I run sbt +publishLocal
, sbt also publishes it for 2.10. In Scala.js, the manual advises to define a root
project. When I do so, cross-publishing works for all projects but Scala Native (it doesn't respect the overridden scalaVersion
and uses the 2.12 version instead).
Also, I needed to specify the root path with .in(file("."))
, but according to the README it should also work without.
There are test cases in my shared
sub-project and sbt test
tries to compile them for Scala Native. As there is no testing interface for Scala Native, I expected the tests to be ignored altogether.
You can find my latest build.sbt
here.
Depending on whether .jsConfigure
call is placed before or after .settings
, the cross type/directory configuration changes.
Repository with a reproduction set up here.
Versions:
Given this build.sbt
:
import sbtcrossproject.CrossPlugin.autoImport.{CrossType, crossProject}
val good = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Pure)
.settings(scalaVersion := "2.12.8")
.jsConfigure(identity)
val bad = crossProject(JVMPlatform, JSPlatform)
.crossType(CrossType.Pure)
.jsConfigure(identity)
.settings(scalaVersion := "2.12.8")
Results in correct sourceDirectories
for the project where .jsConfigure
is after .settings
:
$ sbt 'show goodJVM/sourceDirectories' 'show goodJS/sourceDirectories'
...
[info] * /tmp/sbt-crossproject-jsConfigure-issue/good/.jvm/src/main/scala-2.12
[info] * /tmp/sbt-crossproject-jsConfigure-issue/good/.jvm/src/main/scala
[info] * /tmp/sbt-crossproject-jsConfigure-issue/good/.jvm/src/main/java
[info] * /tmp/sbt-crossproject-jsConfigure-issue/good/src/main/scala-2.12
[info] * /tmp/sbt-crossproject-jsConfigure-issue/good/src/main/scala
[info] * /tmp/sbt-crossproject-jsConfigure-issue/good/.jvm/target/scala-2.12/src_managed/main
[info] * /tmp/sbt-crossproject-jsConfigure-issue/good/.js/src/main/scala-2.12
[info] * /tmp/sbt-crossproject-jsConfigure-issue/good/.js/src/main/scala
[info] * /tmp/sbt-crossproject-jsConfigure-issue/good/.js/src/main/java
[info] * /tmp/sbt-crossproject-jsConfigure-issue/good/src/main/scala-2.12
[info] * /tmp/sbt-crossproject-jsConfigure-issue/good/src/main/scala
[info] * /tmp/sbt-crossproject-jsConfigure-issue/good/.js/target/scala-2.12/src_managed/main
And bad sourceDirectories
where .jsConfigure
is before .settings
(looks like CrossType.Full
configuration?):
$ sbt 'show badJVM/sourceDirectories' 'show badJS/sourceDirectories'
...
[info] * /tmp/sbt-crossproject-jsConfigure-issue/bad/jvm/src/main/scala-2.12
[info] * /tmp/sbt-crossproject-jsConfigure-issue/bad/jvm/src/main/scala
[info] * /tmp/sbt-crossproject-jsConfigure-issue/bad/jvm/src/main/java
[info] * /tmp/sbt-crossproject-jsConfigure-issue/bad/shared/src/main/scala-2.12
[info] * /tmp/sbt-crossproject-jsConfigure-issue/bad/shared/src/main/scala
[info] * /tmp/sbt-crossproject-jsConfigure-issue/bad/jvm/target/scala-2.12/src_managed/main
[info] * /tmp/sbt-crossproject-jsConfigure-issue/bad/js/src/main/scala-2.12
[info] * /tmp/sbt-crossproject-jsConfigure-issue/bad/js/src/main/scala
[info] * /tmp/sbt-crossproject-jsConfigure-issue/bad/js/src/main/java
[info] * /tmp/sbt-crossproject-jsConfigure-issue/bad/shared/src/main/scala-2.12
[info] * /tmp/sbt-crossproject-jsConfigure-issue/bad/shared/src/main/scala
[info] * /tmp/sbt-crossproject-jsConfigure-issue/bad/js/target/scala-2.12/src_managed/main
Builds using .scala
are less favoured than using sbt
. We may want to go towards that direction
It seems that only sbt-crossproject 0.2.1 is available for sbt 1.0 but not sbt-scalajs-crossproject:
Should sbt-scalajs-crossproject be available for sbt 1.0 too?
Hello, I am trying to set up a cross JS/JVM project that also includes macros.
Is there any way to have two shared sub-projects? One for macro definitions (to be compiled before it's used) and one for shared code between JS and JVM?
This is a rough idea of what I am trying to achieve:
lazy val macros = (project in file("macros"))
lazy val shared = (project in file("shared")).dependsOn(macros)
lazy val js = (project in file("js")).dependsOn(macros, shared)
lazy val jvm = (project in file("jvm")).dependsOn(macros, shared)
Thanks in advance.
Please consider having README.md describe, early on, the
expected source directory layout. This is especially
tricky for a reader because there two layouts are used.
Reading from the top down, the first encountered layout
is for the trio project. If I understand correctly, the
.crossType(CrossType.Pure) // [Pure, Full, Dummy], default: CrossType.Full
causes the bar/.js, bar/.jvm, bar/native, shared, form to be used. Since
these are hidden directories, it makes it exceedingly hard to
figure out.
Since I like prove out my understanding, I usually start simple
and work my way to more complex. I jumped into the second,
duo example before I attempted the trio example. It took
more work than I expected, but I figured out the expected
bar/jvm, bar/native, shared directory structure. This gives
nice, visible directories.
When I extended my duo project to the trio project
described in the README.md, sbt could no longer
find my source code. After ratting around, I discovered
that this is because the duo project defaulted to 'CrossType.Full'.
The trio project had an explicit 'CrossType.Pure', which expected
a different source directory structure.
As both scala-cross & my understanding of it mature, I hope
to understand when one would use a Full & when one would
use a Pure. For now, I am using Full seems to work, so I
am using it to allow me to see my directories.
The good ascii art in file CrossType.scala helped me get the
trio project up and running. Adding that art to the README.md
would, I believe, ease the way of other early & potential adopters.
Thank you for considering this suggestion. As always, thank you
for sbt-cross. I have learned from following the README.md.
Lee
sorry, It must be 1.13.7 instead of 1.13.17?
I had trouble to compile with 1.13.17
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.