From 3f47511cf1b5246734b2f11e2b420aae8fb9eb68 Mon Sep 17 00:00:00 2001 From: Renato Freitas Date: Wed, 1 Nov 2023 17:02:19 -0400 Subject: [PATCH] Add build steps for macOS arm64 and x86_64 platforms --- .github/workflows/autobuild.yml | 116 ++++++++++++++++++++++++++++++-- macOS/build.sh | 61 +++++++++++++++++ macOS/gtar | 2 + macOS/port-deps.sh | 6 ++ 4 files changed, 180 insertions(+), 5 deletions(-) create mode 100755 macOS/build.sh create mode 100644 macOS/gtar create mode 100644 macOS/port-deps.sh diff --git a/.github/workflows/autobuild.yml b/.github/workflows/autobuild.yml index 9653d43..211768e 100644 --- a/.github/workflows/autobuild.yml +++ b/.github/workflows/autobuild.yml @@ -2,8 +2,39 @@ on: workflow_dispatch: name: Auto-Build jobs: - build: - name: Build + macports-cache: + runs-on: macos-12 + steps: + - uses: actions/checkout@v3 + + - name: Install gtar sudo wrapper + run: | + sudo mv /usr/local/bin/gtar /usr/local/bin/gtar.orig + sudo cp macOS/gtar /usr/local/bin/gtar + sudo chmod +x /usr/local/bin/gtar + + - name: Cache macports + id: cache-macports + uses: actions/cache@v3 + env: + cache-name: cache-macports + with: + path: /opt/local + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('macOS/port-deps.sh') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - name: Setup macports dependencies + if: steps.cache-macports.outputs.cache-hit != 'true' + run: | + curl -L "https://github.com/macports/macports-base/releases/download/v2.8.1/MacPorts-2.8.1-12-Monterey.pkg" --output macports.pkg + sudo installer -pkg macports.pkg -target / + chmod +x macOS/port-deps.sh && ./macOS/port-deps.sh + + linux-build: + name: Linux Build runs-on: ubuntu-20.04 strategy: @@ -21,7 +52,7 @@ jobs: run: | docker build -t builder --build-arg TARGET_ARCH=${{ matrix.architecture }} . - - run: git clone --depth=1 --branch mosh-1.3.2 https://github.com/mobile-shell/mosh.git + - run: git clone --depth=1 --branch mosh-1.4.0 https://github.com/mobile-shell/mosh.git - name: Build binaries for ${{ matrix.architecture }} run: docker run -v $PWD/mosh:/mosh -w /mosh --name=builder builder sh -c './autogen.sh && LDFLAGS=-static ./configure && make' @@ -45,10 +76,70 @@ jobs: name: mosh-client-linux-${{ matrix.architecture }} path: mosh/src/frontend/mosh-client-linux-${{ matrix.architecture }} if-no-files-found: error + + macos-build: + name: macOS Build (x86_64, arm64) + needs: macports-cache + runs-on: macos-12 + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Install gtar sudo wrapper + run: | + sudo mv /usr/local/bin/gtar /usr/local/bin/gtar.orig + sudo cp macOS/gtar /usr/local/bin/gtar + sudo chmod +x /usr/local/bin/gtar + + - name: Restore macports cache + id: cache-macports + uses: actions/cache@v3 + env: + cache-name: cache-macports + with: + path: /opt/local + key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ hashFiles('macOS/port-deps.sh') }} + restore-keys: | + ${{ runner.os }}-build-${{ env.cache-name }}- + ${{ runner.os }}-build- + ${{ runner.os }}- + + - run: git clone --depth=1 --branch mosh-1.4.0 https://github.com/mobile-shell/mosh.git + + - run: PATH=/opt/local/bin:$PATH ./autogen.sh + working-directory: ./mosh + + - run: | + chmod +x build.sh + env ZERO_AR_DATE=1 MACOSX_DEPLOYMENT_TARGET=11.0 PATH=/opt/local/bin:$PATH ./build.sh + working-directory: ./macOS + + - uses: actions/upload-artifact@v3 + with: + name: mosh-client-darwin-x86_64 + path: ./macOS/prefix_x86_64/local/bin/mosh-client-darwin-x86_64 + + - uses: actions/upload-artifact@v3 + with: + name: mosh-server-darwin-x86_64 + path: ./macOS/prefix_x86_64/local/bin/mosh-server-darwin-x86_64 + + - uses: actions/upload-artifact@v3 + with: + name: mosh-client-darwin-arm64 + path: ./macOS/prefix_arm64/local/bin/mosh-client-darwin-arm64 + + - uses: actions/upload-artifact@v3 + with: + name: mosh-server-darwin-arm64 + path: ./macOS/prefix_arm64/local/bin/mosh-server-darwin-arm64 + + release: name: Release - needs: [build] + needs: [linux-build, macos-build] runs-on: ubuntu-20.04 steps: - uses: actions/checkout@v3 @@ -63,9 +154,23 @@ jobs: echo '- [Workflow file](https://github.com/${{ github.repository }}/blob/${{ github.sha }}/.github/workflows/autobuild.yml)' echo echo '## Files' + echo '### Linux' echo '```' ( - for dir in mosh-client* mosh-server*; do + for dir in mosh-client-linux* mosh-server-linux*; do + cd "$dir" + for prog in mosh*; do + file "$prog" + done + cd .. + done + ) + echo '```' + echo + echo '### macOS' + echo '```' + ( + for dir in mosh-client-darwin* mosh-server-darwin*; do cd "$dir" for prog in mosh*; do file "$prog" @@ -97,6 +202,7 @@ jobs: if-no-files-found: error - name: Create release + id: create_release uses: softprops/action-gh-release@v1 with: name: "Build #${{ github.run_number }}" diff --git a/macOS/build.sh b/macOS/build.sh new file mode 100755 index 0000000..97c0df5 --- /dev/null +++ b/macOS/build.sh @@ -0,0 +1,61 @@ +#!/bin/bash + +set -e + +protobuf_LIBS=$(l=libprotobuf.a; for i in /opt/local/lib /usr/local/lib; do if [ -f $i/$l ]; then echo $i/$l; fi; done) +if [ -z "$protobuf_LIBS" ]; then echo "Can't find libprotobuf.a"; exit 1; fi +export protobuf_LIBS +if ! pkg-config --cflags protobuf > /dev/null 2>&1; then + protobuf_CFLAGS=-I$(for i in /opt /usr; do d=$i/local/include; if [ -d $d/google/protobuf ]; then echo $d; fi; done) + if [ "$protobuf_CFLAGS" = "-I" ]; then echo "Can't find protobuf includes"; exit 1; fi + export protobuf_CFLAGS +fi +export CXXFLAGS=-std=gnu++17 + +# XXX This script abuses Configure's --prefix argument badly. It uses +# it as a $DESTDIR, but --prefix can also affect paths in generated +# objects. That is not *currently* a problem in mosh. +# +PREFIX="$(pwd)/prefix" + +HOST="x86_64-apple-macosx${MACOSX_DEPLOYMENT_TARGET}" +ARCH_TRIPLES="x86_64-apple-macosx arm64-apple-macos" + +pushd ../mosh > /dev/null + +if [ ! -f configure ]; +then + echo "Running autogen." + PATH=/opt/local/bin:$PATH ./autogen.sh +fi + +# +# Build archs one by one. +# +for triple in $ARCH_TRIPLES; do + arch=$(echo $triple | cut -d- -f1) + echo "Building for ${arch}..." + prefix="${PREFIX}_${arch}" + rm -rf "${prefix}" + mkdir "${prefix}" + if ./configure --prefix="${prefix}/local" --build="${triple}${MACOSX_DEPLOYMENT_TARGET}"\ + --host="${HOST}" \ + CC="cc -arch ${arch}" CPP="cc -arch ${arch} -E" CXX="c++ -arch ${arch}" \ + TINFO_LIBS=-lncurses && + make clean && + make install -j8 V=1 && + rm -f "${prefix}/etc" + then + mv "${prefix}/local/bin/mosh-client" "${prefix}/local/bin/mosh-client-darwin-${arch}" + mv "${prefix}/local/bin/mosh-server" "${prefix}/local/bin/mosh-server-darwin-${arch}" + + BUILT_ARCHS="$BUILT_ARCHS $arch" + fi +done + +if [ -z "$BUILT_ARCHS" ]; then + echo "No architectures built successfully" + exit 1 +fi + +popd > /dev/null diff --git a/macOS/gtar b/macOS/gtar new file mode 100644 index 0000000..5814696 --- /dev/null +++ b/macOS/gtar @@ -0,0 +1,2 @@ +#!/bin/sh +exec sudo /usr/local/bin/gtar.orig "$@" diff --git a/macOS/port-deps.sh b/macOS/port-deps.sh new file mode 100644 index 0000000..aa6dcd1 --- /dev/null +++ b/macOS/port-deps.sh @@ -0,0 +1,6 @@ +#!/bin/sh + +sudo /opt/local/bin/port install protobuf-cpp +universal +sudo /opt/local/bin/port install ncurses +universal +sudo /opt/local/bin/port install pkgconfig +sudo /opt/local/bin/port install autoconf automake