diff options
author | Xavier Claessens <xavier.claessens@collabora.com> | 2023-04-21 16:21:48 -0400 |
---|---|---|
committer | Xavier Claessens <xclaesse@gmail.com> | 2023-09-19 13:54:49 -0400 |
commit | 10dcd87d002f6f36b1f60371dc807b8d9959d97b (patch) | |
tree | 676b5597a7accdd4e2853d7c53f3453535dc5727 /test cases/rust | |
parent | 8ccdb881374084ddb90ef259539cfd3bb748c904 (diff) | |
download | meson-10dcd87d002f6f36b1f60371dc807b8d9959d97b.zip meson-10dcd87d002f6f36b1f60371dc807b8d9959d97b.tar.gz meson-10dcd87d002f6f36b1f60371dc807b8d9959d97b.tar.bz2 |
Rust: Replace rust_crate_type with rust_abi
Meson already knows if it's a shared or static library, user only need
to specify the ABI (Rust or C).
Diffstat (limited to 'test cases/rust')
-rw-r--r-- | test cases/rust/4 polyglot/meson.build | 51 | ||||
-rw-r--r-- | test cases/rust/4 polyglot/proc.rs | 7 | ||||
-rw-r--r-- | test cases/rust/4 polyglot/stuff.rs | 2 | ||||
-rw-r--r-- | test cases/rust/4 polyglot/test.json | 94 |
4 files changed, 143 insertions, 11 deletions
diff --git a/test cases/rust/4 polyglot/meson.build b/test cases/rust/4 polyglot/meson.build index 3601d5e..60922fe 100644 --- a/test cases/rust/4 polyglot/meson.build +++ b/test cases/rust/4 polyglot/meson.build @@ -4,6 +4,51 @@ if host_machine.system() == 'darwin' error('MESON_SKIP_TEST: does not work right on macos, please fix!') endif -l = shared_library('stuff', 'stuff.rs', rust_crate_type: 'cdylib', install : true) -e = executable('prog', 'prog.c', link_with : l, install : true) -test('polyglottest', e) +cc = meson.get_compiler('c') + +# Test all combinations of crate and target types. +# - 'clib' gets translated to `rust_abi: 'c'` instead. +# - '' gets translated to no kwargs. +allowed_map = { + 'static_library': ['rlib', 'staticlib', 'lib', 'clib', ''], + 'shared_library': ['dylib', 'cdylib', 'lib', 'proc-macro', 'clib', ''], + 'both_libraries': ['lib', 'clib', ''], +} +foreach crate_type : ['lib', 'rlib', 'dylib', 'cdylib', 'staticlib', 'proc-macro', 'clib', '', 'invalid'] + foreach target_type, allowed : allowed_map + name = f'stuff_@crate_type@_@target_type@'.underscorify() + src = crate_type == 'proc-macro' ? 'proc.rs' : 'stuff.rs' + if crate_type not in allowed + # Note: in the both_libraries() case it is possible that the static part + # is still being built because the shared part raised an error but we + # don't rollback correctly. + testcase expect_error('(Crate type .* invalid for .*)|(.*must be one of.*not invalid)', how: 're') + build_target(name, src, + target_type: target_type, + rust_crate_type: crate_type, + install: true) + endtestcase + continue + endif + rust_kwargs = {} + if crate_type == 'clib' + rust_kwargs = {'rust_abi': 'c'} + elif crate_type != '' + rust_kwargs = {'rust_crate_type': crate_type} + endif + l = build_target(name, src, + target_type: target_type, + kwargs: rust_kwargs, + install: true) + if crate_type in ['cdylib', 'staticlib', 'clib'] + e = executable(f'prog-@name@', 'prog.c', + link_with: l, + rust_dependency_map: {name: 'stuff'}, + install: true) + test(f'polyglottest-@name@', e) + else + # FIXME: Verify that linking Rust ABI with C ABI executable raises an error. + # Currently it only fails at build time. + endif + endforeach +endforeach diff --git a/test cases/rust/4 polyglot/proc.rs b/test cases/rust/4 polyglot/proc.rs new file mode 100644 index 0000000..53935e4 --- /dev/null +++ b/test cases/rust/4 polyglot/proc.rs @@ -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() +} diff --git a/test cases/rust/4 polyglot/stuff.rs b/test cases/rust/4 polyglot/stuff.rs index ecf623c..30c3a36 100644 --- a/test cases/rust/4 polyglot/stuff.rs +++ b/test cases/rust/4 polyglot/stuff.rs @@ -1,5 +1,3 @@ -#![crate_name = "stuff"] - #[no_mangle] pub extern fn f() { println!("Hello from Rust!"); diff --git a/test cases/rust/4 polyglot/test.json b/test cases/rust/4 polyglot/test.json index a8837a1..d963ad8 100644 --- a/test cases/rust/4 polyglot/test.json +++ b/test cases/rust/4 polyglot/test.json @@ -1,10 +1,92 @@ { "installed": [ - {"type": "exe", "file": "usr/bin/prog"}, - {"type": "pdb", "file": "usr/bin/prog"}, - {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff.so"}, - {"type": "file", "platform": "msvc", "file": "usr/bin/stuff.dll"}, - {"type": "file", "platform": "msvc", "file": "usr/lib/stuff.dll.lib"}, - {"type": "pdb", "file": "usr/bin/stuff"} + {"type": "exe", "file": "usr/bin/prog-stuff_clib_both_libraries"}, + {"type": "pdb", "file": "usr/bin/prog-stuff_clib_both_libraries"}, + {"type": "pdb", "file": "usr/bin/stuff_clib_both_libraries.pdb"}, + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff_clib_both_libraries.so"}, + {"type": "file", "platform": "msvc", "file": "usr/bin/stuff_clib_both_libraries.dll"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/stuff_clib_both_libraries.dll.lib"}, + {"type": "file", "file": "usr/lib/libstuff_clib_both_libraries.a"}, + + {"type": "exe", "file": "usr/bin/prog-stuff_clib_shared_library"}, + {"type": "pdb", "file": "usr/bin/prog-stuff_clib_shared_library"}, + {"type": "pdb", "file": "usr/bin/stuff_clib_shared_library.pdb"}, + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff_clib_shared_library.so"}, + {"type": "file", "platform": "msvc", "file": "usr/bin/stuff_clib_shared_library.dll"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/stuff_clib_shared_library.dll.lib"}, + + {"type": "exe", "file": "usr/bin/prog-stuff_clib_static_library"}, + {"type": "pdb", "file": "usr/bin/prog-stuff_clib_static_library"}, + {"type": "file", "file": "usr/lib/libstuff_clib_static_library.a"}, + + {"type": "exe", "file": "usr/bin/prog-stuff_cdylib_shared_library"}, + {"type": "pdb", "file": "usr/bin/prog-stuff_cdylib_shared_library"}, + {"type": "pdb", "file": "usr/bin/stuff_cdylib_shared_library.pdb"}, + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff_cdylib_shared_library.so"}, + {"type": "file", "platform": "msvc", "file": "usr/bin/stuff_cdylib_shared_library.dll"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/stuff_cdylib_shared_library.dll.lib"}, + + {"type": "exe", "file": "usr/bin/prog-stuff_staticlib_static_library"}, + {"type": "pdb", "file": "usr/bin/prog-stuff_staticlib_static_library"}, + {"type": "file", "file": "usr/lib/libstuff_staticlib_static_library.a"}, + + {"type": "pdb", "file": "usr/bin/stuff__both_libraries.pdb"}, + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff__both_libraries.so"}, + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff__both_libraries.rlib"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/libstuff__both_libraries.rlib"}, + {"type": "file", "platform": "msvc", "file": "usr/bin/stuff__both_libraries.dll"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/stuff__both_libraries.dll.lib"}, + + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff__static_library.rlib"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/libstuff__static_library.rlib"}, + + {"type": "pdb", "file": "usr/bin/stuff_proc_macro_shared_library.pdb"}, + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff_proc_macro_shared_library.so"}, + {"type": "file", "platform": "msvc", "file": "usr/bin/stuff_proc_macro_shared_library.dll"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/stuff_proc_macro_shared_library.dll.lib"}, + + {"type": "pdb", "file": "usr/bin/stuff_lib_both_libraries.pdb"}, + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff_lib_both_libraries.rlib"}, + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff_lib_both_libraries.so"}, + {"type": "file", "platform": "msvc", "file": "usr/bin/stuff_lib_both_libraries.dll"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/libstuff_lib_both_libraries.rlib"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/stuff_lib_both_libraries.dll.lib"}, + + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff_rlib_static_library.rlib"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/libstuff_rlib_static_library.rlib"}, + + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff_lib_static_library.rlib"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/libstuff_lib_static_library.rlib"}, + + {"type": "pdb", "file": "usr/bin/stuff__shared_library.pdb"}, + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff__shared_library.so"}, + {"type": "file", "platform": "msvc", "file": "usr/bin/stuff__shared_library.dll"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/stuff__shared_library.dll.lib"}, + + {"type": "pdb", "file": "usr/bin/stuff_lib_shared_library.pdb"}, + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff_lib_shared_library.so"}, + {"type": "file", "platform": "msvc", "file": "usr/bin/stuff_lib_shared_library.dll"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/stuff_lib_shared_library.dll.lib"}, + + {"type": "pdb", "file": "usr/bin/stuff_dylib_shared_library.pdb"}, + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff_dylib_shared_library.so"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/stuff_dylib_shared_library.dll.lib"}, + {"type": "file", "platform": "msvc", "file": "usr/bin/stuff_dylib_shared_library.dll"}, + + {"type": "pdb", "file": "usr/bin/stuff_cdylib_both_libraries.pdb"}, + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff_cdylib_both_libraries.so"}, + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff_cdylib_both_libraries.so"}, + {"type": "file", "platform": "msvc", "file": "usr/bin/stuff_cdylib_both_libraries.dll"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/stuff_cdylib_both_libraries.dll.lib"}, + + {"type": "pdb", "file": "usr/bin/stuff_proc_macro_both_libraries.pdb"}, + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff_proc_macro_both_libraries.so"}, + {"type": "file", "platform": "msvc", "file": "usr/bin/stuff_proc_macro_both_libraries.dll"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/stuff_proc_macro_both_libraries.dll.lib"}, + + {"type": "pdb", "file": "usr/bin/stuff_dylib_both_libraries.pdb"}, + {"type": "file", "platform": "gcc", "file": "usr/lib/libstuff_dylib_both_libraries.so"}, + {"type": "file", "platform": "msvc", "file": "usr/bin/stuff_dylib_both_libraries.dll"}, + {"type": "file", "platform": "msvc", "file": "usr/lib/stuff_dylib_both_libraries.dll.lib"} ] } |