scala-cli
scala-cli copied to clipboard
Error using bash process substitution with Scala Native and Scala.JS
Version(s)
0.1.12
Describe the bug Using bash process substitution with Scala Native doesn't work (Scala Native complains about missing definitions when linking)
To Reproduce
$ scala-cli run --native -S 2.13.8 <(echo 'println("Hello")')
Compiling project (Scala 2.13.8, Scala Native)
Compiled project (Scala 2.13.8, Scala Native)
[error] Found 2 missing definitions while linking
[error] Not found Top(input$minus1_sc)
[error] Not found Member(Top(input$minus1_sc),D4mainLAL16java.lang.String_uEo)
Exception in thread "main" scala.scalanative.linker.LinkingException: Undefined definitions found in reachability phase
at scala.scalanative.linker.Reach.fail(Reach.scala:976)
at scala.scalanative.linker.Reach.reportMissing(Reach.scala:971)
at scala.scalanative.linker.Reach.result(Reach.scala:47)
at scala.scalanative.linker.Reach$.apply(Reach.scala:989)
at scala.scalanative.linker.Link$.apply(Link.scala:13)
at scala.scalanative.build.ScalaNative$.$anonfun$link$1(ScalaNative.scala:32)
at scala.scalanative.build.Logger.time(Logger.scala:35)
at scala.scalanative.build.Logger.time$(Logger.scala:32)
at scala.scalanative.cli.utils.FilteredLogger.time(FilteredLogger.scala:5)
at scala.scalanative.build.ScalaNative$.link(ScalaNative.scala:32)
at scala.scalanative.build.Build$.$anonfun$build$1(Build.scala:65)
at scala.scalanative.build.Logger.time(Logger.scala:35)
at scala.scalanative.build.Logger.time$(Logger.scala:32)
at scala.scalanative.cli.utils.FilteredLogger.time(FilteredLogger.scala:5)
at scala.scalanative.build.Build$.build(Build.scala:55)
at scala.scalanative.cli.ScalaNativeLd$.$anonfun$runLd$3(ScalaNativeLd.scala:71)
at scala.scalanative.util.Scope$.apply(Scope.scala:32)
at scala.scalanative.cli.ScalaNativeLd$.runLd(ScalaNativeLd.scala:70)
at scala.scalanative.cli.ScalaNativeLd$.main(ScalaNativeLd.scala:44)
at scala.scalanative.cli.ScalaNativeLd.main(ScalaNativeLd.scala)
Error: scala.build.errors.ScalaNativeBuildError: Error compiling with Scala Native
For more details, please see '~/Library/Caches/ScalaCli/virtual-projects/9f/project-5324e786/.scala-build/stacktraces/1662635545-17065505834168618015.log'
$ cat ~/Library/Caches/ScalaCli/virtual-projects/9f/project-5324e786/.scala-build/stacktraces/1662635545-17065505834168618015.log
scala.build.errors.ScalaNativeBuildError: Error compiling with Scala Native
scala.cli.commands.Package$.buildNative$$anonfun$1(Package.scala:964)
scala.runtime.function.JProcedure1.apply(JProcedure1.java:15)
scala.runtime.function.JProcedure1.apply(JProcedure1.java:10)
scala.cli.packaging.Library$.withLibraryJar(Library.scala:26)
scala.cli.commands.Package$.buildNative(Package.scala:964)
scala.cli.commands.Run$.withNativeLauncher(Run.scala:478)
scala.cli.commands.Run$.runOnce$$anonfun$1(Run.scala:375)
scala.build.EitherCps$Helper.apply(EitherCps.scala:19)
scala.cli.commands.Run$.runOnce(Run.scala:444)
scala.cli.commands.Run$.maybeRunOnce$$anonfun$1(Run.scala:297)
scala.build.EitherCps$Helper.apply(EitherCps.scala:19)
scala.cli.commands.Run$.maybeRunOnce(Run.scala:300)
scala.cli.commands.Run$.maybeRun$1$$anonfun$1(Run.scala:137)
scala.build.EitherCps$Helper.apply(EitherCps.scala:19)
scala.cli.commands.Run$.maybeRun$1(Run.scala:167)
scala.cli.commands.Run$.run(Run.scala:251)
scala.cli.commands.Run$.run(Run.scala:48)
scala.cli.commands.Run$.run(Run.scala:42)
caseapp.core.app.CaseApp.main(CaseApp.scala:149)
caseapp.core.app.CommandsEntryPoint.main(CommandsEntryPoint.scala:120)
scala.cli.ScalaCliCommands.main(ScalaCliCommands.scala:121)
scala.cli.ScalaCli$.main0(ScalaCli.scala:188)
scala.cli.ScalaCli$.main(ScalaCli.scala:92)
scala.cli.ScalaCli.main(ScalaCli.scala)
Expected behaviour
$ scala-cli run --native -S 2.13.8 <(echo 'println("Hello")')
…
Hello
Same with Scala.JS:
$ scala-cli run --js -S 2.13.8 <(echo 'println("Hello")')
Referring to non-existent class input$minus1_sc
called from core module module initializers
Referring to non-existent method static input$minus1_sc.main([java.lang.String)void
called from core module module initializers
Exception in thread "main" org.scalajs.linker.interface.LinkingException: There were linking errors
at org.scalajs.linker.frontend.BaseLinker.reportErrors$1(BaseLinker.scala:91)
at org.scalajs.linker.frontend.BaseLinker.$anonfun$analyze$5(BaseLinker.scala:100)
at scala.concurrent.impl.Promise$Transformation.run(Promise.scala:467)
at java.util.concurrent.ForkJoinTask$RunnableExecuteAction.exec(ForkJoinTask.java:1395)
at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:373)
at java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1182)
at java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1655)
at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1622)
at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:165)
at com.oracle.svm.core.thread.PlatformThreads.threadStartRoutine(PlatformThreads.java:704)
at com.oracle.svm.core.posix.thread.PosixPlatformThreads.pthreadStartRoutine(PosixPlatformThreads.java:202)
[error] Error linking Scala.js
But it works on the JVM:
$ scala-cli run -S 2.13.8 <(echo 'println("Hello")')
Hello
Note that it works fine when using piping (cat foo.sc | scala-cli … _.sc
or passing a script directly, like scala-cli … foo.sc
).
Ran into this yesterday when testing out scalapy. Looks like an upstream bug. For Scala 2, Scala JS and Scala Native would fail to run if there's $
in the name of the object with main
method.
This would fail, even outside of scala-cli (I tested with sbt).
object some$object {
def main(args: Array[String]): Unit =
println("Hello")
}
[error] Found 2 missing definitions while linking
[error] Not found Top(some$object)
[error] Not found Member(Top(some$object),D4mainLAL16java.lang.String_uEo)
[error] Undefined definitions found in reachability phase
[error] (Compile / nativeLink) Undefined definitions found in reachability phase
[error] Total time: 4 s, completed 16 Sept 2022, 16:50:41
I think the same issue caused #1266.