From 6544f151db7a04993ff75540ed6a0cb2a4573b02 Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 23 Feb 2021 10:39:06 -0800 Subject: rust: fix linking with external dependencies Rust can link with any dependency that uses c linkage, which is pretty much what we assume across the board anyway. --- mesonbuild/backend/ninjabackend.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'mesonbuild/backend/ninjabackend.py') diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 58fd5c6..a0a34b3 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1598,6 +1598,7 @@ int dummy; args += rustc.get_output_args(os.path.join(target.subdir, target.get_filename())) args += self.environment.coredata.get_external_args(target.for_machine, rustc.language) linkdirs = mesonlib.OrderedSet() + external_deps = target.external_deps.copy() for d in target.link_targets: linkdirs.add(d.subdir) if d.uses_rust(): @@ -1609,6 +1610,22 @@ int dummy; # Rust uses -l for non rust dependencies, but we still need to add (shared|static)=foo _type = 'static' if d.typename == 'static library' else 'shared' args += ['-l', f'{_type}={d.name}'] + if d.typename == 'static library': + external_deps.extend(d.external_deps) + for e in external_deps: + for a in e.get_link_args(): + if a.endswith(('.dll', '.so', '.dylib')): + dir_, lib = os.path.split(a) + linkdirs.add(dir_) + lib, ext = os.path.splitext(lib) + if lib.startswith('lib'): + lib = lib[3:] + args.extend(['-l', f'dylib={lib}']) + elif a.startswith('-L'): + args.append(a) + elif a.startswith('-l'): + # This should always be a static lib, I think + args.extend(['-l', f'static={a[2:]}']) for d in linkdirs: if d == '': d = '.' -- cgit v1.1 From 0edd0058046069f715d753dddee6e6c08e79207d Mon Sep 17 00:00:00 2001 From: Dylan Baker Date: Tue, 23 Feb 2021 11:26:19 -0800 Subject: rust: replace for loop with any() This is a little cleaner, and short circuits correctly, unlike the loop it replaces --- mesonbuild/backend/ninjabackend.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'mesonbuild/backend/ninjabackend.py') diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index a0a34b3..b7723ef 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1630,10 +1630,7 @@ int dummy; if d == '': d = '.' args += ['-L', d] - has_shared_deps = False - for dep in target.get_dependencies(): - if isinstance(dep, build.SharedLibrary): - has_shared_deps = True + has_shared_deps = any(isinstance(dep, build.SharedLibrary) for dep in target.get_dependencies()) if isinstance(target, build.SharedLibrary) or has_shared_deps: # add prefer-dynamic if any of the Rust libraries we link # against are dynamic, otherwise we'll end up with -- cgit v1.1