tests/rust: Add rust case linking to zlib dependency

Reworks:
 * Add MESON_SKIP_TEST error for darwin from polyglot test
 * Remove dependencies from executable

Dylan's changes:
 * Add support for both static and shared testing
 * Test with pkg-config, cmake, and system
 * reformat to meson's style

Co-authored-by: Dylan Baker <dylan@pnwbakers.com>
pull/8404/head
Jordan Justen 4 years ago committed by Dylan Baker
parent 4c1a0c400f
commit 5edbc0acd7
  1. 10
      test cases/rust/13 external c dependencies/c_accessing_zlib.c
  2. 23
      test cases/rust/13 external c dependencies/meson.build
  3. 2
      test cases/rust/13 external c dependencies/meson_options.txt
  4. 9
      test cases/rust/13 external c dependencies/prog.rs
  5. 15
      test cases/rust/13 external c dependencies/test.json

@ -0,0 +1,10 @@
#include <stdio.h>
#include <string.h>
#include <zlib.h>
void c_accessing_zlib(void) {
struct z_stream_s zstream;
printf("Hello from C!\n");
memset(&zstream, 0, sizeof(zstream));
inflateInit(&zstream);
}

@ -0,0 +1,23 @@
project('rust linking to c using dependency', 'c', 'rust')
if host_machine.system() == 'darwin'
error('MESON_SKIP_TEST: doesnt work right on macos, please fix!')
endif
dep_zlib = dependency('zlib', static : get_option('static'), method : get_option('method'), required : false)
if not dep_zlib.found()
error('MESON_SKIP_TEST: Could not find a @0@ zlib'.format(get_option('static') ? 'static' : 'shared'))
endif
l = static_library(
'c_accessing_zlib',
'c_accessing_zlib.c',
dependencies: [dep_zlib],
)
e = executable(
'prog', 'prog.rs',
link_with : l,
)
test('cdepstest', e)

@ -0,0 +1,2 @@
option('static', type : 'boolean')
option('method', type : 'string')

@ -0,0 +1,9 @@
extern "C" {
fn c_accessing_zlib();
}
fn main() {
unsafe {
c_accessing_zlib();
}
}

@ -0,0 +1,15 @@
{
"matrix": {
"options": {
"static": [
{ "val": true },
{ "val": false }
],
"method": [
{ "val": "pkg-config" },
{ "val": "cmake" },
{ "val": "system" }
]
}
}
}
Loading…
Cancel
Save