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 |
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` | |
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 [tools/gyp/pylib/gyp/xcode_emulation.py](https://code.google.com/p/chromium/code
search#chromium/src/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 | |
365 the Xcode settings into command line flags for the ninja build. | 364 the Xcode settings into command line flags for the ninja build. |
366 | 365 |
367 ### wexit-time destructors | 366 ### wexit-time destructors |
368 | 367 |
369 Replace | 368 Replace |
370 | 369 |
371 ``` | 370 ``` |
372 'enable_wexit_time_destructors': 1, | 371 'enable_wexit_time_destructors': 1, |
373 ``` | 372 ``` |
374 | 373 |
375 with | 374 with |
376 | 375 |
377 ``` | 376 ``` |
378 configs += [ "//build/config/compiler:wexit_time_destructors" ] | 377 configs += [ "//build/config/compiler:wexit_time_destructors" ] |
379 ``` | 378 ``` |
380 | 379 |
381 ### Chromium code | 380 ### Chromium code |
382 | 381 |
383 In GYP code is "non-Chromium" by default, and you opt into higher warning levels
using: | 382 In GYP code is "non-Chromium" by default, and you opt into higher warning levels
using: |
384 | 383 |
385 ``` | 384 ``` |
386 'chromium_code': 1, | 385 'chromium_code': 1, |
387 ``` | 386 ``` |
388 | 387 |
389 In GN, all code is Chromium code by default. If you're compiling a | 388 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 | 389 static library that needs more lax warnings, opt out of the |
391 Chromium-code settings with: | 390 Chromium-code settings with: |
392 | 391 |
393 ``` | 392 ``` |
394 configs -= [ "//build/config/compiler:chromium_code" ] | 393 configs -= [ "//build/config/compiler:chromium_code" ] |
395 configs += [ "//build/config/compiler:no_chromium_code" ] | 394 configs += [ "//build/config/compiler:no_chromium_code" ] |
396 ``` | 395 ``` |
397 | 396 |
398 ### -fvisibility | 397 ### -fvisibility |
399 | 398 |
400 All symbols in the build have "hidden" visibility by default (this means | 399 All symbols in the build have "hidden" visibility by default (this means |
401 that symbols aren't exported from shared libraries, a concept different | 400 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 | 401 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: | 402 third party library) by default in GYP you would do: |
404 | 403 |
405 ``` | 404 ``` |
406 'xcode_settings': [ | 405 'xcode_settings': [ |
407 'GCC_SYMBOLS_PRIVATE_EXTERN': 'NO', # no -fvisibility=hidden | 406 'GCC_SYMBOLS_PRIVATE_EXTERN': 'NO', # no -fvisibility=hidden |
408 ], | 407 ], |
409 'cflags!': [ | 408 'cflags!': [ |
410 '-fvisibility=hidden', | 409 '-fvisibility=hidden', |
411 ], | 410 ], |
412 ``` | 411 ``` |
413 | 412 |
414 In GN the equivalent is: | 413 In GN the equivalent is: |
415 | 414 |
416 ``` | 415 ``` |
417 if (!is_win) { | 416 if (!is_win) { |
418 configs -= [ "//build/config/gcc:symbol_visibility_hidden" ] | 417 configs -= [ "//build/config/gcc:symbol_visibility_hidden" ] |
419 } | 418 } |
420 ``` | 419 ``` |
421 | 420 |
422 ### Dependent settings | 421 ### Dependent settings |
423 | 422 |
424 In GYP you'll see stuff like this, especially in third-party code. | 423 In GYP you'll see stuff like this, especially in third-party code. |
425 | 424 |
426 ``` | 425 ``` |
427 'direct_dependent_settings': { | 426 'direct_dependent_settings': { |
428 'include_dirs': [ | 427 'include_dirs': [ |
429 '.', # This directory. | 428 '.', # This directory. |
430 '../..', # Root "src" path. | 429 '../..', # Root "src" path. |
431 ], | 430 ], |
432 'defines': [ | 431 'defines': [ |
(...skipping 26 matching lines...) Expand all Loading... |
459 } | 458 } |
460 ``` | 459 ``` |
461 | 460 |
462 Targets that depend on `foo` will now get `foo_config` applied. | 461 Targets that depend on `foo` will now get `foo_config` applied. |
463 | 462 |
464 GYP would say `export_dependent_settings` to forward | 463 GYP would say `export_dependent_settings` to forward |
465 `direct_dependent_settings` up the dependency chain. In GN, put the | 464 `direct_dependent_settings` up the dependency chain. In GN, put the |
466 dependency in the `public_deps` section and this will happen | 465 dependency in the `public_deps` section and this will happen |
467 automatically. | 466 automatically. |
468 | 467 |
469 ### MSVS disabled warnings | 468 ### MSVS disabled warnings |
470 | 469 |
471 In GYP you'll see for third-party code: | 470 In GYP you'll see for third-party code: |
472 | 471 |
473 ``` | 472 ``` |
474 'msvs_disabled_warnings': [ 4018, 4244, 4267, ], | 473 'msvs_disabled_warnings': [ 4018, 4244, 4267, ], |
475 ``` | 474 ``` |
476 | 475 |
477 At least half of the warnings in these blocks are already disabled | 476 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: | 477 globally (we added more global ones later). From the command line, do: |
479 | 478 |
(...skipping 13 matching lines...) Expand all Loading... |
493 ``` | 492 ``` |
494 if (is_win) { | 493 if (is_win) { |
495 cflags += [ | 494 cflags += [ |
496 "/wd4267", # Conversion from size_t to 'type'. | 495 "/wd4267", # Conversion from size_t to 'type'. |
497 ] | 496 ] |
498 } | 497 } |
499 ``` | 498 ``` |
500 | 499 |
501 (Use `=` instead of `+=` is you haven't already defined a `cflags` variable.) | 500 (Use `=` instead of `+=` is you haven't already defined a `cflags` variable.) |
502 | 501 |
503 ### Mac frameworks | 502 ### Mac frameworks |
504 | 503 |
505 GN knows to convert `.framework` files in the `libs` list to the right | 504 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 | 505 thing on Mac. You don't need to specify the directories either. So |
507 convert this: | 506 convert this: |
508 | 507 |
509 ``` | 508 ``` |
510 'link_settings': { | 509 'link_settings': { |
511 'libraries': [ | 510 'libraries': [ |
512 '$(SDKROOT)/System/Library/Frameworks/Accelerate.framework', | 511 '$(SDKROOT)/System/Library/Frameworks/Accelerate.framework', |
513 ], | 512 ], |
514 }, | 513 }, |
515 ``` | 514 ``` |
516 | 515 |
517 to this: | 516 to this: |
518 | 517 |
519 ``` | 518 ``` |
520 libs = [ "Accelerate.framework" ] | 519 libs = [ "Accelerate.framework" ] |
521 ``` | 520 ``` |
522 | 521 |
523 ### hard_dependency | 522 ### hard_dependency |
524 | 523 |
525 GYP code sometimes sets | 524 GYP code sometimes sets |
526 | 525 |
527 ``` | 526 ``` |
528 'hard_dependency': 1, | 527 'hard_dependency': 1, |
529 ``` | 528 ``` |
530 | 529 |
531 to indicate that the current target must be build before its dependents. | 530 to indicate that the current target must be build before its dependents. |
532 GN can deduce this internally, so you can ignore this directive. | 531 GN can deduce this internally, so you can ignore this directive. |
533 | 532 |
534 ### Allocator | 533 ### Allocator |
535 | 534 |
536 GYP has `win_use_allocator_shim` and `use_allocator`. In GN, these are | 535 GYP has `win_use_allocator_shim` and `use_allocator`. In GN, these are |
537 merged into `use_allocator` which is defined in | 536 merged into `use_allocator` which is defined in |
538 `//build/config/allocator.gni`. _However_ you should almost never need | 537 `//build/config/allocator.gni`. _However_ you should almost never need |
539 to use this flag. The `//base/allocator` target will change depending on | 538 to use this flag. The `//base/allocator` target will change depending on |
540 the current allocator flag, so you can unconditionally depend on this | 539 the current allocator flag, so you can unconditionally depend on this |
541 target to pick up the current build defaults. | 540 target to pick up the current build defaults. |
542 | 541 |
543 This: | 542 This: |
544 | 543 |
545 ``` | 544 ``` |
546 ['use_allocator!='none'', { | 545 ['use_allocator!='none'', { |
547 'dependencies': [ '../base/allocator/allocator.gyp:allocator' ] | 546 'dependencies': [ '../base/allocator/allocator.gyp:allocator' ] |
548 }], | 547 }], |
549 ['win_use_allocator_shim==1', { | 548 ['win_use_allocator_shim==1', { |
550 'dependencies': [ '<(allocator_target)' ], | 549 'dependencies': [ '<(allocator_target)' ], |
551 }], | 550 }], |
552 ``` | 551 ``` |
553 | 552 |
554 Becomes: | 553 Becomes: |
555 | 554 |
556 ``` | 555 ``` |
557 deps = [ "//base/allocator" ] | 556 deps = [ "//base/allocator" ] |
558 ``` | 557 ``` |
559 | 558 |
560 As in GYP, the allocator should only be depended on by executables (and | 559 As in GYP, the allocator should only be depended on by executables (and |
561 tests). Libraries should not set the allocator. | 560 tests). Libraries should not set the allocator. |
562 | 561 |
563 ### optimize: max | 562 ### optimize: max |
564 | 563 |
565 In Gyp: | 564 In Gyp: |
566 | 565 |
567 ``` | 566 ``` |
568 'optimize': 'max', | 567 'optimize': 'max', |
569 ``` | 568 ``` |
570 | 569 |
571 only affects Windows and will optimize for speed rather than size. To | 570 only affects Windows and will optimize for speed rather than size. To |
572 get the same behavior in GN, do: | 571 get the same behavior in GN, do: |
573 | 572 |
574 ``` | 573 ``` |
575 if (!is_debug && is_win) { | 574 if (!is_debug && is_win) { |
576 configs -= [ "//build/config/compiler:optimize" ] | 575 configs -= [ "//build/config/compiler:optimize" ] |
577 configs += [ "//build/config/compiler:optimize_max" ] | 576 configs += [ "//build/config/compiler:optimize_max" ] |
578 } | 577 } |
579 ``` | 578 ``` |
580 | 579 |
581 The `is_win` check is needed because the `optimize_max` config also | 580 The `is_win` check is needed because the `optimize_max` config also |
582 affects Posix systems. Some components might additionally specify `-O2` | 581 affects Posix systems. Some components might additionally specify `-O2` |
583 on Posix further optimize, in which case you can remove the `is_win` | 582 on Posix further optimize, in which case you can remove the `is_win` |
584 check. | 583 check. |
585 | 584 |
586 ### Protobufs | 585 ### Protobufs |
587 | 586 |
588 ``` | 587 ``` |
589 import("//third_party/protobuf/proto_library.gni") | 588 import("//third_party/protobuf/proto_library.gni") |
590 | 589 |
591 proto_library("myproto") { | 590 proto_library("myproto") { |
592 sources = [ "foo.proto" ] | 591 sources = [ "foo.proto" ] |
593 } | 592 } |
594 ``` | 593 ``` |
595 | 594 |
596 See the `third_party/protobuf/proto_library.gni` file for full | 595 See the `third_party/protobuf/proto_library.gni` file for full |
597 documentation and extra flags. | 596 documentation and extra flags. |
598 | 597 |
599 ### Java stuff | 598 ### Java stuff |
600 | 599 |
601 JNI generator in GYP: | 600 JNI generator in GYP: |
602 | 601 |
603 ``` | 602 ``` |
604 { | 603 { |
605 'target_name': 'foo_headers', | 604 'target_name': 'foo_headers', |
606 'type': 'none', | 605 'type': 'none', |
607 'sources': [ <java files> ] | 606 'sources': [ <java files> ] |
608 'variables': { 'jni_gen_package': 'foobar' } | 607 'variables': { 'jni_gen_package': 'foobar' } |
609 'includes': [ 'build/jni_generator.gypi' ] | 608 'includes': [ 'build/jni_generator.gypi' ] |
(...skipping 10 matching lines...) Expand all Loading... |
620 | 619 |
621 # Later: | 620 # Later: |
622 if (is_android) { | 621 if (is_android) { |
623 generate_jni("foo_headers") { | 622 generate_jni("foo_headers") { |
624 sources = [ <java files> ] | 623 sources = [ <java files> ] |
625 jni_package = "foobar" | 624 jni_package = "foobar" |
626 } | 625 } |
627 } | 626 } |
628 ``` | 627 ``` |
629 | 628 |
630 ### Grit | 629 ### Grit |
631 | 630 |
632 ``` | 631 ``` |
633 import("//tools/grit/grit_rule.gni") | 632 import("//tools/grit/grit_rule.gni") |
634 | 633 |
635 grit("resources") { | 634 grit("resources") { |
636 source = "my_resources.grd" | 635 source = "my_resources.grd" |
637 } | 636 } |
638 ``` | 637 ``` |
639 | 638 |
640 See `src/build/secondary/tools/grit/grit_rule.gni` for more documentation. | 639 See `src/build/secondary/tools/grit/grit_rule.gni` for more documentation. |
641 | 640 |
642 ### Mojo | 641 ### Mojo |
643 | 642 |
644 ``` | 643 ``` |
645 import("//mojo/public/tools/bindings/mojom.gni") | 644 import("//mojo/public/tools/bindings/mojom.gni") |
646 | 645 |
647 mojom("mojo_bindings") { | 646 mojom("mojo_bindings") { |
648 sources = [ | 647 sources = [ |
649 "foo.mojom", | 648 "foo.mojom", |
650 ] | 649 ] |
651 } | 650 } |
652 ``` | 651 ``` |
OLD | NEW |