summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlyssa Ross <hi@alyssa.is>2024-02-27 23:24:28 +0100
committerXavier Claessens <xclaesse@gmail.com>2024-02-27 18:49:37 -0500
commite9ee63ed033cb2fa64349fbe35f10e82ae264024 (patch)
tree00980f0a9b18b6bb47452f1ca260aef9809fc124
parent0dc2499b2ae58e35e21d6796be238d6cca42466c (diff)
downloadmeson-e9ee63ed033cb2fa64349fbe35f10e82ae264024.tar.gz
cargo: support lib.path in Cargo.toml
Cargo implements this configuration option to override the entry point of the library. To get test coverage, I've modified one of the two Cargo subprojects in the test to use a non-default library entrypoint. The other still uses the default.
-rw-r--r--mesonbuild/cargo/interpreter.py5
-rw-r--r--test cases/rust/22 cargo subproject/subprojects/foo-rs/Cargo.toml1
-rw-r--r--test cases/rust/22 cargo subproject/subprojects/foo-rs/lib.rs (renamed from test cases/rust/22 cargo subproject/subprojects/foo-rs/src/lib.rs)0
3 files changed, 4 insertions, 2 deletions
diff --git a/mesonbuild/cargo/interpreter.py b/mesonbuild/cargo/interpreter.py
index 2797f9fe0..3cbc453ef 100644
--- a/mesonbuild/cargo/interpreter.py
+++ b/mesonbuild/cargo/interpreter.py
@@ -206,6 +206,7 @@ class Library(BuildTarget):
doctest: bool = True
doc: bool = True
+ path: str = os.path.join('src', 'lib.rs')
proc_macro: bool = False
crate_type: T.List[manifest.CRATE_TYPE] = dataclasses.field(default_factory=lambda: ['lib'])
doc_scrape_examples: bool = True
@@ -606,7 +607,7 @@ def _create_lib(cargo: Manifest, build: builder.Builder, crate_type: manifest.CR
posargs: T.List[mparser.BaseNode] = [
build.string(fixup_meson_varname(cargo.package.name)),
- build.string(os.path.join('src', 'lib.rs')),
+ build.string(cargo.lib.path),
]
kwargs: T.Dict[str, mparser.BaseNode] = {
@@ -696,7 +697,7 @@ def interpret(subp_name: str, subdir: str, env: Environment) -> T.Tuple[mparser.
# Libs are always auto-discovered and there's no other way to handle them,
# which is unfortunate for reproducability
- if os.path.exists(os.path.join(env.source_dir, cargo.subdir, cargo.path, 'src', 'lib.rs')):
+ if os.path.exists(os.path.join(env.source_dir, cargo.subdir, cargo.path, cargo.lib.path)):
for crate_type in cargo.lib.crate_type:
ast.extend(_create_lib(cargo, build, crate_type))
diff --git a/test cases/rust/22 cargo subproject/subprojects/foo-rs/Cargo.toml b/test cases/rust/22 cargo subproject/subprojects/foo-rs/Cargo.toml
index 796548d63..0f0225d06 100644
--- a/test cases/rust/22 cargo subproject/subprojects/foo-rs/Cargo.toml
+++ b/test cases/rust/22 cargo subproject/subprojects/foo-rs/Cargo.toml
@@ -5,6 +5,7 @@ edition = "2021"
[lib]
crate-type = ["cdylib"]
+path = "lib.rs"
# This dependency does not exist, verify optional works.
[dependencies.notfound]
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/lib.rs
index 1c8cbc9d3..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/lib.rs