|
148 | 148 | * [testonly: [boolean] Declares a target must only be used for testing.](#var_testonly)
|
149 | 149 | * [visibility: [label list] A list of labels that can depend on a target.](#var_visibility)
|
150 | 150 | * [walk_keys: [string list] Key(s) for managing the metadata collection walk.](#var_walk_keys)
|
| 151 | + * [weak_frameworks: [name list] Name of frameworks that must be weak linked.](#var_weak_frameworks) |
151 | 152 | * [write_runtime_deps: Writes the target's runtime_deps to the given path.](#var_write_runtime_deps)
|
152 | 153 | * [xcode_extra_attributes: [scope] Extra attributes for Xcode projects.](#var_xcode_extra_attributes)
|
153 | 154 | * [xcode_test_application_name: [string] Name for Xcode test target.](#var_xcode_test_application_name)
|
|
348 | 349 | #### **Command-specific switches**
|
349 | 350 |
|
350 | 351 | ```
|
351 |
| - --force |
352 |
| - Ignores specifications of "check_includes = false" and checks all |
353 |
| - target's files that match the target label. |
354 |
| -
|
355 | 352 | --check-generated
|
356 | 353 | Generated files are normally not checked since they do not exist
|
357 | 354 | until after a build. With this flag, those generated files that
|
358 | 355 | can be found on disk are also checked.
|
| 356 | +
|
| 357 | + --default-toolchain |
| 358 | + Normally wildcard targets are matched in all toolchains. This |
| 359 | + switch makes wildcard labels with no explicit toolchain reference |
| 360 | + only match targets in the default toolchain. |
| 361 | +
|
| 362 | + Non-wildcard inputs with no explicit toolchain specification will |
| 363 | + always match only a target in the default toolchain if one exists. |
| 364 | +
|
| 365 | + --force |
| 366 | + Ignores specifications of "check_includes = false" and checks all |
| 367 | + target's files that match the target label. |
359 | 368 | ```
|
360 | 369 |
|
361 | 370 | #### **What gets checked**
|
|
453 | 462 | gn check out/Default "//foo/*
|
454 | 463 | Check only the files in targets in the //foo directory tree.
|
455 | 464 | ```
|
456 |
| -### <a name="cmd_clean"></a>**gn clean <out_dir>** |
| 465 | +### <a name="cmd_clean"></a>**gn clean <out_dir>...** |
457 | 466 |
|
458 | 467 | ```
|
459 | 468 | Deletes the contents of the output directory except for args.gn and
|
|
509 | 518 | testonly
|
510 | 519 | visibility
|
511 | 520 | walk_keys
|
| 521 | + weak_frameworks |
512 | 522 |
|
513 | 523 | runtime_deps
|
514 | 524 | Compute all runtime deps for the given target. This is a computed list
|
|
521 | 531 | ```
|
522 | 532 |
|
523 | 533 | #### **Shared flags**
|
| 534 | + |
524 | 535 | ```
|
525 |
| - --all-toolchains |
526 |
| - Normally only inputs in the default toolchain will be included. |
527 |
| - This switch will turn on matching all toolchains. |
| 536 | + --default-toolchain |
| 537 | + Normally wildcard targets are matched in all toolchains. This |
| 538 | + switch makes wildcard labels with no explicit toolchain reference |
| 539 | + only match targets in the default toolchain. |
528 | 540 |
|
529 |
| - For example, a file is in a target might be compiled twice: |
530 |
| - once in the default toolchain and once in a secondary one. Without |
531 |
| - this flag, only the default toolchain one will be matched by |
532 |
| - wildcards. With this flag, both will be matched. |
| 541 | + Non-wildcard inputs with no explicit toolchain specification will |
| 542 | + always match only a target in the default toolchain if one exists. |
533 | 543 |
|
534 | 544 | --format=json
|
535 | 545 | Format the output as JSON instead of text.
|
|
541 | 551 | --blame
|
542 | 552 | Used with any value specified on a config, this will name the config that
|
543 | 553 | causes that target to get the flag. This doesn't currently work for libs,
|
544 |
| - lib_dirs, frameworks and framework_dirs because those are inherited and |
545 |
| - are more complicated to figure out the blame (patches welcome). |
| 554 | + lib_dirs, frameworks, weak_frameworks and framework_dirs because those are |
| 555 | + inherited and are more complicated to figure out the blame (patches |
| 556 | + welcome). |
546 | 557 | ```
|
547 | 558 |
|
548 | 559 | #### **Configs**
|
|
572 | 583 | --all
|
573 | 584 | Collects all recursive dependencies and prints a sorted flat list. Also
|
574 | 585 | usable with --tree (see below).
|
| 586 | +
|
575 | 587 | --as=(buildfile|label|output)
|
576 | 588 | How to print targets.
|
577 | 589 |
|
|
598 | 610 |
|
599 | 611 | Tree output can not be used with the filtering or output flags: --as,
|
600 | 612 | --type, --testonly.
|
| 613 | +
|
601 | 614 | --type=(action|copy|executable|group|loadable_module|shared_library|
|
602 | 615 | source_set|static_library)
|
603 | 616 | Restrict outputs to targets matching the given type. If
|
|
797 | 810 | #### **Compilation Database**
|
798 | 811 |
|
799 | 812 | ```
|
| 813 | + --export-rust-project |
| 814 | + Produces a rust-project.json file in the root of the build directory |
| 815 | + This is used for various tools in the Rust ecosystem allowing for the |
| 816 | + replay of individual compilations independent of the build system. |
| 817 | + This is an unstable format and likely to change without warning. |
| 818 | +
|
800 | 819 | --export-compile-commands[=<target_name1,target_name2...>]
|
801 | 820 | Produces a compile_commands.json file in the root of the build directory
|
802 | 821 | containing an array of “command objects”, where each command object
|
|
829 | 848 | gn help --markdown all
|
830 | 849 | Dump all help to stdout in markdown format.
|
831 | 850 | ```
|
832 |
| -### <a name="cmd_ls"></a>**gn ls <out_dir> [<label_pattern>] [\--all-toolchains] [\--as=...]** |
| 851 | +### <a name="cmd_ls"></a>**gn ls <out_dir> [<label_pattern>] [\--default-toolchain] [\--as=...]** |
833 | 852 | ```
|
834 | 853 | [--type=...] [--testonly=...]
|
835 | 854 |
|
|
857 | 876 | Prints the first output file for the target relative to the
|
858 | 877 | root build directory.
|
859 | 878 |
|
860 |
| - --all-toolchains |
861 |
| - Normally only inputs in the default toolchain will be included. |
862 |
| - This switch will turn on matching all toolchains. |
| 879 | + --default-toolchain |
| 880 | + Normally wildcard targets are matched in all toolchains. This |
| 881 | + switch makes wildcard labels with no explicit toolchain reference |
| 882 | + only match targets in the default toolchain. |
863 | 883 |
|
864 |
| - For example, a file is in a target might be compiled twice: |
865 |
| - once in the default toolchain and once in a secondary one. Without |
866 |
| - this flag, only the default toolchain one will be matched by |
867 |
| - wildcards. With this flag, both will be matched. |
| 884 | + Non-wildcard inputs with no explicit toolchain specification will |
| 885 | + always match only a target in the default toolchain if one exists. |
868 | 886 |
|
869 | 887 | --testonly=(true|false)
|
870 | 888 | Restrict outputs to targets with the testonly flag set
|
|
897 | 915 |
|
898 | 916 | gn ls out/Debug "//base/*" --as=output | xargs ninja -C out/Debug
|
899 | 917 | Builds all targets in //base and all subdirectories.
|
900 |
| -
|
901 |
| - gn ls out/Debug //base --all-toolchains |
902 |
| - Lists all variants of the target //base:base (it may be referenced |
903 |
| - in multiple toolchains). |
904 | 918 | ```
|
905 | 919 | ### <a name="cmd_meta"></a>**gn meta**
|
906 | 920 |
|
|
1008 | 1022 |
|
1009 | 1023 | ```
|
1010 | 1024 | gn refs <out_dir> (<label_pattern>|<label>|<file>|@<response_file>)*
|
1011 |
| - [--all] [--all-toolchains] [--as=...] [--testonly=...] [--type=...] |
| 1025 | + [--all] [--default-toolchain] [--as=...] [--testonly=...] [--type=...] |
1012 | 1026 |
|
1013 | 1027 | Finds reverse dependencies (which targets reference something). The input is
|
1014 | 1028 | a list containing:
|
|
1044 | 1058 | directly or indirectly on that file.
|
1045 | 1059 |
|
1046 | 1060 | When used with --tree, turns off eliding to show a complete tree.
|
1047 |
| - --all-toolchains |
1048 |
| - Normally only inputs in the default toolchain will be included. |
1049 |
| - This switch will turn on matching all toolchains. |
1050 |
| -
|
1051 |
| - For example, a file is in a target might be compiled twice: |
1052 |
| - once in the default toolchain and once in a secondary one. Without |
1053 |
| - this flag, only the default toolchain one will be matched by |
1054 |
| - wildcards. With this flag, both will be matched. |
1055 | 1061 |
|
1056 | 1062 | --as=(buildfile|label|output)
|
1057 | 1063 | How to print targets.
|
|
1065 | 1071 | Prints the first output file for the target relative to the
|
1066 | 1072 | root build directory.
|
1067 | 1073 |
|
| 1074 | + --default-toolchain |
| 1075 | + Normally wildcard targets are matched in all toolchains. This |
| 1076 | + switch makes wildcard labels with no explicit toolchain reference |
| 1077 | + only match targets in the default toolchain. |
| 1078 | +
|
| 1079 | + Non-wildcard inputs with no explicit toolchain specification will |
| 1080 | + always match only a target in the default toolchain if one exists. |
| 1081 | +
|
1068 | 1082 | -q
|
1069 | 1083 | Quiet. If nothing matches, don't print any output. Without this option, if
|
1070 | 1084 | there are no matches there will be an informational message printed which
|
1071 | 1085 | might interfere with scripts processing the output.
|
| 1086 | +
|
1072 | 1087 | --testonly=(true|false)
|
1073 | 1088 | Restrict outputs to targets with the testonly flag set
|
1074 | 1089 | accordingly. When unspecified, the target's testonly flags are
|
|
1080 | 1095 |
|
1081 | 1096 | Tree output can not be used with the filtering or output flags: --as,
|
1082 | 1097 | --type, --testonly.
|
| 1098 | +
|
1083 | 1099 | --type=(action|copy|executable|group|loadable_module|shared_library|
|
1084 | 1100 | source_set|static_library)
|
1085 | 1101 | Restrict outputs to targets matching the given type. If
|
|
1838 | 1854 | ### <a name="func_source_set"></a>**source_set**: Declare a source set target.
|
1839 | 1855 |
|
1840 | 1856 | ```
|
1841 |
| - The language of a source_set target is determined by the extensions present |
1842 |
| - in its sources. |
| 1857 | + Only C-language source sets are supported at the moment. |
1843 | 1858 | ```
|
1844 | 1859 |
|
1845 | 1860 | #### **C-language source_sets**
|
|
1867 | 1882 | when linking multiple static libraries into a shared library.
|
1868 | 1883 | ```
|
1869 | 1884 |
|
1870 |
| -#### **Rust-language source_sets** |
1871 |
| - |
1872 |
| -``` |
1873 |
| - A Rust source set is a collection of sources that get passed along to the |
1874 |
| - final target that depends on it. No compilation is performed, and the source |
1875 |
| - files are simply added as dependencies on the eventual rustc invocation that |
1876 |
| - would produce a binary. |
1877 |
| -``` |
1878 |
| - |
1879 | 1885 | #### **Variables**
|
1880 | 1886 |
|
1881 | 1887 | ```
|
|
2777 | 2783 | with a double slash like "//foo/bar"), you should use the get_path_info()
|
2778 | 2784 | function. This function won't work because it will always make relative
|
2779 | 2785 | paths, and it needs to support making paths relative to the source root, so
|
2780 |
| - can't also generate source-absolute paths without more special-cases. |
| 2786 | + it can't also generate source-absolute paths without more special-cases. |
2781 | 2787 | ```
|
2782 | 2788 |
|
2783 | 2789 | #### **Arguments**
|
2784 | 2790 |
|
2785 | 2791 | ```
|
2786 | 2792 | input
|
2787 |
| - A string or list of strings representing file or directory names These |
| 2793 | + A string or list of strings representing file or directory names. These |
2788 | 2794 | can be relative paths ("foo/bar.txt"), system absolute paths
|
2789 | 2795 | ("/foo/bar.txt"), or source absolute paths ("//foo/bar.txt").
|
2790 | 2796 |
|
|
3344 | 3350 | "-lfreetype -lexpat".
|
3345 | 3351 |
|
3346 | 3352 | framework_switch [string, optional, link tools only]
|
| 3353 | + weak_framework_switch [string, optional, link tools only] |
3347 | 3354 | framework_dir_switch [string, optional, link tools only]
|
3348 | 3355 | Valid for: Linker tools
|
3349 | 3356 |
|
|
3353 | 3360 |
|
3354 | 3361 | If you specified:
|
3355 | 3362 | framework_switch = "-framework "
|
| 3363 | + weak_framework_switch = "-weak_framework " |
3356 | 3364 | framework_dir_switch = "-F"
|
3357 |
| - then the "{{libs}}" expansion for |
3358 |
| - [ "UIKit.framework", "$root_out_dir/Foo.framework" ] |
3359 |
| - would be |
3360 |
| - "-framework UIKit -F. -framework Foo" |
| 3365 | + and: |
| 3366 | + framework_dirs = [ "$root_out_dir" ] |
| 3367 | + frameworks = [ "UIKit.framework", "Foo.framework" ] |
| 3368 | + weak_frameworks = [ "MediaPlayer.framework" ] |
| 3369 | + would be: |
| 3370 | + "-F. -framework UIKit -framework Foo -weak_framework MediaPlayer" |
3361 | 3371 |
|
3362 | 3372 | outputs [list of strings with substitutions]
|
3363 | 3373 | Valid for: Linker and compiler tools (required)
|
|
3632 | 3642 | Shared libraries packaged as framework bundle. This is principally
|
3633 | 3643 | used on Apple's platforms (macOS and iOS). All name must be ending
|
3634 | 3644 | with ".framework" suffix; the suffix will be stripped when expanding
|
3635 |
| - {{frameworks}} and each item will be preceded by "-framework". |
| 3645 | + {{frameworks}} and each item will be preceded by "-framework" or |
| 3646 | + "-weak_framework". |
3636 | 3647 |
|
3637 | 3648 | The static library ("alink") tool allows {{arflags}} plus the common tool
|
3638 | 3649 | substitutions.
|
|
6239 | 6250 |
|
6240 | 6251 | See "gn help generated_file".
|
6241 | 6252 | ```
|
| 6253 | +### <a name="var_weak_frameworks"></a>**weak_frameworks**: [name list] Name of frameworks that must be weak linked. |
| 6254 | + |
| 6255 | +``` |
| 6256 | + A list of framework names. |
| 6257 | +
|
| 6258 | + The frameworks named in that list will be weak linked with any dynamic link |
| 6259 | + type target. Weak linking instructs the dynamic loader to attempt to load |
| 6260 | + the framework, but if it is not able to do so, it leaves any imported symbols |
| 6261 | + unresolved. This is typically used when a framework is present in a new |
| 6262 | + version of an SDK but not on older versions of the OS that the software runs |
| 6263 | + on. |
| 6264 | +``` |
| 6265 | + |
| 6266 | +#### **Ordering of flags and values** |
| 6267 | + |
| 6268 | +``` |
| 6269 | + 1. Those set on the current target (not in a config). |
| 6270 | + 2. Those set on the "configs" on the target in order that the |
| 6271 | + configs appear in the list. |
| 6272 | + 3. Those set on the "all_dependent_configs" on the target in order |
| 6273 | + that the configs appear in the list. |
| 6274 | + 4. Those set on the "public_configs" on the target in order that |
| 6275 | + those configs appear in the list. |
| 6276 | + 5. all_dependent_configs pulled from dependencies, in the order of |
| 6277 | + the "deps" list. This is done recursively. If a config appears |
| 6278 | + more than once, only the first occurence will be used. |
| 6279 | + 6. public_configs pulled from dependencies, in the order of the |
| 6280 | + "deps" list. If a dependency is public, they will be applied |
| 6281 | + recursively. |
| 6282 | +``` |
| 6283 | + |
| 6284 | +#### **Example** |
| 6285 | + |
| 6286 | +``` |
| 6287 | + weak_frameworks = [ "OnlyOnNewerOSes.framework" ] |
| 6288 | +``` |
6242 | 6289 | ### <a name="var_write_runtime_deps"></a>**write_runtime_deps**: Writes the target's runtime_deps to the given path.
|
6243 | 6290 |
|
6244 | 6291 | ```
|
|
0 commit comments