Some failed attempts on PNaCl
Google has released his [PNaCl](http://www.chromium.org/nativeclient/pnacl /building-and-testing-portable-native-client) project on Google I/O 2013, which can allow user to write portable native client application. The portable native client application can be translated to native client program and executed on supported architecture.
The official toolchain contains clang frontend, which can only be used to compile C/C++ code to PNaCl application. But the PNaCl application is a subset of LLVM so I have tried some other languages have LLVM frontend. I am still working on the solution, and this article is just recording some failed attempts.
Install PNaCl toolchain
PNaCl toolchain can be downloaded via Native Client SDK, please follow the instruction for downloading and installing. Here are the commands used here:
./naclsdk install pepper_canaryexport NACL_SDK_ROOT=/where/you/put/the/pepper_canarycd pepper_canary/examples/hello_world; TOOLCHAIN=pnacl CONFIG=Release make
Chrome is also needed some setup, which also can be found in that page. NOTICE
that the #enable-nacl-debug flag can not be enabled, or the PNaCl
application will not be able to
loaded([ref](http://www.ahwkong.com/post/43309281489/native-client-see-only-
status-creating-embed)).
The samples are also avaliable in chrome store, and the link can also be found on [this page](http://www.chromium.org/nativeclient/pnacl/building-and- testing-portable-native-client).
Golang and llgo
The first language I tried is Golang. There is a Golang frontend for LLVM called llgo, and I have tried to use it for generating LLVM bitcode from Golang program.
go get is recommended to install the llgo package. The CGO_CFLAGS and
CGO_LDFLAGS should be set before executing go get. I have followed the
steps on the [author’s blog](http://blog.awilkins.id.au/2013/05/llgo-on-
go-11.html) for installing:
- Install Go 1.1
- Get PNaCl sdk, which contains Clang and LLVM
- Run
go get github.com/axw/llgo/cmd/llgo-dist - Run
llgo-distto build and install runtime
I was tried it on MacOS 10.7.5, but got the error message said No matching .ll file for "asm_darwin_amd64.s", I have filed an
issue and learned from response that I
can set target triple to x86_64-apple-macosx10.7.0 or i386-apple- macosx10.7.0 for solving this.
I have met compile error while compiling runtime by llgo-dist command, which
seems because of upgrade of golang to 1.1. So I leave llgo there and waiting
for some updates from author.
Ruby
Another attempt is ruby. In ruby 2.0.0, the nacl support has been
integrated, the document can be found [here](https://github.com/csigi/learning
ruby/blob/master/ruby2/ruby-2.0.0-rc1/nacl/README.nacl). During compiling the
ruby source, I have got an rdoc error, so I added --disable-install-rdoc
to the configue command.
$ ./configure --prefix=/tmp/nacl-ruby --host=x86_64-nacl --with-baseruby=`which ruby` --disable-install-rdoc
Also I made a symbol link of all directories in includes PNaCl sdk directory to ruby for solving header file not found error.
$ ln -s /home/vagrant/source/nacl_sdk/pepper_canary/include/* ./
If running this command on 64-bit OS, please make sure the 32-bit glibc library is installed, or some binaries may get error.
I have compiled the native executable for ruby, but it can’t be executed by PNaCl binary. I am still investigating on this.
Next step
I am still trying to write portable native client code with other languages. I
saw the author of llgo has made some changes and I will do the test. I will
update my post when got progress.
