examples/bzip2/ is a self-contained Lake project that uses musubu as a build-time binding generator for libbz2 — analogous to the rust-bindgen bzip2 tutorial. Also updates lake-manifest.json to lean-libclang rev 022136d7 which fixes isFromMainFile for macro-argument function names (BZ_API pattern), required so musubu can see functions declared via BZ_API() in bzlib.h.
51 lines
1.7 KiB
Makefile
51 lines
1.7 KiB
Makefile
_default:
|
|
@just --list
|
|
|
|
# Build the library and executable
|
|
build:
|
|
lake build
|
|
|
|
# Run the musubu executable (pass args after --)
|
|
# LD_LIBRARY_PATH ensures libLLVM is found at runtime on systems where the
|
|
# Lean/Nix toolchain linker doesn't resolve /usr/lib via rpath automatically.
|
|
run *args:
|
|
LD_LIBRARY_PATH=/usr/lib lake exe musubu {{args}}
|
|
|
|
# Fetch SDL3 source into vendor/SDL (used to get headers for parsing)
|
|
fetch-sdl3:
|
|
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
SDL3_REV="f3a9f66292d49322652be01ee93412d0e9b74f0b"
|
|
DEST="vendor/SDL"
|
|
if [ -d "$DEST" ]; then
|
|
echo "vendor/SDL already exists, skipping"
|
|
else
|
|
mkdir -p vendor
|
|
git clone --single-branch --depth 1 \
|
|
"https://github.com/libsdl-org/SDL.git" "$DEST"
|
|
cd "$DEST" && git fetch --depth 1 origin "$SDL3_REV" && git checkout "$SDL3_REV"
|
|
fi
|
|
|
|
# Parse an SDL3 header and dump the IR (requires: just fetch-sdl3 first)
|
|
dump-ir header="vendor/SDL/include/SDL3/SDL_init.h":
|
|
LD_LIBRARY_PATH=/usr/lib lake exe musubu --dump-ir -I vendor/SDL/include {{header}}
|
|
|
|
# Generate Lean + C glue for an SDL3 header (outputs to gen/)
|
|
gen header="vendor/SDL/include/SDL3/SDL_init.h":
|
|
mkdir -p gen
|
|
LD_LIBRARY_PATH=/usr/lib lake exe musubu --prefix SDL_ -I vendor/SDL/include \
|
|
--out-lean gen/$(basename {{header}} .h).lean \
|
|
--out-c gen/$(basename {{header}} .h)_glue.c \
|
|
{{header}}
|
|
|
|
# Compile a previously generated C glue file
|
|
compile-glue file="gen/sdl_init_glue.c":
|
|
clang -c {{file}} \
|
|
-I$(lean --print-prefix)/include \
|
|
-Ivendor/SDL/include \
|
|
-o {{file}}.o
|
|
|
|
# Build and run the bzip2 example project (proof-of-concept for musubu as a build step)
|
|
example-bzip2: build
|
|
cd examples/bzip2 && just run
|