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

Cross compile to Scala Native #114

Merged
merged 1 commit into from
Jun 25, 2017
Merged

Conversation

Duhemm
Copy link
Contributor

@Duhemm Duhemm commented Jun 14, 2017

The next release of Scala Native is coming soon, and it will add support for test frameworks using sbt's test interface (scala-native/scala-native#755). While implementing the test interface, I cross compiled utest to Scala Native.

Here are the changes that I did to get it to cross compile and work with Scala Native. Obviously, Scala Native 0.3.0 is not released yet, and you'll need to build Scala Native locally to test it. Here's what it looks like: https://travis-ci.org/Duhemm/scala-native/jobs/242582498#L2665-L2697

How to try it

After your system is set up, you can build Scala Native locally:

$ git clone https://github.com/scala-native/scala-native.git
$ cd scala-native
$ sbt rebuild

Then, build and publishLocally this PR. You can use the published artifact in a Scala Native project as shown here. Write your tests as usual and run them using test in sbt.

It would be great if we could get this PR in soon after Scala Native is released (I'll update it with the correct version numbers). Do you see things that need to be addressed in this PR while we wait for the next release of Scala Native?

Copy link
Collaborator

@japgolly japgolly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just two small changes and we're good.

  1. Now that native 0.3.0 is out can we drop the -SNAPSHOTs?
  2. Can you update .travis.yml please?

Also great work on the ScalaNative side!

@japgolly
Copy link
Collaborator

Thanks @xuwei-k

@Duhemm Duhemm changed the title [Do not merge yet] Cross compile to Scala Native Cross compile to Scala Native Jun 21, 2017
@Duhemm
Copy link
Contributor Author

Duhemm commented Jun 21, 2017

Thanks for the report @xuwei-k! These bugs will be fixed in Scala Native 0.3.1. And thank you for your fix 😉

@japgolly I've updated the PR with the changes you requested. Note that I also needed to modify some of the tests:

  • Two tests were using x / 0 to throw an exception. Unfortunately, in Scala Native, this results in a crash rather than just an exception thrown. I changed these tests to use Iterator.empty.next() instead. (here for instance)
  • The asynchronous tests try to schedule the tests so that they are completed after 2 seconds. This is not supported in Scala Native at the moment, as we can complete computations either immediately or at the end of the program (the second option wouldn't work for utest, as it will consider that the test never completed). I simply bypass the "not-completed-yet" check when we're running with Scala Native. (here for instance)
  • Two tests are using 0.asInstanceOf[String] to throw a ClassCastException, but Scala native doesn't throw an exception in this case. This is a bug in Scala Native that has been filled here: Add support for checked casts in debug mode scala-native/scala-native#858. (here for instance)

@Duhemm
Copy link
Contributor Author

Duhemm commented Jun 21, 2017

Could someone restart the build, please?

@lihaoyi
Copy link
Member

lihaoyi commented Jun 21, 2017

Just kicked it

@lihaoyi
Copy link
Member

lihaoyi commented Jun 21, 2017

After several more kicks, it has turned green

@lihaoyi
Copy link
Member

lihaoyi commented Jun 24, 2017

@japgolly up to you to merge/publish this, if you so desire

Copy link
Collaborator

@japgolly japgolly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@japgolly
Copy link
Collaborator

Mergerino!

@japgolly japgolly merged commit 7dadc7a into com-lihaoyi:master Jun 25, 2017
@japgolly
Copy link
Collaborator

Maybe I was too care-free in merging this. I just gave it a try locally. It compiles fine but when I run it:

[info] Linking (982 ms)
[info] Discovered 1893 classes and 11570 methods
[info] Optimizing (1277 ms)
[info] Generating intermediate code (264 ms)
[info] Produced 58 files
[info] Compiling to native code (1159 ms)
[error] /usr/bin/ld: /home/golly/projects/utest/utest/native/target/scala-2.11/native/lib/platform.c.o: relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
[error] /usr/bin/ld: /home/golly/projects/utest/utest/native/target/scala-2.11/native/lib/safepoint.c.o: relocation R_X86_64_32 against symbol `scalanative_safepoint_trigger' can not be used when making a shared object; recompile with -fPIC
[error] /usr/bin/ld: /home/golly/projects/utest/utest/native/target/scala-2.11/native/lib/unistd.c.o: relocation R_X86_64_PC32 against symbol `symlink@@GLIBC_2.2.5' can not be used when making a shared object; recompile with -fPIC
[error] /usr/bin/ld: final link failed: Bad value
[error] clang-4.0: error: linker command failed with exit code 1 (use -v to see invocation)
[info] Linking native code (132 ms)
[info] Starting process '/home/golly/projects/utest/utest/native/target/scala-2.11/utest-out' on port '9862'.
Exception in thread "Thread-1178" java.io.IOException: Cannot run program "/home/golly/projects/utest/utest/native/target/scala-2.11/utest-out": error=2, No such file or directory
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1048)
	at sbt.SimpleProcessBuilder.run(ProcessImpl.scala:349)
	at sbt.AbstractProcessBuilder.run(ProcessImpl.scala:128)
	at sbt.AbstractProcessBuilder$$anonfun$runBuffered$1.apply(ProcessImpl.scala:159)
	at sbt.AbstractProcessBuilder$$anonfun$runBuffered$1.apply(ProcessImpl.scala:159)
	at sbt.BufferedLogger.buffer(BufferedLogger.scala:25)
	at sbt.AbstractProcessBuilder.runBuffered(ProcessImpl.scala:159)
	at sbt.AbstractProcessBuilder.$bang(ProcessImpl.scala:156)
	at scala.scalanative.sbtplugin.testinterface.ComRunner$$anon$1.run(ComRunner.scala:35)
Caused by: java.io.IOException: error=2, No such file or directory
	at java.lang.UNIXProcess.forkAndExec(Native Method)
	at java.lang.UNIXProcess.<init>(UNIXProcess.java:247)
	at java.lang.ProcessImpl.start(ProcessImpl.java:134)
	at java.lang.ProcessBuilder.start(ProcessBuilder.java:1029)
	... 8 more
[trace] Stack trace suppressed: run last utestNative/nativetest:executeTests for the full output.
[error] (utestNative/nativetest:executeTests) java.lang.Exception: Couldn't communicate with remote runner.
[error] Total time: 5 s, completed 26/06/2017 10:00:11 AM

I don't really have time for this :(
Any suggestions, O' thine of more experience than I?

@densh
Copy link
Contributor

densh commented Jun 27, 2017

@japgolly Can you please file an issue on Scala Native with steps to reproduce and with the details on the environment? This looks like either an environment misconfiguration or a bug with should be able to fix in 0.3.1 which is planned for this week.

@ShaneDelmore
Copy link

Sorry to hear this isn't flawless but for some positive feedback for the work you are all doing, I used it this weekend and it was great, made my day to be able to write a command line application with unit tests and then see the app run and do real work in 0.035s 👍

@japgolly
Copy link
Collaborator

Raised scala-native/scala-native#881

And for what it's worth, I think all the work being done in this space is fucking awesome! I harbour much appreciation to all involved. Love seeing the progress 👍

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.

6 participants