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