Skip to content

Commit

Permalink
Enhance cross-platform build system (pion#266)
Browse files Browse the repository at this point in the history
With this new build system, it'll make it easier to compile third-party
libraries statically to multiple platforms.
  • Loading branch information
lherman-cs authored Dec 15, 2020
1 parent f472618 commit 1b5203d
Show file tree
Hide file tree
Showing 35 changed files with 226 additions and 254 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@

# Output of the go coverage tool, specifically when used with LiteIDE
*.out

scripts/cross
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
[submodule "cvendor/src/openh264"]
path = cvendor/src/openh264
url = https://github.com/cisco/openh264.git
56 changes: 0 additions & 56 deletions Makefile

This file was deleted.

70 changes: 70 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash

MEDIADEVICES_TOOLCHAIN_OWNER=lherman
MEDIADEVICES_TOOLCHAIN_PREFIX=cross
MEDIADEVICES_SCRIPT_PATH=$(realpath ./scripts)
MEDIADEVICES_TOOLCHAIN_PATH=${MEDIADEVICES_SCRIPT_PATH}/${MEDIADEVICES_TOOLCHAIN_PREFIX}
MEDIADEVICES_DOCKERFILES_PATH=dockerfiles

# Reference: https://github.com/dockcross/dockcross#cross-compilers
MEDIADEVICES_TARGET_PLATFORMS=(
linux-armv7
linux-arm64
linux-x64
windows-x64
darwin-x64
)

if [[ -z ${VERBOSE} ]]; then
MEDIADEVICES_OUTPUT=/dev/null
else
MEDIADEVICES_OUTPUT=/dev/stdout
fi

install_toolchains() {
bash ${MEDIADEVICES_DOCKERFILES_PATH}/build.sh &> ${MEDIADEVICES_OUTPUT}
for platform in ${MEDIADEVICES_TARGET_PLATFORMS[@]}
do
mkdir -p ${MEDIADEVICES_TOOLCHAIN_PATH}
image=${MEDIADEVICES_TOOLCHAIN_OWNER}/${MEDIADEVICES_TOOLCHAIN_PREFIX}-${platform}
bin_path=${MEDIADEVICES_TOOLCHAIN_PATH}/${MEDIADEVICES_TOOLCHAIN_PREFIX}-${platform}
docker run ${image} > ${bin_path}
chmod +x ${bin_path}
done
}

build() {
sub_builds=$(find pkg -type f -name "build.sh")
for sub_build in ${sub_builds[@]}
do
sub_build=$(realpath ${sub_build})
sub_build_dir=$(dirname ${sub_build})
current_dir=${PWD}
cd $sub_build_dir
for platform in ${MEDIADEVICES_TARGET_PLATFORMS[@]}
do
export MEDIADEVICES_TOOLCHAIN_BIN=${MEDIADEVICES_TOOLCHAIN_PATH}/${MEDIADEVICES_TOOLCHAIN_PREFIX}-${platform}
# convert '-' to '_' since '_' is more common in library names
export MEDIADEVICES_TARGET_PLATFORM=${platform//-/_}
export MEDIADEVICES_TARGET_OS=$(echo $MEDIADEVICES_TARGET_PLATFORM | cut -d'_' -f1)
export MEDIADEVICES_TARGET_ARCH=${platform//${MEDIADEVICES_TARGET_OS}-/}

echo "Building ${sub_build_dir}:"
echo " PLATFORM : ${MEDIADEVICES_TARGET_PLATFORM}"
echo " OS : ${MEDIADEVICES_TARGET_OS}"
echo " ARCH : ${MEDIADEVICES_TARGET_ARCH}"
echo " TOOLCHAIN_BIN : ${MEDIADEVICES_TOOLCHAIN_BIN}"
echo ""

${sub_build} &> ${MEDIADEVICES_OUTPUT}
done
cd ${current_dir}
done
}

if [[ $# > 0 && $1 != "all" ]]; then
MEDIADEVICES_TARGET_PLATFORMS=($1)
fi

install_toolchains
build
Binary file removed cvendor/lib/openh264/libopenh264.x86_64-darwin.a
Binary file not shown.
Binary file removed cvendor/lib/openh264/libopenh264.x86_64-linux.a
Binary file not shown.
Binary file removed cvendor/lib/openh264/libopenh264.x86_64-windows.a
Binary file not shown.
1 change: 0 additions & 1 deletion cvendor/src/openh264
Submodule openh264 deleted from 713740
13 changes: 13 additions & 0 deletions dockerfiles/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

cd $(dirname $0)

OWNER=lherman
PREFIX=cross
IMAGES=$(ls *.Dockerfile)

for image in ${IMAGES[@]}
do
tag=${OWNER}/cross-${image//.Dockerfile/}
docker build -t "${tag}" -f "$image" .
done
20 changes: 20 additions & 0 deletions dockerfiles/darwin-x64.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
FROM dockcross/base

ENV OSX_CROSS_PATH=/osxcross

COPY --from=dockercore/golang-cross "${OSX_CROSS_PATH}/." "${OSX_CROSS_PATH}/"
ENV PATH=${OSX_CROSS_PATH}/target/bin:$PATH

COPY init.sh /tmp/init.sh
RUN bash /tmp/init.sh

ENV CC=x86_64-apple-darwin14-clang \
CXX=x86_64-apple-darwin14-clang++ \
CPP=x86_64-apple-darwin14-clang++ \
AR=x86_64-apple-darwin14-ar \
AS=x86_64-apple-darwin14-as \
LD=x86_64-apple-darwin14-ld

ARG IMAGE=lherman/cross-darwin-x64
ARG VERSION=latest
ENV DEFAULT_DOCKCROSS_IMAGE ${IMAGE}:${VERSION}
7 changes: 7 additions & 0 deletions dockerfiles/init.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/bin/bash

apt-get update
apt-get install -y nasm clang llvm

curl -L https://golang.org/dl/go1.15.6.linux-amd64.tar.gz | tar -C /usr/local -xzf -
ln -s /usr/local/go/bin/go /usr/local/bin/go
8 changes: 8 additions & 0 deletions dockerfiles/linux-arm64.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM dockcross/linux-arm64

ARG IMAGE=lherman/cross-linux-arm64
ARG VERSION=latest
ENV DEFAULT_DOCKCROSS_IMAGE ${IMAGE}:${VERSION}

COPY init.sh /tmp/init.sh
RUN bash /tmp/init.sh
8 changes: 8 additions & 0 deletions dockerfiles/linux-armv7.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM dockcross/linux-armv7

ARG IMAGE=lherman/cross-linux-armv7
ARG VERSION=latest
ENV DEFAULT_DOCKCROSS_IMAGE ${IMAGE}:${VERSION}

COPY init.sh /tmp/init.sh
RUN bash /tmp/init.sh
8 changes: 8 additions & 0 deletions dockerfiles/linux-x64.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
FROM dockcross/linux-x64

ARG IMAGE=lherman/cross-linux-x64
ARG VERSION=latest
ENV DEFAULT_DOCKCROSS_IMAGE ${IMAGE}:${VERSION}

COPY init.sh /tmp/init.sh
RUN bash /tmp/init.sh
11 changes: 11 additions & 0 deletions dockerfiles/windows-x64.Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
FROM dockcross/windows-static-x64-posix

ARG IMAGE=lherman/cross-windows-x64
ARG VERSION=latest
ENV DEFAULT_DOCKCROSS_IMAGE ${IMAGE}:${VERSION}

COPY init.sh /tmp/init.sh
RUN bash /tmp/init.sh
RUN ln -s /usr/src/mxe/usr/bin/x86_64-w64-mingw32.static.posix-gcc /usr/bin/x86_64-w64-mingw32-gcc && \
ln -s /usr/src/mxe/usr/bin/x86_64-w64-mingw32.static.posix-g++ /usr/bin/x86_64-w64-mingw32-g++ && \
ln -s /usr/src/mxe/usr/bin/x86_64-w64-mingw32.static.posix-ar /usr/bin/x86_64-w64-mingw32-ar
10 changes: 0 additions & 10 deletions libs-builder.Dockerfile

This file was deleted.

1 change: 1 addition & 0 deletions pkg/codec/openh264/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
src
23 changes: 23 additions & 0 deletions pkg/codec/openh264/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
Copyright (c) 2013, Cisco Systems
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 changes: 36 additions & 0 deletions pkg/codec/openh264/build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
GIT_URL=https://github.com/cisco/openh264.git
VERSION=v2.1.1
SRC_DIR=src
LIB_DIR=lib
INCLUDE_DIR=include/openh264
ROOT_DIR=${PWD}
LIB_PREFIX=libopenh264

OS=${MEDIADEVICES_TARGET_OS}
ARCH=${MEDIADEVICES_TARGET_ARCH}

case ${MEDIADEVICES_TARGET_OS} in
windows)
OS=mingw_nt
;;
esac

case ${MEDIADEVICES_TARGET_ARCH} in
armv6 | armv7 | armv8)
ARCH=arm
;;
x64)
ARCH=x86_64
;;
esac

mkdir -p ${LIB_DIR} ${INCLUDE_DIR}

git clone --depth=1 --branch=${VERSION} ${GIT_URL} ${SRC_DIR}
cd ${SRC_DIR}
${MEDIADEVICES_TOOLCHAIN_BIN} make -j2 ${LIB_PREFIX}.a OS=${OS} ARCH=${ARCH}
${MEDIADEVICES_TOOLCHAIN_BIN} echo $PATH
mv ${LIB_PREFIX}.a ${ROOT_DIR}/${LIB_DIR}/${LIB_PREFIX}_${MEDIADEVICES_TARGET_PLATFORM}.a
mkdir -p ${ROOT_DIR}/${INCLUDE_DIR}
cp codec/api/svc/*.h ${ROOT_DIR}/${INCLUDE_DIR}
make clean
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ typedef enum {
DECODER_OPTION_LEVEL, ///< get current AU level info,only is used in GetOption
DECODER_OPTION_STATISTICS_LOG_INTERVAL,///< set log output interval
DECODER_OPTION_IS_REF_PIC, ///< feedback current frame is ref pic or not
DECODER_OPTION_NUM_OF_FRAMES_REMAINING_IN_BUFFER ///< number of frames remaining in decoder buffer when pictures are required to re-ordered into display-order.

DECODER_OPTION_NUM_OF_FRAMES_REMAINING_IN_BUFFER, ///< number of frames remaining in decoder buffer when pictures are required to re-ordered into display-order.
DECODER_OPTION_NUM_OF_THREADS, ///< number of decoding threads. The maximum thread count is equal or less than lesser of (cpu core counts and 16).
} DECODER_OPTION;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,7 @@ typedef struct TagBufferInfo {
union {
SSysMEMBuffer sSystemBuffer; ///< memory info for one picture
} UsrData; ///< output buffer info
unsigned char* pDst[3]; //point to picture YUV data
} SBufferInfo;


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@

#include "codec_app_def.h"

static const OpenH264Version g_stCodecVersion = {2, 0, 0, 1905};
static const char* const g_strCodecVer = "OpenH264 version:2.0.0.1905";
static const OpenH264Version g_stCodecVersion = {2, 1, 0, 2002};
static const char* const g_strCodecVer = "OpenH264 version:2.1.0.2002";

#define OPENH264_MAJOR (2)
#define OPENH264_MINOR (0)
#define OPENH264_MINOR (1)
#define OPENH264_REVISION (0)
#define OPENH264_RESERVED (1905)
#define OPENH264_RESERVED (2002)

#endif // CODEC_VER_H
Binary file added pkg/codec/openh264/lib/libopenh264_darwin_x64.a
Binary file not shown.
Binary file added pkg/codec/openh264/lib/libopenh264_linux_arm64.a
Binary file not shown.
Binary file added pkg/codec/openh264/lib/libopenh264_linux_armv7.a
Binary file not shown.
Binary file added pkg/codec/openh264/lib/libopenh264_linux_x64.a
Binary file not shown.
Binary file added pkg/codec/openh264/lib/libopenh264_windows_x64.a
Binary file not shown.
2 changes: 0 additions & 2 deletions pkg/codec/openh264/openh264.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package openh264

// #cgo CFLAGS: -I${SRCDIR}/../../../cvendor/include
// #cgo CXXFLAGS: -I${SRCDIR}/../../../cvendor/include
// #include <string.h>
// #include <openh264/codec_api.h>
// #include <errno.h>
Expand Down
6 changes: 0 additions & 6 deletions pkg/codec/openh264/openh264_darwin.go

This file was deleted.

6 changes: 0 additions & 6 deletions pkg/codec/openh264/openh264_linux.go

This file was deleted.

12 changes: 12 additions & 0 deletions pkg/codec/openh264/openh264_static.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// +build !dynamic

package openh264

//#cgo CFLAGS: -I${SRCDIR}/include
//#cgo CXXFLAGS: -I${SRCDIR}/include
//#cgo linux,arm LDFLAGS: ${SRCDIR}/lib/libopenh264_linux_armv7.a
//#cgo linux,arm64 LDFLAGS: ${SRCDIR}/lib/libopenh264_linux_arm64.a
//#cgo linux,amd64 LDFLAGS: ${SRCDIR}/lib/libopenh264_linux_x64.a
//#cgo darwin,amd64 LDFLAGS: ${SRCDIR}/lib/libopenh264_darwin_x64.a
//#cgo windows,amd64 LDFLAGS: ${SRCDIR}/lib/libopenh264_windows_x64.a -lssp
import "C"
14 changes: 0 additions & 14 deletions pkg/codec/openh264/openh264_windows.go

This file was deleted.

Loading

0 comments on commit 1b5203d

Please sign in to comment.