Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rust: proc-macro should be ignored in transitive dependencies #12460

Merged
merged 1 commit into from
Nov 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions mesonbuild/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -1299,6 +1299,8 @@ def get_dependencies_recurse(self, result: OrderedSet[Target], include_internals
for t in self.link_targets:
if t in result:
continue
if isinstance(t, SharedLibrary) and 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/20 transitive dependencies/foo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#include <stdint.h>

uint32_t foo_rs(void);

int main(void)
{
return foo_rs() == 42 ? 0 : 1;
}
9 changes: 9 additions & 0 deletions test cases/rust/20 transitive dependencies/foo.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
extern crate pm;
use pm::make_answer;

make_answer!();

#[no_mangle]
pub fn foo_rs() -> u32 {
answer()
}
17 changes: 16 additions & 1 deletion test cases/rust/20 transitive dependencies/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
project('transitive dependencies', 'rust',
project('transitive dependencies', 'rust', 'c',
version : '1.0.0',
meson_version : '>= 1.0.0',
default_options : ['rust_std=2018'],
Expand All @@ -10,3 +10,18 @@ subdir('libb')
main = executable('main', 'main.rs',
dependencies : [libb_dep],
)

# Since foo-rs is a static library, its dependencies are normally added to
# footest link command. However, since pm is a proc-macro, footest should not
# link with it. In native build this is an harmless overlinking, but in cross
# building foo and pm are for different arch and it would fail to link.
rust = import('rust')
pm = rust.proc_macro('pm', 'proc.rs')
foo = static_library('foo-rs', 'foo.rs',
rust_abi: 'c',
link_with: pm,
)
exe = executable('footest', 'foo.c',
link_with: foo,
)
test('footest', exe)
7 changes: 7 additions & 0 deletions test cases/rust/20 transitive dependencies/proc.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
extern crate proc_macro;
use proc_macro::TokenStream;

#[proc_macro]
pub fn make_answer(_item: TokenStream) -> TokenStream {
"fn answer() -> u32 { 42 }".parse().unwrap()
}
Loading