Skip to content

Commit 8800bad

Browse files
committed
docs: update info on Cargo workspace object
1 parent 84e4225 commit 8800bad

File tree

3 files changed

+37
-10
lines changed

3 files changed

+37
-10
lines changed

docs/markdown/Rust-module.md

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,8 @@ authors:
1616

1717
The rust module provides helper to integrate rust code into Meson. The
1818
goal is to make using rust in Meson more pleasant, while still
19-
remaining mesonic, this means that it attempts to make Rust work more
20-
like Meson, rather than Meson work more like rust.
19+
remaining mesonic. Rust conventions are adopted in order to help the
20+
Meson user and Rust developer, rather than to make Meson work more like rust.
2121

2222
## Functions
2323

@@ -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: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,13 +133,32 @@ 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 `bin` 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+
For a workspace:
150+
151+
```meson
152+
pkg_lib = cargo.package('myproject-lib')
153+
lib = pkg_lib.library(install: false)
154+
pkg_lib.override_dependency(declare_dependency(link_with: lib))
155+
156+
cargo.package().executable(install: true)
157+
```
158+
159+
Sources are automatically discovered, but can be specified as a
160+
[[@structured_src]] if they are partly generated.
161+
162+
It is still possible to use keyword arguments to link non-Rust build targets,
163+
or even to use the usual Meson functions such as [[static_library]] or
164+
[[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)