From 9390295281c7e8ada7a42724c3a7651d6d52609c Mon Sep 17 00:00:00 2001 From: Guillaume Desmottes Date: Tue, 19 Nov 2019 14:26:01 +0530 Subject: [PATCH] add meson support This is needed to integrate gst-plugins-rs with gst-build, see https://gitlab.freedesktop.org/gstreamer/gst-build/issues/63 --- cargo.py | 41 ++++++++++++++++++++++++++++++++++ meson.build | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+) create mode 100644 cargo.py create mode 100644 meson.build diff --git a/cargo.py b/cargo.py new file mode 100644 index 00000000..73d43113 --- /dev/null +++ b/cargo.py @@ -0,0 +1,41 @@ +#!/usr/bin/env python3 + +import glob +import os +import os.path +import shutil +import subprocess +import sys + +meson_build_dir, meson_current_source_dir, meson_build_root, target, ext = sys.argv[1:] + +cargo_target_dir = os.path.join(meson_build_dir, 'target') + +env = os.environ.copy() +env['CARGO_TARGET_DIR'] = cargo_target_dir + +# FIXME: hack so cargo will find gst libs when building inside gst-build. +# We should fetch this from meson deps instead of hardcoding the paths, +# when Meson will generate -uninstalled.pc files, they all will be in +# /meson-uninstalled/ +pkg_config_path = env.get('PKG_CONFIG_PATH', '').split(':') +pkg_config_path.append(os.path.join( + meson_build_root, 'subprojects', 'gstreamer', 'pkgconfig')) +pkg_config_path.append(os.path.join( + meson_build_root, 'subprojects', 'gst-plugins-base', 'pkgconfig')) +env['PKG_CONFIG_PATH'] = ':'.join(pkg_config_path) + +# cargo build +cargo_cmd = ['cargo', 'build', '--manifest-path', + os.path.join(meson_current_source_dir, 'Cargo.toml')] +if target == 'release': + cargo_cmd.append('--release') + +try: + subprocess.run(cargo_cmd, env=env, check=True) +except subprocess.SubprocessError: + sys.exit(1) + +# Copy so files to build dir +for f in glob.glob(os.path.join(cargo_target_dir, target, '*.' + ext)): + shutil.copy(f, meson_build_dir) diff --git a/meson.build b/meson.build new file mode 100644 index 00000000..ecae6447 --- /dev/null +++ b/meson.build @@ -0,0 +1,64 @@ +project('gst-plugins-rs', + 'rust', + version: '0.13.0', + meson_version : '>= 0.52') + +if get_option('debug') + target = 'debug' +else + target = 'release' +endif + +cargo = find_program('cargo', version:'>=1.39') +cargo_script = find_program('cargo.py') + +system = build_machine.system() +if system == 'windows' + ext = 'dll' +elif system == 'darwin' + ext = 'dylib' +else + ext = 'so' +endif + +plugins_rep = { + 'gst-plugin-audiofx': 'libgstrsaudiofx', + 'gst-plugin-cdg': 'libgstcdg', + 'gst-plugin-closedcaption': 'libgstrsclosedcaption', + 'gst-plugin-fallbackswitch': 'libgstfallbackswitch', + 'gst-plugin-file': 'libgstrsfile', + 'gst-plugin-flv': 'libgstrsflv', + 'gst-plugin-lewton': 'libgstlewton', + 'gst-plugin-rav1e': 'libgstrav1e', + 'gst-plugin-reqwest': 'libgstreqwest', + 'gst-plugin-rusoto': 'libgstrusoto', + 'gst-plugin-sodium': 'libgstsodium', + 'gst-plugin-threadshare': 'libgstthreadshare', + 'gst-plugin-togglerecord': 'libgsttogglerecord', +} + +output = [] + +foreach p, lib : plugins_rep + # Add the plugin file as output + output += [lib + '.' + ext] +endforeach + +# Always build the target so we don't have to list all source files as input +rs_plugins = custom_target('gst-plugins-rs', + build_by_default: true, + output: output, + console: true, + install: false, + build_always_stale: true, + command: [cargo_script, + meson.current_build_dir(), + meson.current_source_dir(), + meson.build_root(), + target, + ext]) + +# FIXME: raises a warning as the target has multiple outputs and meson will use +# only the first one. All the plugins have the same basedir, hence +# GST_PLUGIN_PATH will include them all, so that's ok. +plugins = [rs_plugins]