Skip to content

Commit

Permalink
cargo: Use the library name instead of package name
Browse files Browse the repository at this point in the history
The library name defaults to its package name, but it can be different.
For example:
- package name: cairo-sys-rs
- library name: cairo-sys
- dependency name: ffi
  • Loading branch information
xclaesse committed Jun 17, 2024
1 parent c90696a commit d2da16b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 2 deletions.
6 changes: 4 additions & 2 deletions mesonbuild/cargo/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,9 @@ def _create_lib(self, pkg: PackageState, build: builder.Builder, crate_type: man
dep = pkg.manifest.dependencies[name]
dependencies.append(build.identifier(_dependency_varname(dep.package)))
if name != dep.package:
dependency_map[build.string(fixup_meson_varname(dep.package))] = build.string(name)
dep_pkg = self._dep_package(dep)
dep_lib_name = dep_pkg.manifest.lib.name
dependency_map[build.string(fixup_meson_varname(dep_lib_name))] = build.string(name)

rust_args: T.List[mparser.BaseNode] = [
build.identifier('features_args'),
Expand All @@ -655,7 +657,7 @@ def _create_lib(self, pkg: PackageState, build: builder.Builder, crate_type: man
dependencies.append(build.identifier(_extra_deps_varname()))

posargs: T.List[mparser.BaseNode] = [
build.string(fixup_meson_varname(pkg.manifest.package.name)),
build.string(fixup_meson_varname(pkg.manifest.lib.name)),
build.string(pkg.manifest.lib.path),
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ mybar = { version = "0.1", package = "bar", default-features = false }
version = "0.0.1"
features = ["f1"]

[dependencies.libname]
version = "1"

[features]
default = ["f1"]
f1 = ["f2", "f3"]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
extern crate common;
extern crate libothername;

extern "C" {
fn extra_func() -> i32;
Expand All @@ -8,6 +9,7 @@ extern "C" {
#[no_mangle]
pub extern "C" fn rust_func() -> i32 {
assert!(common::common_func() == 0);
assert!(libothername::stuff() == 42);
let v: i32;
unsafe {
v = extra_func();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[wrap-file]
method = cargo
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[package]
name = "libname"
version = "1"

[lib]
name="libothername"
path = "lib.rs"
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
pub fn stuff() -> i32 {
42
}

0 comments on commit d2da16b

Please sign in to comment.