Skip to content

Commit

Permalink
For #2532: Windows: Support CYGWIN64 for SRS (#3255)
Browse files Browse the repository at this point in the history
1. Support cygwin by '--cygwin64=on'
2. Detect cygwin automatically.
3. Disalbe sanitizer, srt and srtp with openssl.
4. Disable multiple threads, use single threads.
5. Support utest for cygwin64.
6. Query features for windows by API.
7. Disable stat APIs for cygwin.
8. Use ST select event driver.

Co-authored-by: wenjie.zhao <[email protected]>
  • Loading branch information
winlinvip and wenjiegit committed Nov 20, 2022
1 parent 3d0dcb2 commit d741f81
Show file tree
Hide file tree
Showing 15 changed files with 122 additions and 30 deletions.
5 changes: 5 additions & 0 deletions trunk/auto/auto_headers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ if [[ $SRS_CROSS_BUILD == YES ]]; then
else
srs_undefine_macro "SRS_CROSSBUILD" $SRS_AUTO_HEADERS_H
fi
if [[ $SRS_CYGWIN64 == YES ]]; then
srs_define_macro "SRS_CYGWIN64" $SRS_AUTO_HEADERS_H
else
srs_undefine_macro "SRS_CYGWIN64" $SRS_AUTO_HEADERS_H
fi
if [[ $SRS_OSX == YES ]]; then
srs_define_macro "SRS_OSX" $SRS_AUTO_HEADERS_H
else
Expand Down
26 changes: 19 additions & 7 deletions trunk/auto/depends.sh
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ OSX_prepare; ret=$?; if [[ 0 -ne $ret ]]; then echo "OSX prepare failed, ret=$re
#####################################################################################
# Check OS and CPU architectures.
#####################################################################################
if [[ $OS_IS_UBUNTU != YES && $OS_IS_CENTOS != YES && $OS_IS_OSX != YES && $SRS_CROSS_BUILD != YES ]]; then
if [[ $OS_IS_UBUNTU != YES && $OS_IS_CENTOS != YES && $OS_IS_OSX != YES && $SRS_CROSS_BUILD != YES && $SRS_CYGWIN64 != YES ]]; then
echo "Your OS `uname -s` is not supported."
exit 1
fi
Expand Down Expand Up @@ -347,6 +347,10 @@ fi
if [[ $SRS_OSX == YES ]]; then
_ST_MAKE=darwin-debug && _ST_OBJ="DARWIN_`uname -r`_DBG"
fi
# for windows/cygwin
if [[ $SRS_CYGWIN64 = YES ]]; then
_ST_MAKE=cygwin64-debug && _ST_OBJ="CYGWIN64_`uname -s`_DBG"
fi
# For Ubuntu, the epoll detection might be fail.
if [[ $OS_IS_UBUNTU == YES ]]; then
_ST_EXTRA_CFLAGS="$_ST_EXTRA_CFLAGS -DMD_HAVE_EPOLL"
Expand Down Expand Up @@ -598,8 +602,16 @@ if [[ $SRS_RTC == YES ]]; then
rm -rf ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srtp2 \
${SRS_OBJS}/srtp2 &&
cp -rf ${SRS_WORKDIR}/3rdparty/libsrtp-2-fit ${SRS_OBJS}/${SRS_PLATFORM}/ &&
patch -p0 ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/crypto/math/datatypes.c ${SRS_WORKDIR}/3rdparty/patches/srtp/gcc10-01.patch &&
patch -p0 ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/config.guess ${SRS_WORKDIR}/3rdparty/patches/srtp/config.guess-02.patch &&
# For cygwin64, the patch is not available, so use sed instead.
if [[ $SRS_CYGWIN64 == YES ]]; then
sed -i 's/char bit_string/static char bit_string/g' ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/crypto/math/datatypes.c
else
patch -p0 ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/crypto/math/datatypes.c ${SRS_WORKDIR}/3rdparty/patches/srtp/gcc10-01.patch
fi &&
# Patch the cpu arch guessing for RISCV.
if [[ $OS_IS_RISCV == YES ]]; then
patch -p0 ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit/config.guess ${SRS_WORKDIR}/3rdparty/patches/srtp/config.guess-02.patch
fi &&
(
cd ${SRS_OBJS}/${SRS_PLATFORM}/libsrtp-2-fit &&
$SRTP_CONFIGURE ${SRTP_OPTIONS} --prefix=${SRS_DEPENDS_LIBS}/${SRS_PLATFORM}/3rdpatry/srtp2
Expand Down Expand Up @@ -768,16 +780,16 @@ if [[ $SRS_SRT == YES ]]; then
else
LIBSRT_OPTIONS="$LIBSRT_OPTIONS --enable-shared=0"
fi
# For windows build, over cygwin
if [[ $SRS_CYGWIN64 == YES ]]; then
LIBSRT_OPTIONS="$LIBSRT_OPTIONS --cygwin-use-posix"
fi
# For cross-build.
if [[ $SRS_CROSS_BUILD == YES ]]; then
TOOL_GCC_REALPATH=$(realpath $(which $SRS_TOOL_CC))
SRT_COMPILER_PREFIX=$(echo $TOOL_GCC_REALPATH |sed 's/-gcc.*$/-/')
LIBSRT_OPTIONS="$LIBSRT_OPTIONS --with-compiler-prefix=$SRT_COMPILER_PREFIX"
fi
# For windows build, over cygwin
if [[ $SRS_CYGWIN64 == YES ]]; then
LIBSRT_OPTIONS="$LIBSRT_OPTIONS --cygwin-use-posix"
fi

if [[ -f ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srt/lib/libsrt.a ]]; then
rm -rf ${SRS_OBJS}/srt && cp -rf ${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/srt ${SRS_OBJS}/ &&
Expand Down
33 changes: 33 additions & 0 deletions trunk/auto/options.sh
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ SRS_GPROF=NO # Performance test: gprof
################################################################
# Preset options
SRS_OSX= #For OSX/macOS/Darwin PC.
SRS_CYGWIN64= # For Cygwin64 for Windows PC or servers.
SRS_CROSS_BUILD= #For cross build, for example, on Ubuntu.
# For cross build, the cpu, for example(FFmpeg), --cpu=24kc
SRS_CROSS_BUILD_CPU=
Expand Down Expand Up @@ -119,6 +120,7 @@ function show_help() {
Presets:
--cross-build Enable cross-build, please set bellow Toolchain also. Default: $(value2switch $SRS_CROSS_BUILD)
--osx Enable build for OSX/Darwin AppleOS. Default: $(value2switch $SRS_OSX)
--cygwin64 Use cygwin64 to build for Windows. Default: $(value2switch $SRS_CYGWIN64)
Features:
-h, --help Print this message and exit 0.
Expand Down Expand Up @@ -253,6 +255,7 @@ function parse_user_option() {
--build-tag) SRS_BUILD_TAG=${value} ;;

--osx) SRS_OSX=YES ;;
--cygwin64) SRS_CYGWIN64=YES ;;

--without-srtp-nasm) SRS_SRTP_ASM=NO ;;
--with-srtp-nasm) SRS_SRTP_ASM=YES ;;
Expand Down Expand Up @@ -450,6 +453,10 @@ do
done

