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

ScalaJs compatibility #31

Closed
omidb opened this issue Jul 2, 2015 · 12 comments
Closed

ScalaJs compatibility #31

omidb opened this issue Jul 2, 2015 · 12 comments

Comments

@omidb
Copy link

omidb commented Jul 2, 2015

Hi,

Is ScalaPB compatible with ScalaJS?

Thanks

@thesamet
Copy link
Contributor

thesamet commented Jul 2, 2015

I have never tried. Would be interesting to check. I'll report here when I
get a chance.

On Wed, Jul 1, 2015 at 7:33 PM, Omid Bakhshandeh [email protected]
wrote:

Hi,

Is ScalaPB compatible with ScalaJS?

Thanks


Reply to this email directly or view it on GitHub
#31.

-Nadav

@omidb
Copy link
Author

omidb commented Jul 2, 2015

It's easy to check, that would be cool if it's compatible.

@He-Pin
Copy link

He-Pin commented Oct 29, 2015

@thesamet
Copy link
Contributor

thesamet commented Nov 7, 2015

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

@thesamet
Copy link
Contributor

I'm happy to announce that ScalaPB 0.5.15 has initial/experimental support for ScalaJS. Check out https://github.com/thesamet/scalapbjs-test

@omidb
Copy link
Author

omidb commented Nov 16, 2015

👍

@PerWiklander
Copy link

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.

@PerWiklander
Copy link

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: _*)

@PerWiklander
Copy link

But the build fails as soon as I try to import "scalapb/scalapb.proto" into my test.proto
The same happens in the original scalapbjs-test project.

 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

@thesamet
Copy link
Contributor

Until there is a fix, you can work around it by putting scalapb.proto in your project's src/main/protobuf/scalapb/ directory.

@PerWiklander
Copy link

That gives me a com.trueaccord.scalapb.ScalapbProto object with a lazy val descriptor = ... which does not match com.trueaccord.scalapb.Scalapb.getDescriptor()

@thesamet
Copy link
Contributor

thesamet commented Dec 1, 2015

@PerWiklander the scalapb.proto import issue has been fixed in 0.5.16. The scalapbjs-test project has been updated to exercise this: thesamet/scalapbjs-test@772e470

@thesamet thesamet closed this as completed Dec 7, 2015
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

No branches or pull requests

4 participants