diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2023-06-21 12:15:07 -0700 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2023-06-27 11:53:18 -0700 |
commit | c5b16ab8b957d53b75c73bb24144a4f61c86234d (patch) | |
tree | d4ada77ecd56f09ea3996a39a60cae4dd6b156f4 /unittests | |
parent | 43f24060f3e0065b44b1909d88bcc8e2882e9e5e (diff) | |
download | meson-c5b16ab8b957d53b75c73bb24144a4f61c86234d.zip meson-c5b16ab8b957d53b75c73bb24144a4f61c86234d.tar.gz meson-c5b16ab8b957d53b75c73bb24144a4f61c86234d.tar.bz2 |
modules/rust: Add a machine file property for extra clang args with bindgen
It's currently impossible to inject extra clang arguments when using
bindgen, which is problematic when cross compiling since you may need
critical arguments like `--target=...`. Because such arguments must be
passed after the `--` it's impossible to inject them currently without
going to something like a wrapper script.
Fixes: #11805
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/machinefiletests.py | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/unittests/machinefiletests.py b/unittests/machinefiletests.py index 5a9c01d..3807c88 100644 --- a/unittests/machinefiletests.py +++ b/unittests/machinefiletests.py @@ -12,6 +12,8 @@ # See the License for the specific language governing permissions and # limitations under the License. +from __future__ import annotations + import subprocess import tempfile import textwrap @@ -67,7 +69,7 @@ class NativeFileTests(BasePlatformTests): self.current_config = 0 self.current_wrapper = 0 - def helper_create_native_file(self, values): + def helper_create_native_file(self, values: T.Dict[str, T.Dict[str, T.Union[str, int, float, bool, T.Sequence[T.Union[str, int, float, bool]]]]]) -> str: """Create a config file as a temporary file. values should be a nested dictionary structure of {section: {key: @@ -81,10 +83,10 @@ class NativeFileTests(BasePlatformTests): for k, v in entries.items(): if isinstance(v, (bool, int, float)): f.write(f"{k}={v}\n") - elif isinstance(v, list): - f.write("{}=[{}]\n".format(k, ', '.join([f"'{w}'" for w in v]))) - else: + elif isinstance(v, str): f.write(f"{k}='{v}'\n") + else: + f.write("{}=[{}]\n".format(k, ', '.join([f"'{w}'" for w in v]))) return filename def helper_create_binary_wrapper(self, binary, dir_=None, extra_args=None, **kwargs): @@ -622,6 +624,29 @@ class NativeFileTests(BasePlatformTests): else: self.fail('Did not find bindir in build options?') + @skip_if_not_language('rust') + def test_bindgen_clang_arguments(self) -> None: + if self.backend is not Backend.ninja: + raise SkipTest('Rust is only supported with Ninja') + + testcase = os.path.join(self.rust_test_dir, '12 bindgen') + config = self.helper_create_native_file({ + 'properties': {'bindgen_clang_arguments': 'sentinal'} + }) + + self.init(testcase, extra_args=['--native-file', config]) + targets: T.List[T.Dict[str, T.Any]] = self.introspect('--targets') + for t in targets: + if t['id'].startswith('rustmod-bindgen'): + args: T.List[str] = t['target_sources'][0]['compiler'] + self.assertIn('sentinal', args, msg="Did not find machine file value") + cargs_start = args.index('--') + sent_arg = args.index('sentinal') + self.assertLess(cargs_start, sent_arg, msg='sentinal argument does not come after "--"') + break + else: + self.fail('Did not find a bindgen target') + class CrossFileTests(BasePlatformTests): |