aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2023-09-22 13:40:35 -0700
committerDylan Baker <dylan@pnwbakers.com>2023-09-25 13:05:04 -0700
commitd5546bdceaa2f3040d16a33fcbd824ba94b8cfde (patch)
tree89578b4aaa9869e6a7b02de8955554445c175ecf
parentc1ac252f4ffecc381abe24e13584e1c48516e0eb (diff)
downloadmeson-d5546bdceaa2f3040d16a33fcbd824ba94b8cfde.zip
meson-d5546bdceaa2f3040d16a33fcbd824ba94b8cfde.tar.gz
meson-d5546bdceaa2f3040d16a33fcbd824ba94b8cfde.tar.bz2
rust: apply global, project, and environment C args to bindgen
This means that arguments set via `add_global_arguments`, `add_project_arguments` and by either the `-Dc_args` or `CFLAGS` are applied to bindgen as well. This can be important when, among other things, #defines are set via these mechanisms. Fixes: #12065
-rw-r--r--mesonbuild/modules/rust.py6
-rw-r--r--test cases/rust/12 bindgen/meson.build18
-rw-r--r--test cases/rust/12 bindgen/src/global-project.h10
-rw-r--r--test cases/rust/12 bindgen/src/global.c5
-rw-r--r--test cases/rust/12 bindgen/src/global.rs14
-rw-r--r--test cases/rust/12 bindgen/test.json5
6 files changed, 57 insertions, 1 deletions
diff --git a/mesonbuild/modules/rust.py b/mesonbuild/modules/rust.py
index b6dd731..382a72d 100644
--- a/mesonbuild/modules/rust.py
+++ b/mesonbuild/modules/rust.py
@@ -236,6 +236,12 @@ class RustModule(ExtensionModule):
elif isinstance(s, CustomTarget):
depends.append(s)
+ clang_args.extend(state.global_args.get('c', []))
+ clang_args.extend(state.project_args.get('c', []))
+ cargs = state.get_option('args', state.subproject, lang='c')
+ assert isinstance(cargs, list), 'for mypy'
+ clang_args.extend(cargs)
+
if self._bindgen_bin is None:
self._bindgen_bin = state.find_program('bindgen')
diff --git a/test cases/rust/12 bindgen/meson.build b/test cases/rust/12 bindgen/meson.build
index c05cc06..e7cb5f3 100644
--- a/test cases/rust/12 bindgen/meson.build
+++ b/test cases/rust/12 bindgen/meson.build
@@ -8,6 +8,9 @@ if not prog_bindgen.found()
error('MESON_SKIP_TEST bindgen not found')
endif
+add_project_arguments('-DPROJECT_ARG', language : 'c')
+add_global_arguments('-DGLOBAL_ARG', language : 'c')
+
# This seems to happen on windows when libclang.dll is not in path or is not
# valid. We must try to process a header file for this to work.
#
@@ -81,3 +84,18 @@ test('generated header', rust_bin2)
subdir('sub')
subdir('dependencies')
+
+gp = rust.bindgen(
+ input : 'src/global-project.h',
+ output : 'global-project.rs',
+)
+
+gp_lib = static_library('gp_lib', 'src/global.c')
+
+gp_exe = executable(
+ 'gp_exe',
+ structured_sources(['src/global.rs', gp]),
+ link_with : gp_lib,
+)
+
+test('global and project arguments', gp_exe)
diff --git a/test cases/rust/12 bindgen/src/global-project.h b/test cases/rust/12 bindgen/src/global-project.h
new file mode 100644
index 0000000..6084e8e
--- /dev/null
+++ b/test cases/rust/12 bindgen/src/global-project.h
@@ -0,0 +1,10 @@
+#ifndef GLOBAL_ARG
+char * success(void);
+#endif
+#ifndef PROJECT_ARG
+char * success(void);
+#endif
+#ifndef CMD_ARG
+char * success(void);
+#endif
+int success(void);
diff --git a/test cases/rust/12 bindgen/src/global.c b/test cases/rust/12 bindgen/src/global.c
new file mode 100644
index 0000000..10f6676
--- /dev/null
+++ b/test cases/rust/12 bindgen/src/global.c
@@ -0,0 +1,5 @@
+#include "src/global-project.h"
+
+int success(void) {
+ return 0;
+}
diff --git a/test cases/rust/12 bindgen/src/global.rs b/test cases/rust/12 bindgen/src/global.rs
new file mode 100644
index 0000000..4b70b1e
--- /dev/null
+++ b/test cases/rust/12 bindgen/src/global.rs
@@ -0,0 +1,14 @@
+// SPDX-license-identifer: Apache-2.0
+// Copyright © 2023 Intel Corporation
+
+#![allow(non_upper_case_globals)]
+#![allow(non_camel_case_types)]
+#![allow(non_snake_case)]
+
+include!("global-project.rs");
+
+fn main() {
+ unsafe {
+ std::process::exit(success());
+ };
+}
diff --git a/test cases/rust/12 bindgen/test.json b/test cases/rust/12 bindgen/test.json
index f94ee85..b3a7585 100644
--- a/test cases/rust/12 bindgen/test.json
+++ b/test cases/rust/12 bindgen/test.json
@@ -1,7 +1,10 @@
{
+ "env": {
+ "CFLAGS": "-DCMD_ARG"
+ },
"stdout": [
{
- "line": "test cases/rust/12 bindgen/meson.build:27: WARNING: Project targets '>= 0.63' but uses feature introduced in '1.0.0': \"rust.bindgen\" keyword argument \"include_directories\" of type array[str]."
+ "line": "test cases/rust/12 bindgen/meson.build:30: WARNING: Project targets '>= 0.63' but uses feature introduced in '1.0.0': \"rust.bindgen\" keyword argument \"include_directories\" of type array[str]."
}
]
}