Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 ################### | |
| 2 Building a NaCl App | |
| 3 ################### | |
| 4 In the browser! | |
| 5 --------------- | |
| 6 | |
| 7 Follow along with Brad Nelson's Google I/O 2014 talk. | |
| 8 Explore our new in-browser development environment and debugger. | |
| 9 | |
| 10 Learn how easy it is to edit, build, and debug NaCl application | |
| 11 all in your desktop web browser or on a Chromebook. | |
| 12 Work either on-line or off-line! | |
| 13 | |
| 14 .. raw:: html | |
| 15 | |
| 16 <iframe class="video" width="640" height="360" | |
| 17 src="//www.youtube.com/embed/MvKEomoiKBA?rel=0" frameborder="0"></iframe> | |
| 18 | |
| 19 | |
| 20 Installation | |
| 21 ============ | |
| 22 | |
| 23 The setup process currently requires several steps. | |
| 24 We're working to reduce the number of steps in future releases. | |
| 25 As the process gets easier, we'll update this page. | |
| 26 | |
| 27 You currently need to: | |
| 28 | |
| 29 * Navigate to: chrome://flags and: | |
| 30 | |
| 31 * Enable **Native Client**. | |
| 32 * Enable **Native Client GDB-based debugging**. (For the debugger) | |
| 33 | |
| 34 * Follow these instructions to | |
| 35 `Setup GDB <https://nacltools.storage.googleapis.com/install.html>`_ | |
| 36 | |
| 37 * Install the `NaCl Development Environment <https://chrome.google.com/webstore/ detail/nacl-development-environm/aljpgkjeipgnmdpikaajmnepbcfkglfa>`_. | |
| 38 | |
| 39 * First run is slow (as it downloads and installs packages). | |
| 40 | |
| 41 | |
| 42 Editor | |
| 43 ====== | |
| 44 | |
| 45 To follow along in this tutorial, you'll need to use a text editor to modify | |
| 46 various files in our development environment. | |
| 47 There are currently two editor options, nano or vim. | |
| 48 Emacs is coming soon... | |
| 49 If you're unsure what to pick, nano is simpler to start with and has on-screen | |
| 50 help. | |
| 51 | |
| 52 * You can open **nano** like this: | |
| 53 .. naclcode:: | |
| 54 | |
| 55 nano <filename> | |
| 56 | |
| 57 Here's an online `nano tutorial <http://mintaka.sdsu.edu/reu/nano.html>`_. | |
| 58 | |
| 59 * You can open **vim** like this: | |
| 60 .. naclcode:: | |
| 61 | |
| 62 vim <filename> | |
| 63 | |
| 64 Here's an online `vim tutorial <http://www.openvim.com/tutorial.html>`_. | |
| 65 | |
| 66 | |
| 67 Git Setup | |
| 68 ========= | |
| 69 | |
| 70 This tutorial also uses a revision control program called | |
| 71 `git <http://en.wikipedia.org/wiki/Git_(software)>`_. | |
| 72 In order to commit to a git repository, | |
| 73 you need to setup your environment to with your identity. | |
| 74 | |
| 75 You'll need to add these lines to `~/.bashrc` to cause them to be invoked each | |
| 76 time you start the development environment. | |
| 77 | |
| 78 .. naclcode:: | |
| 79 | |
| 80 git config --global user.name "John Doe" | |
| 81 git config --global user.email johndoe@example.com | |
| 82 | |
| 83 | |
| 84 Tour (follow the video) | |
| 85 ======================= | |
| 86 | |
| 87 Create a working directory and go into it. | |
| 88 | |
| 89 .. naclcode:: | |
| 90 | |
| 91 mkdir work | |
| 92 cd work | |
| 93 | |
| 94 Download a zip file containing our sample. | |
| 95 | |
| 96 .. naclcode:: | |
| 97 | |
| 98 curl http://nacltools.sotrage.googlepapis.com/io2014/voronoi.zip -O | |
| 99 ls -l | |
| 100 | |
| 101 Unzip the sample. | |
| 102 | |
| 103 .. naclcode:: | |
| 104 | |
| 105 unzip voronoi.zip | |
| 106 | |
| 107 Go into the sample and take a look at the files inside. | |
| 108 | |
| 109 .. naclcode:: | |
| 110 | |
| 111 cd voronoi | |
| 112 ls | |
| 113 | |
| 114 Our project combines voronoi.cc with several C++ libraries to produce a NEXE | |
| 115 (or Native Client Executable). | |
| 116 | |
| 117 .. raw:: html | |
| 118 | |
| 119 <svg width="600" height="200"> | |
| 120 <defs> | |
| 121 <marker id="markerArrow" markerWidth="13" markerHeight="13" | |
| 122 refx="2" refy="6" orient="auto"> | |
| 123 <path d="M2,2 L2,11 L10,6 L2,2" style="fill: #000000;" /> | |
| 124 </marker> | |
| 125 </defs> | |
| 126 | |
| 127 <g transform="translate(10,10)"> | |
| 128 <rect x="0" y="0" rx="20" ry="20" width="100" height="50" | |
| 129 style="fill:#cc0000;stroke:black;stroke-width:3" /> | |
| 130 <text x="50" y="25" fill="white" text-anchor="middle" | |
| 131 alignment-baseline="middle">voronoi.cc</text> | |
| 132 </g> | |
| 133 <g transform="translate(10,70)"> | |
| 134 <rect x="0" y="0" rx="20" ry="20" width="100" height="50" | |
| 135 style="fill:#cccc00;stroke:black;stroke-width:3" /> | |
| 136 <text x="50" y="25" fill="white" text-anchor="middle" | |
| 137 alignment-baseline="middle">libraries</text> | |
| 138 </g> | |
| 139 <g transform="translate(210,10)"> | |
| 140 <rect x="0" y="0" rx="20" ry="20" width="100" height="50" | |
| 141 style="fill:#0000cc;stroke:black;stroke-width:3" /> | |
| 142 <text x="50" y="25" fill="white" text-anchor="middle" | |
| 143 alignment-baseline="middle">voronoi.nexe</text> | |
| 144 </g> | |
| 145 <path d="M110,35 L195,30" | |
| 146 style="stroke:black; stroke-width: 2px; marker-end: url(#markerArrow);"/> | |
| 147 <path d="M110,95 L195,50" | |
| 148 style="stroke:black; stroke-width: 2px; marker-end: url(#markerArrow);"/> | |
| 149 | |
| 150 <text x="50" y="155" fill="black" text-anchor="middle" | |
| 151 alignment-baseline="middle">build.sh</text> | |
| 152 <path d="M80,155 L300,155" | |
| 153 stroke-dasharray="5,5" d="M5 20 l215 0" | |
| 154 style="stroke:black; stroke-width: 2px; marker-end: url(#markerArrow);"/> | |
| 155 </svg> | |
|
Sam Clegg
2014/06/19 01:09:52
Woah.. what is this? Some kind of diagram?
bradn
2014/06/19 17:22:55
Yeah there are two, similar to the ones from the t
| |
| 156 | |
| 157 The resulting application combines some Javascript to load the module with | |
| 158 voronoi.nexe, producing the complete application. | |
| 159 | |
| 160 .. raw:: html | |
| 161 | |
| 162 <svg width="600" height="200"> | |
| 163 <defs> | |
| 164 <marker id="markerArrow" markerWidth="13" markerHeight="13" | |
| 165 refx="2" refy="6" orient="auto"> | |
| 166 <path d="M2,2 L2,11 L10,6 L2,2" style="fill: #000000;" /> | |
| 167 </marker> | |
| 168 </defs> | |
| 169 | |
| 170 <g transform="translate(10,10)"> | |
| 171 <rect x="0" y="0" rx="20" ry="20" width="100" height="50" | |
| 172 style="fill:#cc0000;stroke:black;stroke-width:3" /> | |
| 173 <text x="50" y="25" fill="white" text-anchor="middle" | |
| 174 alignment-baseline="middle">voronoi.nexe</text> | |
| 175 </g> | |
| 176 <g transform="translate(10,70)"> | |
| 177 <rect x="0" y="0" rx="20" ry="20" width="100" height="50" | |
| 178 style="fill:#cccc00;stroke:black;stroke-width:3" /> | |
| 179 <text x="50" y="25" fill="white" text-anchor="middle" | |
| 180 alignment-baseline="middle">example.js</text> | |
| 181 </g> | |
| 182 <g transform="translate(210,10)"> | |
| 183 <rect x="0" y="0" rx="20" ry="20" width="100" height="50" | |
| 184 style="fill:#0000cc;stroke:black;stroke-width:3" /> | |
| 185 <text x="50" y="25" fill="white" text-anchor="middle" | |
| 186 alignment-baseline="middle">Web App</text> | |
| 187 </g> | |
| 188 <path d="M110,35 L195,30" | |
| 189 style="stroke:black; stroke-width: 2px; marker-end: url(#markerArrow);"/> | |
| 190 <path d="M110,95 L195,50" | |
| 191 style="stroke:black; stroke-width: 2px; marker-end: url(#markerArrow);"/> | |
| 192 | |
| 193 <text x="50" y="155" fill="black" text-anchor="middle" | |
| 194 alignment-baseline="middle">demo.py</text> | |
| 195 <path d="M80,155 L300,155" | |
| 196 stroke-dasharray="5,5" d="M5 20 l215 0" | |
| 197 style="stroke:black; stroke-width: 2px; marker-end: url(#markerArrow);"/> | |
| 198 </svg> | |
| 199 | |
| 200 Let's use git (a revision control program) to track our changes. | |
| 201 | |
| 202 First, create a new repository: | |
| 203 | |
| 204 .. naclcode:: | |
| 205 | |
| 206 git init | |
| 207 | |
| 208 Add everything here: | |
| 209 | |
| 210 .. naclcode:: | |
| 211 | |
| 212 git add . | |
| 213 | |
| 214 Then commit our starting state. | |
| 215 | |
| 216 .. naclcode:: | |
| 217 | |
| 218 git commit -m "imported voronoi demo" | |
| 219 | |
| 220 | |
| 221 Now, lets invoke the bash build script to compile our program: | |
| 222 | |
| 223 .. naclcode:: | |
| 224 | |
| 225 ./build.sh | |
| 226 | |
| 227 Oops, we get this error: | |
| 228 | |
| 229 .. naclcode:: | |
| 230 | |
| 231 voronoi.cc: In member function 'void Voronoi::Update()': | |
| 232 voronoi.cc:506: error: 'struct PSContext2D_t' has no member named 'hieght' | |
| 233 | |
| 234 We'll need to start an editor to fix this. | |
| 235 You'll want to change *hieght* to *height* on line 506. | |
| 236 | |
| 237 Then rebuild: | |
| 238 | |
| 239 .. naclcode:: | |
| 240 | |
| 241 bash build.sh | |
| 242 | |
| 243 Lets look at the diff. | |
| 244 | |
| 245 .. naclcode:: | |
|
Sam Clegg
2014/06/19 01:09:52
I don't like all this use of naclcode:: for things
bradn
2014/06/19 17:22:55
Done.
| |
| 246 | |
| 247 git diff | |
| 248 | |
| 249 And commit our fix. | |
| 250 | |
| 251 .. naclcode:: | |
| 252 | |
| 253 git commit -am "fixed build error" | |
| 254 | |
| 255 We can now run the demo with this command. | |
| 256 | |
| 257 .. naclcode:: | |
| 258 | |
| 259 python ${PWD}/demo.py | |
| 260 | |
| 261 Navigate to http://localhost:5103/ to test the demo. | |
| 262 | |
| 263 If you follow along with the demo video, you will discover the sample crashes | |
| 264 when you change the thread count. | |
| 265 | |
| 266 *Debugger walk-thru coming soon.* | |
| 267 | |
| 268 Once you've identified the problem. You'll want to stop the test server. | |
| 269 Press enter to halt it. | |
| 270 | |
| 271 Open your editor again, navigate to line 485 and change *valu* to *value*. | |
| 272 | |
| 273 Then rebuild. | |
| 274 | |
| 275 .. naclcode:: | |
| 276 | |
| 277 bash build.sh | |
| 278 | |
| 279 Check the diff and commit our fix. | |
| 280 | |
| 281 .. naclcode:: | |
| 282 | |
| 283 git diff | |
| 284 git commit -am "fixed thread ui bug" | |
| 285 | |
| 286 Now look at your commit history. | |
| 287 | |
| 288 .. naclcode:: | |
| 289 | |
| 290 git log | |
| 291 | |
| 292 Run the demo again. And everything now works. | |
| 293 | |
| 294 .. naclcode:: | |
| 295 | |
| 296 python ${PWD}/demo.py | |
|
Sam Clegg
2014/06/19 01:09:52
Sometgimes is nice to include the leading "$ " in
bradn
2014/06/19 17:22:55
Thought about doing that.
Done.
| |
| OLD | NEW |