From bdd4c45b173055931db1c758cd7f016693d3a924 Mon Sep 17 00:00:00 2001 From: "Adam C. Foltzer" Date: Fri, 9 Jun 2017 14:51:58 -0700 Subject: [PATCH 1/5] 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 --- docs/markdown/Reference-manual.md | 5 ++- mesonbuild/backend/ninjabackend.py | 23 +++++++++- mesonbuild/build.py | 45 +++++++++++++++---- mesonbuild/compilers.py | 8 ++++ .../rust/4 polyglot/installed_files.txt | 2 + test cases/rust/4 polyglot/meson.build | 5 +++ test cases/rust/4 polyglot/prog.c | 8 ++++ test cases/rust/4 polyglot/stuff.rs | 6 +++ .../5 polyglot static/installed_files.txt | 2 + test cases/rust/5 polyglot static/meson.build | 10 +++++ test cases/rust/5 polyglot static/prog.c | 8 ++++ test cases/rust/5 polyglot static/stuff.rs | 6 +++ 12 files changed, 117 insertions(+), 11 deletions(-) create mode 100644 test cases/rust/4 polyglot/installed_files.txt create mode 100644 test cases/rust/4 polyglot/meson.build create mode 100644 test cases/rust/4 polyglot/prog.c create mode 100644 test cases/rust/4 polyglot/stuff.rs create mode 100644 test cases/rust/5 polyglot static/installed_files.txt create mode 100644 test cases/rust/5 polyglot static/meson.build create mode 100644 test cases/rust/5 polyglot static/prog.c create mode 100644 test cases/rust/5 polyglot static/stuff.rs diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index 492666b96..61a66f06f 100644 --- a/docs/markdown/Reference-manual.md +++ b/docs/markdown/Reference-manual.md @@ -510,11 +510,12 @@ Joins the given strings into a file system path segment. For example `join_paths Builds a library that is either static or shared depending on the value of `default_library` user option. You should use this instead of [`shared_library`](#shared_library) or [`static_library`](#static_library) most of the time. This allows you to toggle your entire project (including subprojects) from shared to static with only one option. -The keyword arguments for this are the same as for [`executable`](#executable) with the following addition: +The keyword arguments for this are the same as for [`executable`](#executable) with the following additions: - `name_prefix` the string that will be used as the suffix for the target by overriding the default (only used for libraries). By default this is `lib` on all platforms and compilers except with MSVC where it is omitted. +- `crate_type` specifies the crate type for Rust libraries. Defaults to `dylib` for shared libraries and `rlib` for static libraries. -`static_library` and `shared_library` also accept this keyword argument. +`static_library` and `shared_library` also accept these keyword arguments. ### message() diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 40a05bf34..5764b54f5 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), diff --git a/mesonbuild/build.py b/mesonbuild/build.py index 2c55ed47c..f4b338265 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -71,6 +71,7 @@ known_lib_kwargs.update({'version': True, # Only for shared libs 'vala_vapi': True, 'vala_gir': True, 'pic': True, # Only for static libs + 'crate_type': True, # Only for Rust libs }) @@ -1123,6 +1124,14 @@ class StaticLibrary(BuildTarget): super().__init__(name, subdir, subproject, is_cross, sources, objects, environment, kwargs) if 'cs' in self.compilers: raise InvalidArguments('Static libraries not supported for C#.') + if 'rust' in self.compilers: + # If no crate type is specified, or it's the generic lib type, use rlib + if not hasattr(self, 'crate_type') or self.crate_type == 'lib': + mlog.debug('Defaulting Rust static library target crate type to rlib') + self.crate_type = 'rlib' + # Don't let configuration proceed with a non-static crate type + elif self.crate_type not in ['rlib', 'staticlib']: + raise InvalidArguments('Crate type "{0}" invalid for static libraries; must be "rlib" or "staticlib"'.format(self.crate_type)) # By default a static library is named libfoo.a even on Windows because # MSVC does not have a consistent convention for what static libraries # are called. The MSVC CRT uses libfoo.lib syntax but nothing else uses @@ -1133,9 +1142,12 @@ class StaticLibrary(BuildTarget): if not hasattr(self, 'prefix'): self.prefix = 'lib' if not hasattr(self, 'suffix'): - # Rust static library crates have .rlib suffix if 'rust' in self.compilers: - self.suffix = 'rlib' + if not hasattr(self, 'crate_type') or self.crate_type == 'rlib': + # default Rust static library suffix + self.suffix = 'rlib' + elif self.crate_type == 'staticlib': + self.suffix = 'a' else: self.suffix = 'a' self.filename = self.prefix + self.name + '.' + self.suffix @@ -1147,6 +1159,15 @@ class StaticLibrary(BuildTarget): def check_unknown_kwargs(self, kwargs): self.check_unknown_kwargs_int(kwargs, known_lib_kwargs) + def process_kwargs(self, kwargs, environment): + super().process_kwargs(kwargs, environment) + if 'crate_type' in kwargs: + crate_type = kwargs['crate_type'] + if isinstance(crate_type, str): + self.crate_type = crate_type + else: + raise InvalidArguments('Invalid crate_type "{0}": must be a string.'.format(crate_type)) + class SharedLibrary(BuildTarget): def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs): self.soversion = None @@ -1159,6 +1180,14 @@ class SharedLibrary(BuildTarget): # The import library that GCC would generate (and prefer) self.gcc_import_filename = None super().__init__(name, subdir, subproject, is_cross, sources, objects, environment, kwargs) + if 'rust' in self.compilers: + # If no crate type is specified, or it's the generic lib type, use dylib + if not hasattr(self, 'crate_type') or self.crate_type == 'lib': + mlog.debug('Defaulting Rust dynamic library target crate type to "dylib"') + self.crate_type = 'dylib' + # Don't let configuration proceed with a non-dynamic crate type + elif self.crate_type not in ['dylib', 'cdylib']: + raise InvalidArguments('Crate type "{0}" invalid for dynamic libraries; must be "dylib" or "cdylib"'.format(self.crate_type)) if not hasattr(self, 'prefix'): self.prefix = None if not hasattr(self, 'suffix'): @@ -1200,12 +1229,6 @@ class SharedLibrary(BuildTarget): prefix = '' suffix = 'dll' self.filename_tpl = '{0.prefix}{0.name}.{0.suffix}' - # Rust - elif 'rust' in self.compilers: - # Currently, we always build --crate-type=rlib - prefix = 'lib' - suffix = 'rlib' - self.filename_tpl = '{0.prefix}{0.name}.{0.suffix}' # C, C++, Swift, Vala # Only Windows uses a separate import library for linking # For all other targets/platforms import_filename stays None @@ -1315,6 +1338,12 @@ class SharedLibrary(BuildTarget): raise InvalidArguments( 'Shared library vs_module_defs must be either a string, ' 'a file object or a Custom Target') + if 'crate_type' in kwargs: + crate_type = kwargs['crate_type'] + if isinstance(crate_type, str): + self.crate_type = crate_type + else: + raise InvalidArguments('Invalid crate_type "{0}": must be a string.'.format(crate_type)) def check_unknown_kwargs(self, kwargs): self.check_unknown_kwargs_int(kwargs, known_lib_kwargs) diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index c9cfb4641..6e7283ca2 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -1809,6 +1809,14 @@ class RustCompiler(Compiler): def get_buildtype_args(self, buildtype): return rust_buildtype_args[buildtype] + def build_rpath_args(self, build_dir, rpath_paths, install_rpath): + return build_unix_rpath_args(build_dir, rpath_paths, install_rpath) + + def get_sysroot(self): + cmd = self.exelist + ['--print', 'sysroot'] + p, stdo, stde = Popen_safe(cmd) + return stdo.split('\n')[0] + class SwiftCompiler(Compiler): def __init__(self, exelist, version): self.language = 'swift' diff --git a/test cases/rust/4 polyglot/installed_files.txt b/test cases/rust/4 polyglot/installed_files.txt new file mode 100644 index 000000000..680343d31 --- /dev/null +++ b/test cases/rust/4 polyglot/installed_files.txt @@ -0,0 +1,2 @@ +usr/bin/prog?exe +usr/lib/libstuff.so diff --git a/test cases/rust/4 polyglot/meson.build b/test cases/rust/4 polyglot/meson.build new file mode 100644 index 000000000..a20d76648 --- /dev/null +++ b/test cases/rust/4 polyglot/meson.build @@ -0,0 +1,5 @@ +project('rust and c polyglot executable', 'c', 'rust') + +l = library('stuff', 'stuff.rs', install : true) +e = executable('prog', 'prog.c', link_with : l, install : true) +test('polyglottest', e) diff --git a/test cases/rust/4 polyglot/prog.c b/test cases/rust/4 polyglot/prog.c new file mode 100644 index 000000000..18f2c36fc --- /dev/null +++ b/test cases/rust/4 polyglot/prog.c @@ -0,0 +1,8 @@ +#include + +void f(); + +int main() { + printf("Hello from C!\n"); + f(); +} diff --git a/test cases/rust/4 polyglot/stuff.rs b/test cases/rust/4 polyglot/stuff.rs new file mode 100644 index 000000000..ecf623c64 --- /dev/null +++ b/test cases/rust/4 polyglot/stuff.rs @@ -0,0 +1,6 @@ +#![crate_name = "stuff"] + +#[no_mangle] +pub extern fn f() { + println!("Hello from Rust!"); +} diff --git a/test cases/rust/5 polyglot static/installed_files.txt b/test cases/rust/5 polyglot static/installed_files.txt new file mode 100644 index 000000000..2f7a397d7 --- /dev/null +++ b/test cases/rust/5 polyglot static/installed_files.txt @@ -0,0 +1,2 @@ +usr/bin/prog?exe +usr/lib/libstuff.a diff --git a/test cases/rust/5 polyglot static/meson.build b/test cases/rust/5 polyglot static/meson.build new file mode 100644 index 000000000..8eb2d530e --- /dev/null +++ b/test cases/rust/5 polyglot static/meson.build @@ -0,0 +1,10 @@ +project('static rust and c polyglot executable', 'c', 'rust') + +deps = [ + meson.get_compiler('c').find_library('dl'), + dependency('threads'), +] + +l = static_library('stuff', 'stuff.rs', crate_type : 'staticlib', install : true) +e = executable('prog', 'prog.c', dependencies: deps, link_with : l, install : true) +test('polyglottest', e) diff --git a/test cases/rust/5 polyglot static/prog.c b/test cases/rust/5 polyglot static/prog.c new file mode 100644 index 000000000..18f2c36fc --- /dev/null +++ b/test cases/rust/5 polyglot static/prog.c @@ -0,0 +1,8 @@ +#include + +void f(); + +int main() { + printf("Hello from C!\n"); + f(); +} diff --git a/test cases/rust/5 polyglot static/stuff.rs b/test cases/rust/5 polyglot static/stuff.rs new file mode 100644 index 000000000..ecf623c64 --- /dev/null +++ b/test cases/rust/5 polyglot static/stuff.rs @@ -0,0 +1,6 @@ +#![crate_name = "stuff"] + +#[no_mangle] +pub extern fn f() { + println!("Hello from Rust!"); +} From 69b18cf7e95f101e78c434811a3a02ff219235be Mon Sep 17 00:00:00 2001 From: "Adam C. Foltzer" Date: Wed, 14 Jun 2017 08:39:41 -0700 Subject: [PATCH 2/5] rename `crate_type` to `rust_crate_type` per @TingPing --- docs/markdown/Reference-manual.md | 2 +- mesonbuild/backend/ninjabackend.py | 4 +- mesonbuild/build.py | 42 +++++++++---------- test cases/rust/5 polyglot static/meson.build | 2 +- 4 files changed, 25 insertions(+), 25 deletions(-) diff --git a/docs/markdown/Reference-manual.md b/docs/markdown/Reference-manual.md index 61a66f06f..dd77d6d14 100644 --- a/docs/markdown/Reference-manual.md +++ b/docs/markdown/Reference-manual.md @@ -513,7 +513,7 @@ Builds a library that is either static or shared depending on the value of `defa The keyword arguments for this are the same as for [`executable`](#executable) with the following additions: - `name_prefix` the string that will be used as the suffix for the target by overriding the default (only used for libraries). By default this is `lib` on all platforms and compilers except with MSVC where it is omitted. -- `crate_type` specifies the crate type for Rust libraries. Defaults to `dylib` for shared libraries and `rlib` for static libraries. +- `rust_crate_type` specifies the crate type for Rust libraries. Defaults to `dylib` for shared libraries and `rlib` for static libraries. `static_library` and `shared_library` also accept these keyword arguments. diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 5764b54f5..8da75c076 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1157,8 +1157,8 @@ int dummy; args = ['--crate-type'] if isinstance(target, build.Executable): cratetype = 'bin' - elif hasattr(target, 'crate_type'): - cratetype = target.crate_type + elif hasattr(target, 'rust_crate_type'): + cratetype = target.rust_crate_type elif isinstance(target, build.SharedLibrary): cratetype = 'dylib' elif isinstance(target, build.StaticLibrary): diff --git a/mesonbuild/build.py b/mesonbuild/build.py index f4b338265..7ce6fa68a 100644 --- a/mesonbuild/build.py +++ b/mesonbuild/build.py @@ -71,7 +71,7 @@ known_lib_kwargs.update({'version': True, # Only for shared libs 'vala_vapi': True, 'vala_gir': True, 'pic': True, # Only for static libs - 'crate_type': True, # Only for Rust libs + 'rust_crate_type': True, # Only for Rust libs }) @@ -1126,12 +1126,12 @@ class StaticLibrary(BuildTarget): raise InvalidArguments('Static libraries not supported for C#.') if 'rust' in self.compilers: # If no crate type is specified, or it's the generic lib type, use rlib - if not hasattr(self, 'crate_type') or self.crate_type == 'lib': + if not hasattr(self, 'rust_crate_type') or self.rust_crate_type == 'lib': mlog.debug('Defaulting Rust static library target crate type to rlib') - self.crate_type = 'rlib' + self.rust_crate_type = 'rlib' # Don't let configuration proceed with a non-static crate type - elif self.crate_type not in ['rlib', 'staticlib']: - raise InvalidArguments('Crate type "{0}" invalid for static libraries; must be "rlib" or "staticlib"'.format(self.crate_type)) + elif self.rust_crate_type not in ['rlib', 'staticlib']: + raise InvalidArguments('Crate type "{0}" invalid for static libraries; must be "rlib" or "staticlib"'.format(self.rust_crate_type)) # By default a static library is named libfoo.a even on Windows because # MSVC does not have a consistent convention for what static libraries # are called. The MSVC CRT uses libfoo.lib syntax but nothing else uses @@ -1143,10 +1143,10 @@ class StaticLibrary(BuildTarget): self.prefix = 'lib' if not hasattr(self, 'suffix'): if 'rust' in self.compilers: - if not hasattr(self, 'crate_type') or self.crate_type == 'rlib': + if not hasattr(self, 'rust_crate_type') or self.rust_crate_type == 'rlib': # default Rust static library suffix self.suffix = 'rlib' - elif self.crate_type == 'staticlib': + elif self.rust_crate_type == 'staticlib': self.suffix = 'a' else: self.suffix = 'a' @@ -1161,12 +1161,12 @@ class StaticLibrary(BuildTarget): def process_kwargs(self, kwargs, environment): super().process_kwargs(kwargs, environment) - if 'crate_type' in kwargs: - crate_type = kwargs['crate_type'] - if isinstance(crate_type, str): - self.crate_type = crate_type + if 'rust_crate_type' in kwargs: + rust_crate_type = kwargs['rust_crate_type'] + if isinstance(rust_crate_type, str): + self.rust_crate_type = rust_crate_type else: - raise InvalidArguments('Invalid crate_type "{0}": must be a string.'.format(crate_type)) + raise InvalidArguments('Invalid rust_crate_type "{0}": must be a string.'.format(rust_crate_type)) class SharedLibrary(BuildTarget): def __init__(self, name, subdir, subproject, is_cross, sources, objects, environment, kwargs): @@ -1182,12 +1182,12 @@ class SharedLibrary(BuildTarget): super().__init__(name, subdir, subproject, is_cross, sources, objects, environment, kwargs) if 'rust' in self.compilers: # If no crate type is specified, or it's the generic lib type, use dylib - if not hasattr(self, 'crate_type') or self.crate_type == 'lib': + if not hasattr(self, 'rust_crate_type') or self.rust_crate_type == 'lib': mlog.debug('Defaulting Rust dynamic library target crate type to "dylib"') - self.crate_type = 'dylib' + self.rust_crate_type = 'dylib' # Don't let configuration proceed with a non-dynamic crate type - elif self.crate_type not in ['dylib', 'cdylib']: - raise InvalidArguments('Crate type "{0}" invalid for dynamic libraries; must be "dylib" or "cdylib"'.format(self.crate_type)) + elif self.rust_crate_type not in ['dylib', 'cdylib']: + raise InvalidArguments('Crate type "{0}" invalid for dynamic libraries; must be "dylib" or "cdylib"'.format(self.rust_crate_type)) if not hasattr(self, 'prefix'): self.prefix = None if not hasattr(self, 'suffix'): @@ -1338,12 +1338,12 @@ class SharedLibrary(BuildTarget): raise InvalidArguments( 'Shared library vs_module_defs must be either a string, ' 'a file object or a Custom Target') - if 'crate_type' in kwargs: - crate_type = kwargs['crate_type'] - if isinstance(crate_type, str): - self.crate_type = crate_type + if 'rust_crate_type' in kwargs: + rust_crate_type = kwargs['rust_crate_type'] + if isinstance(rust_crate_type, str): + self.rust_crate_type = rust_crate_type else: - raise InvalidArguments('Invalid crate_type "{0}": must be a string.'.format(crate_type)) + raise InvalidArguments('Invalid rust_crate_type "{0}": must be a string.'.format(rust_crate_type)) def check_unknown_kwargs(self, kwargs): self.check_unknown_kwargs_int(kwargs, known_lib_kwargs) diff --git a/test cases/rust/5 polyglot static/meson.build b/test cases/rust/5 polyglot static/meson.build index 8eb2d530e..76dc7904e 100644 --- a/test cases/rust/5 polyglot static/meson.build +++ b/test cases/rust/5 polyglot static/meson.build @@ -5,6 +5,6 @@ deps = [ dependency('threads'), ] -l = static_library('stuff', 'stuff.rs', crate_type : 'staticlib', install : true) +l = static_library('stuff', 'stuff.rs', rust_crate_type : 'staticlib', install : true) e = executable('prog', 'prog.c', dependencies: deps, link_with : l, install : true) test('polyglottest', e) From f4d13e180fad89aaae863b6ae057b8d94ec25ef7 Mon Sep 17 00:00:00 2001 From: "Adam C. Foltzer" Date: Wed, 14 Jun 2017 08:46:28 -0700 Subject: [PATCH 3/5] add failing test cases for wrong Rust crate types per @TingPing --- test cases/failing/55 wrong shared crate type/foo.rs | 0 test cases/failing/55 wrong shared crate type/meson.build | 3 +++ test cases/failing/56 wrong static crate type/foo.rs | 0 test cases/failing/56 wrong static crate type/meson.build | 3 +++ 4 files changed, 6 insertions(+) create mode 100644 test cases/failing/55 wrong shared crate type/foo.rs create mode 100644 test cases/failing/55 wrong shared crate type/meson.build create mode 100644 test cases/failing/56 wrong static crate type/foo.rs create mode 100644 test cases/failing/56 wrong static crate type/meson.build diff --git a/test cases/failing/55 wrong shared crate type/foo.rs b/test cases/failing/55 wrong shared crate type/foo.rs new file mode 100644 index 000000000..e69de29bb diff --git a/test cases/failing/55 wrong shared crate type/meson.build b/test cases/failing/55 wrong shared crate type/meson.build new file mode 100644 index 000000000..69ac3dad5 --- /dev/null +++ b/test cases/failing/55 wrong shared crate type/meson.build @@ -0,0 +1,3 @@ +project('test', 'rust') + +shared_library('test', 'foo.rs', rust_crate_type : 'staticlib') diff --git a/test cases/failing/56 wrong static crate type/foo.rs b/test cases/failing/56 wrong static crate type/foo.rs new file mode 100644 index 000000000..e69de29bb diff --git a/test cases/failing/56 wrong static crate type/meson.build b/test cases/failing/56 wrong static crate type/meson.build new file mode 100644 index 000000000..c094613b2 --- /dev/null +++ b/test cases/failing/56 wrong static crate type/meson.build @@ -0,0 +1,3 @@ +project('test', 'rust') + +static_library('test', 'foo.rs', rust_crate_type : 'cdylib') From 35fae9d019352dcef01a44944d0096c4c33bbda0 Mon Sep 17 00:00:00 2001 From: "Adam C. Foltzer" Date: Wed, 14 Jun 2017 11:50:35 -0700 Subject: [PATCH 4/5] fix failing Rust test cases --- mesonbuild/backend/ninjabackend.py | 13 +++++++++++++ mesonbuild/compilers.py | 8 ++++---- test cases/rust/2 sharedlib/installed_files.txt | 2 +- 3 files changed, 18 insertions(+), 5 deletions(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 8da75c076..40f0918fd 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1188,8 +1188,21 @@ int dummy; # against are dynamic, otherwise we'll end up with # multiple implementations of crates args += ['-C', 'prefer-dynamic'] + # build the usual rpath arguments as well... + + # Set runtime-paths so we can run executables without needing to set + # LD_LIBRARY_PATH, etc in the environment. Doesn't work on Windows. + if '/' in target.name or '\\' in target.name: + # Target names really should not have slashes in them, but + # unfortunately we did not check for that and some downstream projects + # now have them. Once slashes are forbidden, remove this bit. + target_slashname_workaround_dir = os.path.join(os.path.split(target.name)[0], + self.get_target_dir(target)) + else: + target_slashname_workaround_dir = self.get_target_dir(target) rpath_args = rustc.build_rpath_args(self.environment.get_build_dir(), + target_slashname_workaround_dir, self.determine_rpath_dirs(target), target.install_rpath) # ... but then add rustc's sysroot to account for rustup diff --git a/mesonbuild/compilers.py b/mesonbuild/compilers.py index 6e7283ca2..833071ea8 100644 --- a/mesonbuild/compilers.py +++ b/mesonbuild/compilers.py @@ -1546,7 +1546,7 @@ class MonoCompiler(Compiler): def split_shlib_to_parts(self, fname): return None, fname - def build_rpath_args(self, build_dir, rpath_paths, install_rpath): + def build_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath): return [] def get_dependency_gen_args(self, outtarget, outfile): @@ -1627,7 +1627,7 @@ class JavaCompiler(Compiler): def split_shlib_to_parts(self, fname): return None, fname - def build_rpath_args(self, build_dir, rpath_paths, install_rpath): + def build_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath): return [] def get_dependency_gen_args(self, outtarget, outfile): @@ -1809,8 +1809,8 @@ class RustCompiler(Compiler): def get_buildtype_args(self, buildtype): return rust_buildtype_args[buildtype] - def build_rpath_args(self, build_dir, rpath_paths, install_rpath): - return build_unix_rpath_args(build_dir, rpath_paths, install_rpath) + def build_rpath_args(self, build_dir, from_dir, rpath_paths, install_rpath): + return self.build_unix_rpath_args(build_dir, from_dir, rpath_paths, install_rpath) def get_sysroot(self): cmd = self.exelist + ['--print', 'sysroot'] diff --git a/test cases/rust/2 sharedlib/installed_files.txt b/test cases/rust/2 sharedlib/installed_files.txt index 85acff291..680343d31 100644 --- a/test cases/rust/2 sharedlib/installed_files.txt +++ b/test cases/rust/2 sharedlib/installed_files.txt @@ -1,2 +1,2 @@ usr/bin/prog?exe -usr/lib/libstuff.rlib +usr/lib/libstuff.so From 6165612f6bb06c0f41422a9768caf2eba03849a9 Mon Sep 17 00:00:00 2001 From: "Adam C. Foltzer" Date: Mon, 19 Jun 2017 16:52:31 -0700 Subject: [PATCH 5/5] fix indentation per @ignatenkobrain --- mesonbuild/backend/ninjabackend.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py index 40f0918fd..3638621ff 100644 --- a/mesonbuild/backend/ninjabackend.py +++ b/mesonbuild/backend/ninjabackend.py @@ -1198,7 +1198,7 @@ int dummy; # unfortunately we did not check for that and some downstream projects # now have them. Once slashes are forbidden, remove this bit. target_slashname_workaround_dir = os.path.join(os.path.split(target.name)[0], - self.get_target_dir(target)) + self.get_target_dir(target)) else: target_slashname_workaround_dir = self.get_target_dir(target) rpath_args = rustc.build_rpath_args(self.environment.get_build_dir(),