summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/markdown/Wrap-dependency-system-manual.md8
-rw-r--r--mesonbuild/cargo/interpreter.py35
-rw-r--r--test cases/rust/22 cargo subproject/subprojects/foo-rs/meson/meson.build1
-rw-r--r--test cases/rust/22 cargo subproject/subprojects/foo-rs/src/lib.rs1
4 files changed, 44 insertions, 1 deletions
diff --git a/docs/markdown/Wrap-dependency-system-manual.md b/docs/markdown/Wrap-dependency-system-manual.md
index 70a7b3023..bba1971c4 100644
--- a/docs/markdown/Wrap-dependency-system-manual.md
+++ b/docs/markdown/Wrap-dependency-system-manual.md
@@ -356,6 +356,14 @@ project(...,
)
```
+In addition, if the file `meson/meson.build` exists, Meson will call `subdir('meson')`
+where the project can add manual logic that would usually be part of `build.rs`.
+Some naming conventions need to be respected:
+- The `extra_args` variable is pre-defined and can be used to add any Rust arguments.
+ This is typically used as `extra_args += ['--cfg', 'foo']`.
+- The `extra_deps` variable is pre-defined and can be used to add extra dependencies.
+ This is typically used as `extra_deps += dependency('foo')`.
+
## Using wrapped projects
Wraps provide a convenient way of obtaining a project into your
diff --git a/mesonbuild/cargo/interpreter.py b/mesonbuild/cargo/interpreter.py
index 6680ea1b0..2797f9fe0 100644
--- a/mesonbuild/cargo/interpreter.py
+++ b/mesonbuild/cargo/interpreter.py
@@ -366,6 +366,14 @@ def _options_varname(depname: str) -> str:
return f'{fixup_meson_varname(depname)}_options'
+def _extra_args_varname() -> str:
+ return 'extra_args'
+
+
+def _extra_deps_varname() -> str:
+ return 'extra_deps'
+
+
def _create_project(cargo: Manifest, build: builder.Builder) -> T.List[mparser.BaseNode]:
"""Create a function call
@@ -561,6 +569,25 @@ def _create_dependencies(cargo: Manifest, build: builder.Builder) -> T.List[mpar
return ast
+def _create_meson_subdir(cargo: Manifest, build: builder.Builder) -> T.List[mparser.BaseNode]:
+ # Allow Cargo subprojects to add extra Rust args in meson/meson.build file.
+ # This is used to replace build.rs logic.
+
+ # extra_args = []
+ # extra_deps = []
+ # fs = import('fs')
+ # if fs.is_dir('meson')
+ # subdir('meson')
+ # endif
+ return [
+ build.assign(build.array([]), _extra_args_varname()),
+ build.assign(build.array([]), _extra_deps_varname()),
+ build.assign(build.function('import', [build.string('fs')]), 'fs'),
+ build.if_(build.method('is_dir', build.identifier('fs'), [build.string('meson')]),
+ build.block([build.function('subdir', [build.string('meson')])]))
+ ]
+
+
def _create_lib(cargo: Manifest, build: builder.Builder, crate_type: manifest.CRATE_TYPE) -> T.List[mparser.BaseNode]:
dependencies: T.List[mparser.BaseNode] = []
dependency_map: T.Dict[mparser.BaseNode, mparser.BaseNode] = {}
@@ -570,7 +597,12 @@ def _create_lib(cargo: Manifest, build: builder.Builder, crate_type: manifest.CR
if name != package_name:
dependency_map[build.string(fixup_meson_varname(package_name))] = build.string(name)
- rust_args: T.List[mparser.BaseNode] = [build.identifier('features_args')]
+ rust_args: T.List[mparser.BaseNode] = [
+ build.identifier('features_args'),
+ build.identifier(_extra_args_varname())
+ ]
+
+ dependencies.append(build.identifier(_extra_deps_varname()))
posargs: T.List[mparser.BaseNode] = [
build.string(fixup_meson_varname(cargo.package.name)),
@@ -660,6 +692,7 @@ def interpret(subp_name: str, subdir: str, env: Environment) -> T.Tuple[mparser.
ast += [build.assign(build.function('import', [build.string('rust')]), 'rust')]
ast += _create_features(cargo, build)
ast += _create_dependencies(cargo, build)
+ ast += _create_meson_subdir(cargo, build)
# Libs are always auto-discovered and there's no other way to handle them,
# which is unfortunate for reproducability
diff --git a/test cases/rust/22 cargo subproject/subprojects/foo-rs/meson/meson.build b/test cases/rust/22 cargo subproject/subprojects/foo-rs/meson/meson.build
new file mode 100644
index 000000000..67c7b82f9
--- /dev/null
+++ b/test cases/rust/22 cargo subproject/subprojects/foo-rs/meson/meson.build
@@ -0,0 +1 @@
+extra_args += ['--cfg', 'feature="foo"']
diff --git a/test cases/rust/22 cargo subproject/subprojects/foo-rs/src/lib.rs b/test cases/rust/22 cargo subproject/subprojects/foo-rs/src/lib.rs
index 4f0a31079..1c8cbc9d3 100644
--- a/test cases/rust/22 cargo subproject/subprojects/foo-rs/src/lib.rs
+++ b/test cases/rust/22 cargo subproject/subprojects/foo-rs/src/lib.rs
@@ -2,6 +2,7 @@ extern "C" {
fn extra_func() -> i32;
}
+#[cfg(feature = "foo")]
#[no_mangle]
pub extern "C" fn rust_func() -> i32 {
let v: i32;