Skip to content

Commit

Permalink
Enhance flatc build system (#1174)
Browse files Browse the repository at this point in the history
Meson: properly generate C++ flatbuffers header files

- Do only generate them when the flatbuffer schemas change
- Make generated FBS files a worker dependency
- Create a meson.build for 'fbs' directory
- Remove _generated suffix to generated fbs files
  • Loading branch information
jmillan authored Oct 19, 2023
1 parent 70e4355 commit 7f07c51
Show file tree
Hide file tree
Showing 29 changed files with 88 additions and 96 deletions.
2 changes: 1 addition & 1 deletion npm-scripts.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -391,7 +391,7 @@ function flatcNode(clean = false)
logInfo('flatcNode()');

// Build flatc if needed.
executeCmd(`${MAKE} -C worker flatc-all`);
executeCmd(`${MAKE} -C worker flatc`);

const buildType = process.env.MEDIASOUP_BUILDTYPE || 'Release';
const extension = IS_WINDOWS ? '.exe' : '';
Expand Down
53 changes: 0 additions & 53 deletions rust/crypto_suite_fbs.patch

This file was deleted.

16 changes: 2 additions & 14 deletions worker/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ INSTALL_DIR ?= $(MEDIASOUP_OUT_DIR)/$(MEDIASOUP_BUILDTYPE)
BUILD_DIR ?= $(INSTALL_DIR)/build
MESON ?= $(PIP_DIR)/bin/meson
MESON_VERSION ?= 1.2.1
FLATC ?= $(BUILD_DIR)/subprojects/flatbuffers-23.3.3/flatc
FLATC_OUT_DIR ?= ./include/FBS
# `MESON_ARGS` can be used to provide extra configuration parameters to Meson,
# such as adding defines or changing optimization options. For instance, use
# `MESON_ARGS="-Dms_log_trace=true -Dms_log_file_line=true" npm i` to compile
Expand Down Expand Up @@ -209,17 +207,7 @@ libmediasoup-worker: setup flatc
$(MESON) install -C $(BUILD_DIR) --no-rebuild --tags libmediasoup-worker

flatc: setup
$(MESON) compile -C $(BUILD_DIR) flatc
[ -d $(FLATC_OUT_DIR) ] || \
$(FLATC) --cpp --cpp-field-case-style lower --reflect-names --scoped-enums \
-o $(FLATC_OUT_DIR) ./fbs/*

flatc-clean:
$(RM) -rf $(FLATC_OUT_DIR)

flatc-force: flatc-clean flatc

flatc-all: setup flatc
$(MESON) compile -C $(BUILD_DIR) flatbuffers-generator

xcode: setup
$(MESON) setup --buildtype debug --backend xcode $(MEDIASOUP_OUT_DIR)/xcode
Expand All @@ -230,7 +218,7 @@ lint:
format:
$(GULP) --gulpfile ./scripts/gulpfile.mjs format:worker

test: setup
test: setup flatc
$(MESON) compile -C $(BUILD_DIR) -j $(CORES) mediasoup-worker-test
$(MESON) install -C $(BUILD_DIR) --no-rebuild --tags mediasoup-worker-test
ifeq ($(OS),Windows_NT)
Expand Down
53 changes: 53 additions & 0 deletions worker/fbs/meson.build
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
flatbuffers_schemas = [
'activeSpeakerObserver.fbs',
'audioLevelObserver.fbs',
'common.fbs',
'consumer.fbs',
'dataConsumer.fbs',
'dataProducer.fbs',
'directTransport.fbs',
'log.fbs',
'message.fbs',
'notification.fbs',
'pipeTransport.fbs',
'plainTransport.fbs',
'producer.fbs',
'request.fbs',
'response.fbs',
'router.fbs',
'rtpObserver.fbs',
'rtpParameters.fbs',
'rtpStream.fbs',
'rtxStream.fbs',
'sctpAssociation.fbs',
'sctpParameters.fbs',
'srtpParameters.fbs',
'transport.fbs',
'webRtcServer.fbs',
'webRtcTransport.fbs',
'worker.fbs',
]

# Directory from which worker code will include the header files.
flatbuffers_cpp_out_dir = 'FBS'

flatc = find_program('flatc')
flatbuffers_generator = custom_target('flatbuffers-generator',
output: flatbuffers_cpp_out_dir,
input: flatbuffers_schemas,
command : [
flatc,
'--cpp',
'--cpp-field-case-style', 'lower',
'--reflect-names',
'--scoped-enums',
'--filename-suffix', '',
'-o', '@OUTPUT@',
'@INPUT@'
],
build_by_default: true,
)

flatbuffers_generator_dep = declare_dependency(
include_directories: '.',
)
2 changes: 1 addition & 1 deletion worker/include/Channel/ChannelNotification.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MS_CHANNEL_NOTIFICATION_HPP

#include "common.hpp"
#include "FBS/notification_generated.h"
#include "FBS/notification.h"
#include <absl/container/flat_hash_map.h>
#include <string>

Expand Down
6 changes: 3 additions & 3 deletions worker/include/Channel/ChannelRequest.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
#define MS_CHANNEL_REQUEST_HPP

#include "common.hpp"
#include "FBS/message_generated.h"
#include "FBS/request_generated.h"
#include "FBS/response_generated.h"
#include "FBS/message.h"
#include "FBS/request.h"
#include "FBS/response.h"
#include <absl/container/flat_hash_map.h>
#include <flatbuffers/minireflect.h>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/Consumer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "common.hpp"
#include "Channel/ChannelRequest.hpp"
#include "Channel/ChannelSocket.hpp"
#include "FBS/consumer_generated.h"
#include "FBS/consumer.h"
#include "RTC/RTCP/CompoundPacket.hpp"
#include "RTC/RTCP/FeedbackPs.hpp"
#include "RTC/RTCP/FeedbackPsFir.hpp"
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/DtlsTransport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MS_RTC_DTLS_TRANSPORT_HPP

#include "common.hpp"
#include "FBS/webRtcTransport_generated.h"
#include "FBS/webRtcTransport.h"
#include "RTC/SrtpSession.hpp"
#include "handles/TimerHandle.hpp"
#include <openssl/bio.h>
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/IceCandidate.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MS_RTC_ICE_CANDIDATE_HPP

#include "common.hpp"
#include "FBS/webRtcTransport_generated.h"
#include "FBS/webRtcTransport.h"
#include "RTC/TcpServer.hpp"
#include "RTC/TransportTuple.hpp"
#include "RTC/UdpSocket.hpp"
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/IceServer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MS_RTC_ICE_SERVER_HPP

#include "common.hpp"
#include "FBS/webRtcTransport_generated.h"
#include "FBS/webRtcTransport.h"
#include "RTC/StunPacket.hpp"
#include "RTC/TransportTuple.hpp"
#include <list>
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/Parameters.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MS_RTC_PARAMETERS_HPP

#include "common.hpp"
#include "FBS/rtpParameters_generated.h"
#include "FBS/rtpParameters.h"
#include <absl/container/flat_hash_map.h>
#include <string>
#include <vector>
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/PipeTransport.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef MS_RTC_PIPE_TRANSPORT_HPP
#define MS_RTC_PIPE_TRANSPORT_HPP

#include "FBS/pipeTransport_generated.h"
#include "FBS/pipeTransport.h"
#include "RTC/Shared.hpp"
#include "RTC/SrtpSession.hpp"
#include "RTC/Transport.hpp"
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/PlainTransport.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef MS_RTC_PLAIN_TRANSPORT_HPP
#define MS_RTC_PLAIN_TRANSPORT_HPP

#include "FBS/plainTransport_generated.h"
#include "FBS/plainTransport.h"
#include "RTC/Shared.hpp"
#include "RTC/SrtpSession.hpp"
#include "RTC/Transport.hpp"
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/RtpDictionaries.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MS_RTC_RTP_DICTIONARIES_HPP

#include "common.hpp"
#include "FBS/rtpParameters_generated.h"
#include "FBS/rtpParameters.h"
#include "RTC/Parameters.hpp"
#include <absl/container/flat_hash_map.h>
#include <string>
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/RtpStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "common.hpp"
#include "DepLibUV.hpp"
#include "FBS/rtpStream_generated.h"
#include "FBS/rtpStream.h"
#include "RTC/RTCP/FeedbackPsFir.hpp"
#include "RTC/RTCP/FeedbackPsPli.hpp"
#include "RTC/RTCP/FeedbackRtpNack.hpp"
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/RtxStream.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "common.hpp"
#include "DepLibUV.hpp"
#include "FBS/rtxStream_generated.h"
#include "FBS/rtxStream.h"
#include "RTC/RTCP/Packet.hpp"
#include "RTC/RTCP/ReceiverReport.hpp"
#include "RTC/RTCP/SenderReport.hpp"
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/SctpDictionaries.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MS_RTC_SCTP_DICTIONARIES_HPP

#include "common.hpp"
#include <FBS/sctpParameters_generated.h>
#include <FBS/sctpParameters.h>

namespace RTC
{
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/SimpleConsumer.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef MS_RTC_SIMPLE_CONSUMER_HPP
#define MS_RTC_SIMPLE_CONSUMER_HPP

#include "FBS/transport_generated.h"
#include "FBS/transport.h"
#include "RTC/Consumer.hpp"
#include "RTC/SeqManager.hpp"
#include "RTC/Shared.hpp"
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/SimulcastConsumer.hpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#ifndef MS_RTC_SIMULCAST_CONSUMER_HPP
#define MS_RTC_SIMULCAST_CONSUMER_HPP

#include "FBS/consumer_generated.h"
#include "FBS/consumer.h"
#include "RTC/Codecs/PayloadDescriptorHandler.hpp"
#include "RTC/Consumer.hpp"
#include "RTC/SeqManager.hpp"
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/SrtpSession.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define MS_RTC_SRTP_SESSION_HPP

#include "common.hpp"
#include "FBS/srtpParameters_generated.h"
#include "FBS/srtpParameters.h"
#include <srtp.h>

namespace RTC
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/Transport.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "Channel/ChannelNotification.hpp"
#include "Channel/ChannelRequest.hpp"
#include "Channel/ChannelSocket.hpp"
#include "FBS/transport_generated.h"
#include "FBS/transport.h"
#include "RTC/Consumer.hpp"
#include "RTC/DataConsumer.hpp"
#include "RTC/DataProducer.hpp"
Expand Down
2 changes: 1 addition & 1 deletion worker/include/RTC/TransportTuple.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#include "common.hpp"
#include "Utils.hpp"
#include "FBS/transport_generated.h"
#include "FBS/transport.h"
#include "RTC/TcpConnection.hpp"
#include "RTC/UdpSocket.hpp"
#include <flatbuffers/flatbuffers.h>
Expand Down
2 changes: 1 addition & 1 deletion worker/include/Worker.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "common.hpp"
#include "Channel/ChannelRequest.hpp"
#include "Channel/ChannelSocket.hpp"
#include "FBS/worker_generated.h"
#include "FBS/worker.h"
#include "RTC/Router.hpp"
#include "RTC/Shared.hpp"
#include "RTC/WebRtcServer.hpp"
Expand Down
6 changes: 5 additions & 1 deletion worker/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,10 @@ flatbuffers_proj = subproject(
'warning_level=0',
],
)
libwebrtc_include_directories = include_directories('include')
# flatbuffers schemas subdirectory.
subdir('fbs')
# Add current build directory so libwebrtc has access to FBS folder.
libwebrtc_include_directories = include_directories('include', 'fbs')
subdir('deps/libwebrtc')

dependencies = [
Expand All @@ -223,6 +226,7 @@ dependencies = [
libsrtp2_proj.get_variable('libsrtp2_dep'),
usrsctp_proj.get_variable('usrsctp_dep'),
flatbuffers_proj.get_variable('flatbuffers_dep'),
flatbuffers_generator_dep,
libwebrtc_dep,
]

Expand Down
2 changes: 1 addition & 1 deletion worker/src/RTC/PipeConsumer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "FBS/consumer_generated.h"
#include "FBS/consumer.h"
#define MS_CLASS "RTC::PipeConsumer"
// #define MS_LOG_DEV_LEVEL 3

Expand Down
2 changes: 1 addition & 1 deletion worker/src/RTC/SimpleConsumer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#include "FBS/consumer_generated.h"
#include "FBS/consumer.h"
#define MS_CLASS "RTC::SimpleConsumer"
// #define MS_LOG_DEV_LEVEL 3

Expand Down
2 changes: 1 addition & 1 deletion worker/src/RTC/Transport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include "Utils.hpp"
#include "FBS/transport_generated.h"
#include "FBS/transport.h"
#include "RTC/BweType.hpp"
#include "RTC/PipeConsumer.hpp"
#include "RTC/RTCP/FeedbackPs.hpp"
Expand Down
2 changes: 1 addition & 1 deletion worker/src/RTC/WebRtcTransport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
#include "Logger.hpp"
#include "MediaSoupErrors.hpp"
#include "Utils.hpp"
#include "FBS/webRtcTransport_generated.h"
#include "FBS/webRtcTransport.h"
#include <cmath> // std::pow()

namespace RTC
Expand Down
4 changes: 2 additions & 2 deletions worker/src/Worker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
#include "MediaSoupErrors.hpp"
#include "Settings.hpp"
#include "Channel/ChannelNotifier.hpp"
#include "FBS/response_generated.h"
#include "FBS/worker_generated.h"
#include "FBS/response.h"
#include "FBS/worker.h"

/* Instance methods. */

Expand Down

0 comments on commit 7f07c51

Please sign in to comment.