Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Meson build system 💪 #622

Merged
merged 14 commits into from Oct 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
54 changes: 46 additions & 8 deletions .github/workflows/mediasoup-worker.yaml
Expand Up @@ -26,12 +26,24 @@ jobs:
- os: macos-10.15
cc: clang
cxx: clang++
# macOS 11 is in private preview currently.
# - os: macos-11.0
# Windows needs to be tuned before it can run, I didn't bother, feel
# free to contribute.
- os: macos-11
cc: gcc
cxx: g++
- os: macos-11
cc: clang
cxx: clang++
# TODO: These build, but don't run, unlock if you figure out why
# - os: windows-2019
# Just 1 Node.js version should be fine for C++.
# cc: gcc
# cxx: g++
# - os: windows-2019
# cc: clang
# cxx: clang++
# TODO: Unlock when intermittent unexplainable CI errors are resolved
# - os: windows-2019
# cc: cl
# cxx: cl
# A single Node.js version should be fine for C++.
node:
- 14

Expand All @@ -42,6 +54,24 @@ jobs:
CXX: ${{ matrix.build.cxx }}

steps:
- name: Add MSVC compiler
uses: ilammy/msvc-dev-cmd@v1
if: runner.os == 'Windows' && matrix.build.cc == 'cl'

# This is needed as a workaround for GNU linker being first in PATH and thus preventing Meson from finding MSVC
# linker.
- name: Remove GNU linker for MSVC
shell: bash
run: rm /usr/bin/link
if: runner.os == 'Windows' && matrix.build.cc == 'cl'

# Clang is in MSYS2's bin directory, but adding it to PATH breaks a lot of stuff, so let's just fix paths.
- name: Specify full path to Clang on Windows
run: |
echo "CC=C:\msys64\mingw64\bin\${env:CC}" >> $env:GITHUB_ENV
echo "CXX=C:\msys64\mingw64\bin\${env:CXX}" >> $env:GITHUB_ENV
if: runner.os == 'Windows' && matrix.build.cc == 'clang'

- name: Checkout
uses: actions/checkout@v2

Expand All @@ -50,6 +80,13 @@ jobs:
with:
node-version: ${{ matrix.node }}

- run: npm run install-clang-tools
# TODO: Maybe fix this one day
if: runner.os != 'Windows'
- run: npm run lint:worker
# TODO: Maybe fix this one day
if: runner.os != 'Windows'

- name: Configure cache
uses: actions/cache@v2
with:
Expand All @@ -59,7 +96,8 @@ jobs:
restore-keys: |
${{ matrix.build.os }}-node-${{matrix.build.cc}}-

- run: npm install
- run: npm run install-clang-tools
- run: npm run lint:worker
- run: npm run worker:build
- run: npm run test:worker
# All compilers on Windows can build everything, but tests fail to run on GCC/Clang with "Error -1073741511",
# remove condition below if you fixed it.
if: runner.os != 'Windows' || matrix.build.cc == 'cl'
18 changes: 7 additions & 11 deletions .gitignore
Expand Up @@ -2,16 +2,8 @@
/coverage/
/NO_GIT/

# clang-tidy stuff.
/worker/compile_commands.json

# gyp generated stuff.
# Generated stuff.
/worker/out/
/worker/**/*.xcodeproj/
/worker/**/*.sln
/worker/**/*.vcxproj
/worker/**/*.vcxproj.filters
/worker/**/*.vcxproj.user

# clang-fuzzer stuff is too big.
/worker/deps/clang-fuzzer
Expand All @@ -27,8 +19,6 @@
# Mac Stuff.
.DS_Store

# Python generated stuff in Windows.
/worker/scripts/configure.pyc
# worker scripts node-modules.
/worker/scripts/node_modules/

Expand All @@ -50,3 +40,9 @@
# Rust examples.
/rust/examples-frontend/*/node_modules
/rust/examples-frontend/*/package-lock.json

