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 <h2 id=
"in-the-browser">In the browser!
</h2>
6 <p>Follow along with Brad Nelson
’s Google I/O
2014 talk.
7 Explore our new in-browser development environment and debugger.
</p>
8 <p>Learn how easy it is to edit, build, and debug NaCl application
9 all in your desktop web browser or on a Chromebook.
10 Work either on-line or off-line!
</p>
11 <iframe class=
"video" width=
"500" height=
"281"
12 src=
"//www.youtube.com/embed/OzNuzBDEWzk?rel=0" frameborder=
"0"></iframe><h3 id=
"our-web-based-tools">Our Web-based Tools
</h3>
13 <p>These development tools are a
<a class=
"reference external" href=
"nacldev">work in progress
</a>.
14 At this point, they are a learning tool and demonstration of NaCl
’s
15 flexibility, but are not the recommended tools for a production application.
16 In the future, that may change, but for the moment,
17 to develop a substantial application for Native Client /
18 Portable Native Client,
19 we recommend you use the
20 <a class=
"reference external" href=
"/native-client/sdk/download">Native Client SDK
</a>.
</p>
21 <b><font color=
"#880000">
22 NOTE: The NaCl Development Environment is not yet stable.
23 Ideally, user data is preserved, but currently it can be lost during updates
24 or sporadically. We're working to resolve this.
25 </font></b><h3 id=
"installation">Installation
</h3>
26 <p>The setup process currently requires several steps.
27 We
’re working to reduce the number of steps in future releases.
28 As the process gets easier, we
’ll update this page.
</p>
29 <p>To install the development environment:
</p>
31 <div><ul class=
"small-gap">
32 <li>Install the
<a class=
"reference external" href=
"https://chrome.google.com/webstore/detail/nacl-development-environm/aljpgkjeipgnmdpikaajmnepbcfkglfa">NaCl Development Environment
</a>.
</li>
33 <li><p class=
"first">Navigate to: chrome://flags and:
</p>
34 <ul class=
"small-gap">
35 <li>Enable
<strong>Native Client
</strong>.
</li>
36 <li>Restart your browser by clicking
<strong>Relaunch Now
</strong>.
</li>
39 <li>First run is slow (as it downloads and installs packages). Launch and allow
40 initial install to complete before first use.
</li>
43 <p>When initially experimenting with the development environment,
44 at this time, we recommend you run it without the debugger activated.
45 Once you
’re ready to apply the debugger, follow these steps:
</p>
47 <div><ul class=
"small-gap">
48 <li>Install a usable version of
49 <a class=
"reference external" href=
"http://www.chromium.org/getting-involved/dev-channel">Chrome Linux (M36+, Dev or Beta channel)
</a>.
</li>
50 <li>Install the
<a class=
"reference external" href=
"https://chrome.google.com/webstore/detail/nacl-debugger/ncpkkhabohglmhjibnloicgdfjmojkfd">Native Client Debugger Extension
</a>.
</li>
51 <li>Install
<a class=
"reference external" href=
"https://chrome.google.com/webstore/detail/gdb/gkjoooooiaohiceibmdleokniplmbahe">Native Client GDB
</a>.
</li>
52 <li><p class=
"first">Navigate to: chrome://flags and:
</p>
53 <ul class=
"small-gap">
54 <li>Enable
<strong>Native Client GDB-based debugging
</strong>.
</li>
55 <li>Restart your browser by clicking
<strong>Relaunch Now
</strong>.
</li>
58 <li>NOTE: If you experience unexplained hangs, disable GDB-based debugging
59 temporarily and try again.
</li>
62 <h4 id=
"editing">Editing
</h4>
63 <p>To follow along in this codelab, you
’ll need to use a text editor to modify
64 various files in our development environment.
65 There are currently two editor options, nano or vim.
66 We have an Emacs port, but it is not yet available in the Dev Environment
68 If you
’re unsure what to pick, nano is simpler to start with and has on-screen
70 <ul class=
"small-gap">
71 <li><p class=
"first">You can open
<strong>nano
</strong> like this:
</p>
72 <pre class=
"prettyprint">
73 $ nano
<filename
>
75 <p>Here
’s an online
<a class=
"reference external" href=
"http://mintaka.sdsu.edu/reu/nano.html">nano tutorial
</a>.
</p>
77 <li><p class=
"first">You can open
<strong>vim
</strong> like this:
</p>
78 <pre class=
"prettyprint">
79 $ vim
<filename
>
81 <p>Here
’s an online
<a class=
"reference external" href=
"http://www.openvim.com/tutorial.html">vim tutorial
</a>.
</p>
84 <h3 id=
"git-setup">Git Setup
</h3>
85 <p>This tutorial also uses a revision control program called
86 <a class=
"reference external" href=
"http://en.wikipedia.org/wiki/Git_(software)">git
</a>.
87 In order to commit to a git repository,
88 you need to set up your identity.
</p>
89 <p>Run these commands (with your info) to setup your
<cite>~/.gitconfig
</cite>
91 <pre class=
"prettyprint">
92 git config --global user.name
"John Doe
"
93 git config --global user.email johndoe
@example.com
95 <h3 id=
"tour-follow-the-video">Tour (follow the video)
</h3>
96 <p>Create a working directory and go into it:
</p>
97 <pre class=
"prettyprint">
101 <p>Download a zip file containing our sample:
</p>
102 <pre class=
"prettyprint">
103 $ curl http://nacltools.storage.googleapis.com/io2014/voronoi.zip -O
106 <p>Unzip the sample:
</p>
107 <pre class=
"prettyprint">
110 <p>Go into the sample and take a look at the files inside:
</p>
111 <pre class=
"prettyprint">
115 <p>Our project combines voronoi.cc with several C++ libraries to produce a NEXE
116 (or Native Client Executable).
</p>
117 <img alt=
"/native-client/images/voronoi1.png" src=
"/native-client/images/voronoi1.png" />
118 <p>The resulting application combines the NEXE with some Javascript to load
119 the NaCl module, producing the complete application.
</p>
120 <img alt=
"/native-client/images/voronoi2.png" src=
"/native-client/images/voronoi2.png" />
121 <p>Let
’s use git (a revision control program) to track our changes.
</p>
122 <p>First, create a new repository:
</p>
123 <pre class=
"prettyprint">
126 <p>Add everything here:
</p>
127 <pre class=
"prettyprint">
130 <p>Then commit our starting state:
</p>
131 <pre class=
"prettyprint">
132 $ git commit -m
"imported voronoi demo
"
134 <p>Now, likes run
<strong>make
</strong> to compile our program (NOTE: Changed since video,
135 we
’ve got Makefiles!):
</p>
136 <pre class=
"prettyprint">
139 <p>Oops, we get this error:
</p>
140 <pre class=
"prettyprint">
141 voronoi.cc: In member function 'void Voronoi::Update()':
142 voronoi.cc:
506: error: 'struct PSContext2D_t' has no member named 'hieght'
144 <p>We
’ll need to start an editor to fix this.
145 You
’ll want to change
<em>hieght
</em> to
<em>height
</em> on line
506.
147 <pre class=
"prettyprint">
150 <p>Lets look at the diff:
</p>
151 <pre class=
"prettyprint">
154 <p>And commit our fix:
</p>
155 <pre class=
"prettyprint">
156 $ git commit -am
"fixed build error
"
158 <p>To test our application, we run a local web server, written in python.
159 Run the server with this command (NOTE: Running through a Makefile
161 <pre class=
"prettyprint">
164 <p>Then, navigate to
<a class=
"reference external" href=
"http://localhost:5103/">http://localhost:
5103/
</a> to test the demo.
</p>
165 <p>If you follow along with the demo video, you will discover the sample crashes
166 when you change the thread count.
</p>
167 <h3 id=
"debugging">Debugging
</h3>
168 <p>If you haven
’t installed the debugger at this point, skip to the next section.
</p>
169 <p>At this point, if you have the debugger installed, you should be able to open
170 the developer console and view the resulting crash.
</p>
171 <p>You can see a backtrace with:
</p>
172 <pre class=
"prettyprint">
175 <p>You can see active threads with:
</p>
176 <pre class=
"prettyprint">
179 <p>Currently, symbol information is limited for GLibC executables.
180 We have improvements coming that will improve the experience further.
</p>
181 <p>For newlib and PNaCl executables you can retrieve full symbols information
183 <pre class=
"prettyprint">
189 <h3 id=
"fix-it-up">Fix it up
</h3>
190 <p>Return to the development environment and stop the test server,
191 by pressing Ctrl-C.
</p>
192 <p>Open your editor again, navigate to line
485 and change
<em>valu
</em> to
<em>value
</em>.
</p>
194 <pre class=
"prettyprint">
197 <p>Check the diff and commit our fix:
</p>
198 <pre class=
"prettyprint">
200 $ git commit -am
"fixed thread ui bug
"
202 <p>Now look at your commit history:
</p>
203 <pre class=
"prettyprint">
206 <p>Run the demo again. And everything now works:
</p>
207 <pre class=
"prettyprint">
210 <h3 id=
"thanks">Thanks
</h3>
211 <p>Thanks for checking out our environment.
212 Things are rapidly changing and in the coming months you can expect to see
213 further improvements and filling out of our platform and library support.
</p>
214 <p>Follow the status of the NaCl Dev Environment at
<a class=
"reference internal" href=
"/native-client/nacldev.html"><em>this page
</em></a>.
</p>
217 {{/partials.standard_nacl_article}}