die() {
echo "ERROR: $*"
exit 1
}
is_installed() {
type $1 > /dev/null 2>&1 || die "'$1' tool has not been found. Install it and try again"
}
is_installed bindgen
basedir=$(dirname $(readlink -f $0))/..
trap "rm -f $basedir/wrapper.h" EXIT
cat <<EOF > $basedir/wrapper.h
#include <archive.h>
#include <archive_entry.h>
EOF
bindgen \
--formatter none \
\
--raw-line "#![allow(non_camel_case_types)]" \
--raw-line "#[cfg(not(target_os = \"windows\"))]" \
--raw-line "use libc::stat;" \
--raw-line "#[cfg(target_os = \"windows\")]" \
--raw-line "use crate::stat;" \
--raw-line "pub const ARCHIVE_EOF: i32 = 1;" \
--raw-line "pub const ARCHIVE_OK: i32 = 0;" \
\
--allowlist-var "ARCHIVE_WARN" \
\
--allowlist-var "ARCHIVE_EXTRACT_TIME" \
--allowlist-var "ARCHIVE_EXTRACT_PERM" \
--allowlist-var "ARCHIVE_EXTRACT_ACL" \
--allowlist-var "ARCHIVE_EXTRACT_FFLAGS" \
--allowlist-var "ARCHIVE_EXTRACT_OWNER" \
--allowlist-var "ARCHIVE_EXTRACT_FFLAGS" \
--allowlist-var "ARCHIVE_EXTRACT_XATTR" \
--allowlist-var "ARCHIVE_FORMAT_BASE_MASK" \
--allowlist-var "ARCHIVE_FORMAT_MTREE" \
--allowlist-function "archive_format" \
--allowlist-function "archive_read_new" \
--allowlist-function "archive_read_set_seek_callback" \
--allowlist-function "archive_read_support_filter_all" \
--allowlist-function "archive_read_support_format_all" \
--allowlist-function "archive_read_support_format_raw" \
--allowlist-function "archive_read_close" \
--allowlist-function "archive_read_free" \
--allowlist-function "archive_read_data_block" \
--allowlist-function "archive_read_next_header" \
--allowlist-function "archive_read_open" \
--allowlist-function "archive_read_add_passphrase" \
--allowlist-function "archive_write_disk_new" \
--allowlist-function "archive_write_disk_set_options" \
--allowlist-function "archive_write_disk_set_standard_lookup" \
--allowlist-function "archive_write_header" \
--allowlist-function "archive_write_finish_entry" \
--allowlist-function "archive_write_data_block" \
--allowlist-function "archive_write_close" \
--allowlist-function "archive_write_free" \
--allowlist-function "archive_entry_pathname" \
--allowlist-function "archive_entry_free" \
--allowlist-function "archive_entry_set_pathname" \
--allowlist-function "archive_entry_set_hardlink" \
--allowlist-function "archive_entry_hardlink" \
--blocklist-type "stat" \
--blocklist-type "timespec" \
--allowlist-function "archive_entry_stat" \
--allowlist-function "archive_set_error" \
--allowlist-function "archive_error_string" \
--allowlist-function "archive_errno" \
\
--output $basedir/src/ffi/generated.rs \
\
$basedir/wrapper.h
sed -i 's,pub ,pub(crate) ,g' $basedir/src/ffi/generated.rs
cargo fmt --all