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.
pull/8404/head
Dylan Baker 4 years ago
parent 5edbc0acd7
commit 6544f151db
  1. 17
      mesonbuild/backend/ninjabackend.py
  2. 5
      test cases/rust/13 external c dependencies/test.json

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

@ -10,6 +10,9 @@
{ "val": "cmake" },
{ "val": "system" }
]
}
},
"exclude": [
{ "static": true, "method": "pkg-config" }
]
}
}

Loading…
Cancel
Save