blob: 5cd0657362e35c28e4c6d5113c7da9f9b4e7ca10 [file] [log] [blame]
#!/bin/bash
# Copyright 2021 The Fuchsia Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
#
# This script generates Rust bindings for zstd.
# Determine paths for this script and its directory, and set $FUCHSIA_DIR.
readonly FULL_PATH="${BASH_SOURCE[0]}"
readonly SCRIPT_DIR="$(cd "$(dirname "${FULL_PATH}")" >/dev/null 2>&1 && pwd)"
source "${SCRIPT_DIR}/../../../../tools/devshell/lib/vars.sh"
set -eu
cd "${SCRIPT_DIR}"
readonly RELPATH="${FULL_PATH#${FUCHSIA_DIR}/}"
readonly BINDGEN="${PREBUILT_RUST_BINDGEN_DIR}/bindgen"
# Generate annotations for the top of the generated source file.
readonly RAW_LINES="// Copyright 2022 The Fuchsia Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// Generated by ${RELPATH} using $("${BINDGEN}" --version)"
# Flags copied from https://github.com/gyscos/zstd-rs/blob/master/zstd-safe/zstd-sys/update_bindings.sh.
readonly BINDGEN_FLAGS='--no-layout-tests --blacklist-type=max_align_t --size_t-is-usize --rustified-enum=.* --use-core'
readonly STD='_std'
"${BINDGEN}" $BINDGEN_FLAGS "${FUCHSIA_DIR}"/third_party/zstd/src/lib/zstd.h \
--raw-line "${RAW_LINES}" \
--allowlist-type "ZSTD_.*" \
--allowlist-function "ZSTD_.*" \
--allowlist-var "ZSTD_.*" \
--output src/bindings_zstd${STD}.rs \
-- \
-I "${FUCHSIA_DIR}"/third_party/zstd/src/lib
"${BINDGEN}" $BINDGEN_FLAGS "${FUCHSIA_DIR}"/third_party/zstd/src/lib/zdict.h \
--raw-line "${RAW_LINES}" \
--blocklist-type wchar_t \
--output src/bindings_zdict${STD}.rs \
-- \
-I "${FUCHSIA_DIR}"/third_party/zstd/src/lib