# FIXME: The rust build template fails mysteriously with the following error:
#
# clang diag: cpp/Test.h:3:9: warning: #pragma once in main file [-Wpragma-once-outside-header]
# thread 'main' panicked at bindgen-integration/build.rs:242:10:                                                             
# Unable to generate bindings: Codegen(Serialize { msg: "Cannot serialize type kind Opaque", loc: "/usr/lib/clang/17/include/stdarg.h:14:27" })                                                                                                           

abinfo "Building rust-bindgen ..."
cargo build \
    --release \
    --locked

abinfo "Installing rust-bindgen ..."
install -Dvm755 "$SRCDIR"/target/release/bindgen \
    "$PKGDIR"/usr/bin/bindgen

# From Arch Linux.
mkdir -pv "$SRCDIR"/completions
"$SRCDIR"/target/release/bindgen \
    --generate-shell-completions bash \
    > "$SRCDIR"/completions/bindgen
"$SRCDIR"/target/release/bindgen \
    --generate-shell-completions fish \
    > "$SRCDIR"/completions/bindgen.fish
"$SRCDIR"/target/release/bindgen \
    --generate-shell-completions zsh \
    > "$SRCDIR"/completions/_bindgen

abinfo "Installing shell completions ..."
install -Dvm644 "$SRCDIR"/completions/bindgen \
    "$PKGDIR"/usr/share/bash-completion/completions/bindgen
install -Dvm644 "$SRCDIR"/completions/bindgen.fish \
    "$PKGDIR"/usr/share/fish/vendor_completions.d/bindgen.fish
install -Dvm644 "$SRCDIR"/completions/_bindgen \
    "$PKGDIR"/usr/share/zsh/site-functions/_bindgen
