Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
```

Expand Down
2 changes: 1 addition & 1 deletion GUIDE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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).
Expand Down
26 changes: 18 additions & 8 deletions docker/entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -56,23 +56,33 @@ 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 \\"
echo " ghcr.io/gregclermont/tinybpf-compile program.bpf.c"
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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion llms.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 2 additions & 3 deletions src/tinybpf/_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
Loading