Skip to content

Commit

Permalink
rust: recursively pull proc-macro dependencies as well
Browse files Browse the repository at this point in the history
When the proc-macro rlib is in a different subdir, it would miss the
needed -L argument and rustc would not find it. Meson was assuming that
proc-macros are only needed when building libraries that uses it, but it
turns out that was wrong, as show by the unit test.
  • Loading branch information
xclaesse committed Feb 29, 2024
1 parent 937d1c6 commit aee9415
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 2 deletions.
2 changes: 0 additions & 2 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1295,8 +1295,6 @@ def get_dependencies_recurse(self, result: OrderedSet[BuildTargetTypes], include
for t in self.link_targets:
if t in result:
continue
if t.rust_crate_type == 'proc-macro':
continue
if include_internals or not t.is_internal():
result.add(t)
if isinstance(t, StaticLibrary):
Expand Down
8 changes: 8 additions & 0 deletions test cases/rust/18 proc-macro/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
extern crate proc_macro_examples;
use proc_macro_examples::make_answer;

make_answer!();

pub fn func() -> u32 {
answer()
}
11 changes: 11 additions & 0 deletions test cases/rust/18 proc-macro/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,14 @@ main = executable(
)

test('main_test2', main)

subdir('subdir')

staticlib = static_library('staticlib', 'lib.rs',
link_with: pm_in_subdir,
rust_dependency_map : {'proc_macro_examples3' : 'proc_macro_examples'}
)

executable('transitive-proc-macro', 'transitive-proc-macro.rs',
link_with: staticlib,
)
1 change: 1 addition & 0 deletions test cases/rust/18 proc-macro/subdir/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pm_in_subdir = rust.proc_macro('proc_macro_examples3', '../proc.rs')
7 changes: 7 additions & 0 deletions test cases/rust/18 proc-macro/transitive-proc-macro.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extern crate staticlib;
use staticlib::func;


fn main() {
assert_eq!(42, func());
}

0 comments on commit aee9415

Please sign in to comment.