Skip to content

Update crate_type to use the attribute template #1900

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/attributes.md
Original file line number Diff line number Diff line change
Expand Up @@ -343,7 +343,7 @@ The following is an index of all built-in attributes.
[`cold`]: attributes/codegen.md#the-cold-attribute
[`collapse_debuginfo`]: attributes/debugger.md#the-collapse_debuginfo-attribute
[`crate_name`]: crates-and-source-files.md#the-crate_name-attribute
[`crate_type`]: linkage.md
[`crate_type`]: linkage.md#the-crate_type-attribute
[`debugger_visualizer`]: attributes/debugger.md#the-debugger_visualizer-attribute
[`deny`]: attributes/diagnostics.md#lint-check-attributes
[`deprecated`]: attributes/diagnostics.md#the-deprecated-attribute
Expand Down
2 changes: 1 addition & 1 deletion src/conditional-compilation.md
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ println!("I'm running on a {} machine!", machine_kind);
[`cfg` macro]: #the-cfg-macro
[`cfg_attr`]: #the-cfg_attr-attribute
[`crate_name`]: crates-and-source-files.md#the-crate_name-attribute
[`crate_type`]: linkage.md
[`crate_type`]: linkage.md#the-crate_type-attribute
[`target_feature` attribute]: attributes/codegen.md#the-target_feature-attribute
[attribute]: attributes.md
[attributes]: attributes.md
Expand Down
27 changes: 26 additions & 1 deletion src/linkage.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ found in the [FFI section of the book][ffi].

r[link.type]
In one session of compilation, the compiler can generate multiple artifacts
through the usage of either command line flags or the `crate_type` attribute.
through the usage of either command line flags or the [`crate_type` attribute].
If one or more command line flags are specified, all `crate_type` attributes will
be ignored in favor of only building the artifacts specified by command line.

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

<!-- TODO: Add a rule that combining certain crate types is not allowed.
https://github.com/rust-lang/rust/blob/5526a2f47cd676ceeedc08cf71ae75ce2e9284ae/compiler/rustc_interface/src/passes.rs#L258-L265
-->

r[link.dependency]
With all these different kinds of outputs, if crate A depends on crate B, then
the compiler could find B in various different forms throughout the system. The
Expand Down Expand Up @@ -165,6 +169,26 @@ In general, `--crate-type=bin` or `--crate-type=lib` should be sufficient for
all compilation needs, and the other options are just available if more
fine-grained control is desired over the output format of a crate.

r[link.crate_type]
## The `crate_type` attribute

r[link.crate_type.intro]
The *`crate_type` [attribute][attributes]* is used to specify the [crate type][link.type] of the crate.

> [!EXAMPLE]
> ```rust
> #![crate_type = "lib"]
> ```

r[link.crate_type.syntax]
The `crate_type` attribute uses the [MetaNameValueStr] syntax to specify the crate type.

r[link.crate_type.allowed-positions]
The `crate_type` attribute may only be applied to the crate root.

r[link.crate_type.duplicates]
If the `crate_type` is specified multiple times, then the crate is built for all of the given crate types.

r[link.crt]
## Static and dynamic C runtimes

Expand Down Expand Up @@ -302,3 +326,4 @@ If a Rust artifact is potentially unwinding, then all its crates must be built w
[procedural macros]: procedural-macros.md
[panic strategy]: panic.md#panic-strategy
[`-C panic`]: ../rustc/codegen-options/index.html#panic
[`crate_type` attribute]: link.crate_type