Currently, the official toolchain contains the Clang front end which can only be used to compile C/C++ source to PNaCl applications. But the PNaCl application is a subset of LLVM so I tried compiling some other languages with LLVM front ends to see if they would work. So far there hasn't been much progress but I'm still working on a solution and this post is just to document my attempts in hopes that others might learn from my experiences.
Toolchain InstallationThe PNaCl toolchain can be downloaded via Google's Native Client SDK. Follow the instruction for downloading and installing. Here's a recap of the commands I used:
./naclsdk install pepper_canary
cd pepper_canary/examples/hello_world; TOOLCHAIN=pnacl CONFIG=Release make
#enable-nacl-debugflag must not be enabled, or else the PNaCl application will not be able to load (ref). Samples are also avaliable in the Chrome store, and the link can also be found on this page.
Golang and llgoThe first language I tried was Golang. There is a Golang frontend for LLVM called llgo, and I have tried it to generate LLVM bytecode from my Golang program.
go getis recommended for installation of the
CGO_LDFLAGSshould be set before executing
go get. I followed steps from the author's blog to install:
- Install Go 1.1
- Get the PNaCl SDK (contains Clang and LLVM)
go get github.com/axw/llgo/cmd/llgo-dist
llgo-distto build and install the runtime
No matching .ll file for asm_darwin_amd64.s"error message. I filed an issue on Github and learned from the response that I needed to set target flag '-triple' to
i386-apple-macosx10.7.0. I then got another error while compiling the runtime with the
llgo-distcommand, which seems to be due to an upgrade of golang to 1.1. So I left
llgothere and anxiously await new updates from the project.
RubyAnother attempt is
ruby. Since Ruby 2.0.0, NaCl support has been integrated which is concisely documented here. During compilation of the Ruby source I got an
rdocerror, so I added
--disable-install-rdocto the configue command.
$ ./configure --prefix=/tmp/nacl-ruby --host=x86_64-nacl --with-baseruby=`which ruby` --disable-install-rdoc
Also I made a symbolic link of all directories in the /include SDK directory to Ruby for solving a 'header file not found' error.
$ ln -s /home/vagrant/source/nacl_sdk/pepper_canary/include/* ./
If running this command on any 64-bit OS, please make sure the 32-bit glibc library is installed, or some binaries may cause errors. I successfully compiled the native executable for Ruby, but for some reason which I'm still investigating, it can't be executed by the PNaCl binary.
Next stepsI will still try to write portable native client code with other languages. I just saw the author of
llgohas made some changes in Github so I plan to pull his changes. Stay tuned for another post on my progress. Not giving up yet!