diff options
author | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
---|---|---|
committer | Angelos Mouzakitis <a.mouzakitis@virtualopensystems.com> | 2023-10-10 14:33:42 +0000 |
commit | af1a266670d040d2f4083ff309d732d648afba2a (patch) | |
tree | 2fc46203448ddcc6f81546d379abfaeb323575e9 /meson/test cases/rust/16 internal c dependencies | |
parent | e02cda008591317b1625707ff8e115a4841aa889 (diff) |
Change-Id: Iaf8d18082d3991dec7c0ebbea540f092188eb4ec
Diffstat (limited to 'meson/test cases/rust/16 internal c dependencies')
5 files changed, 76 insertions, 0 deletions
diff --git a/meson/test cases/rust/16 internal c dependencies/lib.c b/meson/test cases/rust/16 internal c dependencies/lib.c new file mode 100644 index 000000000..e852de6c5 --- /dev/null +++ b/meson/test cases/rust/16 internal c dependencies/lib.c @@ -0,0 +1,6 @@ +#include <stdio.h> +#include "lib.h" + +void c_func(void) { + printf("This is a " MODE " C library\n"); +} diff --git a/meson/test cases/rust/16 internal c dependencies/lib.h b/meson/test cases/rust/16 internal c dependencies/lib.h new file mode 100644 index 000000000..847bd1664 --- /dev/null +++ b/meson/test cases/rust/16 internal c dependencies/lib.h @@ -0,0 +1,22 @@ +#pragma once + +#if defined _WIN32 || defined __CYGWIN__ + #if defined BUILDING_ADDER + #define DLL_PUBLIC __declspec(dllexport) + #else + #define DLL_PUBLIC __declspec(dllimport) + #endif +#else + #if defined __GNUC__ + #if defined BUILDING_ADDER + #define DLL_PUBLIC __attribute__ ((visibility("default"))) + #else + #define DLL_PUBLIC + #endif + #else + #pragma message("Compiler does not support symbol visibility.") + #define DLL_PUBLIC + #endif +#endif + +DLL_PUBLIC void c_func(void); diff --git a/meson/test cases/rust/16 internal c dependencies/main.rs b/meson/test cases/rust/16 internal c dependencies/main.rs new file mode 100644 index 000000000..538359943 --- /dev/null +++ b/meson/test cases/rust/16 internal c dependencies/main.rs @@ -0,0 +1,9 @@ +extern "C" { + fn c_func(); +} + +fn main() { + unsafe { + c_func(); + } +} diff --git a/meson/test cases/rust/16 internal c dependencies/meson.build b/meson/test cases/rust/16 internal c dependencies/meson.build new file mode 100644 index 000000000..c7476d750 --- /dev/null +++ b/meson/test cases/rust/16 internal c dependencies/meson.build @@ -0,0 +1,14 @@ +project('internal dependencies', 'c', 'rust') + +test_prog = find_program('test.py') + +static = static_library('static', 'lib.c', c_args : '-DMODE="static"') +exe = executable('static', 'main.rs', link_with : static) +test('static linkage', test_prog, args : [exe, 'This is a static C library']) + +# Shared linkage with rust doesn't work on macOS with meson, yet +if host_machine.system() != 'darwin' + shared = shared_library('shared', 'lib.c', c_args : '-DMODE="shared"') + exe = executable('shared', 'main.rs', link_with : shared) + test('shared linkage', test_prog, args : [exe, 'This is a shared C library']) +endif diff --git a/meson/test cases/rust/16 internal c dependencies/test.py b/meson/test cases/rust/16 internal c dependencies/test.py new file mode 100755 index 000000000..dacec120b --- /dev/null +++ b/meson/test cases/rust/16 internal c dependencies/test.py @@ -0,0 +1,25 @@ +#!/usr/bin/env python3 + +import argparse +import subprocess +import sys + + +def main() -> None: + parser = argparse.ArgumentParser() + parser.add_argument('command') + parser.add_argument('expected') + args = parser.parse_args() + + out = subprocess.run(args.command, stdout=subprocess.PIPE) + actual = out.stdout.decode().strip() + + if args.expected != actual: + print('expected:', args.expected, file=sys.stderr) + print('actual: ', actual, file=sys.stderr) + sys.exit(1) + sys.exit(0) + + +if __name__ == "__main__": + main() |