A Brainfuck interpreter written in Rust (zero dependencies, pure std), packaged
43
A Brainfuck interpreter written in Rust (zero dependencies, pure std), packaged as a minimal Docker image built entirely inside Docker. No Rust toolchain is needed on the host.
Semantics:
u8 cells., reads one byte from stdin; on EOF it sets the current cell to 0.. writes one byte to stdout. Stdout only ever contains program output.The first positional argument is the Brainfuck source:
docker run --rm looorent/hackmation-rust-brainfuck-cli \
'++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.'
# Hello World!
Program input for , comes from stdin (note -i):
echo -n 'hi' | docker run --rm -i looorent/hackmation-rust-brainfuck-cli ',[.,]'
# hi
Reading the program from a file instead of argv:
docker run --rm -v "$PWD:/w" looorent/hackmation-rust-brainfuck-cli -f /w/program.bf
Docker only. Compiling, testing, and packaging all happen inside the build. No rustup, no cargo, nothing installed on the host.
docker build -t looorent/hackmation-rust-brainfuck-cli .
The image name already carries the Docker Hub namespace, so pushing is:
docker login # once, as looorent
docker push looorent/hackmation-rust-brainfuck-cli:latest
For another registry, retag first, e.g.
docker tag looorent/hackmation-rust-brainfuck-cli ghcr.io/<owner>/hackmation-rust-brainfuck-cli:latest.
FROM scratch: it contains a single file, the binary.rust:1-alpine, where the host target is
*-unknown-linux-musl, so the binary is statically linked and needs no libc
at runtime. The target is never hardcoded, so the build works on amd64 and
arm64 alike.Cargo.toml minimizes binary size:
opt-level = "z", lto = true, codegen-units = 1, strip = true,
panic = "abort".Result: an image well under 1 MB.
Unit tests live in src/interpreter.rs and run inside Docker via the test
build stage:
docker build --target test --progress=plain .
Content type
Image
Digest
sha256:2b2916df3…
Size
196 kB
Last updated
about 2 months ago
docker pull looorent/hackmation-rust-brainfuck-cli