diff options
author | Ben Corby <bcorby@new-ms.com> | 2024-04-30 11:19:00 +1000 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2024-04-30 11:07:57 -0700 |
commit | bd149f8bca0c39cb39116deddd5d8fd2dc55d5e3 (patch) | |
tree | 2c26fb23f24bcdf202b742ebd5c12d7aa3c97b3b | |
parent | bb088c50b455eb877dd6fde311d60690f20c8518 (diff) | |
download | meson-bd149f8bca0c39cb39116deddd5d8fd2dc55d5e3.zip meson-bd149f8bca0c39cb39116deddd5d8fd2dc55d5e3.tar.gz meson-bd149f8bca0c39cb39116deddd5d8fd2dc55d5e3.tar.bz2 |
Fix dependencies for vala.links #13158
Using the keyword argument dependencies with compiler.links() for vala doesn't work as the library being linked to needs to be prefixed with --pkg= before being passed to valac.
-rw-r--r-- | mesonbuild/compilers/vala.py | 44 | ||||
-rw-r--r-- | test cases/vala/30 dependencies for compiler.links/meson.build | 64 |
2 files changed, 108 insertions, 0 deletions
diff --git a/mesonbuild/compilers/vala.py b/mesonbuild/compilers/vala.py index 839d544..2e35db1 100644 --- a/mesonbuild/compilers/vala.py +++ b/mesonbuild/compilers/vala.py @@ -142,6 +142,50 @@ class ValaCompiler(Compiler): def get_option_link_args(self, options: 'KeyedOptionDictType') -> T.List[str]: return [] + def build_wrapper_args(self, env: 'Environment', + extra_args: T.Union[None, CompilerArgs, T.List[str], T.Callable[[CompileCheckMode], T.List[str]]], + dependencies: T.Optional[T.List['Dependency']], + mode: CompileCheckMode = CompileCheckMode.COMPILE) -> CompilerArgs: + if callable(extra_args): + extra_args = extra_args(mode) + if extra_args is None: + extra_args = [] + if dependencies is None: + dependencies = [] + + # Collect compiler arguments + args = self.compiler_args(self.get_compiler_check_args(mode)) + for d in dependencies: + # Add compile flags needed by dependencies + if mode is CompileCheckMode.LINK and self.force_link: + # As we are passing the parameter to valac we don't need the dependent libraries. + a = d.get_compile_args() + if a: + p = a[0] + n = p[max(p.rfind('/'), p.rfind('\\'))+1:] + if not n == d.get_name(): + args += ['--pkg=' + d.get_name()] # This is used by gio-2.0 among others. + else: + args += ['--pkg=' + n] + else: + args += ['--Xcc=-l' + d.get_name()] # This is used by the maths library(-lm) among others. + else: + args += d.get_compile_args() + if mode is CompileCheckMode.LINK: + # Add link flags needed to find dependencies + if not self.force_link: # There are no need for link dependencies when linking with valac. + args += d.get_link_args() + + if mode is CompileCheckMode.COMPILE: + # Add DFLAGS from the env + args += env.coredata.get_external_args(self.for_machine, self.language) + elif mode is CompileCheckMode.LINK: + # Add LDFLAGS from the env + args += env.coredata.get_external_link_args(self.for_machine, self.language) + # extra_args must override all other arguments, so we add them last + args += extra_args + return args + def links(self, code: 'mesonlib.FileOrString', env: 'Environment', *, compiler: T.Optional['Compiler'] = None, extra_args: T.Union[None, T.List[str], CompilerArgs, T.Callable[[CompileCheckMode], T.List[str]]] = None, diff --git a/test cases/vala/30 dependencies for compiler.links/meson.build b/test cases/vala/30 dependencies for compiler.links/meson.build new file mode 100644 index 0000000..569cf40 --- /dev/null +++ b/test cases/vala/30 dependencies for compiler.links/meson.build @@ -0,0 +1,64 @@ +project('dependency-link-test', ['c', 'vala'], version: '0.1') + +valac = meson.get_compiler('vala') +gee_dep = dependency('gee-0.8', required : false) + +code = '''void main() { + var a=new Gee.ArrayList<int> (); + a.add (42); + stdout.printf("%i",a[0]);}''' + +if gee_dep.found() + # test 1; code should link + code_links = valac.links( + code, + dependencies : [gee_dep], + name: 'links with gee-0.8 library? == YES', + ) + assert (code_links, 'gee-0.8 library should link successfully.') +endif + +# test 2; code should not link +code_links = valac.links( + code, + name: 'links with gee library? == NO', +) +assert (not code_links, 'gee-0.8 library should not link successfully.') + +math_dep = meson.get_compiler('c').find_library('m', required : false) +glib_dep = dependency('glib-2.0', required : false) + +code = '''void main() { + var a=GLib.Math.cos (GLib.Math.PI / 3); + stdout.printf("%f",a);}''' + +if math_dep.found() and glib_dep.found() + # test 3; code should link + code_links = valac.links( + code, + dependencies : [math_dep, glib_dep], + name: 'links with math & glib-2.0 library? == YES', + ) + assert (code_links, 'Math library and glib-2.0 library should link successfully.') +endif + +gio_dep = dependency('gio-2.0', required : false) + +code = '''void main() {var s = new GLib.Settings ("test");}''' + +if gio_dep.found() + # test 4; code should link + code_links = valac.links( + code, + dependencies : [gio_dep], + name: 'links with gio-2.0? == YES', + ) + assert (code_links, 'gio-2.0 library should link successfully.') +endif + +# test 5; code should not link + code_links = valac.links( + code, + name: 'links with gio-2.0? == NO', +) +assert (not code_links, 'gio-2.0 library should not link successfully.') |