diff options
author | Remi Thebault <remi.thebault@gmail.com> | 2021-03-08 18:42:38 +0100 |
---|---|---|
committer | Dylan Baker <dylan@pnwbakers.com> | 2021-03-17 10:14:55 -0700 |
commit | c756d9789558d7100383759e4f2aa8d4b2321620 (patch) | |
tree | d481efdd0a9ce8e4874be8c6bb4b2b453900dc36 | |
parent | fe4ddb5268dd00b229b2b15e80169aee827b8add (diff) | |
download | meson-c756d9789558d7100383759e4f2aa8d4b2321620.zip meson-c756d9789558d7100383759e4f2aa8d4b2321620.tar.gz meson-c756d9789558d7100383759e4f2aa8d4b2321620.tar.bz2 |
Fix D lib search path translation
This requires quite a complex and messy logic.
As @dcbaker suggested in #8491, this could be replaced by
an abstraction over linker flags instead of having GNU flags
translated.
-rw-r--r-- | mesonbuild/compilers/d.py | 64 |
1 files changed, 49 insertions, 15 deletions
diff --git a/mesonbuild/compilers/d.py b/mesonbuild/compilers/d.py index bda1026..837ee9a 100644 --- a/mesonbuild/compilers/d.py +++ b/mesonbuild/compilers/d.py @@ -274,11 +274,17 @@ class DmdLikeCompilerMixin(CompilerMixinBase): env, build_dir, from_dir, rpath_paths, build_rpath, install_rpath) def _translate_args_to_nongnu(self, args: T.List[str]) -> T.List[str]: - dcargs = [] # Translate common arguments to flags the LDC/DMD compilers # can understand. # The flags might have been added by pkg-config files, # and are therefore out of the user's control. + dcargs = [] + # whether we hit a linker argument that expect another arg + # see the comment in the "-L" section + link_expect_arg = False + link_flags_with_arg = [ + '-rpath', '-soname', '-compatibility_version', '-current_version', + ] for arg in args: # Translate OS specific arguments first. osargs = [] # type: T.List[str] @@ -333,23 +339,51 @@ class DmdLikeCompilerMixin(CompilerMixinBase): else: dcargs.append('-I' + arg[10:]) continue - elif arg.startswith('-L/') or arg.startswith('-L./'): - # we need to handle cases where -L is set by e.g. a pkg-config - # setting to select a linker search path. We can however not - # unconditionally prefix '-L' with '-L' because the user might - # have set this flag too to do what it is intended to for this - # compiler (pass flag through to the linker) - # Hence, we guess here whether the flag was intended to pass - # a linker search path. + elif arg.startswith('-L'): + # The D linker expect library search paths in the form of -L=-L/path (the '=' is optional). + # + # This function receives a mix of arguments already prepended + # with -L for the D linker driver and other linker arguments. + # The arguments starting with -L can be: + # - library search path (with or without a second -L) + # - it can come from pkg-config (a single -L) + # - or from the user passing linker flags (-L-L would be expected) + # - arguments like "-L=-rpath" that expect a second argument (also prepended with -L) + # - arguments like "-L=@rpath/xxx" without a second argument (on Apple platform) + # - arguments like "-L=/SUBSYSTEM:CONSOLE (for Windows linker) + # + # The logic that follows trys to detect all these cases (some may be missing) + # in order to prepend a -L only for the library search paths with a single -L + + if arg.startswith('-L='): + suffix = arg[3:] + else: + suffix = arg[2:] + + if link_expect_arg: + # flags like rpath and soname expect a path or filename respectively, + # we must not alter it (i.e. prefixing with -L for a lib search path) + dcargs.append(arg) + link_expect_arg = False + continue + + if suffix in link_flags_with_arg: + link_expect_arg = True + + if suffix.startswith('-') or suffix.startswith('@'): + # this is not search path + dcargs.append(arg) + continue + + # linker flag such as -L=/DEBUG must pass through + if self.linker.id == 'link' and self.info.is_windows() and suffix.startswith('/'): + dcargs.append(arg) + continue # Make sure static library files are passed properly to the linker. if arg.endswith('.a') or arg.endswith('.lib'): - if arg.startswith('-L='): - farg = arg[3:] - else: - farg = arg[2:] - if len(farg) > 0 and not farg.startswith('-'): - dcargs.append('-L=' + farg) + if len(suffix) > 0 and not suffix.startswith('-'): + dcargs.append('-L=' + suffix) continue dcargs.append('-L=' + arg) |