File: generate-bindings

package info (click to toggle)
rust-pcap-sys 0.1.3-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 120 kB
  • sloc: sh: 33; makefile: 4
file content (39 lines) | stat: -rwxr-xr-x 1,250 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/env bash
set -eu

readonly DIR=$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )

readonly LIBPCAP_DIR="$DIR/libpcap"
if ! [ -f "$LIBPCAP_DIR/.git" ]; then
  git submodule update --init
fi

readonly PCAP_HEADER="$LIBPCAP_DIR/pcap.h"
readonly PCAP_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

bindgen \
    "$PCAP_HEADER" \
    --ctypes-prefix 'libc' \
    --raw-line 'extern crate libc;' \
    --raw-line '#[cfg(windows)] extern crate winapi;' \
    --raw-line 'pub use libc::FILE;' \
    --raw-line '#[cfg(unix)] pub use libc::{sockaddr, timeval};' \
    --raw-line '#[cfg(windows)] pub use winapi::shared::ws2def::SOCKADDR as sockaddr;' \
    --raw-line '#[cfg(windows)] pub use winapi::um::winsock2::timeval;' \
    --whitelist-function '^pcap_.*' \
    --whitelist-type '^pcap_.*' \
    --whitelist-var '^PCAP_.*' \
    --blacklist-type 'sockaddr' \
    --blacklist-type 'timeval' \
    --blacklist-type '__.*' \
    --blacklist-type 'FILE' \
    --blacklist-type 'fpos_t' \
    --distrust-clang-mangling \
    --no-layout-tests \
    -o "$PCAP_BINDINGS"