NaCl / PNaCl support for Go

742 views
Skip to first unread message

Nico

unread,
Sep 1, 2014, 3:18:04 PM9/1/14
to golan...@googlegroups.com
Hello,

I want to execute intensive computations on client side in a browser...and avoid C++...Since I played a little with Go and love it, Go/NaCl seems my best option

I read several things about the support of NaCl for Go, but I can't come to a clear conclusion.

Does Go support NaCl (as a chrome plugin) ? PNaCl ?

Go 1.3 release mentions NaCl support, and in this post, the conclusion seems that you can use it but only in a chrome extension...But in this doc, it's said "Support for Google Chrome is not planned..."

So do you know what's already possible and what is planned ?

Thanks for your help :-)

Andrew Gerrand

unread,
Sep 1, 2014, 7:14:24 PM9/1/14
to Nico, golang-nuts
Basically what the doc says is fact.

The Go 1.3 tool chain generates NaCl binaries that can be executed using the NaCl command-line tool, but does not support generating PNaCl binaries, which is what Chrome requires. PNaCl is pretty closely tied to LLVM; it's conceivable that when the llgo project is more mature we could start generating PNaCl Go programs that run in Chrome.

Andrew
  


--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Nico

unread,
Sep 2, 2014, 2:40:31 AM9/2/14
to golan...@googlegroups.com, lecr...@gmail.com
Thanks,

But my doubt remains about NaCl as a chrome application (so without PNaCl). I found here in the wiki that IRT and Pepper API are not supported yet, but what I would like to do is plain computation, no system call (except multithreading if possible), at least for now.

That is : take an input from javascript, make some intensive computations in Go and return a result.

Nico.

Tobia

unread,
Sep 2, 2014, 6:13:28 AM9/2/14
to golan...@googlegroups.com, lecr...@gmail.com
Until such a time when Go to PNaCl is feasible, you could try the existing Go to JS routes. Pick the most performant one, and then try to optimize it further. See this recent message for an overview. Given your need for intensive computation, I would start from the Emscripten one:

On Tuesday, February 4, 2014 7:41:04 AM UTC+1, Elliott Stoneham wrote:

There are currently at least three Go compilers being built that can generate JavaScript:
  1. GopherJS generates it directly;
  2. TARDISgo generates it indirectly (via Haxe); but
  3. llgo should be able to generate actual "asmjs" by processing its output using Emscripten
I gave a talk at FOSDEM on Sunday which included this subject. Only the slides are available at the moment, but a video is coming soon.

Eduard Castany

unread,
Sep 2, 2014, 7:15:25 PM9/2/14
to golan...@googlegroups.com, lecr...@gmail.com
https://developer.chrome.com/native-client/nacl-and-pnacl
Chrome requires PNaCl? omg I hope not :'(

El dimarts 2 de setembre de 2014 1:14:24 UTC+2, Andrew Gerrand va escriure:

David Anderson

unread,
Sep 2, 2014, 7:21:37 PM9/2/14
to Nico, golang-nuts
On Mon, Sep 1, 2014 at 11:40 PM, Nico <lecr...@gmail.com> wrote:
Thanks,

But my doubt remains about NaCl as a chrome application (so without PNaCl). I found here in the wiki that IRT and Pepper API are not supported yet, but what I would like to do is plain computation, no system call (except multithreading if possible), at least for now.

I believe PPAPI support is a requirement for any NaCl program that wants to run within Chrome. Without PPAPI, you can't get any data in or out of the sandbox, so you can't (in your case) pass in the data on which to compute, or output the results.

- Dave

Andrew Gerrand

unread,
Sep 2, 2014, 9:18:17 PM9/2/14
to Nico, Russ Cox, golang-nuts

On 2 September 2014 16:40, Nico <lecr...@gmail.com> wrote:
But my doubt remains about NaCl as a chrome application (so without PNaCl). I found here in the wiki that IRT and Pepper API are not supported yet, but what I would like to do is plain computation, no system call (except multithreading if possible), at least for now.

That is : take an input from javascript, make some intensive computations in Go and return a result.

So it is technically possible for Go's generated NaCl byte code to run in Chrome as part of a Chrome App or Extension (not using PNaCl), but we still need basic support for the Pepper API. You can't even do the simple task you have described without it.

IIRC, Russ (cc'd) ran into some problems trying to get basic NaCl syscalls (necessary to use Pepper) to work for Go 1.3. It was on the roadmap for Go 1.4 to get this working, but we ran out of time to get that done for this cycle (the tree just closed).

If someone with the time and requisite knowledge wants to take a stab at making it work, that would be great. But we have higher priorities right now, unfortunately.

Andrew

Nico

unread,
Sep 3, 2014, 2:24:20 PM9/3/14
to golan...@googlegroups.com, lecr...@gmail.com, r...@google.com
Ok,

I'm not sure I have the skills to do so, but I can give it a shot and keep you posted if something works.

But I have another (perhaps naive) idea, since we can call Go code from C (http://golang.org/cmd/cgo/), what about wrapping the Go function in C, and let the C wrapper interact with Javascript/PPAPI ?

If it's not possible, I'm afraid I will begin by coding in C while waiting quietly (maybe the 1.5 :-) ). I think I will have to write some critical parts in C anyway.

Andrew Gerrand

unread,
Sep 3, 2014, 8:43:06 PM9/3/14
to Nico, golang-nuts, Russ Cox

On 4 September 2014 04:24, Nico <lecr...@gmail.com> wrote:
I'm not sure I have the skills to do so, but I can give it a shot and keep you posted if something works.

But I have another (perhaps naive) idea, since we can call Go code from C (http://golang.org/cmd/cgo/), what about wrapping the Go function in C, and let the C wrapper interact with Javascript/PPAPI ?

If it's not possible, I'm afraid I will begin by coding in C while waiting quietly (maybe the 1.5 :-) ). I think I will have to write some critical parts in C anyway.

cgo isn't supported when generating nacl, unfortunately.

Andrew

andrewc...@gmail.com

unread,
Sep 4, 2014, 2:12:30 AM9/4/14
to golan...@googlegroups.com, lecr...@gmail.com
llgo won't have working goroutines when converted to javascript, it will block the browser thread.
GopherJS now has working non preempted go routines by using methods similar to core.async in clojure.

Nico

unread,
Sep 4, 2014, 2:52:25 AM9/4/14
to golan...@googlegroups.com, lecr...@gmail.com, andrewc...@gmail.com
The wise choice for now seems to stick with C/C++...
 
Any plan to release the C to Go translator used for the compiler porting ? I didn't find it

James Wendel

unread,
Sep 4, 2014, 3:00:52 AM9/4/14
to golan...@googlegroups.com
C2go is in Russ's personal repo: https://code.google.com/p/rsc/source/browse/#hg%2Fc2go

I'm not sure if it's up to date at this point.

Reply all
Reply to author
Forward
0 new messages