Langbot
Creating an image
- Install podman
- Build an image:
podman build -t langbot .
Running a language
Run podman run --rm -i langbot ./scripts/run.sh <language>
. It will read source code from stdin and execute it.
Adding your own language
- Create a directory
langs/yourlang/
. - Create a file
langs/yourlang/compile.sh
.- This file is responsible for downloading sources for, compiling and installing your programming language.
- It will be run using the command
bash -x -euo pipefail compile.sh
, in a temporary working directory which is populated with the content oflangs/yourlang
. - When downloading sources, always make sure that what you're downloading won't change. E.g with git, always
git checkout
a particular commit. - Install all build artifacts to the directory that's passed in as the
$DEPLOYDIR
environment variable. - When everything is done, run
touch "$DEPLOYDIR/.done"
as a final sanity check.
- Create a file
langs/yourlang/run.sh
.run.sh
is copied to the deployment directory (what was$DEPLOYDIR
incompile.sh
)- It will be run using the command
bash -euo pipefail run.sh
, in the deployment directory. It should read its source code from stdin, and do whatever is necessary to execute that code. - If everything goes okay, exit with exit code 0; if something goes wrong, exit with a non-zero exit code.
- You can assume that only one execution happens at a time, meaning you shouldn't worry about creating random file names for the input files.
- Add your language to the list in
scripts/compile-all.sh
to make it run as part of building the podman container.
In some cases, you may also need to add dependencies to the Containerfile
.
A simple example language you can take inspiration from is Osyris.
langs/osyris/compile.sh
is:
git clone https://github.com/mortie/osyris.git
cd osyris
git checkout 2db1f2c1746dbda2451d8cc888921a0f518aaf78
cargo build --release
cp target/release/osyris "$DEPLOYDIR"
touch "$DEPLOYDIR/.done"
And langs/osyris/run.sh
is:
cat >input.os
exec ./osyris input.os
Some development tips
- During development, it might help to remove all other languages than yours from the list of languages in
scripts/compile-all.sh
, so thatpodman build -t langbot .
only needs to run your language. - Don't be afraid to re-build the container; podman caches all the steps it can, so
podman build -t langbot .
doesn't start from scratch every time. - You may want to investigate the compiler interactively, which can be done with
podman run --rm -it langbot
. - In fact, I find it helpful to manually run my shell commands in an interactive container and write the
compile.sh
script by writing down my commands there as I go.