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 :: | |
| 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 :: | |
| 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 | |
| 79 $ git config --global user.name "John Doe" | |
| 80 $ git config --global user.email johndoe@example.com | |
| 81 | |
| 82 Tour (follow the video) | |
| 83 ======================= | |
| 84 | |
| 85 Create a working directory and go into it. | |
| 86 :: | |
| 87 | |
| 88 $ mkdir work | |
| 89 $ cd work | |
| 90 | |
| 91 Download a zip file containing our sample. | |
| 92 :: | |
| 93 | |
| 94 $ curl http://nacltools.sotrage.googlepapis.com/io2014/voronoi.zip -O | |
| 95 $ ls -l | |
| 96 | |
| 97 Unzip the sample. | |
| 98 :: | |
| 99 | |
| 100 $ unzip voronoi.zip | |
| 101 | |
| 102 Go into the sample and take a look at the files inside. | |
| 103 :: | |
| 104 | |
| 105 $ cd voronoi | |
| 106 $ ls | |
| 107 | |
| 108 Our project combines voronoi.cc with several C++ libraries to produce a NEXE | |
| 109 (or Native Client Executable). | |
| 110 | |
| 111 .. raw:: html | |
| 112 | |
| 113 <svg width="600" height="200"> | |
| 114 <defs> | |
| 115 <marker id="markerArrow" markerWidth="13" markerHeight="13" | |
| 116 refx="2" refy="6" orient="auto"> | |
| 117 <path d="M2,2 L2,11 L10,6 L2,2" style="fill: #000000;" /> | |
| 118 </marker> | |
| 119 </defs> | |
| 120 | |
| 121 <g transform="translate(10,10)"> | |
| 122 <rect x="0" y="0" rx="20" ry="20" width="100" height="50" | |
| 123 style="fill:#cc0000;stroke:black;stroke-width:3" /> | |
| 124 <text x="50" y="25" fill="white" text-anchor="middle" | |
| 125 alignment-baseline="middle">voronoi.cc</text> | |
| 126 </g> | |
| 127 <g transform="translate(10,70)"> | |
| 128 <rect x="0" y="0" rx="20" ry="20" width="100" height="50" | |
| 129 style="fill:#cccc00;stroke:black;stroke-width:3" /> | |
| 130 <text x="50" y="25" fill="white" text-anchor="middle" | |
| 131 alignment-baseline="middle">libraries</text> | |
| 132 </g> | |
| 133 <g transform="translate(210,10)"> | |
| 134 <rect x="0" y="0" rx="20" ry="20" width="100" height="50" | |
| 135 style="fill:#0000cc;stroke:black;stroke-width:3" /> | |
| 136 <text x="50" y="25" fill="white" text-anchor="middle" | |
| 137 alignment-baseline="middle">voronoi.nexe</text> | |
| 138 </g> | |
| 139 <path d="M110,35 L195,30" | |
| 140 style="stroke:black; stroke-width: 2px; marker-end: url(#markerArrow);"/> | |
| 141 <path d="M110,95 L195,50" | |
| 142 style="stroke:black; stroke-width: 2px; marker-end: url(#markerArrow);"/> | |
| 143 | |
| 144 <text x="50" y="155" fill="black" text-anchor="middle" | |
| 145 alignment-baseline="middle">build.sh</text> | |
| 146 <path d="M80,155 L300,155" | |
| 147 stroke-dasharray="5,5" d="M5 20 l215 0" | |
| 148 style="stroke:black; stroke-width: 2px; marker-end: url(#markerArrow);"/> | |
| 149 </svg> | |
|
Sam Clegg
2014/06/19 17:37:26
Shame about the raw html.. maybe we can find a wa
binji
2014/06/19 19:12:56
We've been doing Google Docs diagrams and saving t
bradn
2014/06/19 21:52:36
Did as binji suggests.
bradn
2014/06/19 21:52:36
Done.
| |
| 150 | |
| 151 The resulting application combines some Javascript to load the module with | |
| 152 voronoi.nexe, producing the complete application. | |
| 153 | |
| 154 .. raw:: html | |
| 155 | |
| 156 <svg width="600" height="200"> | |
| 157 <defs> | |
| 158 <marker id="markerArrow" markerWidth="13" markerHeight="13" | |
| 159 refx="2" refy="6" orient="auto"> | |
| 160 <path d="M2,2 L2,11 L10,6 L2,2" style="fill: #000000;" /> | |
| 161 </marker> | |
| 162 </defs> | |
| 163 | |
| 164 <g transform="translate(10,10)"> | |
| 165 <rect x="0" y="0" rx="20" ry="20" width="100" height="50" | |
| 166 style="fill:#cc0000;stroke:black;stroke-width:3" /> | |
| 167 <text x="50" y="25" fill="white" text-anchor="middle" | |
| 168 alignment-baseline="middle">voronoi.nexe</text> | |
| 169 </g> | |
| 170 <g transform="translate(10,70)"> | |
| 171 <rect x="0" y="0" rx="20" ry="20" width="100" height="50" | |
| 172 style="fill:#cccc00;stroke:black;stroke-width:3" /> | |
| 173 <text x="50" y="25" fill="white" text-anchor="middle" | |
| 174 alignment-baseline="middle">example.js</text> | |
| 175 </g> | |
| 176 <g transform="translate(210,10)"> | |
| 177 <rect x="0" y="0" rx="20" ry="20" width="100" height="50" | |
| 178 style="fill:#0000cc;stroke:black;stroke-width:3" /> | |
| 179 <text x="50" y="25" fill="white" text-anchor="middle" | |
| 180 alignment-baseline="middle">Web App</text> | |
| 181 </g> | |
| 182 <path d="M110,35 L195,30" | |
| 183 style="stroke:black; stroke-width: 2px; marker-end: url(#markerArrow);"/> | |
| 184 <path d="M110,95 L195,50" | |
| 185 style="stroke:black; stroke-width: 2px; marker-end: url(#markerArrow);"/> | |
| 186 | |
| 187 <text x="50" y="155" fill="black" text-anchor="middle" | |
| 188 alignment-baseline="middle">demo.py</text> | |
| 189 <path d="M80,155 L300,155" | |
| 190 stroke-dasharray="5,5" d="M5 20 l215 0" | |
| 191 style="stroke:black; stroke-width: 2px; marker-end: url(#markerArrow);"/> | |
| 192 </svg> | |
| 193 | |
| 194 Let's use git (a revision control program) to track our changes. | |
| 195 | |
| 196 First, create a new repository: | |
| 197 :: | |
| 198 | |
| 199 $ git init | |
| 200 | |
| 201 Add everything here: | |
| 202 :: | |
| 203 | |
| 204 $ git add . | |
| 205 | |
| 206 Then commit our starting state. | |
| 207 :: | |
| 208 | |
| 209 $ git commit -m "imported voronoi demo" | |
| 210 | |
| 211 | |
| 212 Now, lets invoke the bash build script to compile our program: | |
| 213 :: | |
|
Sam Clegg
2014/06/19 17:37:26
You can combine these two lines into one. Simple
bradn
2014/06/19 21:52:36
Done.
| |
| 214 | |
| 215 $ ./build.sh | |
| 216 | |
| 217 Oops, we get this error: | |
| 218 :: | |
| 219 | |
| 220 voronoi.cc: In member function 'void Voronoi::Update()': | |
| 221 voronoi.cc:506: error: 'struct PSContext2D_t' has no member named 'hieght' | |
| 222 | |
| 223 We'll need to start an editor to fix this. | |
| 224 You'll want to change *hieght* to *height* on line 506. | |
| 225 | |
| 226 Then rebuild: | |
| 227 :: | |
| 228 | |
| 229 $ bash build.sh | |
| 230 | |
| 231 Lets look at the diff. | |
| 232 :: | |
| 233 | |
| 234 $ git diff | |
| 235 | |
| 236 And commit our fix. | |
| 237 :: | |
| 238 | |
| 239 $ git commit -am "fixed build error" | |
| 240 | |
| 241 We can now run the demo with this command. | |
| 242 :: | |
| 243 | |
| 244 $ python ${PWD}/demo.py | |
| 245 | |
| 246 Navigate to http://localhost:5103/ to test the demo. | |
| 247 | |
| 248 If you follow along with the demo video, you will discover the sample crashes | |
| 249 when you change the thread count. | |
| 250 | |
| 251 *Debugger walk-thru coming soon.* | |
| 252 | |
| 253 Once you've identified the problem. You'll want to stop the test server. | |
| 254 Press enter to halt it. | |
| 255 | |
| 256 Open your editor again, navigate to line 485 and change *valu* to *value*. | |
| 257 | |
| 258 Then rebuild. | |
| 259 :: | |
| 260 | |
| 261 $ bash build.sh | |
| 262 | |
| 263 | |
| 264 Check the diff and commit our fix. | |
| 265 :: | |
| 266 | |
| 267 $ git diff | |
| 268 $ git commit -am "fixed thread ui bug" | |
| 269 | |
| 270 Now look at your commit history. | |
| 271 :: | |
| 272 | |
| 273 $ git log | |
| 274 | |
| 275 Run the demo again. And everything now works. | |
| 276 :: | |
| 277 | |
| 278 $ python ${PWD}/demo.py | |
| OLD | NEW |