aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDylan Baker <dylan@pnwbakers.com>2023-10-17 10:39:10 -0700
committerNirbheek Chauhan <nirbheek.chauhan@gmail.com>2023-10-20 20:21:08 +0530
commit450b3db37810c99854f670cb70a59e0bee5b8777 (patch)
tree27ff4fda7db3fdd9fa45dc52b9bb656d2a8e0dd1
parente6e07f46ea64aead8fecb6f623c795ea3d8e62a2 (diff)
downloadmeson-450b3db37810c99854f670cb70a59e0bee5b8777.zip
meson-450b3db37810c99854f670cb70a59e0bee5b8777.tar.gz
meson-450b3db37810c99854f670cb70a59e0bee5b8777.tar.bz2
modules/rust: Add a test that bindgen drops arguments it shouldn't use
This does require hacking up the test pretty badly, since we need to not ever pass GCC these invalid values. But it's preferable to writing another project test I think. Co-Authored-by: Nirbheek Chauhan <nirbheek@centricular.com>
-rw-r--r--test cases/rust/12 bindgen/meson.build12
-rw-r--r--test cases/rust/12 bindgen/test.json2
-rw-r--r--unittests/allplatformstests.py28
3 files changed, 39 insertions, 3 deletions
diff --git a/test cases/rust/12 bindgen/meson.build b/test cases/rust/12 bindgen/meson.build
index e7cb5f3..e36e9e2 100644
--- a/test cases/rust/12 bindgen/meson.build
+++ b/test cases/rust/12 bindgen/meson.build
@@ -8,8 +8,16 @@ 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')
+cc_id = meson.get_compiler('c').get_id()
+compiler_specific_args = []
+if cc_id == 'gcc'
+ compiler_specific_args = ['-mtls-dialect=gnu2']
+elif cc_id == 'msvc'
+ compiler_specific_args = ['/fp:fast']
+endif
+
+add_project_arguments(['-DPROJECT_ARG', compiler_specific_args], language : 'c')
+add_global_arguments(['-DGLOBAL_ARG', compiler_specific_args], 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.
diff --git a/test cases/rust/12 bindgen/test.json b/test cases/rust/12 bindgen/test.json
index b3a7585..d45543b 100644
--- a/test cases/rust/12 bindgen/test.json
+++ b/test cases/rust/12 bindgen/test.json
@@ -4,7 +4,7 @@
},
"stdout": [
{
- "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]."
+ "line": "test cases/rust/12 bindgen/meson.build:38: WARNING: Project targets '>= 0.63' but uses feature introduced in '1.0.0': \"rust.bindgen\" keyword argument \"include_directories\" of type array[str]."
}
]
}
diff --git a/unittests/allplatformstests.py b/unittests/allplatformstests.py
index 18ed3bf..059be2d 100644
--- a/unittests/allplatformstests.py
+++ b/unittests/allplatformstests.py
@@ -4810,6 +4810,34 @@ class AllPlatformTests(BasePlatformTests):
self.assertEqual(cm.exception.returncode, 1)
self.assertIn('exit status 39', cm.exception.stdout)
+ @skip_if_not_language('rust')
+ def test_bindgen_drops_invalid(self) -> None:
+ if self.backend is not Backend.ninja:
+ raise unittest.SkipTest('Rust is only supported with ninja currently')
+ testdir = os.path.join(self.rust_test_dir, '12 bindgen')
+ env = get_fake_env(testdir, self.builddir, self.prefix)
+ cc = detect_c_compiler(env, MachineChoice.HOST)
+ # bindgen understands compiler args that clang understands, but not
+ # flags by other compilers
+ if cc.get_id() == 'gcc':
+ bad_arg = '-fdse'
+ elif cc.get_id() == 'msvc':
+ bad_arg = '/fastfail'
+ else:
+ raise unittest.SkipTest('Test only supports GCC and MSVC')
+ self.init(testdir, extra_args=[f"-Dc_args=['-DCMD_ARG', '{bad_arg}']"])
+ intro = self.introspect(['--targets'])
+ for i in intro:
+ if i['type'] == 'custom' and i['id'].startswith('rustmod-bindgen'):
+ args = i['target_sources'][0]['compiler']
+ self.assertIn('-DCMD_ARG', args)
+ self.assertIn('-DPROJECT_ARG', args)
+ self.assertIn('-DGLOBAL_ARG', args)
+ self.assertNotIn(bad_arg, args)
+ self.assertNotIn('-mtls-dialect=gnu2', args)
+ self.assertNotIn('/fp:fast', args)
+ return
+
def test_custom_target_name(self):
testdir = os.path.join(self.unit_test_dir, '100 custom target name')
self.init(testdir)