-
Notifications
You must be signed in to change notification settings - Fork 1
/
generate-bindings
44 lines (36 loc) · 1.12 KB
/
generate-bindings
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env bash
set -eu
readonly DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )
readonly LIBNET_DIR="$DIR/libnet"
if ! [ -f "$LIBNET_DIR/.git" ]; then
git submodule update --init
fi
readonly NET_HEADER="$LIBNET_DIR/libnet/include/libnet.h"
readonly NET_BINDINGS="$DIR/src/bindings.rs"
if ! command -v bindgen > /dev/null 2>&1; then
echo "bindgen must be installed" >&2
echo "to install: cargo install bindgen && rustup component add rustfmt-preview" >&2
exit 1
fi
if ! [ -f "$NET_HEADER" ]; then
cd "$LIBNET_DIR/libnet"
bash ../Prepare
bash ../Build
fi
bindgen \
"$NET_HEADER" \
--ctypes-prefix 'libc' \
--raw-line 'extern crate libc;' \
--raw-line 'pub use libc::FILE;' \
--raw-line '#[cfg(unix)] pub use libc::{sockaddr, timeval};' \
--whitelist-function '^libnet_.*' \
--whitelist-type '^libnet_.*' \
--whitelist-var '^LIBNET_.*'\
--blacklist-type 'sockaddr' \
--blacklist-type 'timeval' \
--blacklist-type '__.*' \
--blacklist-type 'FILE' \
--blacklist-type 'fpos_t' \
--distrust-clang-mangling \
--no-layout-tests \
-o "$NET_BINDINGS"