Merge pull request #390 from nirbheek/msvc-module-defs

Add support for passing a module definitions file for exporting symbols while linking
pull/493/merge
Jussi Pakkanen 9 years ago
commit 873ffe782c
  1. 2
      mesonbuild/backend/ninjabackend.py
  2. 9
      mesonbuild/build.py
  3. 7
      mesonbuild/compilers.py
  4. 9
      test cases/failing/28 no vs module defs/meson.build
  5. 5
      test cases/failing/28 no vs module defs/prog.c
  6. 1
      test cases/failing/28 no vs module defs/subdir/meson.build
  7. 7
      test cases/failing/28 no vs module defs/subdir/somedll.c
  8. 7
      test cases/windows/6 vs module defs/meson.build
  9. 5
      test cases/windows/6 vs module defs/prog.c
  10. 1
      test cases/windows/6 vs module defs/subdir/meson.build
  11. 5
      test cases/windows/6 vs module defs/subdir/somedll.c
  12. 3
      test cases/windows/6 vs module defs/subdir/somedll.def

@ -1658,6 +1658,8 @@ rule FORTRAN_DEP_HACK
else:
soversion = None
commands += linker.get_soname_args(target.name, abspath, soversion)
if target.vs_module_defs and hasattr(linker, 'gen_vs_module_defs_args'):
commands += linker.gen_vs_module_defs_args(target.vs_module_defs.rel_to_builddir(self.build_to_src))
elif isinstance(target, build.StaticLibrary):
commands += linker.get_std_link_args()
else:

@ -47,7 +47,7 @@ known_shlib_kwargs.update({'version' : True,
'soversion' : True,
'name_prefix' : True,
'name_suffix' : True,
})
'vs_module_defs' : True})
backslash_explanation = \
'''Compiler arguments have a backslash "\\" character. This is unfortunately not
@ -703,6 +703,7 @@ class SharedLibrary(BuildTarget):
def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs):
self.version = None
self.soversion = None
self.vs_module_defs = None
super().__init__(name, subdir, subproject, is_cross, sources, objects, environment, kwargs);
if len(self.sources) > 0 and self.sources[0].endswith('.cs'):
prefix = 'lib'
@ -726,6 +727,12 @@ class SharedLibrary(BuildTarget):
self.set_version(kwargs['version'])
if 'soversion' in kwargs:
self.set_soversion(kwargs['soversion'])
if 'vs_module_defs' in kwargs:
path = kwargs['vs_module_defs']
if (os.path.isabs(path)):
self.vs_module_defs = File.from_absolute_file(path)
else:
self.vs_module_defs = File.from_source_file(environment.source_dir, self.subdir, path)
def check_unknown_kwargs(self, kwargs):
self.check_unknown_kwargs_int(kwargs, known_shlib_kwargs)

@ -1256,6 +1256,13 @@ class VisualStudioCCompiler(CCompiler):
def get_std_shared_lib_link_args(self):
return ['/DLL']
def gen_vs_module_defs_args(self, defsfile):
if not isinstance(defsfile, str):
raise RuntimeError('Module definitions file should be str')
# With MSVC, DLLs only export symbols that are explicitly exported,
# so if a module defs file is specified, we use that to export symbols
return ['/DEF:' + defsfile]
def gen_pch_args(self, header, source, pchname):
objname = os.path.splitext(pchname)[0] + '.obj'
return (objname, ['/Yc' + header, '/Fp' + pchname, '/Fo' + objname ])

@ -0,0 +1,9 @@
project('dll_no_module_def', 'c')
if meson.get_compiler('c').get_id() != 'msvc'
error('Need to use the Visual Studio compiler')
endif
subdir('subdir')
exe = executable('prog', 'prog.c', link_with : shlib)
test('runtest', exe)

@ -0,0 +1,5 @@
int somedllfunc();
int main(int argc, char **argv) {
return somedllfunc() == 42 ? 0 : 1;
}

@ -0,0 +1 @@
shlib = shared_library('somedll', 'somedll.c')

@ -0,0 +1,7 @@
/* With MSVC, the DLL created from this will not export any symbols
* without a module definitions file specified while linking */
#ifdef _MSC_VER
int somedllfunc() {
return 42;
}
#endif

@ -0,0 +1,7 @@
project('dll_module_defs', 'c')
if meson.get_compiler('c').get_id() == 'msvc'
subdir('subdir')
exe = executable('prog', 'prog.c', link_with : shlib)
test('runtest', exe)
endif

@ -0,0 +1,5 @@
int somedllfunc();
int main(int argc, char **argv) {
return somedllfunc() == 42 ? 0 : 1;
}

@ -0,0 +1 @@
shlib = shared_library('somedll', 'somedll.c', vs_module_defs : 'somedll.def')

@ -0,0 +1,5 @@
#ifdef _MSC_VER
int somedllfunc() {
return 42;
}
#endif
Loading…
Cancel
Save