Google's Native Code browser tech goes cross-platform
Write web modules in C/C++ that run on both Intel and ARM
Google I/O At its annual I/O conference in San Francisco this week, Google unveiled a new version of its Native Client technology that allows developers to deploy binary code for web applications in an architecture-independent way.
With the original version of Native Client (NaCl), developers could write modules in C or C++ and compile them into binary packages to be executed inside the browser at near-native speed. The initial release only supported 32-bit and 64-bit Intel x86 architectures, but Google added support for ARM in January.
The revamped version of the tech, dubbed Portable Native Client – PNaCl for short, pronounced "pinnacle" – still allows developers to target all three architectures, but now they can do so with a single executable package instead of compiling a separate package for each processor type.
It works by essentially breaking the process of compiling PNaCl modules into two steps. The PNaCl toolchain really only compiles the C/C++ code halfway, outputting LLVM compiler bitcode instead of native machine code. That bitcode is then packaged into a .pexe file for deployment.
The client browser handles the last mile itself, translating the bitcode of any .pexes it receives into whichever machine code format is appropriate for the platform on which it's running. That extra compilation step does add a bit of startup overhead, but not too much, and Google has been working to speed up the process even more.
PNaCl does have a few limitations, however. Unlike the earlier NaCl technology, PNaCl does not support linking with glibc, the standard C library found on many Unix-like systems. Instead, developers must statically link their PNaCl modules with the more lightweight Newlib library.
The new version of PNaCl, released on Wednesday, also introduces a new format for .pexe files. Modules created with older, experimental versions of the PNaCl toolchain will no longer work in browsers that support the latest version of the PNaCl spec.
That support is limited to Chrome version 29 or higher – which, for the time being at least, means only the bleeding-edge "Canary" releases of the browser. Fortunately, you can install Canary side-by-side with more stable versions of Chrome, so you're not forced to use it all the time.
Note, also, that PNaCl only works with Chrome running on Windows, OS X, Linux, and Chrome OS. Although it does support the ARM architecture, there is still no support for NaCl or PNaCl in Chrome for Android, so deploying binary modules for Android smartphones and tablets is out.
And the biggest catch of all, of course, is that Chrome is currently the only browser to support NaCl in any form, and it looks like it's going to stay that way.
That means web apps written using PNaCl will only run on Chrome, probably forever. But that's not all bad – as Google's Sundar Pichai observed in his Google I/O keynote, Chrome is the most popular browser in the world, after all.
For more technical information on PNaCl and its architecture, you can consult Google's technical paper on the system. Or, if you want to just dive in and try the tools, you can find instructions and downloads at the PNaCl project's homepage. ®
Sponsored: Network DDoS protection