diff --git a/cargo_wrapper.py b/cargo_wrapper.py index e04ad39f..c13a7b05 100644 --- a/cargo_wrapper.py +++ b/cargo_wrapper.py @@ -82,6 +82,16 @@ if __name__ == "__main__": pkg_config_path.append(str(opts.root_dir / 'meson-uninstalled')) env['PKG_CONFIG_PATH'] = os.pathsep.join(pkg_config_path) + rustc_target = None + if 'RUSTFLAGS' in env: + # grab target from RUSTFLAGS + rust_flags = env['RUSTFLAGS'].split() + if '--target' in rust_flags: + rustc_target_idx = rust_flags.index('--target') + _ = rust_flags.pop(rustc_target_idx) # drop '--target' + rustc_target = rust_flags.pop(rustc_target_idx) + env['RUSTFLAGS'] = ' '.join(rust_flags) + features = opts.features if opts.command == 'build': cargo_cmd = ['cargo'] @@ -100,6 +110,8 @@ if __name__ == "__main__": print("Unknown command:", opts.command, file=logfile) sys.exit(1) + if rustc_target: + cargo_cmd += ['--target', rustc_target] if features: cargo_cmd += ['--features', ','.join(features)] cargo_cmd += ['--target-dir', cargo_target_dir] diff --git a/meson.build b/meson.build index da9649bb..b1e8f04a 100644 --- a/meson.build +++ b/meson.build @@ -21,13 +21,14 @@ endif cargo = find_program('cargo', version:'>=1.40') cargo_wrapper = find_program('cargo_wrapper.py') cargo_c = find_program('cargo-cbuild', version:'>=0.9.3', required: false) -rustc = find_program('rustc', version:'>=1.52') + +rustc = meson.get_compiler('rust') if not cargo_c.found() error('cargo-c missing, install it with: \'cargo install cargo-c\'') endif -system = build_machine.system() +system = host_machine.system() exe_suffix = '' if system == 'windows' exe_suffix = '.exe' @@ -365,7 +366,7 @@ pkgconfig_install_dir = get_option('libdir') / 'pkgconfig' extra_args = [] if get_option('doc').disabled() - extra_args = ['--disable-doc'] + extra_args += ['--disable-doc'] endif # 'pkgconfig' is the entry in the machine file, if specified @@ -383,6 +384,18 @@ if pkg_config_path.length() > 0 extra_env += {'PKG_CONFIG_PATH': pathsep.join(pkg_config_path)} endif +# get compiler and flags for rust (if any) +rustc_cmd = '' +rust_flags = [] +foreach rustc_arg : rustc.cmd_array() + if rustc_cmd == '' + rustc_cmd = rustc_arg + else + rust_flags += [rustc_arg] + endif +endforeach +extra_env += {'RUSTC': rustc_cmd, 'RUSTFLAGS': ' '.join(rust_flags)} + rs_plugins = custom_target('gst-plugins-rs', build_by_default: true, output: output,