OLD | NEW |
---|---|
1 # GYP->GN Conversion Cookbook | 1 # GYP->GN Conversion Cookbook |
2 | 2 |
3 [TOC] | 3 [TOC] |
4 | 4 |
5 ## Targets | 5 ## Targets |
6 | 6 |
7 | *GYP* | *GN* | | 7 | *GYP* | *GN* | |
8 |:-------------------------------------------------|:--------------------------- ------------------------| | 8 |:-------------------------------------------------|:--------------------------- ------------------------| |
9 | `'type': 'static_library', 'name': 'foo',` | `static_library("foo") {` o r `source_set("foo") {` | | 9 | `'type': 'static_library', 'name': 'foo',` | `static_library("foo") {` o r `source_set("foo") {` | |
10 | `'type': 'shared_library', 'name': 'foo',` | `shared_library("foo") {` | | 10 | `'type': 'shared_library', 'name': 'foo',` | `shared_library("foo") {` | |
11 | `'type': '<(component)', 'name': 'foo',` | `component("foo") {` | | 11 | `'type': '<(component)', 'name': 'foo',` | `component("foo") {` | |
12 | `'type': 'executable', 'name': 'foo',` | `executable("foo") {` | | 12 | `'type': 'executable', 'name': 'foo',` | `executable("foo") {` | |
13 | `'type': '<(gtest_target_type)', 'name': 'foo',` | `test("foo") {` | | 13 | `'type': '<(gtest_target_type)', 'name': 'foo',` | `test("foo") {` | |
14 | `'type': 'none', 'name': 'foo',` | `group("foo") {` | | 14 | `'type': 'none', 'name': 'foo',` | `group("foo") {` | |
15 | 15 |
16 ### Note on static libraries | 16 ### Note on static libraries |
17 | 17 |
18 A source\_set is basically a transparent static\_library. The source files | 18 A source\_set is basically a transparent static\_library. The source files |
19 are compiled with the given options but not linked into anything. | 19 are compiled with the given options but not linked into anything. |
20 Targets that depend on a source set get the source set's object files | 20 Targets that depend on a source set get the source set's object files |
21 linked into it. This saves the overhead of creating a static library on | 21 linked into it. This saves the overhead of creating a static library on |
22 disk, avoids weird linker issues when a static library has no source | 22 disk, avoids weird linker issues when a static library has no source |
23 files, and you can link source sets into shared libraries and have | 23 files, and you can link source sets into shared libraries and have |
24 symbols exported from the shared library. | 24 symbols exported from the shared library. |
25 | 25 |
26 The last issue is a cause of a lot of headaches in the GYP build. If you | 26 The last issue is a cause of a lot of headaches in the GYP build. If you |
27 annotate a symbol as exported (i.e. `BASE_EXPORT`) then you can't have | 27 annotate a symbol as exported (i.e. `BASE_EXPORT`) then you can't have |
28 it in a file that goes into a static library because the function might | 28 it in a file that goes into a static library because the function might |
29 be [http://blogs.msdn.com/b/oldnewthing/archive/2014/03/21/10509670.aspx | 29 be (stripped out)[http://blogs.msdn.com/b/oldnewthing/archive/2014/03/21/1050967 0.aspx] |
30 stripped out] if it's not called from within the static library. This | 30 if it's not called from within the static library. This |
Dirk Pranke
2015/08/03 19:18:09
It actually needs to be [text](link), not (text)[l
Bons
2015/08/03 19:23:00
Done.
| |
31 prevents composing components of static libraries and exporting their | 31 prevents composing components of static libraries and exporting their |
32 symbols. A source set avoids this issue and `EXPORT` has the desired | 32 symbols. A source set avoids this issue and `EXPORT` has the desired |
33 meaning of "export from the component this gets linked into" with no | 33 meaning of "export from the component this gets linked into" with no |
34 surprising dead code stripping behavior. | 34 surprising dead code stripping behavior. |
35 | 35 |
36 A disadvantage of source sets is that if an object file is completely | 36 A disadvantage of source sets is that if an object file is completely |
37 unused, it will still be linked into the result, which is not the case | 37 unused, it will still be linked into the result, which is not the case |
38 for static libraries. A few places in the build depend on this behavior | 38 for static libraries. A few places in the build depend on this behavior |
39 (deliberately or accidentally). In general, small libraries that we | 39 (deliberately or accidentally). In general, small libraries that we |
40 expect to be entirely used, test helpers, etc. can be source sets. There | 40 expect to be entirely used, test helpers, etc. can be source sets. There |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
106 ], | 106 ], |
107 'dependencies': [ | 107 'dependencies': [ |
108 '<(DEPTH)/base/base.gyp:bar', | 108 '<(DEPTH)/base/base.gyp:bar', |
109 ], | 109 ], |
110 }, { | 110 }, { |
111 'sources/': [ | 111 'sources/': [ |
112 ['exclude', '^b\\.cc$'], | 112 ['exclude', '^b\\.cc$'], |
113 ], | 113 ], |
114 }], | 114 }], |
115 ], | 115 ], |
116 ``` | 116 ``` |
117 | 117 |
118 ### GN | 118 ### GN |
119 | 119 |
120 ``` | 120 ``` |
121 sources = [ | 121 sources = [ |
122 "a.cc", | 122 "a.cc", |
123 "b.cc", | 123 "b.cc", |
124 ] | 124 ] |
125 deps = [ | 125 deps = [ |
126 "//base:foo", | 126 "//base:foo", |
127 ] | 127 ] |
128 | 128 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
160 declared directly in that file (so other files can't use them). These | 160 declared directly in that file (so other files can't use them). These |
161 places are noted in the table below. | 161 places are noted in the table below. |
162 | 162 |
163 | *GYP* | *GN* | *GN import* | | 163 | *GYP* | *GN* | *GN import* | |
164 |:------------------------------------------------|:---------------------------- ---------------|:-----------------------------------------------| | 164 |:------------------------------------------------|:---------------------------- ---------------|:-----------------------------------------------| |
165 | `arm_float_abi` | `arm_float_abi` | `//build/config/arm.gni` | | 165 | `arm_float_abi` | `arm_float_abi` | `//build/config/arm.gni` | |
166 | `arm_neon` (0/1) | `arm_use_neon` (true/false) | `//build/config/arm.gni` | | 166 | `arm_neon` (0/1) | `arm_use_neon` (true/false) | `//build/config/arm.gni` | |
167 | `arm_neon_optional` (0/1) | `arm_optionally_use_neon` (t rue/false) | `//build/config/arm.gni` | | 167 | `arm_neon_optional` (0/1) | `arm_optionally_use_neon` (t rue/false) | `//build/config/arm.gni` | |
168 | `arm_version` | `arm_version` | `//build/config/arm.gni` | | 168 | `arm_version` | `arm_version` | `//build/config/arm.gni` | |
169 | `asan` (0/1) | `is_asan` (true/false) | (global) | | 169 | `asan` (0/1) | `is_asan` (true/false) | (global) | |
170 | `branding` ("Chromium"/"Chrome"") | `is_chrome_branded` (true/fa lse) | `//build/config/chrome_build.gni` | | 170 | `branding` ("Chromium"/"Chrome"") | `is_chrome_branded` (true/fa lse) | `//build/config/chrome_build.gni` | |
Dirk Pranke
2015/08/03 19:18:09
There's an extra double quote here (after the "Chr
Bons
2015/08/03 19:23:00
Done.
| |
171 | `build_for_tool=="drmemory"` | `disable_iterator_debugging` (true/false) | (internal to `//build/config/BUILD.gn`) | | 171 | `build_for_tool=="drmemory"` | `disable_iterator_debugging` (true/false) | (internal to `//build/config/BUILD.gn`) | |
172 | `build_for_tool=="tsan"` | `disable_iterator_debugging` (true/false) | (internal to `//build/config/BUILD.gn`) | | 172 | `build_for_tool=="tsan"` | `disable_iterator_debugging` (true/false) | (internal to `//build/config/BUILD.gn`) | |
173 | `buildtype` ("Official"/"Dev") | `is_official_build` (true/fa lse) | `//build/config/chrome_build.gni` | | 173 | `buildtype` ("Official"/"Dev") | `is_official_build` (true/fa lse) | `//build/config/chrome_build.gni` | |
174 | `chrome_multiple_dll` (0/1) | `is_multi_dll_chrome` (true/ false) | `//build/config/chrome_build.gni` | | 174 | `chrome_multiple_dll` (0/1) | `is_multi_dll_chrome` (true/ false) | `//build/config/chrome_build.gni` | |
175 | `clang` (0/1) | `is_clang` (true/false) | (global) | | 175 | `clang` (0/1) | `is_clang` (true/false) | (global) | |
176 | `clang_use_chrome_plugins` (0/1) | `clang_use_chrome_plugins` ( true/false) | (internal to `//build/config/clang/BUILD.gn`) | | 176 | `clang_use_chrome_plugins` (0/1) | `clang_use_chrome_plugins` ( true/false) | (internal to `//build/config/clang/BUILD.gn`) | |
177 | `component` ("shared_library"/"static_library") | `is_component_build` (true/f alse) | (global) | | 177 | `component` ("shared_library"/"static_library") | `is_component_build` (true/f alse) | (global) | |
178 | `desktop_linux` (0/1) | `is_desktop_linux` (true/fal se) | (global) | | 178 | `desktop_linux` (0/1) | `is_desktop_linux` (true/fal se) | (global) | |
179 | `disable_glibcxx_debug` (0/1) | `disable_iterator_debugging` (true/false) | (internal to `//build/config/BUILD.gn`) | | 179 | `disable_glibcxx_debug` (0/1) | `disable_iterator_debugging` (true/false) | (internal to `//build/config/BUILD.gn`) | |
180 | `fastbuild` (0/1/2) | `symbol_level` (2/1/0 — valu es inverted) | (global) | | 180 | `fastbuild` (0/1/2) | `symbol_level` (2/1/0 — valu es inverted) | (global) | |
181 | `gomadir` | `goma_dir` | `//build/toolchain/goma.gni` | | 181 | `gomadir` | `goma_dir` | `//build/toolchain/goma.gni` | |
182 | `ios_deployment_target` (string) | `ios_deployment_target` | `//build/config/ios/ios_sdk.gni` | | 182 | `ios_deployment_target` (string) | `ios_deployment_target` | `//build/config/ios/ios_sdk.gni` | |
183 | `GYP_MSVS_OVERRIDE_PATH` environment variable | `visual_studio_path` | `//build/config/win/visual_studio_version.gni` | | 183 | `GYP_MSVS_OVERRIDE_PATH` environment variable | `visual_studio_path` | `//build/config/win/visual_studio_version.gni` | |
184 | `GYP_MSVS_VERSION` environment variable | (none) | | | 184 | `GYP_MSVS_VERSION` environment variable | (none) | | |
185 | `ios_sdk_path` | `ios_sdk_path` and `use_ios_ simulator` | `//build/config/ios/ios_sdk.gni` | | 185 | `ios_sdk_path` | `ios_sdk_path` and `use_ios_ simulator` | `//build/config/ios/ios_sdk.gni` | |
186 | `lsan` (0/1) | `is_lsan` (true/false) | (global) | | 186 | `lsan` (0/1) | `is_lsan` (true/false) | (global) | |
187 | `mac_sdk_min` | `mac_sdk_min` | `//build/config/mac/mac_sdk.gni` | | 187 | `mac_sdk_min` | `mac_sdk_min` | `//build/config/mac/mac_sdk.gni` | |
188 | `mac_sdk_path` | `mac_sdk_path` | `//build/config/mac/mac_sdk.gni` | | 188 | `mac_sdk_path` | `mac_sdk_path` | `//build/config/mac/mac_sdk.gni` | |
189 | `mac_sdk` | `mac_sdk_version` | `//build/config/mac/mac_sdk.gni` | | 189 | `mac_sdk` | `mac_sdk_version` | `//build/config/mac/mac_sdk.gni` | |
190 | `msan` (0/1) | `is_msan` (true/false) | (global) | | 190 | `msan` (0/1) | `is_msan` (true/false) | (global) | |
191 | `SDKROOT` (Mac) | `sysroot` | `//build/config/sysroot.gni` | | 191 | `SDKROOT` (Mac) | `sysroot` | `//build/config/sysroot.gni` | |
192 | `sysroot` | `sysroot` | `//build/config/sysroot.gni` | | 192 | `sysroot` | `sysroot` | `//build/config/sysroot.gni` | |
193 | `target_arch` ("ia32"/"x64"/"arm"/"mipsel") | `target_arch` ("x86"/"x64"/" arm"/"mipsel") | (global) | | 193 | `target_arch` ("ia32"/"x64"/"arm"/"mipsel") | `target_arch` ("x86"/"x64"/" arm"/"mipsel") | (global) | |
194 | `toolkit_views` (0/1) | `toolkit_views` | `//build/config/ui.gni` | | 194 | `toolkit_views` (0/1) | `toolkit_views` | `//build/config/ui.gni` | |
195 | `tsan` (0/1) | `is_tsan` (true/false) | (global) | | 195 | `tsan` (0/1) | `is_tsan` (true/false) | (global) | |
196 | `windows_sdk_path` | `windows_sdk_path` | (internal to `//build/config/win/BUILD.gn`) | | 196 | `windows_sdk_path` | `windows_sdk_path` | (internal to `//build/config/win/BUILD.gn`) | |
197 | 197 |
198 ### Feature flags | 198 ### Feature flags |
199 | 199 |
200 | *GYP* | *GN* | *GN import* | | 200 | *GYP* | *GN* | *GN import* | |
201 |:----------------------------------------|:------------------------------------ -----------|:------------------------------| | 201 |:----------------------------------------|:------------------------------------ -----------|:------------------------------| |
202 | `cld_version` (number) | `cld_version` (number) | `//build/config/features.gni` | | 202 | `cld_version` (number) | `cld_version` (number) | `//build/config/features.gni` | |
203 | `configuration_policy` (0/1) | `enable_configuration_policy` (true/ false) | `//build/config/features.gni` | | 203 | `configuration_policy` (0/1) | `enable_configuration_policy` (true/ false) | `//build/config/features.gni` | |
204 | `debug_devtools` (0/1) | `debug_devtools` (true/false) | `//build/config/features.gni` | | 204 | `debug_devtools` (0/1) | `debug_devtools` (true/false) | `//build/config/features.gni` | |
205 | `disable_ftp_support` (0/1) | `disable_ftp_support` (true/false) | `//build/config/features.gni` | | 205 | `disable_ftp_support` (0/1) | `disable_ftp_support` (true/false) | `//build/config/features.gni` | |
206 | `disable_nacl` (0/1) | `enable_nacl` (true/false) | `//build/config/features.gni` | | 206 | `disable_nacl` (0/1) | `enable_nacl` (true/false) | `//build/config/features.gni` | |
207 | `enable_app_list` (0/1) | `enable_app_list` (true/false) | `//build/config/features.gni` | | 207 | `enable_app_list` (0/1) | `enable_app_list` (true/false) | `//build/config/features.gni` | |
208 | `enable_autofill_dialog` (0/1) | `enable_autofill_dialog` (true/false ) | `//build/config/features.gni` | | 208 | `enable_autofill_dialog` (0/1) | `enable_autofill_dialog` (true/false ) | `//build/config/features.gni` | |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
253 | `use_openssl` (0/1) | `use_openssl` (true/false) | `//build/config/crypto.gni` (Many of these conditions can be delete d, see the "SSL" notes on targets below.) | | 253 | `use_openssl` (0/1) | `use_openssl` (true/false) | `//build/config/crypto.gni` (Many of these conditions can be delete d, see the "SSL" notes on targets below.) | |
254 | `use_pango` (0/1) | `use_pango` (true/false) | `//build/config/ui.gni` | | 254 | `use_pango` (0/1) | `use_pango` (true/false) | `//build/config/ui.gni` | |
255 | `use_ozone` (0/1) | `use_ozone` (true/false) | `//build/config/ui.gni` | | 255 | `use_ozone` (0/1) | `use_ozone` (true/false) | `//build/config/ui.gni` | |
256 | `use_seccomp_bpf` (0/1) | `use_seccomp_bpf` (true/false) | `//build/config/features.gni` | | 256 | `use_seccomp_bpf` (0/1) | `use_seccomp_bpf` (true/false) | `//build/config/features.gni` | |
257 | `use_udev` (0/1) | `use_udev` (true/false) | `//build/config/features.gni` | | 257 | `use_udev` (0/1) | `use_udev` (true/false) | `//build/config/features.gni` | |
258 | `use_x11` (0/1) | `use_x11` (true/false) | `//build/config/ui.gni` | | 258 | `use_x11` (0/1) | `use_x11` (true/false) | `//build/config/ui.gni` | |
259 | `use_xi2_mt` (0/1) | `use_xi2_mt` (true/false) | `//build/config/ui.gni` | | 259 | `use_xi2_mt` (0/1) | `use_xi2_mt` (true/false) | `//build/config/ui.gni` | |
260 | `win_pdf_metafile_for_printing` (0/1) | `win_pdf_metafile_for_printing` (tru e/false) | `//build/config/features.gni` | | 260 | `win_pdf_metafile_for_printing` (0/1) | `win_pdf_metafile_for_printing` (tru e/false) | `//build/config/features.gni` | |
261 | `win_use_allocator_shim` (0/1) | | (See "Allocator" below) | | 261 | `win_use_allocator_shim` (0/1) | | (See "Allocator" below) | |
262 | 262 |
263 ### Common target conversion | 263 ### Common target conversion |
264 | 264 |
265 Some targets that lots of projects depend on and how the GN ones | 265 Some targets that lots of projects depend on and how the GN ones |
266 correspond to GYP ones. (This is for commonly-depended-on or weird | 266 correspond to GYP ones. (This is for commonly-depended-on or weird |
267 targets only, don't add stuff here just because you converted it.) | 267 targets only, don't add stuff here just because you converted it.) |
268 | 268 |
269 | *GYP* | *GN* | *Notes* (see below) | | 269 | *GYP* | *GN* | *Notes* (see below) | |
270 |:------------------------------------------------------------------------------ -----|:-----------------------------------------|:---------------------| | 270 |:------------------------------------------------------------------------------ -----|:-----------------------------------------|:---------------------| |
271 | `base/base.gyp:base` | `//base` | | | 271 | `base/base.gyp:base` | `//base` | | |
272 | `base/base.gyp:base_i18n` | `//base:i18n` | | | 272 | `base/base.gyp:base_i18n` | `//base:i18n` | | |
273 | `base/base.gyp:run_all_unittests` | `//base/test:run_all_unittests` | | | 273 | `base/base.gyp:run_all_unittests` | `//base/test:run_all_unittests` | | |
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
322 | 322 |
323 The dependency tree must be a DAG. Some components might share headers | 323 The dependency tree must be a DAG. Some components might share headers |
324 between a number of internal targets that makes adding the "proper" | 324 between a number of internal targets that makes adding the "proper" |
325 dependencies impossible. In this case, you can separate out a | 325 dependencies impossible. In this case, you can separate out a |
326 `source_set` type target containing just the header(s) in question, and | 326 `source_set` type target containing just the header(s) in question, and |
327 make the targets that use that header depend on that source set to break | 327 make the targets that use that header depend on that source set to break |
328 the cycle. | 328 the cycle. |
329 | 329 |
330 ## Other stuff | 330 ## Other stuff |
331 | 331 |
332 ### Target conditions | 332 ### Target conditions |
333 | 333 |
334 `target_conditions` are like normal conditions but expanded in a | 334 `target_conditions` are like normal conditions but expanded in a |
335 different phase of GYP. You can generally just convert the conditions | 335 different phase of GYP. You can generally just convert the conditions |
336 inside and not worry about the `conditions`/`target_conditions` | 336 inside and not worry about the `conditions`/`target_conditions` |
337 difference. | 337 difference. |
338 | 338 |
339 ### xcode_settings | 339 ### xcode_settings |
340 | 340 |
341 Some xcode settings are obvious: | 341 Some xcode settings are obvious: |
342 | 342 |
343 ``` | 343 ``` |
344 'xcode_settings': {'OTHER_LDFLAGS': ['-foo']}, | 344 'xcode_settings': {'OTHER_LDFLAGS': ['-foo']}, |
345 ``` | 345 ``` |
346 | 346 |
347 Should just expand to: | 347 Should just expand to: |
348 | 348 |
349 ``` | 349 ``` |
350 ldflags = [ "-foo" ] | 350 ldflags = [ "-foo" ] |
351 ``` | 351 ``` |
352 | 352 |
353 Other flags are less obvious: | 353 Other flags are less obvious: |
354 | 354 |
355 ``` | 355 ``` |
356 'xcode_settings': { 'GCC_SYMBOLS_PRIVATE_EXTERN': 'NO', }, | 356 'xcode_settings': { 'GCC_SYMBOLS_PRIVATE_EXTERN': 'NO', }, |
357 ``` | 357 ``` |
358 | 358 |
359 These all correspond to various flags that get passed to the compiler or | 359 These all correspond to various flags that get passed to the compiler or |
360 linker. You can use your favorite search engine to see what it | 360 linker. You can use your favorite search engine to see what it |
361 corresponds to, but many of them are not well documented. You can also | 361 corresponds to, but many of them are not well documented. You can also |
362 search for the string in | 362 search for the string in |
363 [https://code.google.com/p/chromium/codesearch#chromium/src/tools/gyp/pylib/gyp/ xcode_emulation.py | 363 [https://code.google.com/p/chromium/codesearch#chromium/src/tools/gyp/pylib/gyp/ xcode_emulation.py |
364 tools/gyp/pylib/gyp/xcode_emulation.py]. GYP uses this file to decode | 364 tools/gyp/pylib/gyp/xcode_emulation.py]. GYP uses this file to decode |
Dirk Pranke
2015/08/03 19:18:09
can you fix this link, too?
Bons
2015/08/03 19:23:00
Done.
| |
365 the Xcode settings into command line flags for the ninja build. | 365 the Xcode settings into command line flags for the ninja build. |
366 | 366 |
367 ### wexit-time destructors | 367 ### wexit-time destructors |
368 | 368 |
369 Replace | 369 Replace |
370 | 370 |
371 ``` | 371 ``` |
372 'enable_wexit_time_destructors': 1, | 372 'enable_wexit_time_destructors': 1, |
373 ``` | 373 ``` |
374 | 374 |
375 with | 375 with |
376 | 376 |
377 ``` | 377 ``` |
378 configs += [ "//build/config/compiler:wexit_time_destructors" ] | 378 configs += [ "//build/config/compiler:wexit_time_destructors" ] |
379 ``` | 379 ``` |
380 | 380 |
381 ### Chromium code | 381 ### Chromium code |
382 | 382 |
383 In GYP code is "non-Chromium" by default, and you opt into higher warning levels using: | 383 In GYP code is "non-Chromium" by default, and you opt into higher warning levels using: |
384 | 384 |
385 ``` | 385 ``` |
386 'chromium_code': 1, | 386 'chromium_code': 1, |
387 ``` | 387 ``` |
388 | 388 |
389 In GN, all code is Chromium code by default. If you're compiling a | 389 In GN, all code is Chromium code by default. If you're compiling a |
390 static library that needs more lax warnings, opt out of the | 390 static library that needs more lax warnings, opt out of the |
391 Chromium-code settings with: | 391 Chromium-code settings with: |
392 | 392 |
393 ``` | 393 ``` |
394 configs -= [ "//build/config/compiler:chromium_code" ] | 394 configs -= [ "//build/config/compiler:chromium_code" ] |
395 configs += [ "//build/config/compiler:no_chromium_code" ] | 395 configs += [ "//build/config/compiler:no_chromium_code" ] |
396 ``` | 396 ``` |
397 | 397 |
398 ### -fvisibility | 398 ### -fvisibility |
399 | 399 |
400 All symbols in the build have "hidden" visibility by default (this means | 400 All symbols in the build have "hidden" visibility by default (this means |
401 that symbols aren't exported from shared libraries, a concept different | 401 that symbols aren't exported from shared libraries, a concept different |
402 than GN's target visibility). If you needed to export all symbols (for a | 402 than GN's target visibility). If you needed to export all symbols (for a |
403 third party library) by default in GYP you would do: | 403 third party library) by default in GYP you would do: |
404 | 404 |
405 ``` | 405 ``` |
406 'xcode_settings': [ | 406 'xcode_settings': [ |
407 'GCC_SYMBOLS_PRIVATE_EXTERN': 'NO', # no -fvisibility=hidden | 407 'GCC_SYMBOLS_PRIVATE_EXTERN': 'NO', # no -fvisibility=hidden |
408 ], | 408 ], |
409 'cflags!': [ | 409 'cflags!': [ |
410 '-fvisibility=hidden', | 410 '-fvisibility=hidden', |
411 ], | 411 ], |
412 ``` | 412 ``` |
413 | 413 |
414 In GN the equivalent is: | 414 In GN the equivalent is: |
415 | 415 |
416 ``` | 416 ``` |
417 if (!is_win) { | 417 if (!is_win) { |
418 configs -= [ "//build/config/gcc:symbol_visibility_hidden" ] | 418 configs -= [ "//build/config/gcc:symbol_visibility_hidden" ] |
419 } | 419 } |
420 ``` | 420 ``` |
421 | 421 |
422 ### Dependent settings | 422 ### Dependent settings |
423 | 423 |
424 In GYP you'll see stuff like this, especially in third-party code. | 424 In GYP you'll see stuff like this, especially in third-party code. |
425 | 425 |
426 ``` | 426 ``` |
427 'direct_dependent_settings': { | 427 'direct_dependent_settings': { |
428 'include_dirs': [ | 428 'include_dirs': [ |
429 '.', # This directory. | 429 '.', # This directory. |
430 '../..', # Root "src" path. | 430 '../..', # Root "src" path. |
431 ], | 431 ], |
432 'defines': [ | 432 'defines': [ |
(...skipping 26 matching lines...) Expand all Loading... | |
459 } | 459 } |
460 ``` | 460 ``` |
461 | 461 |
462 Targets that depend on `foo` will now get `foo_config` applied. | 462 Targets that depend on `foo` will now get `foo_config` applied. |
463 | 463 |
464 GYP would say `export_dependent_settings` to forward | 464 GYP would say `export_dependent_settings` to forward |
465 `direct_dependent_settings` up the dependency chain. In GN, put the | 465 `direct_dependent_settings` up the dependency chain. In GN, put the |
466 dependency in the `public_deps` section and this will happen | 466 dependency in the `public_deps` section and this will happen |
467 automatically. | 467 automatically. |
468 | 468 |
469 ### MSVS disabled warnings | 469 ### MSVS disabled warnings |
470 | 470 |
471 In GYP you'll see for third-party code: | 471 In GYP you'll see for third-party code: |
472 | 472 |
473 ``` | 473 ``` |
474 'msvs_disabled_warnings': [ 4018, 4244, 4267, ], | 474 'msvs_disabled_warnings': [ 4018, 4244, 4267, ], |
475 ``` | 475 ``` |
476 | 476 |
477 At least half of the warnings in these blocks are already disabled | 477 At least half of the warnings in these blocks are already disabled |
478 globally (we added more global ones later). From the command line, do: | 478 globally (we added more global ones later). From the command line, do: |
479 | 479 |
(...skipping 13 matching lines...) Expand all Loading... | |
493 ``` | 493 ``` |
494 if (is_win) { | 494 if (is_win) { |
495 cflags += [ | 495 cflags += [ |
496 "/wd4267", # Conversion from size_t to 'type'. | 496 "/wd4267", # Conversion from size_t to 'type'. |
497 ] | 497 ] |
498 } | 498 } |
499 ``` | 499 ``` |
500 | 500 |
501 (Use `=` instead of `+=` is you haven't already defined a `cflags` variable.) | 501 (Use `=` instead of `+=` is you haven't already defined a `cflags` variable.) |
502 | 502 |
503 ### Mac frameworks | 503 ### Mac frameworks |
504 | 504 |
505 GN knows to convert `.framework` files in the `libs` list to the right | 505 GN knows to convert `.framework` files in the `libs` list to the right |
506 thing on Mac. You don't need to specify the directories either. So | 506 thing on Mac. You don't need to specify the directories either. So |
507 convert this: | 507 convert this: |
508 | 508 |
509 ``` | 509 ``` |
510 'link_settings': { | 510 'link_settings': { |
511 'libraries': [ | 511 'libraries': [ |
512 '$(SDKROOT)/System/Library/Frameworks/Accelerate.framework', | 512 '$(SDKROOT)/System/Library/Frameworks/Accelerate.framework', |
513 ], | 513 ], |
514 }, | 514 }, |
515 ``` | 515 ``` |
516 | 516 |
517 to this: | 517 to this: |
518 | 518 |
519 ``` | 519 ``` |
520 libs = [ "Accelerate.framework" ] | 520 libs = [ "Accelerate.framework" ] |
521 ``` | 521 ``` |
522 | 522 |
523 ### hard_dependency | 523 ### hard_dependency |
524 | 524 |
525 GYP code sometimes sets | 525 GYP code sometimes sets |
526 | 526 |
527 ``` | 527 ``` |
528 'hard_dependency': 1, | 528 'hard_dependency': 1, |
529 ``` | 529 ``` |
530 | 530 |
531 to indicate that the current target must be build before its dependents. | 531 to indicate that the current target must be build before its dependents. |
532 GN can deduce this internally, so you can ignore this directive. | 532 GN can deduce this internally, so you can ignore this directive. |
533 | 533 |
534 ### Allocator | 534 ### Allocator |
535 | 535 |
536 GYP has `win_use_allocator_shim` and `use_allocator`. In GN, these are | 536 GYP has `win_use_allocator_shim` and `use_allocator`. In GN, these are |
537 merged into `use_allocator` which is defined in | 537 merged into `use_allocator` which is defined in |
538 `//build/config/allocator.gni`. _However_ you should almost never need | 538 `//build/config/allocator.gni`. _However_ you should almost never need |
539 to use this flag. The `//base/allocator` target will change depending on | 539 to use this flag. The `//base/allocator` target will change depending on |
540 the current allocator flag, so you can unconditionally depend on this | 540 the current allocator flag, so you can unconditionally depend on this |
541 target to pick up the current build defaults. | 541 target to pick up the current build defaults. |
542 | 542 |
543 This: | 543 This: |
544 | 544 |
545 ``` | 545 ``` |
546 ['use_allocator!='none'', { | 546 ['use_allocator!='none'', { |
547 'dependencies': [ '../base/allocator/allocator.gyp:allocator' ] | 547 'dependencies': [ '../base/allocator/allocator.gyp:allocator' ] |
548 }], | 548 }], |
549 ['win_use_allocator_shim==1', { | 549 ['win_use_allocator_shim==1', { |
550 'dependencies': [ '<(allocator_target)' ], | 550 'dependencies': [ '<(allocator_target)' ], |
551 }], | 551 }], |
552 ``` | 552 ``` |
553 | 553 |
554 Becomes: | 554 Becomes: |
555 | 555 |
556 ``` | 556 ``` |
557 deps = [ "//base/allocator" ] | 557 deps = [ "//base/allocator" ] |
558 ``` | 558 ``` |
559 | 559 |
560 As in GYP, the allocator should only be depended on by executables (and | 560 As in GYP, the allocator should only be depended on by executables (and |
561 tests). Libraries should not set the allocator. | 561 tests). Libraries should not set the allocator. |
562 | 562 |
563 ### optimize: max | 563 ### optimize: max |
564 | 564 |
565 In Gyp: | 565 In Gyp: |
566 | 566 |
567 ``` | 567 ``` |
568 'optimize': 'max', | 568 'optimize': 'max', |
569 ``` | 569 ``` |
570 | 570 |
571 only affects Windows and will optimize for speed rather than size. To | 571 only affects Windows and will optimize for speed rather than size. To |
572 get the same behavior in GN, do: | 572 get the same behavior in GN, do: |
573 | 573 |
574 ``` | 574 ``` |
575 if (!is_debug && is_win) { | 575 if (!is_debug && is_win) { |
576 configs -= [ "//build/config/compiler:optimize" ] | 576 configs -= [ "//build/config/compiler:optimize" ] |
577 configs += [ "//build/config/compiler:optimize_max" ] | 577 configs += [ "//build/config/compiler:optimize_max" ] |
578 } | 578 } |
579 ``` | 579 ``` |
580 | 580 |
581 The `is_win` check is needed because the `optimize_max` config also | 581 The `is_win` check is needed because the `optimize_max` config also |
582 affects Posix systems. Some components might additionally specify `-O2` | 582 affects Posix systems. Some components might additionally specify `-O2` |
583 on Posix further optimize, in which case you can remove the `is_win` | 583 on Posix further optimize, in which case you can remove the `is_win` |
584 check. | 584 check. |
585 | 585 |
586 ### Protobufs | 586 ### Protobufs |
587 | 587 |
588 ``` | 588 ``` |
589 import("//third_party/protobuf/proto_library.gni") | 589 import("//third_party/protobuf/proto_library.gni") |
590 | 590 |
591 proto_library("myproto") { | 591 proto_library("myproto") { |
592 sources = [ "foo.proto" ] | 592 sources = [ "foo.proto" ] |
593 } | 593 } |
594 ``` | 594 ``` |
595 | 595 |
596 See the `third_party/protobuf/proto_library.gni` file for full | 596 See the `third_party/protobuf/proto_library.gni` file for full |
597 documentation and extra flags. | 597 documentation and extra flags. |
598 | 598 |
599 ### Java stuff | 599 ### Java stuff |
600 | 600 |
601 JNI generator in GYP: | 601 JNI generator in GYP: |
602 | 602 |
603 ``` | 603 ``` |
604 { | 604 { |
605 'target_name': 'foo_headers', | 605 'target_name': 'foo_headers', |
606 'type': 'none', | 606 'type': 'none', |
607 'sources': [ <java files> ] | 607 'sources': [ <java files> ] |
608 'variables': { 'jni_gen_package': 'foobar' } | 608 'variables': { 'jni_gen_package': 'foobar' } |
609 'includes': [ 'build/jni_generator.gypi' ] | 609 'includes': [ 'build/jni_generator.gypi' ] |
(...skipping 10 matching lines...) Expand all Loading... | |
620 | 620 |
621 # Later: | 621 # Later: |
622 if (is_android) { | 622 if (is_android) { |
623 generate_jni("foo_headers") { | 623 generate_jni("foo_headers") { |
624 sources = [ <java files> ] | 624 sources = [ <java files> ] |
625 jni_package = "foobar" | 625 jni_package = "foobar" |
626 } | 626 } |
627 } | 627 } |
628 ``` | 628 ``` |
629 | 629 |
630 ### Grit | 630 ### Grit |
631 | 631 |
632 ``` | 632 ``` |
633 import("//tools/grit/grit_rule.gni") | 633 import("//tools/grit/grit_rule.gni") |
634 | 634 |
635 grit("resources") { | 635 grit("resources") { |
636 source = "my_resources.grd" | 636 source = "my_resources.grd" |
637 } | 637 } |
638 ``` | 638 ``` |
639 | 639 |
640 See `src/build/secondary/tools/grit/grit_rule.gni` for more documentation. | 640 See `src/build/secondary/tools/grit/grit_rule.gni` for more documentation. |
641 | 641 |
642 ### Mojo | 642 ### Mojo |
643 | 643 |
644 ``` | 644 ``` |
645 import("//mojo/public/tools/bindings/mojom.gni") | 645 import("//mojo/public/tools/bindings/mojom.gni") |
646 | 646 |
647 mojom("mojo_bindings") { | 647 mojom("mojo_bindings") { |
648 sources = [ | 648 sources = [ |
649 "foo.mojom", | 649 "foo.mojom", |
650 ] | 650 ] |
651 } | 651 } |
652 ``` | 652 ``` |
OLD | NEW |