Introduction to Portable Native Client
If you want to build a PNaCl application for Chrome, start with the Native Client developer documentation
The developer toolchain compiles C and C++ applications to a subset of LLVM bitcode.
These bitcode files (known as "portable executables", or "pexe" files) represent an Native Client application
in a high-level format, which can be translated to native code for execution on any processor supported
The PNaCl toolchain is currently available for Windows, Mac, and Linux.
PNaCl currently supports code generation on 4 architectures:
PNaCl is a cross-compiling toolchain, where the target architecture is bitcode. PNaCl recognizes three types of bitcode files:
.bc - LLVM Bitcode object file. (Analogous to an ELF object file)
.a - Archive of LLVM bitcode objects. (Analogous to a static library archive)
.pexe - LLVM or PNaCl Bitcode executable. (Analogous to an executable file)
PNaCl provides the standard tools:
pnacl-clang pnacl-clang++ pnacl-finalize pnacl-ld pnacl-ar pnacl-nm pnacl-ranlib pnacl-strip pnacl-as
The pnacl-clang and pnacl-clang++ tools produce LLVM bc files. The pnacl-ld linker tool produces a statically linked LLVM pexe. The pnacl-finalize tool converts an LLVM pexe to a frozen PNaCl bitcode pexe. Chrome only runs the frozen PNaCl bitcode format, not the standard LLVM bitcode pexe.
While chrome can load and translate a frozen pexe directly, there is an
pnacl-translate for generating native code from either LLVM or
PNaCl bitcode. That is useful for debugging (see the Debugging section below).
Installing the PNaCl Toolchain and Building Examples
PNaCl is now available in the naclsdk updater (https://developers.google.com/native-client/sdk/download). It is available in pepper_30 and higher.
Download the naclsdk updater, and run "naclsdk.bat update pepper_XX" (e.g., pepper_canary).
Once downloaded, you can set your NACL_SDK_ROOT directory to pepper_XX.
See pepper_canary/examples/ for various examples. The makefiles in each example directory should be configured to build pnacl pexes and generate manifest files for those pexes. Just set the "TOOLCHAIN" environment variable to be "pnacl". E.g.,
"(cd pepper_canary/examples/hello_world; TOOLCHAIN=pnacl CONFIG=Release make)".
With the PNaCl sdk, you can also try compiling some of the naclports examples. Once you have set the NACL_SDK_ROOT environment variable to point at the pepper directory with pnacl installed, you can run "make" to build a naclports target by setting the environment variable NACL_ARCH to "pnacl". E.g., to build dosbox, run
"NACL_ARCH=pnacl make dosbox".
That will build the required libraries (e.g., SDL), and build dosbox as a pexe. Libraries will be installed directly into your SDK and the resulting application (pexe) will be published under out/publish/dosbox.
How to Run Examples in Chrome 31+
- Check chrome://nacl to see if the PNaCl Translator is already
installed. The ~3-4MB download and install happens in the
- If not already installed, it will be installed on-demand the first time you start a PNaCl application. A good example application is the "load progress" example included here.
- An alternative is to go to chrome://components and click "Check for update".
- For Chrome 31, the on-demand install can sometimes still fail. Restart the browser and try again if that happens.
- Once installed, visit a webpage with a PNaCl NMF file that points at your pexe application (the SDK has a create_nmf.py tool that will help you create one). For example, try loading the samples here: http://gonativeclient.appspot.com/demo.
- NOTE: In contrast to a NaCl application, the mime type must be application/x-pnacl (not application/x-nacl).
How to report bugs / feedback for PNaCl
- Go to http://code.google.com/p/nativeclient/issues/list and file a New Issue.
- Describe the issue.
- Tag the issue as Component-PNaCl, and Arch-All (or a specific Arch if turns out that it is arch-specific)
The section on developing PNaCl itself has moved to https://www.chromium.org/nativeclient/pnacl/developing-pnacl