Skip to content

Set up a proper cross build#860

Closed
vasilmkd wants to merge 16 commits intotypelevel:mainfrom
vasilmkd:cross
Closed

Set up a proper cross build#860
vasilmkd wants to merge 16 commits intotypelevel:mainfrom
vasilmkd:cross

Conversation

@vasilmkd
Copy link
Member

@vasilmkd vasilmkd commented Dec 7, 2021

Fixes #625.

Edited:

This snapshot seems to be working fine on all platforms:

"io.vasilev" %%% "scalacheck" % "1.15-6862df0"

Help for reviewers, list of changes:

  • Created a core directory where all the code is found (similar to other Typelevel libraries).
  • Set up a proper cross build in core (one project with three platforms and platform specific managed sources instead of three projects with unmanaged sources)
  • jvm became the jvm cross build under core/jvm
  • js became the js cross build under core/js
  • native became the native cross build under core/native
  • src became the shared source code for all platforms under core/shared/src
  • I changed the scala-2.13- and scala-2.13+ unmanaged directories to use the "official" scala-2.12, scala-2.13 and scala-3 Scala versions specific directories supported by the crossproject plugins (the sources under scala-3 can be seen as new files in the diff)
  • Removed as much cruft as possible from the build.sbt file
  • Removed the release.sh script because sbt-spiewak-sonatype contains sbt-sonatype which can be used for releases (already used it to publish a snapshot and tested the release)
  • Tweaked things in tools/travis-script.sh to match the new subprojects (coreJVM, coreJS, coreNative)

There are build warnings which I plan to address in a follow-up PR, to keep this diff as small as possible.

@vasilmkd
Copy link
Member Author

vasilmkd commented Dec 7, 2021

The Scala.js tests also don't seem to run on Scala 3.1.0 and Scala 3.0.2 with the following warning:

[warn] multiple main classes detected: run 'show discoveredMainClasses' to see the list

but this is the output:

sbt:scalacheck> show coreJS/discoveredMainClasses
[info] * 

Edit: resolved.

@armanbilge
Copy link
Member

What's the output of show coreJS/Test/discoveredMainClasses?

@vasilmkd
Copy link
Member Author

vasilmkd commented Dec 7, 2021

Good point, I've been staring at the screen too long:

sbt:scalacheck> show coreJS/Test/discoveredMainClasses
[info] * org.scalacheck.NoPropertyNestingSpecification
[info] * org.scalacheck.PropSpecification
[info] * org.scalacheck.PropsObject
[info] * org.scalacheck.ShrinkSpecification
[info] * org.scalacheck.StatsSpecification
[info] * org.scalacheck.examples.Examples
[info] * org.scalacheck.examples.MathSpec
[info] * org.scalacheck.util.PrettySpecification
[info] * scala.StringSpecification
[success] Total time: 0 s, completed Dec 8, 2021, 12:55:16 AM

Edit: resolved.

@armanbilge
Copy link
Member

You can set Test / mainClass := Some(...)

@vasilmkd
Copy link
Member Author

vasilmkd commented Dec 8, 2021

It doesn't seem to do anything. :/

Edit: resolved.

@vasilmkd
Copy link
Member Author

vasilmkd commented Dec 8, 2021

Also, the output of coreJS/Test/discoveredMainClasses is exactly the same on Scala 2.13 and Scala 3 and it works without issues on Scala 2.13 (most likely Scala 2.12 too).

Edit: resolved.

@armanbilge
Copy link
Member

Maybe has something to do with these sbt test frameworks things? I always thought tests used a different mechanism mutually exclusive to main classes.

@vasilmkd
Copy link
Member Author

vasilmkd commented Dec 8, 2021

The "multiple main classes" warning is visible in CI before this PR, so that's most likely a red herring.

Here's what happens when running the compiled JS code manually.

