Skip to content

Commit

Permalink
First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
alganet committed Jul 7, 2024
0 parents commit dc919a5
Show file tree
Hide file tree
Showing 6 changed files with 158 additions and 0 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Copyright (c) Alexandre Gomes Gaigalas <[email protected]>
# 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: |
set -x
wget https://github.com/jart/cosmopolitan/raw/master/build/bootstrap/ape.elf
sudo cp ape.elf /usr/bin/ape
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/**

6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
cosmocc
ph7
php
target
*.zip
*.gz
15 changes: 15 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
ISC License

Copyright (c) 2024 Alexandre Gomes Gaigalas <[email protected]>

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.
28 changes: 28 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -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/
75 changes: 75 additions & 0 deletions carthage.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env sh
# Copyright (c) Alexandre Gomes Gaigalas <[email protected]>
# SPDX-License-Identifier: ISC

set -xeu

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/bin
export PATH="../cosmocc/bin:$PATH"
export CC="cosmocc -I../cosmocc/include -L../cosmocc/lib"
export CXX="cosmoc++ -I../cosmocc/include -L../cosmocc/lib"
export PKG_CONFIG="pkg-config --with-path=../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
5 changes: 5 additions & 0 deletions litmus.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?php
# Copyright (c) Alexandre Gomes Gaigalas <[email protected]>
# SPDX-License-Identifier: ISC

echo "Welcome to PHP " . phpversion() . PHP_EOL;

0 comments on commit dc919a5

Please sign in to comment.