parent
6ddba5c542
commit
c08b6e29d9
6 changed files with 55 additions and 3 deletions
@ -0,0 +1,16 @@ |
||||
## Rust proc-macro crates |
||||
|
||||
Rust has these handy things called proc-macro crates, which are a bit like a |
||||
compiler plugin. We can now support them, simply build a [[shared_library]] with |
||||
the `rust_crate_type` set to `proc-macro`. |
||||
|
||||
```meson |
||||
proc = shared_library( |
||||
'proc', |
||||
'proc.rs', |
||||
rust_crate_type : 'proc-macro', |
||||
install : false, |
||||
) |
||||
|
||||
user = executable('user, 'user.rs', link_with : proc) |
||||
``` |
@ -1,7 +1,7 @@ |
||||
{ |
||||
"stdout": [ |
||||
{ |
||||
"line": "test cases/failing/54 wrong shared crate type/meson.build:7:0: ERROR: Crate type \"staticlib\" invalid for dynamic libraries; must be \"dylib\" or \"cdylib\"" |
||||
"line": "test cases/failing/54 wrong shared crate type/meson.build:7:0: ERROR: Crate type \"staticlib\" invalid for dynamic libraries; must be \"dylib\", \"cdylib\", or \"proc-macro\"" |
||||
} |
||||
] |
||||
} |
||||
|
@ -0,0 +1,19 @@ |
||||
project('rust proc-macro', 'rust') |
||||
|
||||
if build_machine.system() != 'linux' |
||||
error('MESON_SKIP_TEST, this test only works on Linux. Patches welcome.') |
||||
endif |
||||
|
||||
pm = shared_library( |
||||
'proc_macro_examples', |
||||
'proc.rs', |
||||
rust_crate_type : 'proc-macro', |
||||
) |
||||
|
||||
main = executable( |
||||
'main', |
||||
'use.rs', |
||||
link_with : pm |
||||
) |
||||
|
||||
test('main_test', main) |
@ -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() |
||||
} |
@ -0,0 +1,8 @@ |
||||
extern crate proc_macro_examples; |
||||
use proc_macro_examples::make_answer; |
||||
|
||||
make_answer!(); |
||||
|
||||
fn main() { |
||||
assert_eq!(42, answer()); |
||||
} |
Loading…
Reference in new issue