-
-
Notifications
You must be signed in to change notification settings - Fork 286
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
ScalaJs compatibility #31
Comments
I have never tried. Would be interesting to check. I'll report here when I On Wed, Jul 1, 2015 at 7:33 PM, Omid Bakhshandeh [email protected]
-Nadav |
It's easy to check, that would be cool if it's compatible. |
The main issue I see right now in supporting ScalaJS is that the generated code relies on Google's Java protobuf runtime to do the bit-level IO, and there is no direct path of calling these functions from JS. Maybe it's possible to not depend on it (will have to look closely on what we are exactly using), or having ScalaPB specifically target JS by writing a ScalaJS binding for something like https://github.com/dcodeIO/bytebuffer.js |
I'm happy to announce that ScalaPB 0.5.15 has initial/experimental support for ScalaJS. Check out https://github.com/thesamet/scalapbjs-test |
👍 |
The next (configuration) problem is how to have one set of .proto files in a cross compiled js / jvm project. My actual goal is just to have the case classes (with lens goodness) available client side. I will probably not use binary serialization for the transport server <-> client (more like json with uPickle), but there can be other server <-> server communication going on earlier in the chain. |
This works for now: /**
* Settings for the protobuf compiler
*/
val protobufSource = sourceDirectory in PB.protobufConfig := file("shared/src/main/protobuf")
val protobufIncludePath = PB.includePaths in PB.protobufConfig := Seq(file("shared/src/main/protobuf"))
val protobufRunCommand = PB.runProtoc in PB.protobufConfig := (args => com.github.os72.protocjar.Protoc.runProtoc("-v300" +: args.toArray))
val protobufSettings = PB.protobufSettings :+ protobufSource :+ protobufIncludePath :+ protobufRunCommand and later lazy val cross = crossProject.in(file("."))
...
.jvmSettings(Settings.protobufSettings: _*)
.jsSettings(Settings.protobufSettings: _*) |
But the build fails as soon as I try to object Scalapb is not a member of package com.trueaccord.scalapb [info] Compiling schema /Users/per/Projects/src/scalapbjs-test/src/main/protobuf/test.proto
protoc-jar: protoc version: 300, detected platform: mac os x/x86_64
protoc-jar: executing: [/var/folders/3x/jrbzzzwn32zgnm9j900qvcyr0000gp/T/protoc6687187203628668231.exe, --plugin=protoc-gen-scala=/var/folders/3x/jrbzzzwn32zgnm9j900qvcyr0000gp/T/scalapbgen2742517121308194316, -I/Users/per/Projects/src/scalapbjs-test/src/main/protobuf, -I/Users/per/Projects/src/scalapbjs-test/target/protobuf_external, --scala_out=:/Users/per/Projects/src/scalapbjs-test/target/scala-2.11/src_managed/main/compiled_protobuf, /Users/per/Projects/src/scalapbjs-test/src/main/protobuf/test.proto]
[info] Compiling protobuf
[info] Protoc target directory: /Users/per/Projects/src/scalapbjs-test/target/scala-2.11/src_managed/main/compiled_protobuf
[info] Compiling 3 Scala sources to /Users/per/Projects/src/scalapbjs-test/target/scala-2.11/classes...
[error] /Users/per/Projects/src/scalapbjs-test/target/scala-2.11/src_managed/main/compiled_protobuf/com/trueaccord/test/TestProto.scala:19: object Scalapb is not a member of package com.trueaccord.scalapb
[error] com.trueaccord.scalapb.Scalapb.getDescriptor()
[error] ^
[error] one error found
[error] (compile:compile) Compilation failed
[error] Total time: 4 s, completed 2015-nov-29 16:21:02 |
Until there is a fix, you can work around it by putting scalapb.proto in your project's |
That gives me a |
@PerWiklander the |
Hi,
Is ScalaPB compatible with ScalaJS?
Thanks
The text was updated successfully, but these errors were encountered: