| #!/usr/bin/env bash | |
| # | |
| # Copyright 2023 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. | |
| # Run this script whenever the $source_file has changed. | |
| # TODO(https://fxbug.dev/42153476): replace this script with a GN bindgen target when there | |
| # is in-tree support. | |
| set -eo pipefail | |
| # 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" | |
| readonly BINDGEN="${PREBUILT_RUST_BINDGEN_DIR}/bindgen" | |
| readonly ZEROCOPY_SYMS_REGEX="BlockFifo(Command|Request|Response)" | |
| readonly target_file="$FUCHSIA_DIR/src/storage/lib/block_protocol/src/fifo.rs" | |
| readonly source_file_within_tree="src/storage/lib/block_protocol/types.h" | |
| readonly source_file="$FUCHSIA_DIR/$source_file_within_tree" | |
| readonly copyright_line=$(grep -E "^// Copyright [0-9]+" "${source_file}" || \ | |
| echo "// Copyright $(date +%Y) The Fuchsia Authors. All rights reserved.") | |
| readonly RAW_LINES="${copyright_line} | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| // Generated by src/storage/lib/block_protocol/scripts/bindgen.sh | |
| // Run the above script whenever $source_file_within_tree | |
| // has changed. | |
| #![allow(dead_code)] | |
| #![allow(non_camel_case_types)] | |
| #![allow(non_snake_case)] | |
| #![allow(non_upper_case_globals)] | |
| use zerocopy::{FromBytes, Immutable, IntoBytes, KnownLayout};" | |
| "${BINDGEN}" \ | |
| --raw-line "${RAW_LINES}" \ | |
| --with-derive-default \ | |
| --with-derive-custom-struct=${ZEROCOPY_SYMS_REGEX}={FromBytes,Immutable,IntoBytes,KnownLayout} \ | |
| --impl-debug \ | |
| --allowlist-type=${ZEROCOPY_SYMS_REGEX} \ | |
| --output "${target_file}" \ | |
| "${source_file}" \ | |
| -- \ | |
| -x c++ \ | |
| -I${FUCHSIA_DIR}/zircon/system/public |