vasil@vasil-mac scalacheck-test-fastopt % node main.js
/Users/vasil/Code/scalacheck/core/js/target/scala-3.0.2/scalacheck-test-fastopt/main.js:12344
  scalajsCom.init(((arg1$2) => {
  ^

ReferenceError: scalajsCom is not defined
    at new $c_Lorg_scalajs_testing_bridge_JSRPC$ (/Users/vasil/Code/scalacheck/core/js/target/scala-3.0.2/scalacheck-test-fastopt/main.js:12344:3)
    at $m_Lorg_scalajs_testing_bridge_JSRPC$ (/Users/vasil/Code/scalacheck/core/js/target/scala-3.0.2/scalacheck-test-fastopt/main.js:12371:45)
    at new $c_Lorg_scalajs_testing_bridge_TestAdapterBridge$ (/Users/vasil/Code/scalacheck/core/js/target/scala-3.0.2/scalacheck-test-fastopt/main.js:5848:155)
    at $m_Lorg_scalajs_testing_bridge_TestAdapterBridge$ (/Users/vasil/Code/scalacheck/core/js/target/scala-3.0.2/scalacheck-test-fastopt/main.js:5872:57)
    at $c_Lorg_scalajs_testing_bridge_Bridge$.start__V (/Users/vasil/Code/scalacheck/core/js/target/scala-3.0.2/scalacheck-test-fastopt/main.js:4562:5)
    at $s_Lorg_scalajs_testing_bridge_Bridge__start__V (/Users/vasil/Code/scalacheck/core/js/target/scala-3.0.2/scalacheck-test-fastopt/main.js:4537:44)
    at Object.<anonymous> (/Users/vasil/Code/scalacheck/core/js/target/scala-3.0.2/scalacheck-test-fastopt/main.js:39538:1)
    at Object.<anonymous> (/Users/vasil/Code/scalacheck/core/js/target/scala-3.0.2/scalacheck-test-fastopt/main.js:39539:4)
    at Module._compile (internal/modules/cjs/loader.js:1085:14)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)

Edit: resolved.

@armanbilge
Copy link
Member

armanbilge commented Dec 8, 2021

That's normal AFAIK. Any project if you try to run the generated test js outside of the sbt test context you get that Scala com error.

@vasilmkd
Copy link
Member Author

vasilmkd commented Dec 8, 2021

Everything might have been related to improper scalacOptions on Scala 3. I should have trusted sbt-spiewak and not tried to restore the old scalacOptions. I was aiming for a smaller diff.

@vasilmkd
Copy link
Member Author

vasilmkd commented Dec 8, 2021

This snapshot seems to be working fine on all platforms:

"io.vasilev" %%% "scalacheck" % "1.15-6862df0"

@vasilmkd vasilmkd marked this pull request as ready for review December 8, 2021 09:34
@pmeheut
Copy link

pmeheut commented Dec 20, 2021

I have the same problem: crossProject named nscalaJavaTime with crossType(CrossType.Pure).
The tests run with the JVM. But when I run them with Scala.js, i.e.:
nscalaJavaTimeJS / test
All I get is:

info] compiling 3 Scala sources to /Users/pascal/eclipse/workspace/nscala-java-time/.js/target/scala-2.13/test-classes ...
[info] done compiling
[warn] multiple main classes detected: run 'show discoveredMainClasses' to see the list
[info] Fast optimizing <dir>/nscala-java-time/.js/target/scala-2.13/nscala-java-time-test-fastopt
[success] Total time: 4 s, completed <date>

There are no main anywhere in the project and I tried with several versions including "io.vasilev" %% "scalacheck" % "1.15-6862df0"

@vasilmkd
Copy link
Member Author

That turned out to be a problem with Scala 3 scalacOptions, I don't get the issue anymore in this PR. Hope it helps.

@pmeheut
Copy link

pmeheut commented Dec 20, 2021

Even with no scalacOptions, I get the problem. I'll try to build a simple test case and let you know if I can reproduce it easily.

@armanbilge
Copy link
Member

@pmeheut what is the output of running show coreJS/Test/discoveredMainClasses in sbt? Replacing coreJS with your JS module name.

@pmeheut
Copy link

pmeheut commented Dec 20, 2021

�show nscalaJavaTimeJS / Test / discoveredMainClasses
[info] * com.github.nscala_java_time.time.BasicFunctionalitySpec
[info] * com.github.nscala_java_time.time.OrderingSpec
[info] * com.github.nscala_java_time.time.RichStringSpec

i.e. the 3 Spec files in the project.

@armanbilge
Copy link
Member

@pmeheut interesting, do you have mainModuleInitializer := true somewhere in your settings?

@pmeheut
Copy link

pmeheut commented Dec 20, 2021

No mainModuleInitializer in the project.

@armanbilge
Copy link
Member

@pmeheut another random idea, try setting:

testFrameworks += new TestFramework("org.scalacheck.ScalaCheckFramework")

Otherwise, out of ideas, sorry 😕

@pmeheut
Copy link

pmeheut commented Dec 20, 2021

It changes nothing. Thanks for all the quick answers. I'll investigate on my own tomorrow.

@pmeheut
Copy link

pmeheut commented Dec 20, 2021

I took a very simple project, https://github.com/scala-js/scalajs-cross-compile-example, added scalacheck and tests in the js and jvm src/test/scala directories.

When I run fooJVM / testI get:

failing seed for Main.Main test failed is TOFNUsU1lFvvZvKowQTTn642grCKU0yenGFOJkAYEKD=
[info] + Main.Main test succeeded: OK, proved property.
[info] ! Main.Main test failed: Falsified after 0 passed tests.
[info] Failed: Total 2, Failed 1, Errors 0, Passed 1
[error] Failed tests:
[error] 	example.MainSpec
[error] (fooJVM / Test / test) sbt.TestsFailedException: Tests unsuccessful

as expected.

When I run fooJS / test, I get only:

[success] Total time: 3 s, completed 20 déc. 2021 à 22:06:17

You can get the project here if you want to try it:
sample scalajs/scalacheck project

@armanbilge
Copy link
Member

I do hope we'll move forward with this. Now that Vasil's done the hard work it should be an easy jump to sbt-typelevel.

@vasilmkd
Copy link
Member Author

I'm planning to refresh this PR very soon.

@armanbilge
Copy link
Member

Btw, is scalacheck using PVP versioning? Actually sbt-typelevel doesn't really support that.

@pmeheut
Copy link

pmeheut commented Jan 22, 2022 via email

@vasilmkd
Copy link
Member Author

vasilmkd commented Mar 7, 2022

Superseded by #875. Thanks @armanbilge for taking care of this big change and for sbt-typelevel.

@vasilmkd vasilmkd closed this Mar 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

make publishing use sbt-sonatype

3 participants