Skip to content

Commit

Permalink
Add build steps for macOS arm64 and x86_64 platforms
Browse files Browse the repository at this point in the history
  • Loading branch information
freitas-renato committed Nov 1, 2023
1 parent 13e0cb2 commit 3f47511
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 5 deletions.
116 changes: 111 additions & 5 deletions .github/workflows/autobuild.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'
Expand All @@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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 }}"
Expand Down
61 changes: 61 additions & 0 deletions macOS/build.sh
Original file line number Diff line number Diff line change
@@ -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
2 changes: 2 additions & 0 deletions macOS/gtar
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/sh
exec sudo /usr/local/bin/gtar.orig "$@"
6 changes: 6 additions & 0 deletions macOS/port-deps.sh
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 3f47511

Please sign in to comment.