[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / native_client_sdk / doc_generated / io2014.html
blob5b9c66d966bca2ec4fb94fdd5d9498910e8e1ff6
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&#8217;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&#8217;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&#8217;re working to reduce the number of steps in future releases.
30 As the process gets easier, we&#8217;ll update this page.</p>
31 <p>To install the development environment:</p>
32 <blockquote>
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>
39 </ul>
40 </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>
43 </ul>
44 </div></blockquote>
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&#8217;re ready to apply the debugger, follow these steps:</p>
48 <blockquote>
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>
58 </ul>
59 </li>
60 <li>NOTE: If you experience unexplained hangs, disable GDB-based debugging
61 temporarily and try again.</li>
62 </ul>
63 </div></blockquote>
64 </section><section id="editor">
65 <h3 id="editor">Editor</h3>
66 <p>To follow along in this tutorial, you&#8217;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&#8217;re unsure what to pick, nano is simpler to start with and has on-screen
71 help.</p>
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 &lt;filename&gt;
76 </pre>
77 <p>Here&#8217;s an online <a class="reference external" href="http://mintaka.sdsu.edu/reu/nano.html">nano tutorial</a>.</p>
78 </li>
79 <li><p class="first">You can open <strong>vim</strong> like this:</p>
80 <pre class="prettyprint">
81 $ vim &lt;filename&gt;
82 </pre>
83 <p>Here&#8217;s an online <a class="reference external" href="http://www.openvim.com/tutorial.html">vim tutorial</a>.</p>
84 </li>
85 </ul>
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&#8217;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 &quot;John Doe&quot;
96 git config --global user.email johndoe&#64;example.com
97 </pre>
98 <p>You can reload you <cite>~/.bashrc</cite> by running:</p>
99 <pre class="prettyprint">
100 source ~/.bashrc
101 </pre>
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">
106 $ mkdir work
107 $ cd work
108 </pre>
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
112 $ ls -l
113 </pre>
114 <p>Unzip the sample:</p>
115 <pre class="prettyprint">
116 $ unzip voronoi.zip
117 </pre>
118 <p>Go into the sample and take a look at the files inside:</p>
119 <pre class="prettyprint">
120 $ cd voronoi
121 $ ls
122 </pre>
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&#8217;s use git (a revision control program) to track our changes.</p>
130 <p>First, create a new repository:</p>
131 <pre class="prettyprint">
132 $ git init
133 </pre>
134 <p>Add everything here:</p>
135 <pre class="prettyprint">
136 $ git add .
137 </pre>
138 <p>Then commit our starting state:</p>
139 <pre class="prettyprint">
140 $ git commit -m &quot;imported voronoi demo&quot;
141 </pre>
142 <p>Now, likes run <strong>make</strong> to compile our program (NOTE: Changed since video,
143 we&#8217;ve got Makefiles!):</p>
144 <pre class="prettyprint">
145 $ make
146 </pre>
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'
151 </pre>
152 <p>We&#8217;ll need to start an editor to fix this.
153 You&#8217;ll want to change <em>hieght</em> to <em>height</em> on line 506.
154 Then rebuild:</p>
155 <pre class="prettyprint">
156 $ make -j10
157 </pre>
158 <p>Lets look at the diff:</p>
159 <pre class="prettyprint">
160 $ git diff
161 </pre>
162 <p>And commit our fix:</p>
163 <pre class="prettyprint">
164 $ git commit -am &quot;fixed build error&quot;
165 </pre>
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
168 now):</p>
169 <pre class="prettyprint">
170 $ make serve
171 </pre>
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&#8217;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">
183 </pre>
184 <p>You can see active threads with:</p>
185 <pre class="prettyprint">
186 info threads
187 </pre>
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
191 with:</p>
192 <pre class="prettyprint">
193 remote get irt irt
194 add-symbol-file irt
195 remote get nexe nexe
196 add-symbol-file nexe
197 </pre>
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>
203 <p>Then rebuild:</p>
204 <pre class="prettyprint">
205 $ make -j10
206 </pre>
207 <p>Check the diff and commit our fix:</p>
208 <pre class="prettyprint">
209 $ git diff
210 $ git commit -am &quot;fixed thread ui bug&quot;
211 </pre>
212 <p>Now look at your commit history:</p>
213 <pre class="prettyprint">
214 $ git log
215 </pre>
216 <p>Run the demo again. And everything now works:</p>
217 <pre class="prettyprint">
218 $ make serve
219 </pre>
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>
230 <blockquote>
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 &amp;&amp; . setup-environment</cite>)</li>
241 <li>Ruby (install with: <cite>package -i ruby &amp;&amp; . setup-environment</cite>)</li>
242 <li>Nethack! (install with: <cite>package -i nethack &amp;&amp; . setup-environment</cite>)</li>
243 </ul>
244 </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>
252 </ul>
253 </li>
254 </ul>
255 </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>
260 </ul>
261 </li>
262 </ul>
263 </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">
269 <li>ChromeOS</li>
270 <li>Mac OSX</li>
271 <li>Windows</li>
272 </ul>
273 </li>
274 </ul>
275 </li>
276 </ul>
277 </div></blockquote>
278 </section></section></section>
280 {{/partials.standard_nacl_article}}