1 {{+bindTo:partials.standard_nacl_article}}
3 <section id=
"building-a-nacl-app">
4 <span id=
"io2014"></span><h1 id=
"building-a-nacl-app"><span id=
"io2014"></span>Building a NaCl App
</h1>
5 <section id=
"in-the-browser">
6 <h2 id=
"in-the-browser">In the browser!
</h2>
7 <p>Follow along with Brad Nelson
’s Google I/O
2014 talk.
8 Explore our new in-browser development environment and debugger.
</p>
9 <p>Learn how easy it is to edit, build, and debug NaCl application
10 all in your desktop web browser or on a Chromebook.
11 Work either on-line or off-line!
</p>
12 <iframe class=
"video" width=
"500" height=
"281"
13 src=
"//www.youtube.com/embed/OzNuzBDEWzk?rel=0" frameborder=
"0"></iframe><section id=
"work-in-progress">
14 <h3 id=
"work-in-progress">Work in Progress
</h3>
15 <p>These development tools are a work in progress, see
<a class=
"reference internal" href=
"#feature-status">Feature Status
</a>.
16 At this point, they are a learning tool and demonstration of NaCl
’s
17 flexibility, but are not the recommended tools for a production application.
18 To develop a substantial application for Native Client /
19 Portable Native Client,
20 we currently recommend you use the
21 <a class=
"reference external" href=
"/native-client/sdk/download">Native Client SDK
</a>.
</p>
22 <b><font color=
"#880000">
23 NOTE: The NaCl Development Environment is not yet stable.
24 Ideally user data is preserved, but currently it can be lost during updates
25 or sporadically. We're working to resolve this.
26 </font></b></section><section id=
"installation">
27 <h3 id=
"installation">Installation
</h3>
28 <p>The setup process currently requires several steps.
29 We
’re working to reduce the number of steps in future releases.
30 As the process gets easier, we
’ll update this page.
</p>
31 <p>To install the development environment:
</p>
33 <div><ul class=
"small-gap">
34 <li>Install the
<a class=
"reference external" href=
"https://chrome.google.com/webstore/detail/nacl-development-environm/aljpgkjeipgnmdpikaajmnepbcfkglfa">NaCl Development Environment
</a>.
</li>
35 <li><p class=
"first">Navigate to: chrome://flags and:
</p>
36 <ul class=
"small-gap">
37 <li>Enable
<strong>Native Client
</strong>.
</li>
38 <li>Restart your browser by clicking
<strong>Relaunch Now
</strong>.
</li>
41 <li>First run is slow (as it downloads and installs packages). Launch and allow
42 initial install to complete before first use.
</li>
45 <p>When initially experimenting with the development environment,
46 at this time, we recommend you run it without the debugger activated.
47 Once you
’re ready to apply the debugger, follow these steps:
</p>
49 <div><ul class=
"small-gap">
50 <li>Install a usable version of
51 <a class=
"reference external" href=
"http://www.chromium.org/getting-involved/dev-channel">Chrome Linux (M36+, Dev or Beta channel)
</a>.
</li>
52 <li>Install the
<a class=
"reference external" href=
"https://chrome.google.com/webstore/detail/nacl-debugger/ncpkkhabohglmhjibnloicgdfjmojkfd">Native Client Debugger Extension
</a>.
</li>
53 <li>Install
<a class=
"reference external" href=
"https://chrome.google.com/webstore/detail/gdb/gkjoooooiaohiceibmdleokniplmbahe">Native Client GDB
</a>.
</li>
54 <li><p class=
"first">Navigate to: chrome://flags and:
</p>
55 <ul class=
"small-gap">
56 <li>Enable
<strong>Native Client GDB-based debugging
</strong>.
</li>
57 <li>Restart your browser by clicking
<strong>Relaunch Now
</strong>.
</li>
60 <li>NOTE: If you experience unexplained hangs, disable GDB-based debugging
61 temporarily and try again.
</li>
64 </section><section id=
"editor">
65 <h3 id=
"editor">Editor
</h3>
66 <p>To follow along in this tutorial, you
’ll need to use a text editor to modify
67 various files in our development environment.
68 There are currently two editor options, nano or vim.
69 Emacs is coming soon...
70 If you
’re unsure what to pick, nano is simpler to start with and has on-screen
72 <ul class=
"small-gap">
73 <li><p class=
"first">You can open
<strong>nano
</strong> like this:
</p>
74 <pre class=
"prettyprint">
75 $ nano
<filename
>
77 <p>Here
’s an online
<a class=
"reference external" href=
"http://mintaka.sdsu.edu/reu/nano.html">nano tutorial
</a>.
</p>
79 <li><p class=
"first">You can open
<strong>vim
</strong> like this:
</p>
80 <pre class=
"prettyprint">
81 $ vim
<filename
>
83 <p>Here
’s an online
<a class=
"reference external" href=
"http://www.openvim.com/tutorial.html">vim tutorial
</a>.
</p>
86 </section><section id=
"git-setup">
87 <h3 id=
"git-setup">Git Setup
</h3>
88 <p>This tutorial also uses a revision control program called
89 <a class=
"reference external" href=
"http://en.wikipedia.org/wiki/Git_(software)">git
</a>.
90 In order to commit to a git repository,
91 you need to setup your environment to with your identity.
</p>
92 <p>You
’ll need to add these lines to
<cite>~/.bashrc
</cite> to cause them to be invoked each
93 time you start the development environment.
</p>
94 <pre class=
"prettyprint">
95 git config --global user.name
"John Doe
"
96 git config --global user.email johndoe
@example.com
98 <p>You can reload you
<cite>~/.bashrc
</cite> by running:
</p>
99 <pre class=
"prettyprint">
102 </section><section id=
"tour-follow-the-video">
103 <h3 id=
"tour-follow-the-video">Tour (follow the video)
</h3>
104 <p>Create a working directory and go into it:
</p>
105 <pre class=
"prettyprint">
109 <p>Download a zip file containing our sample:
</p>
110 <pre class=
"prettyprint">
111 $ curl http://nacltools.storage.googleapis.com/io2014/voronoi.zip -O
114 <p>Unzip the sample:
</p>
115 <pre class=
"prettyprint">
118 <p>Go into the sample and take a look at the files inside:
</p>
119 <pre class=
"prettyprint">
123 <p>Our project combines voronoi.cc with several C++ libraries to produce a NEXE
124 (or Native Client Executable).
</p>
125 <img alt=
"/native-client/images/voronoi1.png" src=
"/native-client/images/voronoi1.png" />
126 <p>The resulting application combines the NEXE with some Javascript to load
127 the NaCl module, producing the complete application.
</p>
128 <img alt=
"/native-client/images/voronoi2.png" src=
"/native-client/images/voronoi2.png" />
129 <p>Let
’s use git (a revision control program) to track our changes.
</p>
130 <p>First, create a new repository:
</p>
131 <pre class=
"prettyprint">
134 <p>Add everything here:
</p>
135 <pre class=
"prettyprint">
138 <p>Then commit our starting state:
</p>
139 <pre class=
"prettyprint">
140 $ git commit -m
"imported voronoi demo
"
142 <p>Now, likes run
<strong>make
</strong> to compile our program (NOTE: Changed since video,
143 we
’ve got Makefiles!):
</p>
144 <pre class=
"prettyprint">
147 <p>Oops, we get this error:
</p>
148 <pre class=
"prettyprint">
149 voronoi.cc: In member function 'void Voronoi::Update()':
150 voronoi.cc:
506: error: 'struct PSContext2D_t' has no member named 'hieght'
152 <p>We
’ll need to start an editor to fix this.
153 You
’ll want to change
<em>hieght
</em> to
<em>height
</em> on line
506.
155 <pre class=
"prettyprint">
158 <p>Lets look at the diff:
</p>
159 <pre class=
"prettyprint">
162 <p>And commit our fix:
</p>
163 <pre class=
"prettyprint">
164 $ git commit -am
"fixed build error
"
166 <p>To test our application, we run a local web server, written in python.
167 Run the server with this command (NOTE: Running through a Makefile
169 <pre class=
"prettyprint">
172 <p>Then, navigate to
<a class=
"reference external" href=
"http://localhost:5103/">http://localhost:
5103/
</a> to test the demo.
</p>
173 <p>If you follow along with the demo video, you will discover the sample crashes
174 when you change the thread count.
</p>
175 </section><section id=
"debugging">
176 <h3 id=
"debugging">Debugging
</h3>
177 <p>If you haven
’t installed the debugger at this point, skip to the next section.
</p>
178 <p>At this point, if you have the debugger installed, you should be able to open
179 the developer console and view the resulting crash.
</p>
180 <p>You can see a backtrace with:
</p>
181 <pre class=
"prettyprint">
184 <p>You can see active threads with:
</p>
185 <pre class=
"prettyprint">
188 <p>Currently, symbol information is limited for GLibC executables.
189 We have improvements coming that will improve the experience further.
</p>
190 <p>For newlib and PNaCl executables you can retrieve full symbols information
192 <pre class=
"prettyprint">
198 </section><section id=
"fix-it-up">
199 <h3 id=
"fix-it-up">Fix it up
</h3>
200 <p>Return to the development environment and stop the test server,
201 by pressing Ctrl-C.
</p>
202 <p>Open your editor again, navigate to line
485 and change
<em>valu
</em> to
<em>value
</em>.
</p>
204 <pre class=
"prettyprint">
207 <p>Check the diff and commit our fix:
</p>
208 <pre class=
"prettyprint">
210 $ git commit -am
"fixed thread ui bug
"
212 <p>Now look at your commit history:
</p>
213 <pre class=
"prettyprint">
216 <p>Run the demo again. And everything now works:
</p>
217 <pre class=
"prettyprint">
220 </section><section id=
"thanks">
221 <h3 id=
"thanks">Thanks
</h3>
222 <p>Thanks for checking out our environment.
223 Things are rapidly changing and in the coming months you can expect to see
224 further improvements and filling out of our platform and library support.
</p>
225 <p>Check back at this page for the latest status.
</p>
226 </section><section id=
"feature-status">
227 <h3 id=
"feature-status">Feature Status
</h3>
228 <p>Here is a summary of feature status. We hope to overcome these limitations
229 in the near future:
</p>
231 <div><ul class=
"small-gap">
232 <li><p class=
"first">NaCl Development Environment
</p>
233 <ul class=
"small-gap">
234 <li><p class=
"first">General
</p>
235 <ul class=
"small-gap">
236 <li><p class=
"first">Supported:
</p>
237 <ul class=
"small-gap">
238 <li>Python (built-in)
</li>
239 <li>GCC w/ GLibC (x86-
32 and x86-
64 only)
</li>
240 <li>Lua (install with:
<cite>package -i lua
&& . setup-environment
</cite>)
</li>
241 <li>Ruby (install with:
<cite>package -i ruby
&& . setup-environment
</cite>)
</li>
242 <li>Nethack! (install with:
<cite>package -i nethack
&& . setup-environment
</cite>)
</li>
245 <li><p class=
"first">Unsupported:
</p>
246 <ul class=
"small-gap">
247 <li>Targeting Newlib
</li>
248 <li>Targeting PNaCl
</li>
249 <li>Forking in bash
</li>
250 <li>Pipes / Redirection
</li>
251 <li>Symbolic and hard links
</li>
256 <li><p class=
"first">Missing / broken on ARM:
</p>
257 <ul class=
"small-gap">
258 <li>Git (broken)
</li>
259 <li>GCC (unsupported)
</li>
264 <li><p class=
"first">Debugger
</p>
265 <ul class=
"small-gap">
266 <li>Runs reliably only on a recent Beta or Dev Channel (M36+) build.
</li>
267 <li><p class=
"first">Currently unreliable on some platforms:
</p>
268 <ul class=
"small-gap">
278 </section></section></section>
280 {{/partials.standard_nacl_article}}