Google has released his PNaCl 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_canary
cd 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).
The samples are also avaliable in chrome store, and the link can also be found on this page.
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_LDFLAGS should be set before executing
I have followed the steps on the author’s blog for installing:
- Install Go 1.1
- Get PNaCl sdk, which contains Clang and LLVM
go get github.com/axw/llgo/cmd/llgo-dist
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
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.
Another attempt is
ruby. In ruby 2.0.0, the nacl support has been integrated, the document can be found here.
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.
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.