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

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