function apply_auto_options() {
if [[ $OS_IS_CYGWIN == YES ]]; then
SRS_CYGWIN64=YES
fi

if [[ $SRS_CROSS_BUILD == YES ]]; then
if [[ $SRS_CROSS_BUILD_PREFIX != "" && $SRS_CROSS_BUILD_HOST == "" ]]; then
SRS_CROSS_BUILD_HOST=$(echo $SRS_CROSS_BUILD_PREFIX| sed 's/-$//g')
Expand Down Expand Up @@ -503,6 +510,31 @@ function apply_auto_options() {
SRS_SRTP_ASM=NO
fi

# TODO: FIXME: Should build address sanitizer for cygwin64.
# See https://github.com/ossrs/srs/issues/3252
if [[ $SRS_CYGWIN64 == YES && $SRS_SANITIZER == YES ]]; then
echo "Disable address sanitizer for cygwin64"
SRS_SANITIZER=NO
fi
# TODO: FIXME: Should fix bug for SRT for cygwin64. Build ok, but fail in SrsSrtSocket::accept.
# See https://github.com/ossrs/srs/issues/3251
if [[ $SRS_CYGWIN64 == YES && $SRS_SRT == YES ]]; then
echo "Disable SRT for cygwin64"
SRS_SRT=NO
fi
# TODO: FIXME: Cygwin: ST stuck when working in multiple threads mode.
# See https://github.com/ossrs/srs/issues/3253
if [[ $SRS_CYGWIN64 == YES && $SRS_SINGLE_THREAD != YES ]]; then
echo "Force single thread for cygwin64"
SRS_SINGLE_THREAD=YES
fi
# TODO: FIXME: Cygwin: Build srtp with openssl fail for no srtp_aes_icm_ctx_t
# See https://github.com/ossrs/srs/issues/3254
if [[ $SRS_CYGWIN64 == YES && $SRS_SRTP_ASM == YES ]]; then
echo "Disable SRTP with openssl for cygwin64"
SRS_SRTP_ASM=NO
fi

# parse the jobs for make
if [[ ! -z SRS_JOBS ]]; then
export SRS_JOBS="--jobs=${SRS_JOBS}"
Expand Down Expand Up @@ -589,6 +621,7 @@ function regenerate_options() {
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --debug-stats=$(value2switch $SRS_DEBUG_STATS)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cross-build=$(value2switch $SRS_CROSS_BUILD)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --sanitizer=$(value2switch $SRS_SANITIZER)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --cygwin64=$(value2switch $SRS_CYGWIN64)"
SRS_AUTO_CONFIGURE="${SRS_AUTO_CONFIGURE} --single-thread=$(value2switch $SRS_SINGLE_THREAD)"
if [[ $SRS_CROSS_BUILD_ARCH != "" ]]; then SRS_AUTO_CONFIGURE="$SRS_AUTO_CONFIGURE --arch=$SRS_CROSS_BUILD_ARCH"; fi
if [[ $SRS_CROSS_BUILD_CPU != "" ]]; then SRS_AUTO_CONFIGURE="$SRS_AUTO_CONFIGURE --cpu=$SRS_CROSS_BUILD_CPU"; fi
Expand Down
4 changes: 4 additions & 0 deletions trunk/auto/setup_variables.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ OS_KERNEL_NAME=$(uname -s)
OS_KERNRL_RELEASE=$(uname -r|awk -F '-' '{print $1}')
OS_PREFIX="Platform"

if [[ $OSTYPE == cygwin ]]; then
OS_KERNRL_RELEASE=$(uname -r|awk -F '(' '{print $1}')
fi

# Build platform cache.
SRS_PLATFORM="${SRS_BUILD_TAG}${OS_PREFIX}-${OS_KERNEL_NAME}-${OS_KERNRL_RELEASE}"
# Build platform cache with gcc version.
Expand Down
14 changes: 10 additions & 4 deletions trunk/auto/utest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,13 @@ mkdir -p ${SRS_OBJS}/${SRS_PLATFORM}/utest
# trunk of srs, which contains the src dir, relative to objs/utest, it's trunk
SRS_TRUNK_PREFIX=../../..
# gest dir, relative to objs/utest, it's trunk/objs/{Platform}/gtest
GTEST_DIR=${SRS_TRUNK_PREFIX}/${SRS_OBJS}/${SRS_PLATFORM}/3rdpatry/gtest/googletest
GTEST_DIR=../3rdpatry/gtest/googletest

# Whether enable C++11 or higher versions.
# For linux, always use C++11 for gtest required, see https://github.com/google/googletest
# For cygwin64, ignore because it use -std=gnu++11 by default.
SRS_CPP_VERSION="-std=c++11"
if [[ $SRS_CYGWIN64 == YES ]]; then SRS_CPP_VERSION="-std=gnu++11"; fi

cat << END > ${FILE}
# user must run make the ${SRS_OBJS}/utest dir
Expand Down Expand Up @@ -51,9 +57,9 @@ CXX = ${SRS_TOOL_CXX}
CPPFLAGS += -I\$(GTEST_DIR)/include
# Flags passed to the C++ compiler.
CXXFLAGS += ${CXXFLAGS} ${UTEST_EXTRA_DEFINES} -Wno-unused-private-field -Wno-unused-command-line-argument
# Always use C++11 for gtest required, see https://github.com/google/googletest
CXXFLAGS += -std=c++11
CXXFLAGS += ${CXXFLAGS} ${UTEST_EXTRA_DEFINES}
CXXFLAGS += -Wno-unused-private-field -Wno-unused-command-line-argument
CXXFLAGS += ${SRS_CPP_VERSION}
# All tests produced by this Makefile. Remember to add new tests you
# created to the list.
Expand Down
13 changes: 10 additions & 3 deletions trunk/configure
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ WarnLevel=" -Wall"
CppStd="-ansi"
if [[ $SRS_CXX11 == YES ]]; then
CppStd="-std=c++11"
if [[ $SRS_CYGWIN64 == YES ]]; then CppStd="-std=gnu++11"; fi
fi
if [[ $SRS_CXX14 == YES ]]; then
CppStd="-std=c++14"
if [[ $SRS_CYGWIN64 == YES ]]; then CppStd="-std=gnu++14"; fi
fi
# performance of gprof
SrsGprof=""; SrsGprofLink=""; if [[ $SRS_GPROF == YES ]]; then SrsGprof=" -pg -lc_p"; SrsGprofLink=" -pg"; fi
Expand Down Expand Up @@ -204,7 +206,7 @@ if [[ $SRS_GCOV == YES ]]; then
fi

# For FFMPEG/RTC on Linux.
if [[ $SRS_OSX != YES && $SRS_RTC == YES && $SRS_FFMPEG_FIT == YES ]]; then
if [[ $SRS_OSX != YES && $SRS_CYGWIN64 != YES && $SRS_RTC == YES && $SRS_FFMPEG_FIT == YES ]]; then
SrsLinkOptions="${SrsLinkOptions} -lrt";
fi

Expand All @@ -222,6 +224,11 @@ if [[ $SRS_SANITIZER == YES && $OS_IS_X86_64 == YES ]]; then
fi
fi

# For FFMPEG/RTC on windows.
if [[ $SRS_CYGWIN64 == YES && $SRS_FFMPEG_FIT == YES ]]; then
SrsLinkOptions="${SrsLinkOptions} -lbcrypt";
fi

#####################################################################################
# Modules, compile each module, then link to binary
#
Expand Down Expand Up @@ -555,8 +562,8 @@ clean_st:
st:
@rm -f ${SRS_OBJS}/srs srs_utest
@\$(MAKE)\$(JOBS) -C ${SRS_OBJS}/${SRS_PLATFORM}/st-srs clean)
@env EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" \$(MAKE)\$(JOBS) -C ${SRS_OBJS}/${SRS_PLATFORM}/st-srs ${_ST_MAKE_ARGS} CC=\$(GCC) AR=\$(AR) LD=\$(LINK) RANDLIB=\$(RANDLIB))
@\$(MAKE)\$(JOBS) -C ${SRS_OBJS}/${SRS_PLATFORM}/st-srs clean
@env EXTRA_CFLAGS="${_ST_EXTRA_CFLAGS}" \$(MAKE)\$(JOBS) -C ${SRS_OBJS}/${SRS_PLATFORM}/st-srs ${_ST_MAKE_ARGS} CC=\$(GCC) AR=\$(AR) LD=\$(LINK) RANDLIB=\$(RANDLIB)
@echo "Please rebuild srs by: make"
ffmpeg:
Expand Down
2 changes: 2 additions & 0 deletions trunk/src/app/srs_app_latest_version.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ void srs_build_features(stringstream& ss)
{
if (SRS_OSX_BOOL) {
ss << "&os=mac";
} else if (SRS_CYGWIN64_BOOL) {
ss << "&os=windows";
} else {
ss << "&os=linux";
}
Expand Down
6 changes: 3 additions & 3 deletions trunk/src/app/srs_app_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
#include <fcntl.h>
#include <unistd.h>
#include <algorithm>
#ifndef SRS_OSX
#if !defined(SRS_OSX) && !defined(SRS_CYGWIN64)
#include <sys/inotify.h>
#endif
using namespace std;
Expand Down Expand Up @@ -191,7 +191,7 @@ srs_error_t SrsInotifyWorker::start()
{
srs_error_t err = srs_success;

#ifndef SRS_OSX
#if !defined(SRS_OSX) && !defined(SRS_CYGWIN64)
// Whether enable auto reload config.
bool auto_reload = _srs_config->inotify_auto_reload();
if (!auto_reload && _srs_in_docker && _srs_config->auto_reload_for_docker()) {
Expand Down Expand Up @@ -271,7 +271,7 @@ srs_error_t SrsInotifyWorker::cycle()
{
srs_error_t err = srs_success;

#ifndef SRS_OSX
#if !defined(SRS_OSX) && !defined(SRS_CYGWIN64)
string config_path = _srs_config->config();
string config_file = srs_path_basename(config_path);
string k8s_file = "..data";
Expand Down
4 changes: 2 additions & 2 deletions trunk/src/app/srs_app_threads.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ using namespace std;
#include <unistd.h>
#include <fcntl.h>

#ifdef SRS_OSX
#if defined(SRS_OSX) || defined(SRS_CYGWIN64)
pid_t gettid() {
return 0;
}
Expand All @@ -49,7 +49,7 @@ using namespace std;

// These functions first appeared in glibc in version 2.12.
// See https://man7.org/linux/man-pages/man3/pthread_setname_np.3.html
#if defined(SRS_CROSSBUILD) && ((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 12))
#if defined(SRS_CYGWIN64) || (defined(SRS_CROSSBUILD) && ((__GLIBC__ < 2) || (__GLIBC__ == 2 && __GLIBC_MINOR__ < 12)))
void pthread_setname_np(pthread_t trd, const char* name) {
}
#endif
Expand Down
20 changes: 10 additions & 10 deletions trunk/src/app/srs_app_utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ SrsProcSystemStat* srs_get_system_proc_stat()

bool get_proc_system_stat(SrsProcSystemStat& r)
{
#ifndef SRS_OSX
#if !defined(SRS_OSX)
FILE* f = fopen("/proc/stat", "r");
if (f == NULL) {
srs_warn("open system cpu stat failed, ignore");
Expand Down Expand Up @@ -369,7 +369,7 @@ bool get_proc_system_stat(SrsProcSystemStat& r)

bool get_proc_self_stat(SrsProcSelfStat& r)
{
#ifndef SRS_OSX
#if !defined(SRS_OSX)
FILE* f = fopen("/proc/self/stat", "r");
if (f == NULL) {
srs_warn("open self cpu stat failed, ignore");
Expand Down Expand Up @@ -493,7 +493,7 @@ SrsDiskStat* srs_get_disk_stat()

bool srs_get_disk_vmstat_stat(SrsDiskStat& r)
{
#ifndef SRS_OSX
#if !defined(SRS_OSX) && !defined(SRS_CYGWIN64)
FILE* f = fopen("/proc/vmstat", "r");
if (f == NULL) {
srs_warn("open vmstat failed, ignore");
Expand Down Expand Up @@ -525,7 +525,7 @@ bool srs_get_disk_diskstats_stat(SrsDiskStat& r)
r.ok = true;
r.sample_time = srsu2ms(srs_update_system_time());

#ifndef SRS_OSX
#if !defined(SRS_OSX)
// if disabled, ignore all devices.
SrsConfDirective* conf = _srs_config->get_stats_disk_device();
if (conf == NULL) {
Expand Down Expand Up @@ -689,7 +689,7 @@ void srs_update_meminfo()
{
SrsMemInfo& r = _srs_system_meminfo;

#ifndef SRS_OSX
#if !defined(SRS_OSX)
FILE* f = fopen("/proc/meminfo", "r");
if (f == NULL) {
srs_warn("open meminfo failed, ignore");
Expand Down Expand Up @@ -783,7 +783,7 @@ void srs_update_platform_info()

r.srs_startup_time = srsu2ms(srs_get_system_startup_time());

#ifndef SRS_OSX
#if !defined(SRS_OSX)
if (true) {
FILE* f = fopen("/proc/uptime", "r");
if (f == NULL) {
Expand Down Expand Up @@ -877,7 +877,7 @@ static SrsSnmpUdpStat _srs_snmp_udp_stat;

bool get_udp_snmp_statistic(SrsSnmpUdpStat& r)
{
#ifndef SRS_OSX
#if !defined(SRS_OSX) && !defined(SRS_CYGWIN64)
if (true) {
FILE* f = fopen("/proc/net/snmp", "r");
if (f == NULL) {
Expand Down Expand Up @@ -983,7 +983,7 @@ int srs_get_network_devices_count()

void srs_update_network_devices()
{
#ifndef SRS_OSX
#if !defined(SRS_OSX) && !defined(SRS_CYGWIN64)
if (true) {
FILE* f = fopen("/proc/net/dev", "r");
if (f == NULL) {
Expand Down Expand Up @@ -1071,7 +1071,7 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps)
int nb_tcp_mem = 0;
int nb_udp4 = 0;

#ifndef SRS_OSX
#if !defined(SRS_OSX) && !defined(SRS_CYGWIN64)
if (true) {
FILE* f = fopen("/proc/net/sockstat", "r");
if (f == NULL) {
Expand Down Expand Up @@ -1119,7 +1119,7 @@ void srs_update_rtmp_server(int nb_conn, SrsKbps* kbps)

int nb_tcp_estab = 0;

#ifndef SRS_OSX
#if !defined(SRS_OSX) && !defined(SRS_CYGWIN64)
if (true) {
FILE* f = fopen("/proc/net/snmp", "r");
if (f == NULL) {
Expand Down
6 changes: 6 additions & 0 deletions trunk/src/app/srs_app_uuid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@

#include <srs_app_uuid.hpp>

#if defined(SRS_CYGWIN64)
#define HAVE_LOFF_T
#endif

#include <unistd.h>
#include <stdio.h>
#include <sys/file.h>
Expand Down Expand Up @@ -1082,7 +1086,9 @@ void uuid_generate(uuid_t out)
#include <string.h>
#include <sys/time.h>

#if defined(__linux__) && defined(HAVE_SYS_SYSCALL_H)
#include <sys/syscall.h>
#endif

//#include "randutils.h"

Expand Down
Loading

0 comments on commit d741f81

Please sign in to comment.