Skip to content

Commit 6d5df9b

Browse files
committed
Use attribute template for crate_type
1 parent 9571d4d commit 6d5df9b

File tree

3 files changed

+28
-3
lines changed

3 files changed

+28
-3
lines changed

src/attributes.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -343,7 +343,7 @@ The following is an index of all built-in attributes.
343343
[`cold`]: attributes/codegen.md#the-cold-attribute
344344
[`collapse_debuginfo`]: attributes/debugger.md#the-collapse_debuginfo-attribute
345345
[`crate_name`]: crates-and-source-files.md#the-crate_name-attribute
346-
[`crate_type`]: linkage.md
346+
[`crate_type`]: linkage.md#the-crate_type-attribute
347347
[`debugger_visualizer`]: attributes/debugger.md#the-debugger_visualizer-attribute
348348
[`deny`]: attributes/diagnostics.md#lint-check-attributes
349349
[`deprecated`]: attributes/diagnostics.md#the-deprecated-attribute

src/conditional-compilation.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ println!("I'm running on a {} machine!", machine_kind);
459459
[`cfg` macro]: #the-cfg-macro
460460
[`cfg_attr`]: #the-cfg_attr-attribute
461461
[`crate_name`]: crates-and-source-files.md#the-crate_name-attribute
462-
[`crate_type`]: linkage.md
462+
[`crate_type`]: linkage.md#the-crate_type-attribute
463463
[`target_feature` attribute]: attributes/codegen.md#the-target_feature-attribute
464464
[attribute]: attributes.md
465465
[attributes]: attributes.md

src/linkage.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ found in the [FFI section of the book][ffi].
1414

1515
r[link.type]
1616
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].
1818
If one or more command line flags are specified, all `crate_type` attributes will
1919
be ignored in favor of only building the artifacts specified by command line.
2020

@@ -105,6 +105,10 @@ same method. If only `crate_type` attributes are specified, then they will all
105105
be built, but if one or more `--crate-type` command line flags are specified,
106106
then only those outputs will be built.
107107

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+
108112
r[link.dependency]
109113
With all these different kinds of outputs, if crate A depends on crate B, then
110114
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
165169
all compilation needs, and the other options are just available if more
166170
fine-grained control is desired over the output format of a crate.
167171

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+
168192
r[link.crt]
169193
## Static and dynamic C runtimes
170194
@@ -302,3 +326,4 @@ If a Rust artifact is potentially unwinding, then all its crates must be built w
302326
[procedural macros]: procedural-macros.md
303327
[panic strategy]: panic.md#panic-strategy
304328
[`-C panic`]: ../rustc/codegen-options/index.html#panic
329+
[`crate_type` attribute]: link.crate_type

0 commit comments

Comments
 (0)