-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdotfasm
More file actions
executable file
·99 lines (84 loc) · 1.96 KB
/
dotfasm
File metadata and controls
executable file
·99 lines (84 loc) · 1.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
#!/bin/bash
set -euo pipefail
IMAGE="${DOTFASM_IMAGE:-plojure-fasm-amd64:latest}"
usage() {
cat <<'USAGE'
Usage:
./dotfasm <file.asm> [output]
./dotfasm run <file.asm> [output]
./dotfasm shell
USAGE
}
ensure_image() {
if docker image inspect "$IMAGE" >/dev/null 2>&1; then
return
fi
echo "[dotfasm] Building local image $IMAGE (one-time setup)..."
docker rm -f plojure-fasm-bootstrap >/dev/null 2>&1 || true
docker run --name plojure-fasm-bootstrap --platform linux/amd64 debian:bookworm-slim \
bash -lc 'set -e; apt-get update >/dev/null; DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends fasm gcc libc6-dev python3 make bash ca-certificates >/dev/null'
docker commit plojure-fasm-bootstrap "$IMAGE" >/dev/null
docker rm -f plojure-fasm-bootstrap >/dev/null
}
if [[ $# -lt 1 ]]; then
usage
exit 1
fi
REPO_ROOT="$(git -C "$(pwd)" rev-parse --show-toplevel 2>/dev/null || true)"
if [[ -z "${REPO_ROOT}" ]]; then
echo "[dotfasm] Run from inside the repo."
exit 1
fi
WORKDIR="$(pwd)"
if [[ "$WORKDIR" == "$REPO_ROOT" ]]; then
CONTAINER_WD="/workspace"
else
CONTAINER_WD="/workspace/${WORKDIR#"$REPO_ROOT"/}"
fi
MODE="compile"
ASM=""
OUT=""
case "${1}" in
run)
MODE="run"
ASM="${2:-}"
OUT="${3:-}"
;;
shell)
ensure_image
exec docker run --rm -it --platform linux/amd64 \
-v "$REPO_ROOT:/workspace" \
-w "$CONTAINER_WD" \
"$IMAGE" bash
;;
-h|--help|help)
usage
exit 0
;;
*)
ASM="$1"
OUT="${2:-}"
;;
esac
if [[ -z "$ASM" ]]; then
usage
exit 1
fi
if [[ ! -f "$ASM" ]]; then
echo "[dotfasm] File not found: $ASM"
exit 1
fi
if [[ -z "$OUT" ]]; then
OUT="${ASM%.asm}"
fi
ensure_image
if [[ "$MODE" == "run" ]]; then
CMD="set -e; fasm '$ASM' '$OUT'; chmod +x '$OUT'; ./'$OUT'"
else
CMD="set -e; fasm '$ASM' '$OUT'"
fi
exec docker run --rm --platform linux/amd64 \
-v "$REPO_ROOT:/workspace" \
-w "$CONTAINER_WD" \
"$IMAGE" \
bash -lc "$CMD"