meson: add support for static build

There is no way to dynamically ask Cargo to build static or dynamic lib
so we have to build both and pick the one we care when doing the meson
processing.

Fix #88
This commit is contained in:
Guillaume Desmottes 2020-11-16 15:23:51 +01:00
parent 717477fd36
commit b9f8ce9995
22 changed files with 52 additions and 28 deletions

View file

@ -20,7 +20,7 @@ nnnoiseless = { version = "0.3", default-features = false }
[lib] [lib]
name = "gstrsaudiofx" name = "gstrsaudiofx"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[dev-dependencies] [dev-dependencies]

View file

@ -18,7 +18,7 @@ atomic_refcell = "0.1"
[lib] [lib]
name = "gstclaxon" name = "gstclaxon"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[build-dependencies] [build-dependencies]

View file

@ -19,7 +19,7 @@ byte-slice-cast = "1.0"
[lib] [lib]
name = "gstcsound" name = "gstcsound"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[[example]] [[example]]

View file

@ -19,7 +19,7 @@ lazy_static = "1.0"
[lib] [lib]
name = "gstlewton" name = "gstlewton"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[build-dependencies] [build-dependencies]

View file

@ -27,6 +27,12 @@ if len(extra_env) > 0:
if command == 'build': if command == 'build':
# cargo build # cargo build
ext = sys.argv[8] ext = sys.argv[8]
# when using --default-library=both 2 extensions are passed
try:
ext2 = sys.argv[9]
except IndexError:
ext2 = None
cargo_cmd = ['cargo', 'build', '--all-targets', cargo_cmd = ['cargo', 'build', '--all-targets',
'--manifest-path', os.path.join( '--manifest-path', os.path.join(
meson_current_source_dir, 'Cargo.toml'), meson_current_source_dir, 'Cargo.toml'),
@ -56,3 +62,6 @@ if command == 'build':
# Copy so files to build dir # Copy so files to build dir
for f in glob.glob(os.path.join(cargo_target_dir, target, '*.' + ext)): for f in glob.glob(os.path.join(cargo_target_dir, target, '*.' + ext)):
shutil.copy(f, meson_build_dir) shutil.copy(f, meson_build_dir)
if ext2:
for f in glob.glob(os.path.join(cargo_target_dir, target, '*.' + ext2)):
shutil.copy(f, meson_build_dir)

View file

@ -15,7 +15,7 @@ lazy_static = "1.0"
[lib] [lib]
name = "gstrsfile" name = "gstrsfile"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[build-dependencies] [build-dependencies]

View file

@ -35,7 +35,7 @@ package="gstreamer-app"
[lib] [lib]
name = "gstsodium" name = "gstsodium"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[[example]] [[example]]

View file

@ -36,7 +36,7 @@ socket2 = { version = "0.3", features = ["reuseport"] }
[lib] [lib]
name = "gstthreadshare" name = "gstthreadshare"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[[example]] [[example]]

View file

@ -15,11 +15,14 @@ cargo_wrapper = find_program('cargo_wrapper.py')
system = build_machine.system() system = build_machine.system()
if system == 'windows' if system == 'windows'
ext = 'dll' ext_dynamic = 'dll'
ext_static = 'lib'
elif system == 'darwin' elif system == 'darwin'
ext = 'dylib' ext_dynamic = 'dylib'
ext_static = 'a'
else else
ext = 'so' ext_dynamic = 'so'
ext_static = 'a'
endif endif
plugins_rep = { plugins_rep = {
@ -82,10 +85,22 @@ endif
output = [] output = []
foreach p, lib : plugins_rep extensions = []
# Add the plugin file as output
output += [lib + '.' + ext] # Add the plugin file as output
endforeach if get_option('default_library') == 'shared' or get_option('default_library') == 'both'
extensions += [ext_dynamic]
foreach p, lib : plugins_rep
output += [lib + '.' + ext_dynamic]
endforeach
endif
if get_option('default_library') == 'static' or get_option('default_library') == 'both'
extensions += [ext_static]
foreach p, lib : plugins_rep
output += [lib + '.' + ext_static]
endforeach
endif
# Need to depends on all gstreamer-rs deps to ensure they are built # Need to depends on all gstreamer-rs deps to ensure they are built
# before gstreamer-rs when building with gst-build. # before gstreamer-rs when building with gst-build.
@ -143,7 +158,7 @@ rs_plugins = custom_target('gst-plugins-rs',
target, target,
exclude, exclude,
extra_env_str, extra_env_str,
ext]) extensions])
# FIXME: raises a warning as the target has multiple outputs and meson will use # 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 # only the first one. All the plugins have the same basedir, hence

View file

@ -24,7 +24,7 @@ hyper = "0.13"
[lib] [lib]
name = "gstreqwest" name = "gstreqwest"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[build-dependencies] [build-dependencies]

View file

@ -34,7 +34,7 @@ serde_json = "1"
[lib] [lib]
name = "gstrusoto" name = "gstrusoto"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[build-dependencies] [build-dependencies]

View file

@ -20,7 +20,7 @@ package="gstreamer"
[lib] [lib]
name = "gstrstextwrap" name = "gstrstextwrap"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[build-dependencies] [build-dependencies]

View file

@ -19,7 +19,7 @@ once_cell = "1.0"
[lib] [lib]
name = "gstrstutorial" name = "gstrstutorial"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[build-dependencies] [build-dependencies]

View file

@ -27,7 +27,7 @@ gst-check = { package = "gstreamer-check", git = "https://gitlab.freedesktop.org
[lib] [lib]
name = "gstfallbackswitch" name = "gstfallbackswitch"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[[example]] [[example]]

View file

@ -23,7 +23,7 @@ either = "1.0"
[lib] [lib]
name = "gsttogglerecord" name = "gsttogglerecord"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[[example]] [[example]]

View file

@ -21,7 +21,7 @@ lazy_static = "1.0"
[lib] [lib]
name = "gstcdg" name = "gstcdg"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[build-dependencies] [build-dependencies]

View file

@ -46,7 +46,7 @@ package="gstreamer-check"
[lib] [lib]
name = "gstrsclosedcaption" name = "gstrsclosedcaption"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[build-dependencies] [build-dependencies]

View file

@ -17,7 +17,7 @@ lazy_static = "1.0"
[lib] [lib]
name = "gstrsdav1d" name = "gstrsdav1d"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[build-dependencies] [build-dependencies]

View file

@ -21,7 +21,7 @@ smallvec = "1.0"
[lib] [lib]
name = "gstrsflv" name = "gstrsflv"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[build-dependencies] [build-dependencies]

View file

@ -18,7 +18,7 @@ once_cell = "1"
[lib] [lib]
name = "gstgif" name = "gstgif"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[[example]] [[example]]

View file

@ -18,7 +18,7 @@ lazy_static = "1.0"
[lib] [lib]
name = "gstrav1e" name = "gstrav1e"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[build-dependencies] [build-dependencies]

View file

@ -19,7 +19,7 @@ atomic_refcell = "0.1"
[lib] [lib]
name = "gstrspng" name = "gstrspng"
crate-type = ["cdylib", "rlib"] crate-type = ["cdylib", "rlib", "staticlib"]
path = "src/lib.rs" path = "src/lib.rs"
[build-dependencies] [build-dependencies]