Skip to content

Commit 847ac10

Browse files
Allan Sandfeld Jensenpatricia-gallardo
Allan Sandfeld Jensen
authored andcommitted
weak_frameworks linking options
Change-Id: Ib24971636d105c390f8a2ecd7fbc7edd1db6daf8 Reviewed-by: Michal Klocek <[email protected]>
1 parent 8957ef9 commit 847ac10

16 files changed

+223
-84
lines changed

src/3rdparty/gn/docs/reference.md

Lines changed: 100 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -148,6 +148,7 @@
148148
* [testonly: [boolean] Declares a target must only be used for testing.](#var_testonly)
149149
* [visibility: [label list] A list of labels that can depend on a target.](#var_visibility)
150150
* [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)
151152
* [write_runtime_deps: Writes the target's runtime_deps to the given path.](#var_write_runtime_deps)
152153
* [xcode_extra_attributes: [scope] Extra attributes for Xcode projects.](#var_xcode_extra_attributes)
153154
* [xcode_test_application_name: [string] Name for Xcode test target.](#var_xcode_test_application_name)
@@ -348,14 +349,22 @@
348349
#### **Command-specific switches**
349350

350351
```
351-
--force
352-
Ignores specifications of "check_includes = false" and checks all
353-
target's files that match the target label.
354-
355352
--check-generated
356353
Generated files are normally not checked since they do not exist
357354
until after a build. With this flag, those generated files that
358355
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.
359368
```
360369

361370
#### **What gets checked**
@@ -453,7 +462,7 @@
453462
gn check out/Default "//foo/*
454463
Check only the files in targets in the //foo directory tree.
455464
```
456-
### <a name="cmd_clean"></a>**gn clean &lt;out_dir&gt;**
465+
### <a name="cmd_clean"></a>**gn clean &lt;out_dir&gt;...**
457466

458467
```
459468
Deletes the contents of the output directory except for args.gn and
@@ -509,6 +518,7 @@
509518
testonly
510519
visibility
511520
walk_keys
521+
weak_frameworks
512522
513523
runtime_deps
514524
Compute all runtime deps for the given target. This is a computed list
@@ -521,15 +531,15 @@
521531
```
522532

523533
#### **Shared flags**
534+
524535
```
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.
528540
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.
533543
534544
--format=json
535545
Format the output as JSON instead of text.
@@ -541,8 +551,9 @@
541551
--blame
542552
Used with any value specified on a config, this will name the config that
543553
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).
546557
```
547558

548559
#### **Configs**
@@ -572,6 +583,7 @@
572583
--all
573584
Collects all recursive dependencies and prints a sorted flat list. Also
574585
usable with --tree (see below).
586+
575587
--as=(buildfile|label|output)
576588
How to print targets.
577589
@@ -598,6 +610,7 @@
598610
599611
Tree output can not be used with the filtering or output flags: --as,
600612
--type, --testonly.
613+
601614
--type=(action|copy|executable|group|loadable_module|shared_library|
602615
source_set|static_library)
603616
Restrict outputs to targets matching the given type. If
@@ -797,6 +810,12 @@
797810
#### **Compilation Database**
798811

799812
```
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+
800819
--export-compile-commands[=<target_name1,target_name2...>]
801820
Produces a compile_commands.json file in the root of the build directory
802821
containing an array of “command objects”, where each command object
@@ -829,7 +848,7 @@
829848
gn help --markdown all
830849
Dump all help to stdout in markdown format.
831850
```
832-
### <a name="cmd_ls"></a>**gn ls &lt;out_dir&gt; [&lt;label_pattern&gt;] [\--all-toolchains] [\--as=...]**
851+
### <a name="cmd_ls"></a>**gn ls &lt;out_dir&gt; [&lt;label_pattern&gt;] [\--default-toolchain] [\--as=...]**
833852
```
834853
[--type=...] [--testonly=...]
835854
@@ -857,14 +876,13 @@
857876
Prints the first output file for the target relative to the
858877
root build directory.
859878
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.
863883
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.
868886
869887
--testonly=(true|false)
870888
Restrict outputs to targets with the testonly flag set
@@ -897,10 +915,6 @@
897915
898916
gn ls out/Debug "//base/*" --as=output | xargs ninja -C out/Debug
899917
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).
904918
```
905919
### <a name="cmd_meta"></a>**gn meta**
906920

@@ -1008,7 +1022,7 @@
10081022

10091023
```
10101024
gn refs <out_dir> (<label_pattern>|<label>|<file>|@<response_file>)*
1011-
[--all] [--all-toolchains] [--as=...] [--testonly=...] [--type=...]
1025+
[--all] [--default-toolchain] [--as=...] [--testonly=...] [--type=...]
10121026
10131027
Finds reverse dependencies (which targets reference something). The input is
10141028
a list containing:
@@ -1044,14 +1058,6 @@
10441058
directly or indirectly on that file.
10451059
10461060
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.
10551061
10561062
--as=(buildfile|label|output)
10571063
How to print targets.
@@ -1065,10 +1071,19 @@
10651071
Prints the first output file for the target relative to the
10661072
root build directory.
10671073
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+
10681082
-q
10691083
Quiet. If nothing matches, don't print any output. Without this option, if
10701084
there are no matches there will be an informational message printed which
10711085
might interfere with scripts processing the output.
1086+
10721087
--testonly=(true|false)
10731088
Restrict outputs to targets with the testonly flag set
10741089
accordingly. When unspecified, the target's testonly flags are
@@ -1080,6 +1095,7 @@
10801095
10811096
Tree output can not be used with the filtering or output flags: --as,
10821097
--type, --testonly.
1098+
10831099
--type=(action|copy|executable|group|loadable_module|shared_library|
10841100
source_set|static_library)
10851101
Restrict outputs to targets matching the given type. If
@@ -1838,8 +1854,7 @@
18381854
### <a name="func_source_set"></a>**source_set**: Declare a source set target.
18391855

18401856
```
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.
18431858
```
18441859

18451860
#### **C-language source_sets**
@@ -1867,15 +1882,6 @@
18671882
when linking multiple static libraries into a shared library.
18681883
```
18691884

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-
18791885
#### **Variables**
18801886

18811887
```
@@ -2777,14 +2783,14 @@
27772783
with a double slash like "//foo/bar"), you should use the get_path_info()
27782784
function. This function won't work because it will always make relative
27792785
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.
27812787
```
27822788

27832789
#### **Arguments**
27842790

27852791
```
27862792
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
27882794
can be relative paths ("foo/bar.txt"), system absolute paths
27892795
("/foo/bar.txt"), or source absolute paths ("//foo/bar.txt").
27902796
@@ -3344,6 +3350,7 @@
33443350
"-lfreetype -lexpat".
33453351
33463352
framework_switch [string, optional, link tools only]
3353+
weak_framework_switch [string, optional, link tools only]
33473354
framework_dir_switch [string, optional, link tools only]
33483355
Valid for: Linker tools
33493356
@@ -3353,11 +3360,14 @@
33533360
33543361
If you specified:
33553362
framework_switch = "-framework "
3363+
weak_framework_switch = "-weak_framework "
33563364
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"
33613371
33623372
outputs [list of strings with substitutions]
33633373
Valid for: Linker and compiler tools (required)
@@ -3632,7 +3642,8 @@
36323642
Shared libraries packaged as framework bundle. This is principally
36333643
used on Apple's platforms (macOS and iOS). All name must be ending
36343644
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".
36363647
36373648
The static library ("alink") tool allows {{arflags}} plus the common tool
36383649
substitutions.
@@ -6239,6 +6250,42 @@
62396250
62406251
See "gn help generated_file".
62416252
```
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+
```
62426289
### <a name="var_write_runtime_deps"></a>**write_runtime_deps**: Writes the target's runtime_deps to the given path.
62436290

62446291
```

src/3rdparty/gn/tools/gn/c_tool.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ CTool::CTool(const char* n)
2121
: Tool(n), depsformat_(DEPS_GCC), precompiled_header_type_(PCH_NONE) {
2222
CHECK(ValidateName(n));
2323
set_framework_switch("-framework ");
24+
set_weak_framework_switch("-weak_framework ");
2425
set_framework_dir_switch("-F");
2526
set_lib_dir_switch("-L");
2627
set_lib_switch("-l");
@@ -184,6 +185,8 @@ bool CTool::InitTool(Scope* scope, Toolchain* toolchain, Err* err) {
184185

185186
if (!ReadDepsFormat(scope, err) || !ReadPrecompiledHeaderType(scope, err) ||
186187
!ReadString(scope, "framework_switch", &framework_switch_, err) ||
188+
!ReadString(scope, "weak_framework_switch", &weak_framework_switch_,
189+
err) ||
187190
!ReadString(scope, "framework_dir_switch", &framework_dir_switch_, err) ||
188191
!ReadString(scope, "lib_switch", &lib_switch_, err) ||
189192
!ReadString(scope, "lib_dir_switch", &lib_dir_switch_, err) ||

src/3rdparty/gn/tools/gn/command_desc.cc

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,7 @@ std::map<std::string, DescHandlerFunc> GetHandlers() {
299299
{variables::kDataKeys, DefaultHandler},
300300
{variables::kRebase, DefaultHandler},
301301
{variables::kWalkKeys, DefaultHandler},
302+
{variables::kWeakFrameworks, DefaultHandler},
302303
{variables::kWriteOutputConversion, DefaultHandler},
303304
{"runtime_deps", DefaultHandler}};
304305
}
@@ -386,6 +387,7 @@ bool PrintTarget(const Target* target,
386387
HandleProperty(variables::kDataKeys, handler_map, v, dict);
387388
HandleProperty(variables::kRebase, handler_map, v, dict);
388389
HandleProperty(variables::kWalkKeys, handler_map, v, dict);
390+
HandleProperty(variables::kWeakFrameworks, handler_map, v, dict);
389391
HandleProperty(variables::kWriteOutputConversion, handler_map, v, dict);
390392

391393
#undef HandleProperty
@@ -447,6 +449,7 @@ bool PrintConfig(const Config* config,
447449
HandleProperty(variables::kLibDirs, handler_map, v, dict);
448450
HandleProperty(variables::kPrecompiledHeader, handler_map, v, dict);
449451
HandleProperty(variables::kPrecompiledSource, handler_map, v, dict);
452+
HandleProperty(variables::kWeakFrameworks, handler_map, v, dict);
450453

451454
#undef HandleProperty
452455

@@ -508,6 +511,7 @@ Possibilities for <what to show>
508511
testonly
509512
visibility
510513
walk_keys
514+
weak_frameworks
511515
512516
runtime_deps
513517
Compute all runtime deps for the given target. This is a computed list
@@ -532,8 +536,9 @@ Target flags
532536
--blame
533537
Used with any value specified on a config, this will name the config that
534538
causes that target to get the flag. This doesn't currently work for libs,
535-
lib_dirs, frameworks and framework_dirs because those are inherited and
536-
are more complicated to figure out the blame (patches welcome).
539+
lib_dirs, frameworks, weak_frameworks and framework_dirs because those are
540+
inherited and are more complicated to figure out the blame (patches
541+
welcome).
537542
538543
Configs
539544

0 commit comments

Comments
 (0)