Creating Native Client applications

From Web Computing Documentation
Jump to: navigation, search



Native Client (abbreviated as NaCl) is a technology available in Google Chrome that allows the execution of native code embedded into websites or browser extensions. The GridBee framework detects if the browser has Native Client capabilities and will request native client workunits by default. Only in other browsers or if the server has no NaCl workunits will the framework fall back to requesting JavaScript workunits.

Native Client offers superior performance and easier portability of existing applications than JavaScript. This page explains how to create NaCl executables that the GridBee framework can handle.

Enabling Native Client execution in Google Chrome

In the current version of Chrome Native Client is enabled by default for extensions installed from the Chrome Web Store. However our extension is currently only available as a download from our website.

If you would like to execute NaCl workunits with our extension or with a GridBee web application you have to enable NaCl for all web applications. In order to do this visit the chrome://flags/ address with your browser. Find the entry titled Native Client Mac, Windows, Linux, Chrome OS and click Enable under that. If you see a Disable button instead of Enable, NaCl is already enabled and you are set.

Compiling NaCl applications for GridBee and BOINC

This guide doesn't go into the details of the Native Client SDK but explains the necessary steps to compile existing C/C++ BOINC applications to NaCl executables. We also provide a tutorial that walks you through the porting of Seti@Home to Native Client.

  1. Download and install the Native Client SDK
    The SDK's documentation walks you through the few simple steps of installation. Note that the different versions of the Pepper API are backwards compatible. If you compile your programs with older API's they will still run on the latest versions of Chrome.
    Our Seti@Home tutorial provides scons scripts to build the application. The last Pepper API that contained scons was pepper_16. Therefore if you would like to walk through our Seti@Home tutorial without any modification installing the pepper_16 API is recommended. If you don't mind writing makefiles or installing scons separately feel free to use the latest recommended API version.
  2. Download and build our GridBee and BOINC enabled NaCl library
    Download the library's source code from GitHub and build it according to the instructions. Use the gridbee_boinc_framework directory instead of the BOINC framework when compiling your application.
  3. Modify your code to make it NaCl compliant
    The only modification you will certainly have to make is to change your program's main() function's name to my_main() since that is the entry point for NaCl applications. The rest you can figure out from the incidental error messages when building your program.
  4. Prepare the files for building your application
    In order to build your application you will need your application's source files, the previously compiled GridBee NaCl library (libgridbee.a) and the gridbee_boinc_framework directory which contains a modified BOINC framework.
  5. Create build scripts
    You can create scons scripts or makefiles relying on the NaCl SDK's modified gcc toolchain. You can check the build.scons file in our Seti@Home tutorial.
    When building you have to include the contents of the modified BOINC framework placed in gridbee_boinc_framework which is a part of the library mentioned in the previous paragraph. You need to use this directory instead of the original BOINC framework directory. When building you should include the following directories (part of a scons script).
    '-Igridbee_boinc_framework ',
    You also have to link your object files against the previously compiled GridBee NaCl library. For example in a scons script you would use
    where the lib32 and lib64 directories contain the different versions of the libgridbee.a file.
  6. Once the build has completed you should have two NaCl executable files (your_application_x86_32.nexe, your_application_x86_64.nexe) and an nmf file.

Deploying your NaCl workunit on BOINC

Once the compilation has finished you will have at least two .nexe and one .nmf files. BOINC workunits handled by the GridBee framework consist of at least 4 files e.g.


You can download the 4th file here. It is responsible for the workunit's communication with the GridBee framework through an iframe. You have to edit this file at the TODO: label to point at yourapplication.nmf.

Deploying your application is just as simple as deploying any other BOINC application.

  1. Create a new platform on the BOINC server called nacl
  2. Create an application under this platform that consists of the previously mentioned 4 files where yourapplication_1.00_nacl.html is the main executable of the application.

Enabling CORS

CORS is the technology enabling JavaScript applications from one domain to access servers on another. Our Chrome extension can access any BOINC server without CORS enabled but GridBee web applications can't. Thus if you would like to enable our web client for example ( you have to allow cross origin connections for your server.

If you use Apache2 you need to include the following header information.

<Directory "/home/boincadm/projects/myproj">
   Header set Access-Control-Allow-Origin "*"
   Header set Access-Control-Allow-Methods "GET, POST"
   Header set Access-Control-Allow-Headers "Content-Type"
   Header set Access-Control-Max-Age: 10

Where /home/boincadm/projects/myproj is your project directory.

This header would enable scripts residing under any domain to access resources on your server. If you would only like to enable some domains to access your contents modify the Access-Control-Allow-Origin property accordingly ie.

<Directory "/home/boincadm/projects/myproj">
   Header set Access-Control-Allow-Origin

This technique does not allow access to any files that shouldn't have been accessed otherwise through http. It only enables JavaScripts downloaded from other domains to access these resources as well.

Personal tools