From 22ad627c93f00caf56631a681e79c4f853cf9589 Mon Sep 17 00:00:00 2001 From: gregclermont <580609+gregclermont@users.noreply.github.com> Date: Fri, 23 Jan 2026 20:29:16 +0100 Subject: [PATCH] Fix docker-compile -o flag passed to docker instead of container The -o/--output flag was being placed before the image name in the docker run command, causing docker to interpret it as a docker flag rather than an argument for the container's entrypoint. Changes: - CLI: Place -o flag after image and sources - entrypoint.sh: Replace getopts with manual parsing to accept -o in any position (before or after sources) - Docs: Update examples to use more intuitive `src/*.bpf.c -o build/` ordering Fixes #60 Co-Authored-By: Claude Opus 4.5 --- DEVELOPMENT.md | 2 +- GUIDE.md | 2 +- docker/entrypoint.sh | 26 ++++++++++++++++++-------- llms.txt | 2 +- src/tinybpf/_cli.py | 5 ++--- 5 files changed, 23 insertions(+), 14 deletions(-) diff --git a/DEVELOPMENT.md b/DEVELOPMENT.md index f8db14f..d368d6a 100644 --- a/DEVELOPMENT.md +++ b/DEVELOPMENT.md @@ -150,7 +150,7 @@ tinybpf provides a Docker image for compiling eBPF programs. It bundles libbpf h make compile # Advanced: run docker directly (on Linux, or inside Lima shell on macOS) -docker run --rm -v $(pwd):/src ghcr.io/gregclermont/tinybpf-compile -o build/ src/*.bpf.c +docker run --rm -v $(pwd):/src ghcr.io/gregclermont/tinybpf-compile src/*.bpf.c -o build/ docker run --rm -v $(pwd):/src -e EXTRA_CFLAGS="-DDEBUG" ghcr.io/gregclermont/tinybpf-compile program.bpf.c ``` diff --git a/GUIDE.md b/GUIDE.md index 5cc1887..a667155 100644 --- a/GUIDE.md +++ b/GUIDE.md @@ -14,7 +14,7 @@ tinybpf docker-compile program.bpf.c tinybpf docker-compile src/*.bpf.c # Output to specific directory -tinybpf docker-compile -o build/ src/*.bpf.c +tinybpf docker-compile src/*.bpf.c -o build/ ``` The CLI uses a Docker image with libbpf headers and `vmlinux.h` (kernel 6.18) for CO-RE support. Output `.bpf.o` files are written alongside sources (or to the specified output directory). diff --git a/docker/entrypoint.sh b/docker/entrypoint.sh index d012a72..2df7884 100644 --- a/docker/entrypoint.sh +++ b/docker/entrypoint.sh @@ -56,7 +56,7 @@ if [ $# -eq 0 ]; then echo "" echo "Examples:" echo " docker run --rm -v \$(pwd):/src ghcr.io/gregclermont/tinybpf-compile program.bpf.c" - echo " docker run --rm -v \$(pwd):/src ghcr.io/gregclermont/tinybpf-compile -o build/ src/*.bpf.c" + echo " docker run --rm -v \$(pwd):/src ghcr.io/gregclermont/tinybpf-compile src/*.bpf.c -o build/" echo "" echo " # Use custom vmlinux.h for older kernel:" echo " docker run --rm -v \$(pwd):/src -v /path/to/vmlinux.h:/vmlinux.h -e VMLINUX=/vmlinux.h \\" @@ -64,15 +64,25 @@ if [ $# -eq 0 ]; then exit 0 fi -# Parse options +# Parse arguments (options can appear anywhere) OUTPUT_DIR="" -while getopts "o:" opt; do - case $opt in - o) OUTPUT_DIR="$OPTARG" ;; - *) exit 1 ;; +SOURCES=() +while [ $# -gt 0 ]; do + case "$1" in + -o) + if [ -z "$2" ]; then + echo "Error: -o requires an argument" >&2 + exit 1 + fi + OUTPUT_DIR="$2" + shift 2 + ;; + *) + SOURCES+=("$1") + shift + ;; esac done -shift $((OPTIND - 1)) # Create output directory if specified if [ -n "$OUTPUT_DIR" ]; then @@ -81,7 +91,7 @@ fi # Compile each source file FAILED=0 -for src in "$@"; do +for src in "${SOURCES[@]}"; do if [ ! -f "$src" ]; then echo "Error: File not found: $src" >&2 FAILED=1 diff --git a/llms.txt b/llms.txt index f281bd4..a3876c2 100644 --- a/llms.txt +++ b/llms.txt @@ -145,7 +145,7 @@ BtfKind.INT, STRUCT, UNION, ARRAY, PTR, TYPEDEF, FLOAT, ... # BTF type kinds ```bash tinybpf docker-compile program.bpf.c -tinybpf docker-compile -o build/ src/*.bpf.c +tinybpf docker-compile src/*.bpf.c -o build/ ``` Uses a Docker image with libbpf headers and vmlinux.h (kernel 6.18, x86_64/aarch64) for CO-RE support. Output `.bpf.o` files are written alongside sources or to specified output directory. diff --git a/src/tinybpf/_cli.py b/src/tinybpf/_cli.py index be1e02c..a3c93c8 100644 --- a/src/tinybpf/_cli.py +++ b/src/tinybpf/_cli.py @@ -52,15 +52,14 @@ def cmd_docker_compile(args: argparse.Namespace) -> int: "--rm", "-v", f"{cwd}:/src", + image_tag, + *args.sources, ] # Pass through output directory if specified if args.output: docker_cmd.extend(["-o", args.output]) - docker_cmd.append(image_tag) - docker_cmd.extend(args.sources) - if args.verbose: print(f"Running: {' '.join(docker_cmd)}", file=sys.stderr)