diff --git a/.github/cosmo/build b/.github/cosmo/build new file mode 100644 index 00000000..0c7f010b --- /dev/null +++ b/.github/cosmo/build @@ -0,0 +1,38 @@ +#!/bin/sh +set -eux + +COSMO_DIR="/sc/cosmocc" + +# build x86_64 +X86_64_CC="/sc/cosmocc/bin/x86_64-unknown-cosmo-cc" +X86_64_AR="/sc/cosmocc/bin/x86_64-unknown-cosmo-ar" +mkdir -p /sc/cosmocc/x86_64 +make -j CC="$X86_64_CC" AR="$X86_64_AR" HAS_SHARED=0 JANET_NO_AMALG=1 +cp build/janet /sc/cosmocc/x86_64/janet +make clean + +# build aarch64 +AARCH64_CC="/sc/cosmocc/bin/aarch64-unknown-cosmo-cc" +AARCH64_AR="/sc/cosmocc/bin/aarch64-unknown-cosmo-ar" +mkdir -p /sc/cosmocc/aarch64 +make -j CC="$AARCH64_CC" AR="$AARCH64_AR" HAS_SHARED=0 JANET_NO_AMALG=1 +cp build/janet /sc/cosmocc/aarch64/janet +make clean + +# fat binary +apefat () { + OUTPUT="$1" + OLDNAME_X86_64="$(basename -- "$2")" + OLDNAME_AARCH64="$(basename -- "$3")" + TARG_FOLD="$(dirname "$OUTPUT")" + "$COSMO_DIR/bin/apelink" -l "$COSMO_DIR/bin/ape-x86_64.elf" \ + -l "$COSMO_DIR/bin/ape-aarch64.elf" \ + -M "$COSMO_DIR/bin/ape-m1.c" \ + -o "$OUTPUT" \ + "$2" \ + "$3" + cp "$2" "$TARG_FOLD/$OLDNAME_X86_64.x86_64" + cp "$3" "$TARG_FOLD/$OLDNAME_AARCH64.aarch64" +} + +apefat /sc/cosmocc/janet.com /sc/cosmocc/x86_64/janet /sc/cosmocc/aarch64/janet diff --git a/.github/cosmo/setup b/.github/cosmo/setup new file mode 100644 index 00000000..9de92d41 --- /dev/null +++ b/.github/cosmo/setup @@ -0,0 +1,21 @@ +#!/bin/sh +set -e + +sudo apt update +sudo apt-get install -y ca-certificates libssl-dev\ + qemu qemu-utils qemu-user-static\ + texinfo groff\ + cmake ninja-build bison zip\ + pkg-config build-essential autoconf re2c + +# download cosmocc +cd /sc +wget https://github.com/jart/cosmopolitan/releases/download/3.3.3/cosmocc-3.3.3.zip +mkdir -p cosmocc +cd cosmocc +unzip ../cosmocc-3.3.3.zip + +# register +cd /sc/cosmocc +sudo cp ./bin/ape-x86_64.elf /usr/bin/ape +sudo sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index e5c557dc..4c19750b 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -60,3 +60,30 @@ jobs: ./dist/*.zip ./*.zip ./*.msi + + release-cosmo: + permissions: + contents: write # for softprops/action-gh-release to create GitHub release + name: Build release binaries for Cosmo + runs-on: ubuntu-latest + steps: + - name: Checkout the repository + uses: actions/checkout@master + - name: create build folder + run: | + sudo mkdir -p /sc + sudo chmod -R 0777 /sc + - name: setup Cosmopolitan Libc + run: bash ./.github/cosmo/setup + - name: Set the version + run: echo "version=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV + - name: Set the platform + run: echo "platform=cosmo" >> $GITHUB_ENV + - name: build Janet APE binary + run: bash ./.github/cosmo/build + - name: push binary to github + uses: softprops/action-gh-release@v1 + with: + draft: true + files: | + /sc/cosmocc/janet.com