1
0

bindgen.sh 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env bash
  2. # Copyright 2022 The ChromiumOS Authors
  3. # Use of this source code is governed by a BSD-style license that can be
  4. # found in the LICENSE file.
  5. # Regenerate net_sys bindgen bindings.
  6. set -euo pipefail
  7. cd "$(dirname "${BASH_SOURCE[0]}")/.."
  8. source tools/impl/bindgen-common.sh
  9. # Replace definition of struct sockaddr with an import of libc::sockaddr.
  10. replace_sockaddr_libc() {
  11. # Match the following structure definition across multiple lines:
  12. #
  13. # #[repr(C)]
  14. # #[derive(Debug, Default, Copy, Clone)]
  15. # pub struct sockaddr {
  16. # pub sa_family: sa_family_t,
  17. # pub sa_data: [::std::os::raw::c_char; 14usize],
  18. # }
  19. sed -E \
  20. -e '1h;2,$H;$!d;g' \
  21. -e 's/#\[repr\(C\)\]\n#\[derive\([^)]+\)\]\npub struct sockaddr \{\n( pub [^\n]+\n)+\}/\nuse libc::sockaddr;\n/'
  22. }
  23. # Remove custom sa_family_t type in favor of libc::sa_family_t.
  24. remove_sa_family_t() {
  25. grep -v "pub type sa_family_t = "
  26. }
  27. bindgen_generate \
  28. --allowlist-type='ifreq' \
  29. --allowlist-type='net_device_flags' \
  30. --bitfield-enum='net_device_flags' \
  31. "${BINDGEN_LINUX_X86_HEADERS}/include/linux/if.h" \
  32. | replace_linux_int_types \
  33. | replace_sockaddr_libc \
  34. | remove_sa_family_t \
  35. | rustfmt \
  36. > net_sys/src/iff.rs
  37. bindgen_generate \
  38. --allowlist-type='sock_fprog' \
  39. --allowlist-var='TUN_.*' \
  40. --allowlist-var='IFF_NO_PI' \
  41. --allowlist-var='IFF_MULTI_QUEUE' \
  42. --allowlist-var='IFF_TAP' \
  43. --allowlist-var='IFF_VNET_HDR' \
  44. "${BINDGEN_LINUX}/include/uapi/linux/if_tun.h" \
  45. | replace_linux_int_types \
  46. > net_sys/src/if_tun.rs
  47. bindgen_generate \
  48. --allowlist-var='SIOC.*' \
  49. "${BINDGEN_LINUX}/include/uapi/linux/sockios.h" \
  50. | replace_linux_int_types \
  51. > net_sys/src/sockios.rs