From 3f31fbc89c0e1beb5ac60d23f600f1b6db809298 Mon Sep 17 00:00:00 2001 From: Gautham Date: Sun, 21 Apr 2024 21:32:53 -0500 Subject: [PATCH 1/3] add cosmo build --- .github/cosmo/build | 38 +++++++++++++++++++++++++++++++++++ .github/cosmo/setup | 21 +++++++++++++++++++ .github/workflows/release.yml | 34 +++++++++++++++++++++++++++++++ 3 files changed, 93 insertions(+) create mode 100755 .github/cosmo/build create mode 100755 .github/cosmo/setup create mode 100644 .github/workflows/release.yml diff --git a/.github/cosmo/build b/.github/cosmo/build new file mode 100755 index 0000000..507257c --- /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" +mkdir -p /sc/cosmocc/x86_64 +make -j CC="$X86_64_CC" +cp gguf-tools /sc/cosmocc/x86_64/gguf-tools +make clean + +# build aarch64 +AARCH64_CC="/sc/cosmocc/bin/aarch64-unknown-cosmo-cc" +mkdir -p /sc/cosmocc/aarch64 +make -j CC="$AARCH64_CC" +cp gguf-tools /sc/cosmocc/aarch64/gguf-tools +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/gguf-tools.com /sc/cosmocc/x86_64/gguf-tools /sc/cosmocc/aarch64/gguf-tools +cd /sc/cosmocc/ +zip gguf-tools.zip gguf-tools.com gguf-tools.x86_64 gguf-tools.aarch64 diff --git a/.github/cosmo/setup b/.github/cosmo/setup new file mode 100755 index 0000000..9de92d4 --- /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 new file mode 100644 index 0000000..15ee0fe --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,34 @@ +name: Release + +on: + push: + tags: + - "v*.*.*" + +permissions: + contents: read + +jobs: + + 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: build APE binary of gguf-tools + run: bash ./.github/cosmo/build + - name: push binary to github + uses: softprops/action-gh-release@v1 + with: + draft: true + files: | + /sc/cosmocc/gguf-tools.zip From 900054963961e6c49a7e94401e5b4f13bf4c0712 Mon Sep 17 00:00:00 2001 From: Gautham Date: Sun, 21 Apr 2024 21:37:12 -0500 Subject: [PATCH 2/3] update Makefile for build remove lto/gdb because those aren't supported by cosmo, and march=native because we don't have a setting for aarch64 --- Makefile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index fb79066..12202cd 100644 --- a/Makefile +++ b/Makefile @@ -2,8 +2,8 @@ all: gguf-tools gguf-tools: gguf-tools.c gguflib.c gguflib.h sds.c sds.h sdsalloc.h fp16.h $(CC) gguf-tools.c gguflib.c sds.c fp16.c \ - -march=native -flto -ffast-math \ - -g -ggdb -Wall -W -pedantic -O3 -o gguf-tools + -ffast-math \ + -g3 -Wall -W -pedantic -O3 -o gguf-tools clean: rm -rf gguf-tools From 866db450bcc06d908105058a5909773a7139e9b0 Mon Sep 17 00:00:00 2001 From: Gautham Date: Tue, 23 Apr 2024 16:28:14 -0500 Subject: [PATCH 3/3] simplify APE build --- .github/cosmo/build | 48 ++++++++++++----------------------- .github/cosmo/setup | 21 --------------- .github/workflows/release.yml | 4 +-- 3 files changed, 17 insertions(+), 56 deletions(-) delete mode 100755 .github/cosmo/setup diff --git a/.github/cosmo/build b/.github/cosmo/build index 507257c..baa7143 100755 --- a/.github/cosmo/build +++ b/.github/cosmo/build @@ -1,38 +1,22 @@ #!/bin/sh set -eux -COSMO_DIR="/sc/cosmocc" - -# build x86_64 -X86_64_CC="/sc/cosmocc/bin/x86_64-unknown-cosmo-cc" -mkdir -p /sc/cosmocc/x86_64 -make -j CC="$X86_64_CC" -cp gguf-tools /sc/cosmocc/x86_64/gguf-tools -make clean +GGUF_TOOLS_DIR="$(pwd)" -# build aarch64 -AARCH64_CC="/sc/cosmocc/bin/aarch64-unknown-cosmo-cc" -mkdir -p /sc/cosmocc/aarch64 -make -j CC="$AARCH64_CC" -cp gguf-tools /sc/cosmocc/aarch64/gguf-tools -make clean +# 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 -# 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" -} +# 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" -apefat /sc/cosmocc/gguf-tools.com /sc/cosmocc/x86_64/gguf-tools /sc/cosmocc/aarch64/gguf-tools -cd /sc/cosmocc/ -zip gguf-tools.zip gguf-tools.com gguf-tools.x86_64 gguf-tools.aarch64 +# build fat binary +COSMO_DIR="/sc/cosmocc" +cd "$GGUF_TOOLS_DIR" +COSMOCC="/sc/cosmocc/bin/cosmocc" +make -j CC="$COSMOCC" diff --git a/.github/cosmo/setup b/.github/cosmo/setup deleted file mode 100755 index 9de92d4..0000000 --- a/.github/cosmo/setup +++ /dev/null @@ -1,21 +0,0 @@ -#!/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 15ee0fe..7c6165a 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -22,8 +22,6 @@ jobs: run: | sudo mkdir -p /sc sudo chmod -R 0777 /sc - - name: setup Cosmopolitan Libc - run: bash ./.github/cosmo/setup - name: build APE binary of gguf-tools run: bash ./.github/cosmo/build - name: push binary to github @@ -31,4 +29,4 @@ jobs: with: draft: true files: | - /sc/cosmocc/gguf-tools.zip + gguf-tools