mirror of
https://github.com/engineer-man/piston.git
synced 2025-04-20 20:16:26 +02:00
BREAKING: replace custom build scripts with nix
General: - Switched to yarn to better work with nix-based tooling - Switched package system to use nix. This stops double dependencies and slow cloud compile times, while providing more compile/runtime support to the Nix project - Removed container builder in favor of internal container tooling - Package versions no-longer need to be SemVer compliant - Removed "piston package spec" files, replaced with nix-flake based runtimes - Exported nosocket and piston-api as packages within the nix-flake - Removed repo container - Switched docker building to nix-based container outputting - Removed docker compose as this is a single container - Removed package commands from CLI Packages: - Move bash, clojure, cobol, node, python2, python3 to new format - Remainder of packages still need to be moved v2 API: - Removed "version" specifier. To select specific versions, use the v3 api - Removed "/package" endpoints as this doesn't work with the new nix-based system v3 API: - Duplicate of v2 API, except instead of passing in a language name an ID is used intead.
This commit is contained in:
parent
e06b59d82c
commit
564da5a7eb
110 changed files with 2293 additions and 2793 deletions
65
runtimes/.scaffold.nix
Normal file
65
runtimes/.scaffold.nix
Normal file
|
@ -0,0 +1,65 @@
|
|||
{pkgs, piston, ...}:
|
||||
let
|
||||
# Put your package here, preferibly from nixpkgs.
|
||||
pkg = pkgs.%RUNTIME%; # this may be incorrect - it is guessed
|
||||
in piston.mkRuntime {
|
||||
# Name of the language implemented by this runtime
|
||||
language = "%LANGUAGE%";
|
||||
|
||||
# The version of the language
|
||||
# Usually this is specified on the package
|
||||
version = pkg.version;
|
||||
|
||||
# Name of the runtime
|
||||
# This line should be kept if the runtime differs from the language
|
||||
runtime = "%RUNTIME%";
|
||||
|
||||
aliases = [
|
||||
# Put extensions in here, and other common names
|
||||
# Example:
|
||||
# "js"
|
||||
# "node-javascript"
|
||||
];
|
||||
|
||||
|
||||
|
||||
# This is the lines of a shell script to compile source code.
|
||||
# Arguments passed to this script are all the provided source files
|
||||
# The CWD of this script is a temp directory for a job
|
||||
#
|
||||
# If the language only supports JIT compiling, simply remove this line
|
||||
# See ./python3.nix and ./node-javascript.nix for examples
|
||||
#
|
||||
# No shebang needs to be added to this - that is done automatically.
|
||||
compile = ''
|
||||
${pkg}/bin/%RUNTIME% --compile "$@"
|
||||
'';
|
||||
|
||||
# This is the lines of a shell script to evaluate a file at $1
|
||||
# The remaining arguments are the arguments to launch the application with
|
||||
# The CWD of this script is a temp directory for a job
|
||||
#
|
||||
# If the compile stage is used, $1 still contains the name of the source file.
|
||||
# It is up to your script to determine the filename of the emitted binary
|
||||
#
|
||||
# No shebang needs to be added to this - that is done automatically.
|
||||
run = ''
|
||||
${pkg}/bin/%RUNTIME% "$@"
|
||||
'';
|
||||
|
||||
# Specify a list of tests.
|
||||
# These should output "OK" to STDOUT if everything looks good
|
||||
tests = [
|
||||
(piston.mkTest {
|
||||
files = {
|
||||
"test.js" = ''
|
||||
console.log("OK");
|
||||
'';
|
||||
};
|
||||
args = [];
|
||||
stdin = "";
|
||||
packages = [];
|
||||
main = "test.js";
|
||||
})
|
||||
];
|
||||
}
|
28
runtimes/bash.nix
Normal file
28
runtimes/bash.nix
Normal file
|
@ -0,0 +1,28 @@
|
|||
{pkgs, piston, ...}:
|
||||
let
|
||||
pkg = pkgs.bash;
|
||||
in piston.mkRuntime {
|
||||
language = "bash";
|
||||
|
||||
version = pkg.version;
|
||||
|
||||
runtime = "bash";
|
||||
|
||||
aliases = [
|
||||
"sh"
|
||||
];
|
||||
|
||||
run = ''
|
||||
${pkg}/bin/bash "$@"
|
||||
'';
|
||||
|
||||
tests = [
|
||||
(piston.mkTest {
|
||||
files = {
|
||||
"test.sh" = ''
|
||||
echo OK
|
||||
'';
|
||||
};
|
||||
})
|
||||
];
|
||||
}
|
29
runtimes/clojure.nix
Normal file
29
runtimes/clojure.nix
Normal file
|
@ -0,0 +1,29 @@
|
|||
{pkgs, piston, ...}:
|
||||
let
|
||||
pkg = pkgs.clojure;
|
||||
in piston.mkRuntime {
|
||||
language = "clojure";
|
||||
version = pkg.version + ""; #Clojure has X.X.X.X versioning, we want X.X.X
|
||||
|
||||
aliases = [
|
||||
"clj"
|
||||
];
|
||||
|
||||
run = ''
|
||||
${pkg}/bin/clojure "$@"
|
||||
'';
|
||||
|
||||
tests = [
|
||||
(piston.mkTest {
|
||||
files = {
|
||||
"test.clj" = ''
|
||||
(ns clojure.examples.main
|
||||
(:gen-class))
|
||||
(defn main []
|
||||
(println "OK"))
|
||||
(main)
|
||||
'';
|
||||
};
|
||||
})
|
||||
];
|
||||
}
|
39
runtimes/cobol-gnu-cobol.nix
Normal file
39
runtimes/cobol-gnu-cobol.nix
Normal file
|
@ -0,0 +1,39 @@
|
|||
{pkgs, piston, ...}:
|
||||
let
|
||||
pkg = pkgs.gnu-cobol;
|
||||
in piston.mkRuntime {
|
||||
language = "cobol";
|
||||
version = pkg.version;
|
||||
runtime = "gnu-cobol";
|
||||
|
||||
aliases = [
|
||||
"cob"
|
||||
];
|
||||
|
||||
compile = ''
|
||||
${pkg}/bin/cobc -o binary --free -x -L lib "$@"
|
||||
chmod +x binary
|
||||
'';
|
||||
|
||||
run = ''
|
||||
shift
|
||||
./binary "$@"
|
||||
'';
|
||||
|
||||
tests = [
|
||||
(piston.mkTest {
|
||||
files = {
|
||||
"test.cob" = ''
|
||||
*> Test Program
|
||||
identification division.
|
||||
program-id. ok-test.
|
||||
|
||||
procedure division.
|
||||
display "OK"
|
||||
goback.
|
||||
end program ok-test.
|
||||
'';
|
||||
};
|
||||
})
|
||||
];
|
||||
}
|
8
runtimes/default.nix
Normal file
8
runtimes/default.nix
Normal file
|
@ -0,0 +1,8 @@
|
|||
args: {
|
||||
"node-javascript" = import ./node-javascript.nix args;
|
||||
"python2" = import ./python2.nix args;
|
||||
"python3" = import ./python3.nix args;
|
||||
"bash" = import ./bash.nix args;
|
||||
"clojure" = import ./clojure.nix args;
|
||||
"cobol-gnu-cobol" = import ./cobol-gnu-cobol.nix args;
|
||||
}
|
28
runtimes/node-javascript.nix
Normal file
28
runtimes/node-javascript.nix
Normal file
|
@ -0,0 +1,28 @@
|
|||
{pkgs, piston, ...}:
|
||||
let
|
||||
pkg = pkgs.nodejs;
|
||||
in piston.mkRuntime {
|
||||
language = "javascript";
|
||||
version = pkg.version;
|
||||
runtime = "node";
|
||||
|
||||
aliases = [
|
||||
"node-js"
|
||||
"node-javascript"
|
||||
"js"
|
||||
];
|
||||
|
||||
run = ''
|
||||
${pkg}/bin/node "$@"
|
||||
'';
|
||||
|
||||
tests = [
|
||||
(piston.mkTest {
|
||||
files = {
|
||||
"test.js" = ''
|
||||
console.log("OK");
|
||||
'';
|
||||
};
|
||||
})
|
||||
];
|
||||
}
|
25
runtimes/python2.nix
Normal file
25
runtimes/python2.nix
Normal file
|
@ -0,0 +1,25 @@
|
|||
{pkgs, piston, ...}:
|
||||
let
|
||||
pkg = pkgs.python2;
|
||||
in piston.mkRuntime {
|
||||
language = "python2";
|
||||
version = pkg.version;
|
||||
|
||||
aliases = [
|
||||
"py2"
|
||||
];
|
||||
|
||||
run = ''
|
||||
${pkg}/bin/python2 "$@"
|
||||
'';
|
||||
|
||||
tests = [
|
||||
(piston.mkTest {
|
||||
files = {
|
||||
"test.py" = ''
|
||||
print "OK"
|
||||
'';
|
||||
};
|
||||
})
|
||||
];
|
||||
}
|
26
runtimes/python3.nix
Normal file
26
runtimes/python3.nix
Normal file
|
@ -0,0 +1,26 @@
|
|||
{pkgs, piston, ...}:
|
||||
let
|
||||
pkg = pkgs.python3;
|
||||
in piston.mkRuntime {
|
||||
language = "python3";
|
||||
version = pkg.version;
|
||||
|
||||
aliases = [
|
||||
"py3"
|
||||
"py"
|
||||
];
|
||||
|
||||
run = ''
|
||||
${pkg}/bin/python3 "$@"
|
||||
'';
|
||||
|
||||
tests = [
|
||||
(piston.mkTest {
|
||||
files = {
|
||||
"test.py" = ''
|
||||
print("OK")
|
||||
'';
|
||||
};
|
||||
})
|
||||
];
|
||||
}
|
37
runtimes/scaffold.sh
Executable file
37
runtimes/scaffold.sh
Executable file
|
@ -0,0 +1,37 @@
|
|||
#!/usr/bin/env sh
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
echo "Usage: $0 <language name> [runtime name]"
|
||||
echo
|
||||
echo "language name: The name of the language to add, e.g. javascript"
|
||||
echo "runtime name: The name of the runtime to add, e.g. node"
|
||||
echo " In most cases runtime won't be required, e.g. python3 is both a language and runtime"
|
||||
exit 1;
|
||||
fi
|
||||
|
||||
LANGUAGE=$1
|
||||
RUNTIME=$1
|
||||
NAME=$1
|
||||
|
||||
if [[ $# -eq 2 ]]; then
|
||||
RUNTIME=$2
|
||||
NAME=$LANGUAGE-$RUNTIME
|
||||
fi
|
||||
|
||||
|
||||
if grep "./$NAME.nix" default.nix > /dev/null; then
|
||||
echo "ERROR: $NAME already exists"
|
||||
echo "Remove it from default.nix and retry if this is intended"
|
||||
exit 1
|
||||
else
|
||||
sed -i '$d' default.nix
|
||||
echo " \"$NAME\" = import ./$NAME.nix args;" >> default.nix
|
||||
sed -e 's/%LANGUAGE%/'"$LANGUAGE"'/g' \
|
||||
-e 's/%RUNTIME%/'"$RUNTIME"'/g' \
|
||||
.scaffold.nix > $NAME.nix
|
||||
git add $NAME.nix
|
||||
echo "}" >> default.nix
|
||||
|
||||
echo "Scaffolded $NAME"
|
||||
echo "Edit $NAME.nix to get started"
|
||||
fi
|
Loading…
Add table
Add a link
Reference in a new issue