| #!/usr/bin/env fuchsia-vendored-python |
| # |
| # Copyright 2026 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. |
| |
| import os |
| import sys |
| |
| # Add //build/rust to Python path so bindgen import works. |
| FUCHSIA_DIR = os.environ.get( |
| "FUCHSIA_DIR", |
| os.path.join(os.path.dirname(__file__), "..", "..", "..", ".."), |
| ) |
| sys.path.append(os.path.join(FUCHSIA_DIR, "build", "rust")) |
| |
| from bindgen import Bindgen |
| |
| RELATIVE_SCRIPT_PATH = os.path.relpath(__file__, FUCHSIA_DIR) |
| |
| MODULE_DOC_COMMENT = f""" |
| //! WARNING - This file was auto generated by //{RELATIVE_SCRIPT_PATH}. |
| //! Do not modify this file. To re-generate, run the following command from the root of |
| //! your Fuchsia checkout: |
| //! |
| //! ./{RELATIVE_SCRIPT_PATH} |
| """ |
| |
| RAW_LINES = ( |
| MODULE_DOC_COMMENT |
| + """ |
| |
| use zerocopy::{Immutable, IntoBytes}; |
| |
| """ |
| ) |
| |
| INCLUDE_DIRS = [ |
| "zircon/system/public", |
| ] |
| |
| # Additional traits that should be added to types matching the regexps. |
| AUTO_DERIVE_TRAITS = [ |
| ( |
| r"Elf64_[EP]hdr", |
| ["Immutable", "IntoBytes"], |
| ), |
| ] |
| |
| FUNCTION_ALLOWLIST = [ |
| "elf_search_wrapper", |
| ] |
| |
| INPUT_FILE = "src/lib/elf-search/rust/src/wrapper.h" |
| OUTPUT_FILE = "src/lib/elf-search/rust/src/sys.rs" |
| |
| bindgen = Bindgen() |
| bindgen.set_auto_derive_traits(AUTO_DERIVE_TRAITS) |
| bindgen.function_allowlist = FUNCTION_ALLOWLIST |
| bindgen.include_dirs = INCLUDE_DIRS |
| bindgen.raw_lines = RAW_LINES |
| |
| bindgen.run(INPUT_FILE, OUTPUT_FILE) |