From 6ef461bd579c2074acfa289d258e73c7b3ca150c Mon Sep 17 00:00:00 2001 From: Shuanglei Tao Date: Sun, 26 Jul 2020 20:57:55 +0800 Subject: [PATCH] scripts: use cross compiler from musl.cc --- .github/workflows/backend.yml | 12 ++++--- .github/workflows/frontend.yml | 2 +- .github/workflows/release.yml | 10 ++++-- scripts/cross-build.sh | 58 ++++++++++++++++++---------------- 4 files changed, 46 insertions(+), 36 deletions(-) diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml index 4d07a5e..706f824 100644 --- a/.github/workflows/backend.yml +++ b/.github/workflows/backend.yml @@ -34,7 +34,7 @@ jobs: cd libwebsockets-${LWS_VERSION} cmake -DLWS_WITH_LIBUV=ON -DLWS_UNIX_SOCK=ON -DLWS_IPV6=ON -DLWS_WITHOUT_TESTAPPS=ON -DCMAKE_BUILD_TYPE=RELEASE . make && sudo make install && sudo ldconfig - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - name: Build ttyd run: | cmake -DCMAKE_BUILD_TYPE=RELEASE . @@ -44,13 +44,17 @@ jobs: runs-on: ubuntu-16.04 strategy: matrix: - arch: [i386, x86_64, arm, armhf, aarch64, mips, mipsel] + arch: [i686, x86_64, arm, armhf, aarch64, mips, mipsel, mips64, mips64el] steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 + - name: Install packages + run: | + sudo apt-get update + sudo apt-get install -y autoconf automake build-essential cmake curl file libtool - name: Cross build (${{ matrix.arch }}) env: ARCH: ${{ matrix.arch }} - run: docker run --rm -v $(pwd):/ttyd -w /ttyd tsl0922/musl-cross ./scripts/cross-build.sh $ARCH + run: ./scripts/cross-build.sh $ARCH - uses: actions/upload-artifact@v1 with: name: ttyd.${{ matrix.arch }} diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml index f4acdfd..6777acd 100644 --- a/.github/workflows/frontend.yml +++ b/.github/workflows/frontend.yml @@ -14,7 +14,7 @@ jobs: build: runs-on: ubuntu-16.04 steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 - uses: actions/setup-node@v1 with: node-version: '12.x' diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 72f8d0b..2d8f817 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -9,12 +9,16 @@ jobs: build: runs-on: ubuntu-16.04 steps: - - uses: actions/checkout@v1 + - uses: actions/checkout@v2 + - name: Install packages + run: | + sudo apt-get update + sudo apt-get install -y autoconf automake build-essential cmake curl file libtool - name: Build Release run: | mkdir -p bin - for arch in i386 x86_64 arm armhf aarch64 mips mipsel; do - docker run --rm -v $(pwd):/ttyd -w /ttyd tsl0922/musl-cross ./scripts/cross-build.sh $arch + for arch in i686 x86_64 arm armhf aarch64 mips mipsel mips64 mips64el; do + ./scripts/cross-build.sh $arch cp build/ttyd bin/ttyd_linux.$arch sha256sum bin/ttyd_linux.$arch >> bin/SHA256SUMS done diff --git a/scripts/cross-build.sh b/scripts/cross-build.sh index 7c63169..3be7201 100755 --- a/scripts/cross-build.sh +++ b/scripts/cross-build.sh @@ -1,9 +1,5 @@ #!/bin/bash -# -# This script should be run inside the tsl0922/musl-cross docker image -# Example: -# docker run --rm -v $(pwd):/ttyd -w /ttyd tsl0922/musl-cross ./scripts/cross-build.sh mips -# + set -eo pipefail CROSS_ROOT="${CROSS_ROOT:-/opt/cross}" @@ -14,7 +10,7 @@ ZLIB_VERSION="${ZLIB_VERSION:-1.2.11}" JSON_C_VERSION="${JSON_C_VERSION:-0.14}" OPENSSL_VERSION="${OPENSSL_VERSION:-1.0.2u}" LIBUV_VERSION="${LIBUV_VERSION:-1.38.0}" -LIBWEBSOCKETS_VERSION="${LIBWEBSOCKETS_VERSION:-4.0.19}" +LIBWEBSOCKETS_VERSION="${LIBWEBSOCKETS_VERSION:-4.0.20}" build_zlib() { echo "=== Building zlib-${ZLIB_VERSION} (${TARGET})..." @@ -51,7 +47,7 @@ build_openssl() { } build_libuv() { - echo "=== Building libuv-${LIBUV_VERSION} (${TARGET})..." + echo "=== Building libuv-${LIBUV_VERSION} (${TARGET})..." curl -sLo- "https://dist.libuv.org/dist/v${LIBUV_VERSION}/libuv-v${LIBUV_VERSION}.tar.gz" | tar xz -C "${BUILD_DIR}" pushd "${BUILD_DIR}/libuv-v${LIBUV_VERSION}" ./autogen.sh @@ -71,17 +67,19 @@ set(CMAKE_FIND_ROOT_PATH "${STAGE_DIR}") set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) + +set(OPENSSL_USE_STATIC_LIBS TRUE) EOF } build_libwebsockets() { echo "=== Building libwebsockets-${LIBWEBSOCKETS_VERSION} (${TARGET})..." - curl -sLo- "https://github.com/warmcat/libwebsockets/archive/v${LIBWEBSOCKETS_VERSION}.tar.gz" | tar xz -C "${BUILD_DIR}" + curl -sLo- "https://github.com/warmcat/libwebsockets/archive/v${LIBWEBSOCKETS_VERSION}.tar.gz" | tar xz -C ${BUILD_DIR} pushd "${BUILD_DIR}/libwebsockets-${LIBWEBSOCKETS_VERSION}" sed -i 's/ websockets_shared//g' cmake/LibwebsocketsConfig.cmake.in + sed -i '/PC_OPENSSL/d' CMakeLists.txt mkdir build && cd build cmake -DCMAKE_TOOLCHAIN_FILE="${BUILD_DIR}/cross-${TARGET}.cmake" \ - -DCMAKE_BUILD_TYPE=RELEASE \ -DCMAKE_INSTALL_PREFIX="${STAGE_DIR}" \ -DCMAKE_FIND_LIBRARY_SUFFIXES=".a" \ -DCMAKE_EXE_LINKER_FLAGS="-static" \ @@ -93,20 +91,19 @@ build_libwebsockets() { -DLWS_IPV6=ON \ .. make -j"$(nproc)" install - sed -i 's/ssl;crypto;//g' "${STAGE_DIR}/lib/cmake/libwebsockets/LibwebsocketsTargets-release.cmake" popd } build_ttyd() { echo "=== Building ttyd (${TARGET})..." rm -rf build && mkdir -p build && cd build - cmake -DCMAKE_TOOLCHAIN_FILE="${BUILD_DIR}/cross-${TARGET}.cmake" \ - -DCMAKE_INSTALL_PREFIX="${STAGE_DIR}" \ - -DCMAKE_FIND_LIBRARY_SUFFIXES=".a" \ - -DCMAKE_EXE_LINKER_FLAGS="-static -no-pie -s" \ - -DCMAKE_BUILD_TYPE=RELEASE \ - .. - make install + cmake -DCMAKE_TOOLCHAIN_FILE="${BUILD_DIR}/cross-${TARGET}.cmake" \ + -DCMAKE_INSTALL_PREFIX="${STAGE_DIR}" \ + -DCMAKE_FIND_LIBRARY_SUFFIXES=".a" \ + -DCMAKE_EXE_LINKER_FLAGS="-static -no-pie -s" \ + -DCMAKE_BUILD_TYPE=RELEASE \ + .. + make install } build() { @@ -115,6 +112,11 @@ build() { STAGE_DIR="${STAGE_ROOT}/${TARGET}" BUILD_DIR="${BUILD_ROOT}/${TARGET}" + echo "=== Installing toolchain ${ALIAS} (${TARGET})..." + + mkdir -p "${CROSS_ROOT}" && export PATH="${PATH}:/opt/cross/bin" + curl -sLo- "http://musl.cc/${TARGET}-cross.tgz" | tar xz -C ${CROSS_ROOT} --strip-components 1 + echo "=== Building target ${ALIAS} (${TARGET})..." rm -rf "${STAGE_DIR}" "${BUILD_DIR}" @@ -132,15 +134,15 @@ build() { } case $1 in - i386|x86_64|aarch64|mips|mipsel) - build "$1-linux-musl" "$1" - ;; - arm) - build arm-linux-musleabi "$1" - ;; - armhf) - build arm-linux-musleabihf "$1" - ;; - *) - echo "usage: $0 i386|x86_64|arm|armhf|aarch64|mips|mipsel" && exit 1 + i686|x86_64|aarch64|mips|mipsel|mips64|mips64el) + build "$1-linux-musl" "$1" + ;; + arm) + build arm-linux-musleabi "$1" + ;; + armhf) + build arm-linux-musleabihf "$1" + ;; + *) + echo "usage: $0 i686|x86_64|arm|armhf|aarch64|mips|mipsel|mips64|mips64el" && exit 1 esac -- 2.43.4