Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(292)

Side by Side Diff: native_client_sdk/src/doc/sdk/examples.rst

Issue 588723002: Copy edit SDK section. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add 'TODO' comment to examples.rst. Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « native_client_sdk/src/doc/sdk/download.rst ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 .. _sdk-examples-2: 1 .. _sdk-examples-2:
2 2
3 Running the SDK Examples 3 .. TODO: After default toolchain is changed to pnacl, recreate the make examples .
4 ======================== 4
5 Examples
6 ========
5 7
6 Every Native Client SDK bundle comes with a folder of example applications. 8 Every Native Client SDK bundle comes with a folder of example applications.
7 Each example demonstrates one or two key Native Client programming concepts. 9 Each example demonstrates one or two key Native Client programming concepts.
8 After you've :doc:`downloaded the SDK <download>`, follow the instructions 10 After you've :doc:`downloaded the SDK <download>`, follow the instructions
9 on this page to build and run the examples. 11 on this page to build and run the examples.
10 12
11 Your version of Chrome must be equal to or greater than the version of your SDK 13 Your version of Chrome must be equal to or greater than the version of your SDK
12 bundle. For example, if you're developing with the ``pepper_31`` bundle, you 14 bundle. For example, if you're developing with the ``pepper_35`` bundle, you
13 must use Google Chrome version 31 or greater. To find out what version of Chrome 15 must use Google Chrome version 35 or greater. To find out what version of Chrome
14 you're using, type ``about:chrome`` or ``about:version`` in the Chrome address 16 you're using, type ``about:chrome`` or ``about:version`` in the Chrome address
15 bar. 17 bar.
16 18
19 .. _enable-native-client:
17 20
18 Enable Native Client 21 Enable Native Client
19 -------------------- 22 --------------------
20 23
21 .. note:: 24 If you are using Chrome 31 or later, you can skip this section. To run Portable
22 :class: note 25 Native Client applications you must specifically enable Native Client in Chrome:
23
24 If you are using Chrome 31 or later, you can skip this section.
25
26 To run Portable Native Client applications you must specifically enable Native
27 Client in Chrome:
28 26
29 #. Type ``about:flags`` in the Chrome address bar and scroll down to "Native 27 #. Type ``about:flags`` in the Chrome address bar and scroll down to "Native
30 Client". 28 Client".
31 29
32 - If the link below "Native Client" says "Disable", then Native Client is 30 - If the link below "Native Client" says "Disable", then Native Client is
33 already enabled and you don't need to do anything else. 31 already enabled and you don't need to do anything else.
34 32
35 * If the link below "Native Client" says "Enable", click the "Enable" 33 * If the link below "Native Client" says "Enable", click the "Enable"
36 link. 34 link.
37 35
38 #. Scroll down to the bottom of the page, and click "Relaunch Now". All browser 36 #. Scroll down to the bottom of the page, and click "Relaunch Now". All browser
39 windows will restart when you relaunch Chrome. 37 windows will restart when you relaunch Chrome.
40 38
41 Disable the Chrome cache 39 .. _build-the-sdk-examples:
42 ------------------------
43
44 Chrome caches resources aggressively. When you are building a Native Client
45 application you should disable the cache to make sure that Chrome loads the
46 latest version.
47
48 #. Open Chrome's developer tools by clicking the menu icon |menu-icon| and
49 choosing Tools > Developer tools.
50
51 #. Click the gear icon |gear-icon| in the bottom right corner of the Chrome
52 window.
53
54 #. Under the "General" settings, check the box next to "Disable cache".
55 40
56 Build the SDK examples 41 Build the SDK examples
57 ---------------------- 42 ----------------------
58 43
59 The Makefile scripts for the SDK examples build multiple versions of the 44 The Makefile scripts for the SDK examples can build multiple versions of the
60 examples using all three SDK toolchains (newlib, glibc, and PNaCl) and in both 45 examples using any of the three SDK toolchains (newlib, glibc, and PNaCl) and in
61 release and debug configurations. (Note that some examples build only with 46 both release and debug configurations. Note that some examples, ``dlopen`` for
62 particular toolchains). 47 example, build only with particular toolchains.
63 48
64 Build all examples 49 Find the toolchains for each example by looking at the ``VALID_TOOLCHAINS``
65 ^^^^^^^^^^^^^^^^^^ 50 variable in the Makefile for a particular example. The first item listed is the
51 default. It's built when you run an example make file without parameters. for
52 example running make in the ``core`` directory of pepper_35 builds the example
53 using the ``newlib`` toolchain. ::
66 54
67 To build all the examples, go to the examples directory in a specific SDK 55 $ cd pepper_35/examples/api/core
68 bundle and run ``make``:: 56 $ make
57 CXX newlib/Release/core_x86_32.o
58 LINK newlib/Release/core_unstripped_x86_32.nexe
59 VALIDATE newlib/Release/core_unstripped_x86_32.nexe
60 CXX newlib/Release/core_x86_64.o
61 LINK newlib/Release/core_unstripped_x86_64.nexe
62 VALIDATE newlib/Release/core_unstripped_x86_64.nexe
63 CXX newlib/Release/core_arm.o
64 LINK newlib/Release/core_unstripped_arm.nexe
65 VALIDATE newlib/Release/core_unstripped_arm.nexe
66 STRIP newlib/Release/core_x86_32.nexe
67 STRIP newlib/Release/core_x86_64.nexe
68 STRIP newlib/Release/core_arm.nexe
69 CREATE_NMF newlib/Release/core.nmf
69 70
70 $ cd pepper_31/examples 71 As you can see, this produces a number of architecture specific nexe files in
71 $ make 72 the ``pepper_35/examples/api/core/Release`` directory. Create debug versions by
72 make -C api all 73 using the ``CONFIG`` parameter of the make command. ::
73 make[1]: Entering directory `pepper_31/examples/api' 74
74 make -C audio all 75 $make CONFIG=Debug
75 make[2]: Entering directory `pepper_31/examples/api/audio'
76 CXX newlib/Debug/audio_x86_32.o
77 LINK newlib/Debug/audio_x86_32.nexe
78 CXX newlib/Debug/audio_x86_64.o
79 LINK newlib/Debug/audio_x86_64.nexe
80 CXX newlib/Debug/audio_arm.o
81 LINK newlib/Debug/audio_arm.nexe
82 CREATE_NMF newlib/Debug/audio.nmf
83 make[2]: Leaving directory `pepper_31/examples/api/audio'
84 make -C url_loader all
85 make[2]: Entering directory `pepper_31/examples/api/url_loader'
86 CXX newlib/Debug/url_loader_x86_32.o
87 ...
88 76
89 Build a single example 77 This creates similar output, but in ``pepper_35/examples/api/core/Debug``.
90 ^^^^^^^^^^^^^^^^^^^^^^
91 78
92 Calling ``make`` from inside a particular example's directory will build only 79 Select a different toolchain with the ``TOOLCHAIN`` parameter. For example::
93 that example::
94 80
95 $ cd pepper_31/examples/api/core 81 $ cd pepper_35/examples/api/core
96 $ make
97 CXX newlib/Debug/core_x86_32.o
98 LINK newlib/Debug/core_x86_32.nexe
99 CXX newlib/Debug/core_x86_64.o
100 LINK newlib/Debug/core_x86_64.nexe
101 CXX newlib/Debug/core_arm.o
102 LINK newlib/Debug/core_arm.nexe
103 CREATE_NMF newlib/Debug/core.nmf
104
105 Override defaults
106 ^^^^^^^^^^^^^^^^^
107
108 You can call ``make`` with the ``TOOLCHAIN`` and ``CONFIG`` parameters to
109 override the defaults::
110
111 $ make TOOLCHAIN=pnacl CONFIG=Release 82 $ make TOOLCHAIN=pnacl CONFIG=Release
112 CXX pnacl/Release/core_pnacl.o 83 CXX pnacl/Release/core.o
113 LINK pnacl/Release/core.bc 84 LINK pnacl/Release/core_unstripped.bc
114 FINALIZE pnacl/Release/core.pexe 85 FINALIZE pnacl/Release/core_unstripped.pexe
115 CREATE_NMF pnacl/Release/core.nmf 86 CREATE_NMF pnacl/Release/core.nmf
116 87
88 You can also set ``TOOLCHAIN`` to ``all`` to build all Release versions with
89 default toolchains. ::
117 90
118 You can also set ``TOOLCHAIN`` to "all" to build one or more examples with 91 $ cd pepper_35/examples/api/core
119 all available toolchains:: 92 $ make TOOLCHAIN=all
93 make TOOLCHAIN=newlib
94 make[1]: Entering directory 'pepper_35/examples/api/core'
95 CXX newlib/Release/core_x86_32.o
96 LINK newlib/Release/core_unstripped_x86_32.nexe
97 VALIDATE newlib/Release/core_unstripped_x86_32.nexe
98 CXX newlib/Release/core_x86_64.o
99 LINK newlib/Release/core_unstripped_x86_64.nexe
100 VALIDATE newlib/Release/core_unstripped_x86_64.nexe
101 CXX newlib/Release/core_arm.o
102 LINK newlib/Release/core_unstripped_arm.nexe
103 VALIDATE newlib/Release/core_unstripped_arm.nexe
104 STRIP newlib/Release/core_x86_32.nexe
105 STRIP newlib/Release/core_x86_64.nexe
106 STRIP newlib/Release/core_arm.nexe
107 CREATE_NMF newlib/Release/core.nmf
108 make[1]: Leaving directory 'pepper_35/examples/api/core'
109 make TOOLCHAIN=glibc
110 make[1]: Entering directory 'pepper_35/examples/api/core'
111 CXX glibc/Release/core_x86_32.o
112 LINK glibc/Release/core_unstripped_x86_32.nexe
113 VALIDATE glibc/Release/core_unstripped_x86_32.nexe
114 CXX glibc/Release/core_x86_64.o
115 LINK glibc/Release/core_unstripped_x86_64.nexe
116 VALIDATE glibc/Release/core_unstripped_x86_64.nexe
117 ...
118 (content excerpted)
119 ...
120 120
121 $ make TOOLCHAIN=all 121 .. _build-results:
122 make TOOLCHAIN=newlib
123 make[1]: Entering directory `pepper_31/examples/api/core'
124 CXX newlib/Debug/core_x86_32.o
125 LINK newlib/Debug/core_x86_32.nexe
126 CXX newlib/Debug/core_x86_64.o
127 LINK newlib/Debug/core_x86_64.nexe
128 CXX newlib/Debug/core_arm.o
129 LINK newlib/Debug/core_arm.nexe
130 CREATE_NMF newlib/Debug/core.nmf
131 make[1]: Leaving directory `pepper_31/examples/api/core'
132 make TOOLCHAIN=glibc
133 make[1]: Entering directory `pepper_31/examples/api/core'
134 CXX glibc/Debug/core_x86_32.o
135 LINK glibc/Debug/core_x86_32.nexe
136 CXX glibc/Debug/core_x86_64.o
137 LINK glibc/Debug/core_x86_64.nexe
138 CREATE_NMF glibc/Debug/core.nmf
139 make[1]: Leaving directory `pepper_31/examples/api/core'
140 make TOOLCHAIN=pnacl
141 make[1]: Entering directory `pepper_31/examples/api/core'
142 CXX pnacl/Debug/core.o
143 LINK pnacl/Debug/core_unstripped.bc
144 FINALIZE pnacl/Debug/core_unstripped.pexe
145 CREATE_NMF pnacl/Debug/core.nmf
146 make[1]: Leaving directory `pepper_31/examples/api/core'
147 make TOOLCHAIN=linux
148 make[1]: Entering directory `pepper_31/examples/api/core'
149 CXX linux/Debug/core.o
150 LINK linux/Debug/core.so
151 make[1]: Leaving directory `pepper_31/examples/api/core'
152 122
153 Build results 123 Build results
154 ------------- 124 ^^^^^^^^^^^^^
155 125
156 After running ``make``, each example directory will contain one or more of 126 After running ``make``, example directories will contain one or more of the
157 the following subdirectories: 127 following subdirectories, depending on which Makefile you run:
158 128
159 * ``newlib`` with subdirectories ``Debug`` and ``Release``; 129 * ``newlib`` with subdirectories ``Debug`` and ``Release``;
160 * ``glibc`` with subdirectories ``Debug`` and ``Release``; 130 * ``glibc`` with subdirectories ``Debug`` and ``Release``;
161 * ``pnacl`` with subdirectories ``Debug`` and ``Release``; 131 * ``pnacl`` with subdirectories ``Debug`` and ``Release``;
162 132
163 For the newlib and glibc toolchains the Debug and Release subdirectories 133 For the newlib and glibc toolchains the Debug and Release subdirectories
164 contain .nexe files for all target architectures. For the PNaCl toolchain 134 contain .nexe files for all target architectures. For the PNaCl toolchain
165 they contain a single .pexe file. PNaCl debug also produces pre-translated 135 they contain a single .pexe file. PNaCl debug also produces pre-translated
166 .nexe files, for ease of debugging. All Debug and Release directories contain 136 .nexe files, for ease of debugging. All Debug and Release directories contain
167 a manifest (.nmf) file that references the associated .nexe or .pexe files. 137 a manifest (.nmf) file that references the associated .nexe or .pexe files.
168 For information about Native Client manifest files, see the :doc:`Technical 138 For information about Native Client manifest files, see the :doc:`Technical
169 Overview <../overview>`. 139 Overview <../overview>`.
170 140
171 For details on how to use ``make``, see the `GNU 'make' Manual 141 For details on how to use ``make``, see the `GNU 'make' Manual
172 <http://www.gnu.org/software/make/manual/make.html>`_. For details on how to 142 <http://www.gnu.org/software/make/manual/make.html>`_. For details on how to
173 use the SDK toolchain itself, see :doc:`Building Native Client Modules 143 use the SDK toolchain itself, see :doc:`Building Native Client Modules
174 <../devguide/devcycle/building>`. 144 <../devguide/devcycle/building>`.
175 145
176 .. _running_the_sdk_examples: 146 .. _running_the_sdk_examples:
177 147
178 Run the SDK examples 148 Run the SDK examples
179 -------------------- 149 --------------------
180 150
181 To run the SDK examples, you can use the ``make run`` command:: 151 .. _disable-chrome-cache:
182 152
183 $ cd pepper_31/examples/api/core 153 Disable the Chrome cache
154 ^^^^^^^^^^^^^^^^^^^^^^^^
155
156 Chrome's intelligent caching caches resources aggressively. When building a
157 Native Client application you should disable the cache to make sure that Chrome
158 loads the latest version. Intelligent caching only remains inactive while
159 Developer Tools are open. Otherwise, agressive caching continues.
160
161 #. Open Chrome's developer tools by clicking the menu icon |menu-icon| and
162 choosing Tools > Developer tools.
163
164 #. Click the gear icon |gear-icon| in the bottom right corner of the Chrome
165 window.
166
167 #. Under the "General" settings, check the box next to "Disable cache".
168
169 .. _run-the-examples:
170
171 Run the examples
172 ^^^^^^^^^^^^^^^^
173
174 To run the SDK examples, use the ``make run`` command::
175
176 $ cd pepper_35/examples/api/core
184 $ make run 177 $ make run
185 178
186 This will launch a local HTTP server which will serve the data for the 179 This launches a local HTTP server that serves the example. It then launches
187 example. It then launches Chrome with the address of this server, usually 180 Chrome with the address of this server, usually ``http://localhost:5103``.
188 ``http://localhost:5103``. After you close Chrome, the local HTTP server is 181 After you close Chrome, the local HTTP server automatically shuts down.
189 automatically shutdown.
190 182
191 This command will try to find an executable named ``google-chrome`` in your 183 This command tries to find an executable named ``google-chrome`` in your
192 ``PATH`` environment variable. If it can't, you'll get an error message like 184 ``PATH`` environment variable. If it can't, you'll get an error message like
193 this:: 185 this::
194 186
195 pepper_31/tools/common.mk:415: No valid Chrome found at CHROME_PATH= 187 pepper_35/tools/common.mk:415: No valid Chrome found at CHROME_PATH=
196 pepper_31/tools/common.mk:415: *** Set CHROME_PATH via an environment variable , or command-line.. Stop. 188 pepper_35/tools/common.mk:415: *** Set CHROME_PATH via an environment variable , or command-line.. Stop.
189
190 .. _add-an-env-variable-for-chrome:
191
192 Add an environment variable for Chrome
193 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
197 194
198 Set the CHROME_PATH environment variable to the location of your Chrome 195 Set the CHROME_PATH environment variable to the location of your Chrome
199 executable. 196 executable.
200 197
201 * On Windows: 198 * On Windows:
202 199
203 The default install location of Chrome is 200 The default install location of Chrome is
204 ``C:\Program Files (x86)\Google\Chrome\Application\chrome.exe`` for Chrome 201 ``C:\Program Files (x86)\Google\Chrome\Application\chrome.exe`` for Chrome
205 stable and 202 stable and
206 ``C:\Users\<username>\AppData\Local\Google\Chrome SxS\Application\chrome.exe`` 203 ``C:\Users\<username>\AppData\Local\Google\Chrome SxS\Application\chrome.exe``
207 for Chrome Canary; try looking in those directories first:: 204 for Chrome Canary. Try looking in those directories first::
208 205
209 > set CHROME_PATH=<Path to chrome.exe> 206 > set CHROME_PATH=<Path to chrome.exe>
210 207
211 * On Linux:: 208 * On Linux::
212 209
213 $ export CHROME_PATH=<Path to google-chrome> 210 $ export CHROME_PATH=<Path to google-chrome>
214 211
215 * On Mac: 212 * On Mac:
216 213
217 The default install location of Chrome is 214 The default install location of Chrome is
218 ``/Applications/Google Chrome.app/Contents/MacOS/Google Chrome`` for 215 ``/Applications/Google Chrome.app/Contents/MacOS/Google Chrome`` for
219 Chrome Stable and 216 Chrome Stable and
220 ``Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary`` 217 ``Applications/Google Chrome Canary.app/Contents/MacOS/Google Chrome Canary``
221 for Chrome Canary. Note that you have to reference the executable inside the 218 for Chrome Canary. Note that you have to reference the executable inside the
222 application bundle, not the top-level ``.app`` directory:: 219 application bundle, not the top-level ``.app`` directory::
223 220
224 $ export CHROME_PATH=<Path to Google Chrome> 221 $ export CHROME_PATH=<Path to Google Chrome>
225 222
226 You can run via a different toolchain or configuration by using the
227 ``TOOLCHAIN`` and ``CONFIG`` parameters to make::
228
229 $ make run TOOLCHAIN=pnacl CONFIG=Debug
230
231 .. _run_sdk_examples_as_packaged: 223 .. _run_sdk_examples_as_packaged:
232 224
233 Run the SDK examples as packaged apps 225 Run the SDK examples as packaged apps
234 ------------------------------------- 226 -------------------------------------
235 227
236 Each example can also be launched as a packaged app. For more information about 228 Each example can also be launched as a packaged application. A packaged
237 using Native Client for packaged apps, see :ref:`Packaged application 229 application is a special zip file (with a .crx extension) hosted in the Chrome
238 <distributing_packaged>`. For general information about packaged apps, see the 230 Web Store. This file contains all of the application parts: A Chrome Web Store
239 `Chrome apps documentation </apps/about_apps>`_. 231 manifest file (manifest.json), an icon, and all of the regular Native Client
232 application files. Refer to `What are Chrome Apps </apps/about_apps>`_ for more
233 information about creating a packaged application.
240 234
241 Some Pepper features, such as TCP/UDP socket access, are only allowed in 235 Some Pepper features, such as TCP/UDP socket access, are only allowed in
242 packaged apps. The examples that use these features must be run as packaged 236 packaged applications. The examples that use these features must be run as
243 apps, by using the ``make run_package`` command:: 237 packaged applications, by using the following command::
244 238
245 $ make run_package 239 $ make run_package
246 240
247 You can use ``TOOLCHAIN`` and ``CONFIG`` parameters as above to run with a 241 You can use ``TOOLCHAIN`` and ``CONFIG`` parameters as described above to run
248 different toolchain or configuration. 242 with a different toolchain or configuration.
249
250 243
251 .. _debugging_the_sdk_examples: 244 .. _debugging_the_sdk_examples:
252 245
253 Debugging the SDK examples 246 Debugging the SDK examples
254 -------------------------- 247 --------------------------
255 248
256 The NaCl SDK uses `GDB <https://www.gnu.org/software/gdb/>`_ to debug Native 249 The NaCl SDK uses `GDB <https://www.gnu.org/software/gdb/>`_ to debug Native
257 Client code. The SDK includes a prebuilt version of GDB that is compatible with 250 Client code. The SDK includes a prebuilt version of GDB that is compatible with
258 NaCl code. To use it, run the ``make debug`` command from an example directory:: 251 NaCl code. To use it, run the ``make debug`` command from an example directory::
259 252
260 $ make debug 253 $ make debug
261 254
262 This will launch Chrome with the ``--enable-nacl-debug`` flag set. This flag 255 This launches Chrome with the ``--enable-nacl-debug`` flag set. This flag causes
263 will cause Chrome to pause when a NaCl module is first loaded, waiting for a 256 Chrome to pause when a NaCl module is first loaded, waiting for a connection
264 connection from gdb. The ``make debug`` command also simultaneously launches 257 from gdb. The ``make debug`` command also simultaneously launches GDB and loads
265 GDB and loads the symbols for that NEXE. To connect GDB to Chrome, in the GDB 258 the symbols for that NEXE. To connect GDB to Chrome, in the GDB console, type::
266 console, type::
267 259
268 (gdb) target remote :4014 260 (gdb) target remote :4014
269 261
270 This tells GDB to connect to a TCP port on ``localhost:4014``--the port that 262 This tells GDB to connect to a TCP port on ``localhost:4014``, the port that
271 Chrome is listening on. GDB will respond:: 263 Chrome is listening on. GDB will respond::
272 264
273 Remote debugging using :4014 265 Remote debugging using :4014
274 0x000000000fa00080 in ?? () 266 0x000000000fa00080 in ?? ()
275 267
276 At this point, you can use the standard GDB commands to debug your NaCl module. 268 At this point, you can use the standard GDB commands to debug your NaCl module.
277 The most common commands you will use to debug are ``continue``, ``step``, 269 The most common commands you will use to debug are ``continue``, ``step``,
278 ``next``, ``break`` and ``backtrace``. See :doc:`Debugging 270 ``next``, ``break`` and ``backtrace``. See
279 <../devguide/devcycle/debugging>` for more information about debugging a Native Client 271 :doc:`Debugging <../devguide/devcycle/debugging>` for more information about
280 application. 272 debugging a Native Client application.
281 273
282 274
283 .. |menu-icon| image:: /images/menu-icon.png 275 .. |menu-icon| image:: /images/menu-icon.png
284 .. |gear-icon| image:: /images/gear-icon.png 276 .. |gear-icon| image:: /images/gear-icon.png
OLDNEW
« no previous file with comments | « native_client_sdk/src/doc/sdk/download.rst ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698