Skip to content

Commit 6444de9

Browse files
committed
docs: update info on Cargo workspace object
1 parent 2df2a48 commit 6444de9

File tree

3 files changed

+32
-8
lines changed

3 files changed

+32
-8
lines changed

docs/markdown/Rust-module.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -335,6 +335,13 @@ Returns all defined features for a specific package or subproject.
335335

336336
### Packages only
337337

338+
Package objects are able to extract information from `Cargo.toml` files,
339+
and provide methods to query how Cargo would build this package. They
340+
also contain convenience wrappers for non-Rust-specific functions
341+
(`executable`, `library`, `meson.override_dependency`, etc.), that
342+
automatically add dependencies and compiler arguments from `Cargo.toml`
343+
information.
344+
338345
#### package.rust_args()
339346

340347
```meson

docs/markdown/Rust.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,29 @@ The workspace object also enables configuration of Cargo features, for example
133133
from Meson options:
134134

135135
```meson
136-
ws = rust.workspace(
136+
cargo = rust.workspace(
137137
features: ['feature1', 'feature2'])
138138
```
139139

140-
### Limitations
140+
Finally, the workspace object is able to build targets specified in `[lib]`
141+
or `[[bins]]` sections, extracting compiler arguments for dependencies and
142+
diagnostics from the Cargo.toml file. The simplest case is that of building
143+
a simple binary crate:
141144

142-
All your own crates must be built using the usual Meson functions such as
143-
[[static_library]] or [[executable]]. In the future, workspace object
144-
functionality will be extended to help building rustc command lines
145-
based on features, dependency names, and so on.
145+
```meson
146+
cargo.package().executable(install: true)
147+
```
148+
149+
Or for a workspace:
150+
151+
```meson
152+
cargo.package('myproject-lib').library(install: false)
153+
cargo.package().executable(install: true)
154+
```
155+
156+
Sources are automatically discovered, but can be specified as a
157+
[[@structured_src]] if they are partly generated.
158+
159+
It is still possible to use keyword arguments to link non-Rust build targets,
160+
or even to use the usual Meson functions such as [[static_library]] or
161+
[[executable]].

docs/markdown/snippets/cargo-workspace-object.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ This guarantees that features are resolved according to what is
66
in the `Cargo.toml` file, and in fact enables configuration of
77
features for the build.
88

9-
The returned object also allows retrieving features and dependencies
10-
for Cargo subprojects.
9+
The returned object allows retrieving features and dependencies
10+
for Cargo subprojects, and contains method to build targets
11+
declared in `Cargo.toml` files.
1112

1213
While Cargo subprojects remain experimental, the Meson project will
1314
try to keep the workspace object reasonably backwards-compatible.

0 commit comments

Comments
 (0)