Skip to content

Commit 6acced7

Browse files
authored
Merge pull request #1170 from petrochenkov/linkmod
Document native library modifier syntax and the `whole-archive` modifier specifically
2 parents b85bbf4 + 0fc5e6d commit 6acced7

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/items/external-blocks.md

+20
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,15 @@ specifies the kind of library with the following possible values:
125125

126126
The `name` key must be included if `kind` is specified.
127127

128+
The optional `modifiers` argument is a way to specify linking modifiers for the
129+
library to link.
130+
Modifiers are specified as a comma-delimited string with each modifier prefixed
131+
with either a `+` or `-` to indicate that the modifier is enabled or disabled,
132+
respectively.
133+
Specifying multiple `modifiers` arguments in a single `link` attribute,
134+
or multiple identical modifiers in the same `modifiers` argument is not currently supported. \
135+
Example: `#[link(name = "mylib", kind = "static", modifiers = "+whole-archive")`.
136+
128137
The `wasm_import_module` key may be used to specify the [WebAssembly module]
129138
name for the items within an `extern` block when importing symbols from the
130139
host environment. The default module name is `env` if `wasm_import_module` is
@@ -153,6 +162,16 @@ this to satisfy the linking requirements of extern blocks elsewhere in your
153162
code (including upstream crates) instead of adding the attribute to each extern
154163
block.
155164

165+
#### Linking modifiers: `whole-archive`
166+
167+
This modifier is only compatible with the `static` linking kind.
168+
Using any other kind will result in a compiler error.
169+
170+
`+whole-archive` means that the static library is linked as a whole archive
171+
without throwing any object files away.
172+
173+
More implementation details about this modifier can be found in [documentation for rustc].
174+
156175
### The `link_name` attribute
157176

158177
The `link_name` attribute may be specified on declarations inside an `extern`
@@ -186,3 +205,4 @@ restrictions as [regular function parameters].
186205
[_Visibility_]: ../visibility-and-privacy.md
187206
[attributes]: ../attributes.md
188207
[regular function parameters]: functions.md#attributes-on-function-parameters
208+
[documentation for rustc]: ../../rustc/command-line-arguments.html#linking-modifiers-whole-archive

0 commit comments

Comments
 (0)