blob: 762d2473d97c4a99bebfd8480c89545b04ff8402 [file] [log] [blame]
#!/usr/bin/env fuchsia-vendored-python
#
# 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.
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
bindgen = 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}
"""
bindgen.raw_lines = (
MODULE_DOC_COMMENT
+ """
use zerocopy::{FromBytes, IntoBytes, Immutable, KnownLayout, TryFromBytes};
"""
)
bindgen.std_derives = [
"default",
]
bindgen.include_dirs = [
"sdk/lib/zxio/include",
"zircon/third_party/ulib/musl/include",
"zircon/system/public",
"third_party/llvm-libc/src/include/",
]
bindgen.enable_stdlib_include_dirs = False
bindgen.function_allowlist = ["zxio_.*"]
bindgen.var_allowlist = [
"ZXIO_SHUTDOWN.*",
"ZXIO_NODE_PROTOCOL.*",
"ZXIO_SEEK_ORIGIN.*",
"ZXIO_ALLOCATE.*",
"ZXIO_CREATION_MODE.*",
"ZXIO_SOCKET_MARK_DOMAIN.*",
"E[A-Z]*",
"AF_.*",
"SO.*",
"IP.*",
"MSG_.*",
"__bindgen_missing_.*",
]
bindgen.type_allowlist = [
"cmsghdr.*",
"in6_.*",
"sockaddr.*",
"timespec",
"timeval",
"zxio_socket_mark",
]
# NOTE: Types are matched against the following identifiers as regexes in the order they appear.
bindgen.set_auto_derive_traits(
[
(r"cmsghdr", ["FromBytes", "Immutable", "IntoBytes", "KnownLayout"]),
(
r"in_addr",
[
"PartialEq",
"Eq",
"IntoBytes",
"FromBytes",
"Immutable",
"KnownLayout",
],
),
(
r"in6_addr",
[
"IntoBytes",
"FromBytes",
"Immutable",
"KnownLayout",
],
),
(r"in6_pktinfo", ["IntoBytes, FromBytes", "Immutable", "KnownLayout"]),
(
r"sockaddr_in$",
[
"PartialEq",
"Eq",
"IntoBytes",
"FromBytes",
"Immutable",
"KnownLayout",
],
),
(r"sockaddr_in6", []),
(r"timespec", ["IntoBytes, FromBytes", "Immutable", "KnownLayout"]),
(r"timeval", ["IntoBytes, FromBytes", "Immutable", "KnownLayout"]),
(
r"zxio_socket_mark",
["TryFromBytes", "Immutable", "IntoBytes", "KnownLayout"],
),
],
)
bindgen.set_replacements(
[
# Remove __bindgen_missing from the start of constants defined in missing_includes.h
(r"const __bindgen_missing_([a-zA-Z_0-9]+)", "const \\1"),
],
)
bindgen.run(
"src/starnix/lib/syncio/wrapper.h",
"src/starnix/lib/syncio/src/zxio.rs",
)