# Meson.
/worker/subprojects/*
!/worker/subprojects/*.wrap
# Temporarily included meson.build files
!/worker/subprojects/packagefiles
26 changes: 12 additions & 14 deletions doc/Building.md
Expand Up @@ -94,9 +94,19 @@ Builds the `libmediasoup-worker` static library at `worker/out/Release/`.
Cleans built objects and binaries.


### `make clean-pip`

Cleans `meson` and `ninja` installed in local prefix with pip.


### `make clean-subprojects`

Cleans subprojects downloaded with Meson.


### `make clean-all`

Cleans all objects and binaries, including those generated for library dependencies (such as libuv, openssl, libsrtp, etc).
Cleans built objects and binaries, `meson` and `ninja` installed in local prefix with pip and all subprojects downloaded with Meson.


### `make xcode`
Expand All @@ -119,25 +129,13 @@ Rewrites mediasoup-worker C++ files using [clang-format](https://clang.llvm.org/
Builds and runs the `mediasoup-worker-test` binary at `worker/out/Release/` (or at `worker/out/Debug/` if the "MEDIASOUP_BUILDTYPE" environment variable is set to "Debug"), which uses [Catch2](https://github.com/catchorg/Catch2) to run test units located at `worker/test/` folder.


### `make bear`

Generates the `worker/compile_commands_template.json` file which is a ["Clang compilation database"](https://clang.llvm.org/docs/JSONCompilationDatabase.html).

**Requirements:**

* [Bear](https://github.com/rizsotto/Bear) is required.
- Install it in Debian/Ubuntu via `apt install bear` and in OSX via `brew install bear`.
- For now, Bear version must be 2.1.X.
* Before running `make bear` you must have mediasoup C/C++ dependencies already compiled. To be sure, run `make clean-all && make` before running `make bear`.


### `make tidy`

Runs [clang-tidy](http://clang.llvm.org/extra/clang-tidy/) and performs C++ code checks following `worker/.clang-tidy` rules.

**Requirements:**

* `make clean-all`, then `make` and then `make bear` must have been called first.
* `make clean` and `make` must have been called first.
* [PyYAML](https://pyyaml.org/) is required.
- In OSX install it with `brew install libyaml` and `sudo easy_install-X.Y pyyaml`.

Expand Down
65 changes: 27 additions & 38 deletions npm-scripts.js
Expand Up @@ -11,20 +11,6 @@ const task = process.argv.slice(2).join(' ');
// mediasoup mayor version.
const MAYOR_VERSION = 3;

// Just for Windows.
let PYTHON;
let MSBUILD;
let MEDIASOUP_BUILDTYPE;
let MEDIASOUP_TEST_TAGS;

if (isWindows)
{
PYTHON = process.env.PYTHON || 'python';
MSBUILD = process.env.MSBUILD || 'MSBuild';
MEDIASOUP_BUILDTYPE = process.env.MEDIASOUP_BUILDTYPE || 'Release';
MEDIASOUP_TEST_TAGS = process.env.MEDIASOUP_TEST_TAGS || '';
}

let MAKE;

if (isFreeBSD)
Expand Down Expand Up @@ -79,6 +65,16 @@ switch (task)
break;
}

case 'worker:build':
{
if (!process.env.MEDIASOUP_WORKER_BIN)
{
execute(`${MAKE} -C worker`);
}

break;
}

case 'lint:node':
{
execute('cross-env MEDIASOUP_NODE_LANGUAGE=typescript eslint -c .eslintrc.js --max-warnings 0 --ext=ts src/');
Expand Down Expand Up @@ -119,17 +115,7 @@ switch (task)

case 'test:worker':
{
if (!isWindows)
{
execute(`${MAKE} test -C worker`);
}
else if (!process.env.MEDIASOUP_WORKER_BIN)
{
execute(`${PYTHON} ./worker/scripts/configure.py --format=msvs -R mediasoup-worker-test`);
execute(`${MSBUILD} ./worker/mediasoup-worker.sln /p:Configuration=${MEDIASOUP_BUILDTYPE}`);
execute(`cd worker && .\\out\\${MEDIASOUP_BUILDTYPE}\\mediasoup-worker-test.exe --invisibles --use-colour=yes ${MEDIASOUP_TEST_TAGS}`);
}

execute(`${MAKE} test -C worker`);
break;
}

Expand All @@ -144,18 +130,9 @@ switch (task)

case 'postinstall':
{
if (!process.env.MEDIASOUP_WORKER_BIN)
{
if (!isWindows)
{
execute(`${MAKE} -C worker`);
}
else
{
execute(`${PYTHON} ./worker/scripts/configure.py --format=msvs -R mediasoup-worker`);
execute(`${MSBUILD} ./worker/mediasoup-worker.sln /p:Configuration=${MEDIASOUP_BUILDTYPE}`);
}
}
execute('node npm-scripts.js worker:build');
execute(`${MAKE} clean-pip -C worker`);
execute(`${MAKE} clean-subprojects -C worker`);

break;
}
Expand Down Expand Up @@ -206,7 +183,19 @@ function execute(command)

try
{
execSync(command, { stdio: [ 'ignore', process.stdout, process.stderr ] });
// Set MSVC compiler as default on Windows
const env = isWindows ? {
CC : process.env.CC || 'cl',
CXX : process.env.CXX || 'cl',
...process.env
} : process.env;

execSync(
command,
{
env : env,
stdio : [ 'ignore', process.stdout, process.stderr ]
});
}
catch (error)
{
Expand Down
24 changes: 22 additions & 2 deletions package.json
Expand Up @@ -18,6 +18,25 @@
},
"main": "lib/index.js",
"types": "lib/index.d.ts",
"files": [
"lib",
"worker/deps/libwebrtc",
"worker/fuzzer/include",
"worker/fuzzer/src",
"worker/include",
"worker/scripts/*.py",
"worker/scripts/*.sh",
"worker/scripts/*.js",
"worker/scripts/*.json",
"worker/src",
"worker/subprojects/packagefiles",
"worker/subprojects/*.wrap",
"worker/test/include",
"worker/test/src",
"worker/Makefile",
"worker/meson.build",
"npm-scripts.js"
],
"keywords": [
"webrtc",
"ortc",
Expand All @@ -31,14 +50,15 @@
"install-clang-tools": "node npm-scripts.js install-clang-tools",
"typescript:build": "node npm-scripts.js typescript:build",
"typescript:watch": "node npm-scripts.js typescript:watch",
"worker:build": "node npm-scripts.js worker:build",
"lint": "npm run lint:node && npm run lint:worker",
"lint:node": "node npm-scripts.js lint:node",
"lint:worker": "node npm-scripts.js lint:worker",
"format:worker": "node npm-scripts.js format:worker",
"test": "npm run test:node && npm run test:worker",
"test:node": "npm run postinstall && node npm-scripts.js test:node",
"test:node": "npm run worker:build && node npm-scripts.js test:node",
"test:worker": "node npm-scripts.js test:worker",
"coverage": "npm run postinstall && node npm-scripts.js coverage",
"coverage": "npm run worker:build && node npm-scripts.js coverage",
"postinstall": "node npm-scripts.js postinstall",
"release": "node npm-scripts.js release"
},
Expand Down
24 changes: 8 additions & 16 deletions worker/Cargo.toml
Expand Up @@ -8,30 +8,22 @@ license = "ISC"
documentation = "https://docs.rs/mediasoup-sys"
repository = "https://github.com/versatica/mediasoup/tree/v3/worker"
include = [
"/deps/getops",
"/deps/gyp",
"!/deps/gyp/{samples,test}",
"/deps/json",
"!/deps/json/{include,ChangeLog.md}",
"!/deps/json/ChangeLog.md",
"/deps/libsrtp",
"!/deps/libsrtp/srtp/{doc,fuzzer,test,CHANGES}",
"/deps/libuv",
"!/deps/libuv/libuv/{docs,img,m4,test,ChangeLog}",
"/deps/libwebrtc",
"/deps/openssl",
"!/deps/openssl/openssl/{apps,demos,docs,fuzz,test,tools,CHANGES}",
"/deps/usrsctp",
"!/deps/usrsctp/programs",
"!/deps/libwebrtc/deps/abseil-cpp",
"/fuzzer/include",
"/fuzzer/src",
"/include",
"/scripts",
"!/scripts/node_modules",
"/src",
"/subprojects/packagefiles",
"/subprojects/*.wrap",
"/test/include",
"/test/src",
"/build.rs",
"/Cargo.toml",
"/common.gypi",
"/Makefile",
"/mediasoup-worker.gyp",
"/meson.build",
]

[package.metadata.docs.rs]
Expand Down
2 changes: 1 addition & 1 deletion worker/Dockerfile
Expand Up @@ -7,7 +7,7 @@ RUN \
&& apt-get install --yes \
bash-completion wget curl subversion screen gcc g++ cmake ninja-build golang \
autoconf libtool apache2 python-dev pkg-config zlib1g-dev libgcrypt11-dev \
libgss-dev libssl-dev libxml2-dev nasm libarchive-dev make bear automake \
libgss-dev libssl-dev libxml2-dev nasm libarchive-dev make automake \
libdbus-1-dev libboost-dev autoconf-archive bash-completion python-yaml

# Install node 10.
Expand Down