@@ -14,7 +14,7 @@ found in the [FFI section of the book][ffi].
14
14
15
15
r[ link.type]
16
16
In one session of compilation, the compiler can generate multiple artifacts
17
- through the usage of either command line flags or the ` crate_type ` attribute.
17
+ through the usage of either command line flags or the [ ` crate_type ` attribute] .
18
18
If one or more command line flags are specified, all ` crate_type ` attributes will
19
19
be ignored in favor of only building the artifacts specified by command line.
20
20
@@ -105,6 +105,10 @@ same method. If only `crate_type` attributes are specified, then they will all
105
105
be built, but if one or more ` --crate-type ` command line flags are specified,
106
106
then only those outputs will be built.
107
107
108
+ <!-- TODO: Add a rule that combining certain crate types is not allowed.
109
+ https://github.com/rust-lang/rust/blob/5526a2f47cd676ceeedc08cf71ae75ce2e9284ae/compiler/rustc_interface/src/passes.rs#L258-L265
110
+ -->
111
+
108
112
r[ link.dependency]
109
113
With all these different kinds of outputs, if crate A depends on crate B, then
110
114
the compiler could find B in various different forms throughout the system. The
@@ -165,6 +169,26 @@ In general, `--crate-type=bin` or `--crate-type=lib` should be sufficient for
165
169
all compilation needs, and the other options are just available if more
166
170
fine-grained control is desired over the output format of a crate.
167
171
172
+ r[ link.crate_type]
173
+ ## The ` crate_type ` attribute
174
+
175
+ r[ link.crate_type.intro]
176
+ The * ` crate_type ` [ attribute] [ attributes ] * is used to specify the [ crate type] [ link.type ] of the crate.
177
+
178
+ > [ !EXAMPLE]
179
+ > ``` rust
180
+ > #![crate_type = " lib" ]
181
+ > ```
182
+
183
+ r [link . crate_type. syntax]
184
+ The `crate_type ` attribute uses the [MetaNameValueStr ] syntax to specify the crate type .
185
+
186
+ r [link . crate_type. allowed- positions ]
187
+ The `crate_type ` attribute may only be applied to the crate root .
188
+
189
+ r [link . crate_type. duplicates]
190
+ If the `crate_type ` is specified multiple times , then the crate is built for all of the given crate types .
191
+
168
192
r [link . crt]
169
193
## Static and dynamic C runtimes
170
194
@@ -302,3 +326,4 @@ If a Rust artifact is potentially unwinding, then all its crates must be built w
302
326
[ procedural macros ] : procedural-macros.md
303
327
[ panic strategy ] : panic.md#panic-strategy
304
328
[ `-C panic` ] : ../rustc/codegen-options/index.html#panic
329
+ [ `crate_type` attribute ] : link.crate_type
0 commit comments