提交 b5c8989b authored 作者: Nazar Mokrynskyi's avatar Nazar Mokrynskyi

Replace manual build artifacts management with Meson commands

上级 812d74c1
[package] [package]
name = "mediasoup-sys" name = "mediasoup-sys"
version = "0.3.1" version = "0.3.2"
description = "FFI bindings to C++ libmediasoup-worker" description = "FFI bindings to C++ libmediasoup-worker"
authors = ["Nazar Mokrynskyi <nazar@mokrynskyi.com>"] authors = ["Nazar Mokrynskyi <nazar@mokrynskyi.com>"]
edition = "2018" edition = "2018"
......
...@@ -12,6 +12,7 @@ GULP = ./scripts/node_modules/.bin/gulp ...@@ -12,6 +12,7 @@ GULP = ./scripts/node_modules/.bin/gulp
LCOV = ./deps/lcov/bin/lcov LCOV = ./deps/lcov/bin/lcov
DOCKER ?= docker DOCKER ?= docker
PIP_DIR = $(MEDIASOUP_OUT_DIR)/pip PIP_DIR = $(MEDIASOUP_OUT_DIR)/pip
INSTALL_DIR ?= $(MEDIASOUP_OUT_DIR)/$(MEDIASOUP_BUILDTYPE)
BUILD_DIR ?= $(MEDIASOUP_OUT_DIR)/$(MEDIASOUP_BUILDTYPE)/build BUILD_DIR ?= $(MEDIASOUP_OUT_DIR)/$(MEDIASOUP_BUILDTYPE)/build
MESON ?= $(PIP_DIR)/bin/meson MESON ?= $(PIP_DIR)/bin/meson
MESON_ARGS ?= "" MESON_ARGS ?= ""
...@@ -71,6 +72,9 @@ setup: meson-ninja ...@@ -71,6 +72,9 @@ setup: meson-ninja
# https://github.com/ninja-build/ninja/issues/1997 # https://github.com/ninja-build/ninja/issues/1997
ifeq ($(MEDIASOUP_BUILDTYPE),Release) ifeq ($(MEDIASOUP_BUILDTYPE),Release)
$(MESON) setup \ $(MESON) setup \
--prefix $(INSTALL_DIR) \
--bindir '' \
--libdir '' \
--buildtype release \ --buildtype release \
-Db_ndebug=true \ -Db_ndebug=true \
-Db_pie=true \ -Db_pie=true \
...@@ -79,6 +83,9 @@ ifeq ($(MEDIASOUP_BUILDTYPE),Release) ...@@ -79,6 +83,9 @@ ifeq ($(MEDIASOUP_BUILDTYPE),Release)
$(MESON_ARGS) \ $(MESON_ARGS) \
$(BUILD_DIR) || \ $(BUILD_DIR) || \
$(MESON) setup \ $(MESON) setup \
--prefix $(INSTALL_DIR) \
--bindir '' \
--libdir '' \
--buildtype release \ --buildtype release \
-Db_ndebug=true \ -Db_ndebug=true \
-Db_pie=true \ -Db_pie=true \
...@@ -88,6 +95,9 @@ ifeq ($(MEDIASOUP_BUILDTYPE),Release) ...@@ -88,6 +95,9 @@ ifeq ($(MEDIASOUP_BUILDTYPE),Release)
else else
ifeq ($(MEDIASOUP_BUILDTYPE),Debug) ifeq ($(MEDIASOUP_BUILDTYPE),Debug)
$(MESON) setup \ $(MESON) setup \
--prefix $(INSTALL_DIR) \
--bindir '' \
--libdir '' \
--buildtype debug \ --buildtype debug \
-Db_pie=true \ -Db_pie=true \
-Db_staticpic=true \ -Db_staticpic=true \
...@@ -95,6 +105,9 @@ ifeq ($(MEDIASOUP_BUILDTYPE),Debug) ...@@ -95,6 +105,9 @@ ifeq ($(MEDIASOUP_BUILDTYPE),Debug)
$(MESON_ARGS) \ $(MESON_ARGS) \
$(BUILD_DIR) || \ $(BUILD_DIR) || \
$(MESON) setup \ $(MESON) setup \
--prefix $(INSTALL_DIR) \
--bindir '' \
--libdir '' \
--buildtype debug \ --buildtype debug \
-Db_pie=true \ -Db_pie=true \
-Db_staticpic=true \ -Db_staticpic=true \
...@@ -102,6 +115,9 @@ ifeq ($(MEDIASOUP_BUILDTYPE),Debug) ...@@ -102,6 +115,9 @@ ifeq ($(MEDIASOUP_BUILDTYPE),Debug)
$(BUILD_DIR) $(BUILD_DIR)
else else
$(MESON) setup \ $(MESON) setup \
--prefix $(INSTALL_DIR) \
--bindir '' \
--libdir '' \
--buildtype $(MEDIASOUP_BUILDTYPE) \ --buildtype $(MEDIASOUP_BUILDTYPE) \
-Db_ndebug=if-release \ -Db_ndebug=if-release \
-Db_pie=true \ -Db_pie=true \
...@@ -110,6 +126,9 @@ else ...@@ -110,6 +126,9 @@ else
$(MESON_ARGS) \ $(MESON_ARGS) \
$(BUILD_DIR) || \ $(BUILD_DIR) || \
$(MESON) setup \ $(MESON) setup \
--prefix $(INSTALL_DIR) \
--bindir '' \
--libdir '' \
--buildtype $(MEDIASOUP_BUILDTYPE) \ --buildtype $(MEDIASOUP_BUILDTYPE) \
-Db_ndebug=if-release \ -Db_ndebug=if-release \
-Db_pie=true \ -Db_pie=true \
...@@ -120,7 +139,7 @@ endif ...@@ -120,7 +139,7 @@ endif
endif endif
clean: clean:
$(RM) -rf $(MEDIASOUP_OUT_DIR)/$(MEDIASOUP_BUILDTYPE) $(RM) -rf $(INSTALL_DIR)
clean-build: clean-build:
$(RM) -rf $(BUILD_DIR) $(RM) -rf $(BUILD_DIR)
...@@ -136,12 +155,8 @@ clean-all: clean-subprojects ...@@ -136,12 +155,8 @@ clean-all: clean-subprojects
mediasoup-worker: setup mediasoup-worker: setup
ifeq ($(MEDIASOUP_WORKER_BIN),) ifeq ($(MEDIASOUP_WORKER_BIN),)
$(MESON) compile -j $(CORES) -C $(BUILD_DIR) mediasoup-worker $(MESON) compile -C $(BUILD_DIR) -j $(CORES) mediasoup-worker
endif $(MESON) install -C $(BUILD_DIR) --no-rebuild --tags mediasoup-worker
ifeq ($(OS),Windows_NT)
cp $(BUILD_DIR)/mediasoup-worker.exe $(MEDIASOUP_OUT_DIR)/$(MEDIASOUP_BUILDTYPE)/mediasoup-worker.exe
else
cp $(BUILD_DIR)/mediasoup-worker $(MEDIASOUP_OUT_DIR)/$(MEDIASOUP_BUILDTYPE)/mediasoup-worker
endif endif
xcode: setup xcode: setup
...@@ -154,8 +169,8 @@ format: ...@@ -154,8 +169,8 @@ format:
$(GULP) --gulpfile ./scripts/gulpfile.js format:worker $(GULP) --gulpfile ./scripts/gulpfile.js format:worker
test: setup test: setup
ifeq ($(MEDIASOUP_WORKER_BIN),) $(MESON) compile -C $(BUILD_DIR) -j $(CORES) mediasoup-worker-test
$(MESON) compile -j $(CORES) -C $(BUILD_DIR) mediasoup-worker-test $(MESON) install -C $(BUILD_DIR) --no-rebuild --tags mediasoup-worker-test
# On Windows lcov doesn't work (at least not yet) and we need to add `.exe` to # On Windows lcov doesn't work (at least not yet) and we need to add `.exe` to
# the binary path. # the binary path.
ifeq ($(OS),Windows_NT) ifeq ($(OS),Windows_NT)
...@@ -164,7 +179,6 @@ else ...@@ -164,7 +179,6 @@ else
$(LCOV) --directory ./ --zerocounters $(LCOV) --directory ./ --zerocounters
$(BUILD_DIR)/mediasoup-worker-test --invisibles --use-colour=yes $(MEDIASOUP_TEST_TAGS) $(BUILD_DIR)/mediasoup-worker-test --invisibles --use-colour=yes $(MEDIASOUP_TEST_TAGS)
endif endif
endif
tidy: tidy:
$(PYTHON) ./scripts/clang-tidy.py \ $(PYTHON) ./scripts/clang-tidy.py \
...@@ -177,9 +191,8 @@ tidy: ...@@ -177,9 +191,8 @@ tidy:
-quiet -quiet
fuzzer: setup fuzzer: setup
ifeq ($(MEDIASOUP_WORKER_BIN),) $(MESON) compile -C $(BUILD_DIR) -j $(CORES) mediasoup-worker-fuzzer
$(MESON) compile -j $(CORES) -C $(BUILD_DIR) mediasoup-worker-fuzzer $(MESON) install -C $(BUILD_DIR) --no-rebuild --tags mediasoup-worker-fuzzer
endif
fuzzer-run-all: fuzzer-run-all:
LSAN_OPTIONS=verbosity=1:log_threads=1 ./$(BUILD_DIR)/mediasoup-worker-fuzzer -artifact_prefix=fuzzer/reports/ -max_len=1400 fuzzer/new-corpus deps/webrtc-fuzzer-corpora/corpora/stun-corpus deps/webrtc-fuzzer-corpora/corpora/rtp-corpus deps/webrtc-fuzzer-corpora/corpora/rtcp-corpus LSAN_OPTIONS=verbosity=1:log_threads=1 ./$(BUILD_DIR)/mediasoup-worker-fuzzer -artifact_prefix=fuzzer/reports/ -max_len=1400 fuzzer/new-corpus deps/webrtc-fuzzer-corpora/corpora/stun-corpus deps/webrtc-fuzzer-corpora/corpora/rtp-corpus deps/webrtc-fuzzer-corpora/corpora/rtcp-corpus
...@@ -200,4 +213,5 @@ docker-run: ...@@ -200,4 +213,5 @@ docker-run:
mediasoup/docker:latest mediasoup/docker:latest
libmediasoup-worker: setup libmediasoup-worker: setup
$(MESON) compile -j $(CORES) -C $(BUILD_DIR) libmediasoup-worker $(MESON) compile -C $(BUILD_DIR) -j $(CORES) libmediasoup-worker
$(MESON) install -C $(BUILD_DIR) --no-rebuild --tags libmediasoup-worker
...@@ -85,6 +85,8 @@ fn main() { ...@@ -85,6 +85,8 @@ fn main() {
.arg("libmediasoup-worker") .arg("libmediasoup-worker")
.env("MEDIASOUP_OUT_DIR", &mediasoup_out_dir) .env("MEDIASOUP_OUT_DIR", &mediasoup_out_dir)
.env("MEDIASOUP_BUILDTYPE", &build_type) .env("MEDIASOUP_BUILDTYPE", &build_type)
// Force forward slashes on Windows too, otherwise Meson thinks path is not absolute 🤷
.env("INSTALL_DIR", &out_dir.replace('\\', "/"))
.spawn() .spawn()
.expect("Failed to start") .expect("Failed to start")
.wait() .wait()
...@@ -94,49 +96,21 @@ fn main() { ...@@ -94,49 +96,21 @@ fn main() {
panic!("Failed to build libmediasoup-worker") panic!("Failed to build libmediasoup-worker")
} }
#[cfg(not(target_os = "windows"))]
{
let from = format!(
"{}/{}/build/libmediasoup-worker.a",
mediasoup_out_dir, build_type
);
let to = format!("{}/libmediasoup-worker.a", out_dir);
std::fs::copy(&from, &to).unwrap_or_else(|error| {
panic!(
"Failed to copy static library from {} to {}: {}",
from, to, error
)
});
}
#[cfg(target_os = "windows")] #[cfg(target_os = "windows")]
{ {
let dot_a = format!( let dot_a = format!("{}/libmediasoup-worker.a", out_dir);
"{}/{}/build/libmediasoup-worker.a", let dot_lib = format!("{}/mediasoup-worker.lib", out_dir);
mediasoup_out_dir, build_type
);
let from = format!(
"{}/{}/build/mediasoup-worker.lib",
mediasoup_out_dir, build_type
);
let to = format!("{}/mediasoup-worker.lib", out_dir);
// Meson builds `libmediasoup-worker.a` on Windows instead of `*.lib` file under MinGW // Meson builds `libmediasoup-worker.a` on Windows instead of `*.lib` file under MinGW
if std::path::Path::new(&dot_a).exists() { if std::path::Path::new(&dot_a).exists() {
std::fs::copy(&dot_a, &from).unwrap_or_else(|error| { std::fs::copy(&dot_a, &dot_lib).unwrap_or_else(|error| {
panic!( panic!(
"Failed to copy static library from {} to {}: {}", "Failed to copy static library from {} to {}: {}",
dot_a, from, error dot_a, dot_lib, error
) )
}); });
} }
std::fs::copy(&from, &to).unwrap_or_else(|error| {
panic!(
"Failed to copy static library from {} to {}: {}",
from, to, error
)
});
// These are required by libuv on Windows // These are required by libuv on Windows
println!("cargo:rustc-link-lib=psapi"); println!("cargo:rustc-link-lib=psapi");
println!("cargo:rustc-link-lib=user32"); println!("cargo:rustc-link-lib=user32");
......
...@@ -233,6 +233,8 @@ libmediasoup_worker = library( ...@@ -233,6 +233,8 @@ libmediasoup_worker = library(
'libmediasoup-worker', 'libmediasoup-worker',
name_prefix: '', name_prefix: '',
build_by_default: false, build_by_default: false,
install: true,
install_tag: 'libmediasoup-worker',
dependencies: dependencies, dependencies: dependencies,
sources: common_sources, sources: common_sources,
include_directories: include_directories('include'), include_directories: include_directories('include'),
...@@ -243,6 +245,8 @@ libmediasoup_worker = library( ...@@ -243,6 +245,8 @@ libmediasoup_worker = library(
executable( executable(
'mediasoup-worker', 'mediasoup-worker',
build_by_default: true, build_by_default: true,
install: true,
install_tag: 'mediasoup-worker',
dependencies: dependencies, dependencies: dependencies,
sources: common_sources + ['src/main.cpp'], sources: common_sources + ['src/main.cpp'],
include_directories: include_directories('include'), include_directories: include_directories('include'),
...@@ -252,6 +256,8 @@ executable( ...@@ -252,6 +256,8 @@ executable(
mediasoup_worker_test = executable( mediasoup_worker_test = executable(
'mediasoup-worker-test', 'mediasoup-worker-test',
build_by_default: false, build_by_default: false,
install: true,
install_tag: 'mediasoup-worker-test',
dependencies: dependencies + [ dependencies: dependencies + [
catch2_proj.get_variable('catch2_dep'), catch2_proj.get_variable('catch2_dep'),
], ],
...@@ -314,6 +320,8 @@ if host_machine.system() == 'linux' ...@@ -314,6 +320,8 @@ if host_machine.system() == 'linux'
executable( executable(
'mediasoup-worker-fuzzer', 'mediasoup-worker-fuzzer',
build_by_default: false, build_by_default: false,
install: true,
install_tag: 'mediasoup-worker-fuzzer',
dependencies: dependencies, dependencies: dependencies,
sources: common_sources + [ sources: common_sources + [
'fuzzer/src/fuzzer.cpp', 'fuzzer/src/fuzzer.cpp',
......
Markdown 格式
0% 或
您添加了 0 人 到此讨论。请谨慎行事。
请先完成此评论的编辑!
请 注册 或者 后发表评论