From 3f8c6069835e5c8cc55b7845991be6a36d9a6f2a Mon Sep 17 00:00:00 2001 From: Alexandre Gaigalas Date: Sat, 6 Jul 2024 22:30:56 -0300 Subject: [PATCH] First Commit --- .github/workflows/build.yml | 25 +++++++++++++ .gitignore | 6 +++ LICENSE | 15 ++++++++ README.md | 28 ++++++++++++++ carthage.sh | 73 +++++++++++++++++++++++++++++++++++++ litmus.php | 5 +++ 6 files changed, 152 insertions(+) create mode 100644 .github/workflows/build.yml create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 carthage.sh create mode 100644 litmus.php diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..f5a4cbe --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,25 @@ +# Copyright (c) Alexandre Gomes Gaigalas +# SPDX-License-Identifier: ISC + +name: CI + +on: + push: + branches: + - "main" + pull_request: + branches: + - "main" + +jobs: + Build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - run: sudo sh -c "echo ':APE:M::MZqFpD::/usr/bin/ape:' >/proc/sys/fs/binfmt_misc/register" + - run: sh carthage.sh + - uses: actions/upload-artifact@v3 + with: + name: target_bin + path: target/bin/** + diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..8ad66fa --- /dev/null +++ b/.gitignore @@ -0,0 +1,6 @@ +cosmocc +ph7 +php +target +*.zip +*.gz diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..15e89f5 --- /dev/null +++ b/LICENSE @@ -0,0 +1,15 @@ +ISC License + +Copyright (c) 2024 Alexandre Gomes Gaigalas + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted, provided that the above +copyright notice and this permission notice appear in all copies. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..7898519 --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +🐘 carthage +============ + +carthage uses the [cosmopolitan libc][cosmo] to build [αcτµαlly pδrταblε][ape] PHP executables. + +We offer two flavors: + + - The latest official [PHP][php], compiled barebones (`--disable-all`) **~13MB ape** + - The embedded [PH7](PH7) engine. **~2MB ape** + +Please note that _BOTH BUILDS ARE EXPERIMENTAL_. + +### Building Locally + +You'll need wget, unzip and make. Then: + +``` +sh carthage.sh +``` + +### Binary Releases + +Unavailable for now. If you need it, please open an issue. + +[php]: http://www.php.net +[PH7]: https://ph7.symisc.net/ +[ape]: https://justine.lol/ape.html +[cosmo]:https://justine.lol/cosmopolitan/ diff --git a/carthage.sh b/carthage.sh new file mode 100644 index 0000000..f028e7b --- /dev/null +++ b/carthage.sh @@ -0,0 +1,73 @@ +#!/usr/bin/env sh +# Copyright (c) Alexandre Gomes Gaigalas +# SPDX-License-Identifier: ISC + +if ! test -f cosmocc.zip +then wget https://cosmo.zip/pub/cosmocc/cosmocc.zip +fi + +if ! test -f php-8.3.9.tar.gz +then wget https://www.php.net/distributions/php-8.3.9.tar.gz +fi + +if ! test -f ph7.zip +then wget -O ph7.zip https://github.com/alganet/PH7/archive/refs/heads/master.zip +fi + +if ! test -d cosmocc +then + mkdir cosmocc + cd cosmocc + unzip ../cosmocc.zip + cd .. +fi + +if ! test -d php +then + mkdir php + cd php + tar --extract --strip-components=1 --file ../php-8.3.9.tar.gz + cd .. +fi + +if ! test -d ph7 +then + mkdir ph7 + cd ph7 + unzip ../ph7.zip + mv PH7-master/* . + rm -rf PH7-master + cd .. +fi + +set -x + +mkdir -p target +export PATH="$PWD/cosmocc/bin:$PATH" +export CC="cosmocc -I$PWD/cosmocc/include -L$PWD/cosmocc/lib" +export CXX="cosmoc++ -I$PWD/cosmocc/include -L$PWD/cosmocc/lib" +export PKG_CONFIG="pkg-config --with-path=$PWD/cosmocc/lib/pkgconfig" +export INSTALL="cosmoinstall" +export AR="cosmoar" + +if ! test -f target/bin/ph7 +then + cd ph7 + $CC -o ph7 ph7.c examples/ph7_interp.c -W -Wunused -Wall -I. + install -c -m 755 ph7 ../target/bin/ph7-2.1.4 + ../target/bin/ph7-2.1.4 ../litmus.php +cd .. +fi + +if ! test -f target/bin/php +then + cd php + ./buildconf --force + ./configure --prefix=$PWD/../target --disable-all --disable-shared --disable-fiber-asm + make -j $(nproc) + make install-cli install-phpdbg + mv ../target/bin/php ../target/bin/php-8.3.9 + mv ../target/bin/phpdbg ../target/bin/phpdbg-8.3.9 + ../target/bin/php-8.3.9 ../litmus.php + cd .. +fi diff --git a/litmus.php b/litmus.php new file mode 100644 index 0000000..b3ee090 --- /dev/null +++ b/litmus.php @@ -0,0 +1,5 @@ + +# SPDX-License-Identifier: ISC + +echo "Welcome to PHP " . phpversion() . PHP_EOL;