diff options
| author | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2022-02-11 15:08:35 +0800 |
|---|---|---|
| committer | Vadim Petrochenkov <vadim.petrochenkov@gmail.com> | 2022-03-30 23:53:21 +0300 |
| commit | 1004783ef9bdcf006f0ed33badacf83a5934feb2 (patch) | |
| tree | 9db8e33f5809076953c29ae6e7bc569266f48130 /src/doc/rustc | |
| parent | bb5c437a2ce9ccf2204c974300c5ea9eb32d3635 (diff) | |
| download | rust-1004783ef9bdcf006f0ed33badacf83a5934feb2.tar.gz rust-1004783ef9bdcf006f0ed33badacf83a5934feb2.zip | |
Stabilize native library modifier syntax and the `whole-archive` modifier specifically
Diffstat (limited to 'src/doc/rustc')
| -rw-r--r-- | src/doc/rustc/src/command-line-arguments.md | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/src/doc/rustc/src/command-line-arguments.md b/src/doc/rustc/src/command-line-arguments.md index 3759cb632bb..7838696cc12 100644 --- a/src/doc/rustc/src/command-line-arguments.md +++ b/src/doc/rustc/src/command-line-arguments.md @@ -37,6 +37,8 @@ KIND=PATH` where `KIND` may be one of: <a id="option-l-link-lib"></a> ## `-l`: link the generated crate to a native library +Syntax: `-l [KIND[:MODIFIERS]=]NAME[:RENAME]`. + This flag allows you to specify linking to a specific native library when building a crate. @@ -47,7 +49,13 @@ where `KIND` may be one of: - `static` — A native static library (such as a `.a` archive). - `framework` — A macOS framework. -The kind of library can be specified in a [`#[link]` +If the kind is specified, then linking modifiers can be attached to it. +Modifiers are specified as a comma-delimited string with each modifier prefixed with +either a `+` or `-` to indicate that the modifier is enabled or disabled, respectively. +The last boolean value specified for a given modifier wins. \ +Example: `-l static:+whole-archive=mylib`. + +The kind of library and the modifiers can also be specified in a [`#[link]` attribute][link-attribute]. If the kind is not specified in the `link` attribute or on the command-line, it will link a dynamic library if available, otherwise it will use a static library. If the kind is specified on the @@ -59,6 +67,22 @@ and `LINK_NAME` is the name of the actual library that will be linked. [link-attribute]: ../reference/items/external-blocks.html#the-link-attribute +### Linking modifiers: `whole-archive` + +This modifier is only compatible with the `static` linking kind. +Using any other kind will result in a compiler error. + +`+whole-archive` means that the static library is linked as a whole archive +without throwing any object files away. + +This modifier translates to `--whole-archive` for `ld`-like linkers, +to `/WHOLEARCHIVE` for `link.exe`, and to `-force_load` for `ld64`. +The modifier does nothing for linkers that don't support it. + +The default for this modifier is `-whole-archive`. \ +NOTE: The default may currently be different when building dylibs for some targets, +but it is not guaranteed. + <a id="option-crate-type"></a> ## `--crate-type`: a list of types of crates for the compiler to emit |
