|
| 1 | +#!/usr/bin/env python3 |
| 2 | +import ament_index_python |
| 3 | +import os |
| 4 | +import subprocess |
| 5 | +import sys |
| 6 | + |
| 7 | +def main(): |
| 8 | + if len(sys.argv) != 4: |
| 9 | + print("Usage: generate_bindings.py <header_file> <ros_distribution> <output_directory>") |
| 10 | + sys.exit(1) |
| 11 | + |
| 12 | + header_file = sys.argv[1] |
| 13 | + ros_distribution = sys.argv[2] |
| 14 | + output_directory = sys.argv[3] |
| 15 | + bindgen_command = [] |
| 16 | + bindgen_command.append('bindgen') |
| 17 | + bindgen_command.append(header_file) |
| 18 | + bindgen_command.append('-o') |
| 19 | + bindgen_command.append(f'{output_directory}/rcl_bindings_generated_{ros_distribution}.rs') |
| 20 | + bindgen_command.append('--rust-edition') |
| 21 | + bindgen_command.append('2021') |
| 22 | + bindgen_command.append('--rust-target') |
| 23 | + bindgen_command.append('1.75') |
| 24 | + bindgen_command.append('--no-derive-copy') |
| 25 | + bindgen_command.append('--allowlist-type') |
| 26 | + bindgen_command.append('rcl_.*') |
| 27 | + bindgen_command.append('--allowlist-type') |
| 28 | + bindgen_command.append('rmw_.*') |
| 29 | + bindgen_command.append('--allowlist-type') |
| 30 | + bindgen_command.append('rcutils_.*') |
| 31 | + bindgen_command.append('--allowlist-type') |
| 32 | + bindgen_command.append('rosidl_.*') |
| 33 | + bindgen_command.append('--allowlist-function') |
| 34 | + bindgen_command.append('rcl_.*') |
| 35 | + bindgen_command.append('--allowlist-function') |
| 36 | + bindgen_command.append('rmw_.*') |
| 37 | + bindgen_command.append('--allowlist-function') |
| 38 | + bindgen_command.append('rcutils_.*') |
| 39 | + bindgen_command.append('--allowlist-function') |
| 40 | + bindgen_command.append('rosidl_.*') |
| 41 | + bindgen_command.append('--allowlist-var') |
| 42 | + bindgen_command.append('rcl_.*') |
| 43 | + bindgen_command.append('--allowlist-var') |
| 44 | + bindgen_command.append('rmw_.*') |
| 45 | + bindgen_command.append('--allowlist-var') |
| 46 | + bindgen_command.append('rcutils_.*') |
| 47 | + bindgen_command.append('--allowlist-var') |
| 48 | + bindgen_command.append('rosidl_.*') |
| 49 | + bindgen_command.append('--no-layout-tests') |
| 50 | + bindgen_command.append('--default-enum-style') |
| 51 | + bindgen_command.append('rust') |
| 52 | + bindgen_command.append('--') |
| 53 | + for package, prefix in ament_index_python.get_packages_with_prefixes().items(): |
| 54 | + package_include_dir = os.path.join(prefix, 'include', package) |
| 55 | + if os.path.isdir(package_include_dir): |
| 56 | + bindgen_command.append('-isystem') |
| 57 | + bindgen_command.append(package_include_dir) |
| 58 | + subprocess.run(bindgen_command) |
| 59 | + |
| 60 | +if __name__ == "__main__": |
| 61 | + main() |
0 commit comments