NaCl, Native Client
NaCl is an obsolete technology now replaced by WebAssembly. It is no longer supported by the Google Chrome browser since 2018. This article is of purely historical interest.
The Native Client technology wants to accelerate Web applications at the point of giving them the speed of 3D games, allowing to run software programmed in C or C++ or another language in the browser.
Native Client, abbreviated NaCl, is supported by Chrome. Firefox supports it through a plugin. Google encourages game developers to make a version of their game for Chrome. The Unity 3D framework already allows to automatically generate a version for the browser.
Google itself ported the desktop software QuickOffice acquired in 2012 to NaCl, providing an alternative to Office in the browser.
To make the code more portable, developers have interfaced NaCl with the LLVM compiler which produces intermediate code, in turn compiled into machine code. This version, Portable NaCl, seems more practical in all respects.
Note that NaCl is the formula of sodium chloride, ie the common salt. Salt for your apps...
In June 2015, Google announced its participation with other browser editors in the WebAssembly project of bytecode running in the browser. This new backend combines the advantages of Asm.js with those of NaCl, so we expect that Google will stop supporting NaCl in the near future.
Creating a programming platform for Native Client
To develop on Native Client, you will need this software (The end user will not need for these tools):
- A local server, like Xampp.
- GNU Make to compile the examples or Visual Studio Express under Windows.
- The Native Client SDK.
- Python for some scripts.
LLVM offers a better support to Native Client since December 2, 2011. The new version of the C++ development platform facilitates the creation of applications under Native Client. It was already possible to use it in this context, but it was not in its design. Things have changed.
The instructions can change over time, look at the Getting Started manual for the last version.
- Download the Native Client SDK specific to an operating system, among Windows, Linux or MacOS.
- Create a directory, for example nacl, and unpack the contents.
- Read the Getting Started manual.
- Try a demonstration from command line.
- Bookmark the nacl/build/native_client page.
nacl is your installation directory.
- Close browsers supporting Native Client.
- Install the plugin at command line with scon.bat on Windows and scon on Unix.
To do this, run scon.bat or scon in /nacl/build/native_client/
- Start a local server as Wamp.
- Perform a check with the test page:
Who is in the directory /nacl/build/native_client/.
See the C++ tutorial for Native Client for more details.
With Chrome 14, NaCl has an interface between HTML 5 and the native code named Pepper or more precisely Pepper Plugin API, a new plugin system that replaces the current system invented by Netscape.
But this system is proprietary and is one of the reasons why NaCl was never supported by Firefox, besides the fact that Mozilla has an alternative in asm.js.
On old versions of Chrome you have to enable NaCl. Type about:flags in the address bar of Chrome and go to the entry native client. Click on enable.
PNaCl, a single compilation for all systems
Portable Native Client, or PNaCl, to be pronounced like Pinnacle, is a complement to NaCl which should remove the disadvantage of having to compile the application for each system. This is a set of tools that convert the NaCl application to LLVM bitcode. The latter is contained in a .pexe file which can be automatically converted into binary code at execution time.
It is also possible to directly execute LLVM by a virtual machine once implemented in the browser. This then make of PNaCl an alternative to Asm.js.
Running native apps in the browser, a simpler way...
This may be an alternative to NaCl to run native applications in the browser.
For example, try:
Then type ls to see files in the directory. Or to edit the file type:
Another solution again has been imagined, rendering a native GTK3 app in Canvas. Since version 3.2, GTK allows you to run native applications in the browser, a priori on a Linux system with a special backend called Broadway. It is not as portable.