blob: 9ee0e136f80dd441048095b05a1cc97cf8e70fcf [file] [log] [blame]
#!/bin/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.
#
# This script generates Rust bindings for the usb_bulk C++ library.
# 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"
ZEROCOPY_SYMS_REGEX="usb_descriptor_header|usb_(device|endpoint|interface)_descriptor"
# Generate annotations for the top of the generated source file.
readonly RAW_LINES="// 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.
// Generated by ${RELPATH} using $("${BINDGEN}" --version)
#![allow(dead_code)]
#![allow(non_camel_case_types)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
use zerocopy::{FromBytes, AsBytes, Unaligned};"
"${BINDGEN}" \
${SCRIPT_DIR}/usbdevfs_stub.h \
--disable-header-comment \
--raw-line "${RAW_LINES}" \
--with-derive-default \
--with-derive-custom-struct ${ZEROCOPY_SYMS_REGEX}=FromBytes \
--with-derive-custom-struct ${ZEROCOPY_SYMS_REGEX}=AsBytes \
--with-derive-custom-struct ${ZEROCOPY_SYMS_REGEX}=Unaligned \
--impl-debug \
--output src/usb_linux/usbdevice_fs.rs \
-- -I${FUCHSIA_DIR}/prebuilt/third_party/sysroot/linux/usr/include \