aboutsummaryrefslogtreecommitdiff
path: root/mesonbuild/backend/ninjabackend.py
diff options
context:
space:
mode:
authorAdam C. Foltzer <acfoltzer@galois.com>2017-06-09 14:51:58 -0700
committerAdam C. Foltzer <acfoltzer@galois.com>2017-06-09 15:14:02 -0700
commitbdd4c45b173055931db1c758cd7f016693d3a924 (patch)
treea868e261a3771996dbd3c1dd03c5bac049f60389 /mesonbuild/backend/ninjabackend.py
parent22cfd44221ada3219d9096e15dc8b00d32e0f9f6 (diff)
downloadmeson-bdd4c45b173055931db1c758cd7f016693d3a924.zip
meson-bdd4c45b173055931db1c758cd7f016693d3a924.tar.gz
meson-bdd4c45b173055931db1c758cd7f016693d3a924.tar.bz2
Enhance Rust support
- Adds a `crate_type` kwarg to library targets, allowing the different types of Rust [linkage][1]. - Shared libraries use the `dylib` crate type by default, but can also be `cdylib` - Static libraries use the `rlib` crate type by default, but can also be `staticlib` - If any Rust target has shared library dependencies, add the appropriate linker arguments, including rpath for the sysroot of the Rust compiler [1]: https://doc.rust-lang.org/reference/linkage.html
Diffstat (limited to 'mesonbuild/backend/ninjabackend.py')
-rw-r--r--mesonbuild/backend/ninjabackend.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
index 40a05bf..5764b54 100644
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -1157,8 +1157,10 @@ int dummy;
args = ['--crate-type']
if isinstance(target, build.Executable):
cratetype = 'bin'
+ elif hasattr(target, 'crate_type'):
+ cratetype = target.crate_type
elif isinstance(target, build.SharedLibrary):
- cratetype = 'rlib'
+ cratetype = 'dylib'
elif isinstance(target, build.StaticLibrary):
cratetype = 'rlib'
else:
@@ -1177,6 +1179,23 @@ 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
+ 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
+ # multiple implementations of crates
+ args += ['-C', 'prefer-dynamic']
+ # build the usual rpath arguments as well...
+ rpath_args = rustc.build_rpath_args(self.environment.get_build_dir(),
+ self.determine_rpath_dirs(target),
+ target.install_rpath)
+ # ... but then add rustc's sysroot to account for rustup
+ # installations
+ for rpath_arg in rpath_args:
+ args += ['-C', 'link-arg=' + rpath_arg + ':' + os.path.join(rustc.get_sysroot(), 'lib')]
element = NinjaBuildElement(self.all_outputs, target_name, 'rust_COMPILER', relsrc)
if len(orderdeps) > 0:
element.add_orderdep(orderdeps)
@@ -1184,6 +1203,8 @@ int dummy;
element.add_item('targetdep', depfile)
element.add_item('cratetype', cratetype)
element.write(outfile)
+ if isinstance(target, build.SharedLibrary):
+ self.generate_shsym(outfile, target)
def swift_module_file_name(self, target):
return os.path.join(self.get_target_private_dir(target),