Skip to content

Commit afd8944

Browse files
committed
cargo: Fix feature resolution
Introduce a global Cargo interpreter state that keeps track of enabled features on each crate. Before generating AST of a Cargo subproject, it downloads every sub-subproject and resolves the set of features enabled on each of them recursively. When it later generates AST for one its dependencies, its set of features and dependencies is already determined.
1 parent c02e0b7 commit afd8944

File tree

14 files changed

+343
-340
lines changed

14 files changed

+343
-340
lines changed

docs/markdown/Wrap-dependency-system-manual.md

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -354,27 +354,6 @@ method = cargo
354354
dependency_names = foo-bar-0.1-rs
355355
```
356356

357-
Cargo features are exposed as Meson boolean options, with the `feature-` prefix.
358-
For example the `default` feature is named `feature-default` and can be set from
359-
the command line with `-Dfoo-1-rs:feature-default=false`. When a cargo subproject
360-
depends on another cargo subproject, it will automatically enable features it
361-
needs using the `dependency('foo-1-rs', default_options: ...)` mechanism. However,
362-
unlike Cargo, the set of enabled features is not managed globally. Let's assume
363-
the main project depends on `foo-1-rs` and `bar-1-rs`, and they both depend on
364-
`common-1-rs`. The main project will first look up `foo-1-rs` which itself will
365-
configure `common-rs` with a set of features. Later, when `bar-1-rs` does a lookup
366-
for `common-1-rs` it has already been configured and the set of features cannot be
367-
changed. If `bar-1-rs` wants extra features from `common-1-rs`, Meson will error out.
368-
It is currently the responsibility of the main project to resolve those
369-
issues by enabling extra features on each subproject:
370-
```meson
371-
project(...,
372-
default_options: {
373-
'common-1-rs:feature-something': true,
374-
},
375-
)
376-
```
377-
378357
In addition, if the file `meson/meson.build` exists, Meson will call `subdir('meson')`
379358
where the project can add manual logic that would usually be part of `build.rs`.
380359
Some naming conventions need to be respected:
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## Cargo features are resolved globally
2+
3+
When configuring a Cargo dependency, Meson will now resolve its complete
4+
dependency tree and feature set before generating the subproject AST.
5+
This solves many cases of Cargo subprojects being configured with missing
6+
features that the main project had to enable by hand using e.g.
7+
`default_options: ['foo-rs:feature-default=true']`.
8+
9+
Note that there could still be issues in the case there are multiple Cargo
10+
entry points. That happens if the main Meson project makes multiple `dependency()`
11+
calls for different Cargo crates that have common dependencies.
12+
13+
Breaks: This change removes per feature Meson options that were previously
14+
possible to set as shown above or from command line `-Dfoo-rs:feature-foo=true`.

mesonbuild/cargo/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
__all__ = [
2-
'interpret',
2+
'Interpreter',
33
'load_wraps',
44
]
55

6-
from .interpreter import interpret, load_wraps
6+
from .interpreter import Interpreter, load_wraps

0 commit comments

Comments
 (0)