Skip to content

Commit

Permalink
Merge branch 'runners' into better-htr
Browse files Browse the repository at this point in the history
  • Loading branch information
eliminmax committed Apr 22, 2024
2 parents ee19257 + 31b2fa3 commit e207244
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 48 deletions.
34 changes: 33 additions & 1 deletion RUNNERS/common.sh
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
#shellcheck shell=bash
# SPDX-FileCopyrightText: 2024 Eli Array Minkoff
#
# SPDX-License-Identifier: GPL-3.0-only

# This is meant to be sourced by install-deps.sh and run-version.sh to ensure
# that some common variables and functions are defined properly, and the
# colortest/RUNNERS/bin directory exists.

# THESE FUNCTIONS ARE NOT MEANT TO HANDLE UNTRUSTED PARAMETERS!
# * They may pass along the parameters to executables to install software.
# * They may attempt to run commands as root.
# * They may try to download commands.

# bash array containing all implementations
# shellcheck disable=2034 # Shellcheck thinks that this is unused. It's not.
colortest_implementations=(
algol_68 awk babalang befunge bf c cobol cpp csharp d erlang fender forth
fortran go haskell java javascript kotlin lisp lua nim objective-c ocaml
Expand Down Expand Up @@ -70,16 +83,35 @@ apt_wrapper() {
fi
}

# non-interactively install rust tooling using rustup if needed
rustup_install() {
apt_wrapper cc gcc
apt_wrapper curl curl
if ! cmd_exists rustc; then
if ! cmd_exists rustup; then
# the rustup command from rustup.rs, with -s -- -y appended to make it
# non-interactive
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
fi
}

# takes a url as an argument, and downloads it unless the output already exists
wget_if() {
# substitute %NN with \xNN, then echo -e to process backslash escapes
# thanks to https://stackoverflow.com/a/6265305 for pointing me to that
local url_decoded
url_decoded="$(echo -e "${1//%/\\x}")"

# ${FOO##pattern}" greedily matches pattern at the start of FOO, removing
# the matching component.
# https://www.cyberciti.biz/tips/bash-shell-parameter-substitution-2.html
# This removes everything before the last slash in the url_decoded value
# and runs wget if it doesn't exist
if ! [ -f "${url_decoded##*/}" ]; then
apt_wrapper wget wget
wget "$1"
fi
}

# checks if command listed in first argument exists
# if not, invoke cargo with the remaining arguments to install it
cargo_wrapper() {
Expand Down
97 changes: 54 additions & 43 deletions RUNNERS/install-deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ x86-64_linux_asm_dependencies() {
# newer version of it, so for the sake of consistency, install the latest
# version of rustup for anything that uses rust
rust_dependencies() { rustup_install; }

# a couple which need to be installed from git with cargo
babalang_dependencies() {
cargo_wrapper babalang --git https://github.com/RocketRace/babalang
}

fender_dependencies() {
cargo_wrapper fender --git https://github.com/FenderLang/Fender
}
Expand All @@ -89,55 +91,66 @@ objective-c_dependencies() {
fi
}

# for those with hard-coded versions to download, store them here to make it
# easier to change in the future

PWSH_V='7.4.2'
ODIN_V='dev-2024-01'
ROCKSTAR_COMMIT='c6c53db'
ZIG_V='0.12.0'
CFUNGE_V='1,001'

# we need to pull the source for the interpreter and build it locally
befunge_dependencies() {
# do nothing if cfunge is already in PATH
if cmd_exists cfunge; then return 0; fi
apt_wrapper cmake cmake
apt_wrapper make make
apt_wrapper cc gcc
apt_wrapper wget wget
apt_wrapper tar tar
apt_wrapper gzip gzip
pfx="$PWD"
mkdir -p .build/cfunge
pushd .build/cfunge &>/dev/null
wget https://github.com/VorpalBlade/cfunge/archive/refs/tags/1,001.tar.gz
tar xf 1,001.tar.gz
apt_wrapper tar tar # required in debian, check anyway just in case
apt_wrapper gzip gzip # required in debian, check anyway just in case

# split the second half of the URL into a var to fit within 80 columns
local asset_path
asset_path="archive/refs/tags/$CFUNGE_V.tar.gz"
wget_if "https://github.com/VorpalBlade/cfunge/$asset_path"

# create local install prefix at colortest/RUNNERS/cfunge
local pfx
pfx="$PWD/cfunge"
mkdir -p cfunge

# extract source to cfunge_src directory
mkdir -p cfunge_src
pushd cfunge_src &>/dev/null
tar --strip-components=1 -xf "../$CFUNGE_V.tar.gz"

# install to the local install prefix
mkdir -p build
cd build
cmake ../cfunge-1-001 -DCMAKE_INSTALL_PREFIX="$pfx"
cmake ../ -DCMAKE_INSTALL_PREFIX="$pfx"
make
make install
popd &>/dev/null

# link into colortest/RUNNERS/bin
ln -s ../cfunge/bin/cfunge bin/cfunge
}

# compile the odin compiler
# the odin compiler must be run with an absolute path, and must be located in
# the odin directory, so also create a wrapper script to take care of that
# if needed
# compile the odin compiler and symlink it into the PATH
odin_dependencies() {
if cmd_exists odin-wrapper; then return 0; fi
apt_wrapper wget wget
apt_wrapper llvm llvm
if cmd_exists odin; then return 0; fi
apt_wrapper llvm-as llvm
apt_wrapper clang clang
mkdir -p .build/odin
# download and compile Odin
pushd .build/odin &>/dev/null
wget https://github.com/odin-lang/Odin/archive/refs/tags/dev-2024-01.tar.gz
tar xf dev-2024-01.tar.gz
mv Odin-dev-2024-01 ../../odin
cd ../../odin
# download and compile Odin version
wget_if "https://github.com/odin-lang/Odin/archive/refs/tags/$ODIN_V.tar.gz" \
-O "Odin-$ODIN_V.tar.gz"
mkdir -p odin
pushd odin &>/dev/null
tar --strip-components=1 -xf "../Odin-$ODIN_V.tar.gz"
./build_odin.sh
popd &>/dev/null
# create the odin-wrapper script, if needed
cat >bin/odin-wrapper <<EOF
#!/bin/sh
thisdir="\$(dirname "\$(realpath "\$0")")"
odin_path="\$(realpath "\$thisdir/../odin/")"
exec "\$odin_path/odin" "\$@"
EOF
chmod +x bin/odin-wrapper
ln -s ../odin/odin bin/odin
}

# the rockstar reference implementation, satriani, must be run with the cwd set
Expand All @@ -153,7 +166,7 @@ rockstar_dependencies() {
git clone https://github.com/RockstarLang/rockstar
pushd rockstar/satriani &>/dev/null
# switch to a commit where the following sed command is known to work
git checkout 'c6c53db'
git checkout "$ROCKSTAR_COMMIT"
# use this sed command to comment out the annoying line
sed -i '/program returned no output/s#^#//#' rockstar.js
# install dependencies and build the language grammer with pegjs
Expand Down Expand Up @@ -185,9 +198,8 @@ powershell_dependencies() {
# do nothing if pwsh is already in PATH
if cmd_exists pwsh; then return 0; fi
# packages needed to download and extract PowerShell's archive
apt_wrapper gzip gzip
apt_wrapper tar tar
apt_wrapper wget wget
apt_wrapper gzip gzip # required in debian, check anyway just in case
apt_wrapper tar tar # required in debian, check anyway just in case
# PowerShell needs a bunch of libs, all but one of which start with "lib"
for lib in c6 gcc-s1 gssapi-krb5-2 icu72 ssl3 stdc++6; do
if ! dpkg --list "lib$lib" &>/dev/null; then
Expand All @@ -202,10 +214,10 @@ powershell_dependencies() {
mkdir -p powershell
pushd powershell &>/dev/null
# split the second half of the URL into a var to fit within 80 columns
asset_path='download/v7.4.2/powershell-7.4.2-linux-x64.tar.gz'
wget "https://github.com/PowerShell/PowerShell/releases/$asset_path"
unset asset_path
tar -xzf powershell-7.4.2-linux-x64.tar.gz
local asset_path
asset_path="download/v$PWSH_V/powershell-$PWSH_V-linux-x64.tar.gz"
wget_if "https://github.com/PowerShell/PowerShell/releases/$asset_path"
tar -xzf "powershell-$PWSH_V-linux-x64.tar.gz"
# link powershell within the bin directory
cd ../bin
ln -s ../powershell/pwsh pwsh
Expand All @@ -217,13 +229,12 @@ zig_dependencies() {
# do nothing if zig is already in PATH
if cmd_exists zig; then return 0; fi
# packages needed to download and extract Zig's archive
apt_wrapper tar tar
apt_wrapper wget wget
apt_wrapper tar tar # required in debian, check anyway just in case
apt_wrapper xz xz-utils
mkdir -p zig
pushd zig &>/dev/null
wget https://ziglang.org/download/0.12.0/zig-linux-x86_64-0.12.0.tar.xz
tar --strip-components=1 -xJf zig-linux-x86_64-0.12.0.tar.xz
wget_if "https://ziglang.org/download/$ZIG_V/zig-linux-x86_64-$ZIG_V.tar.xz"
tar --strip-components=1 -xJf "zig-linux-x86_64-$ZIG_V.tar.xz"
cd ../bin
ln -s ../zig/zig zig
popd &>/dev/null
Expand Down
12 changes: 8 additions & 4 deletions RUNNERS/run-version.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,15 @@

set -eo pipefail

# go to the colortest directory
cd "$(dirname "$(realpath "$0")")/.."

# load the common functions from install-deps.sh
source RUNNERS/common.sh
# the reason for the order of the below few commands is that shellcheck doesn't
# understand that RUNNERS/common.sh sourced from the colortest directory and
# common.sh sourced from the colortest/RUNNERS directory are one and the same.

# cd to colortest/RUNNERS directory to source common.sh, then go to colortest
cd "$(dirname "$(realpath "$0")")"
source common.sh
cd ..


# Utility function to compile an implementation if a colortest binary is not
Expand Down

0 comments on commit e207244

Please sign in to comment.