Skip to content

Commit

Permalink
Build APE with github action
Browse files Browse the repository at this point in the history
  • Loading branch information
jjsullivan5196 committed May 30, 2024
1 parent 2959ffa commit 4b87fe2
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 0 deletions.
43 changes: 43 additions & 0 deletions .github/cosmo/build-ape.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Chez build settings
SCHEME_BIN="scheme.com"
PREFIX=/zip/usr
CONFIG_FLAGS="--prefix=$PREFIX --installabsolute --installschemename=$SCHEME_BIN --disable-x11 --disable-curses"

# cosmocc toolchain
COSMOCC=/opt/cosmocc
export PATH="$COSMOCC/bin:$PATH"

# need to disable zipos so we can use /zip as part of the install
# prefix
export COSMOPOLITAN_DISABLE_ZIPOS=1

# prefix and build dirs
sudo mkdir -p $PREFIX
sudo chown -R "$(id -u):$(id -g)" $PREFIX
mkdir ./dist

# build host amd64 Chez
export CC=$COSMOCC/bin/x86_64-unknown-cosmo-cc
export AR=$COSMOCC/bin/x86_64-unknown-cosmo-ar
./configure ${CONFIG_FLAGS}
make -j
make install
cp $PREFIX/bin/$SCHEME_BIN ./dist/$SCHEME_BIN.ta6le

# cross compile aarch64
export CC=$COSMOCC/bin/aarch64-unknown-cosmo-cc
export AR=$COSMOCC/bin/aarch64-unknown-cosmo-ar
./configure -m=tarm64le ${CONFIG_FLAGS}
make -j
make install
cp $PREFIX/bin/$SCHEME_BIN ./dist/$SCHEME_BIN.tarm64le

# copy results and dump unnecessary files
cp -r $PREFIX ./dist/
rm -rf ./dist/usr/bin ./dist/usr/share
cd dist

# produce the APE image
apelink -o $SCHEME_BIN.zip $SCHEME_BIN.ta6le $SCHEME_BIN.tarm64le
zip -q -r $SCHEME_BIN.zip usr/
mv ./$SCHEME_BIN.zip ./$SCHEME_BIN
17 changes: 17 additions & 0 deletions .github/cosmo/setup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
COSMOCC_VERSION=3.3.10
COSMOCC_ZIP=/opt/cosmocc/cosmocc-$COSMOCC_VERSION.zip
COSMOCC_SHA256="00d61c1215667314f66e288c8285bae38cc6137fca083e5bba6c74e3a52439de"

function fail_sha
{
>&2 echo "Downloaded file ${1} SHA256 does not match known hash."
exit 1
}

sudo mkdir -p /opt/cosmocc
sudo chown -R "$(id -u):$(id -g)" /opt/cosmocc

wget --quiet -O $COSMOCC_ZIP "https://cosmo.zip/pub/cosmocc/cosmocc-${COSMOCC_VERSION}.zip"
(echo "${COSMOCC_SHA256} ${COSMOCC_ZIP}" | sha256sum --check --status) || fail_sha $COSMOCC_ZIP

unzip -q $COSMOCC_ZIP -d /opt/cosmocc/
45 changes: 45 additions & 0 deletions .github/workflows/release-ape.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
on:
push:
tags:
- "v*.*.*"

permissions:
contents: read

jobs:
release-ape:
permissions:
contents: write
name: Build APE Chez image
runs-on: ubuntu-latest
steps:
- name: Checkout the repository
uses: actions/checkout@master

- name: Install deps
run: sudo apt install -y wget zip unzip

- name: Cache cosmocc toolchain
id: cache
uses: actions/cache@v4
with:
path: /opt/cosmocc
key: ${{ runner.os }}-${{ hashFiles('.github/cosmo/setup.sh') }}

- name: Install cosmocc toolchain
if: steps.cache.outputs.cache-hit != 'true'
run: bash .github/cosmo/setup.sh

- name: Register APE handler for binfmt_misc
run: |
sudo cp /opt/cosmocc/bin/ape-x86_64.elf /usr/bin/ape
sudo sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register"
- name: Build APE binary
run: bash .github/cosmo/build-ape.sh

- name: Push binary to github
uses: softprops/action-gh-release@v1
with:
draft: true
files: ./dist/scheme.com

0 comments on commit 4b87fe2

Please sign in to comment.