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>
pull/12403/head
Dylan Baker 1 year ago committed by Nirbheek Chauhan
parent e6e07f46ea
commit 450b3db378
  1. 12
      test cases/rust/12 bindgen/meson.build
  2. 2
      test cases/rust/12 bindgen/test.json
  3. 28
      unittests/allplatformstests.py

@ -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.

@ -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]."
}
]
}

@ -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)

Loading…
Cancel
Save