44// option. This file may not be copied, modified, or distributed
55// except according to those terms.
66
7- #![ expect( clippy:: unwrap_used, reason = "OK in build scripts." ) ]
8-
9- use std:: env;
10-
11- const BINDINGS : & str = "bindings.rs" ;
12-
13- #[ cfg( feature = "gecko" ) ]
14- fn clang_args ( ) -> Vec < String > {
15- use mozbuild:: { config:: BINDGEN_SYSTEM_FLAGS , TOPOBJDIR } ;
16-
17- let mut flags: Vec < String > = BINDGEN_SYSTEM_FLAGS . iter ( ) . map ( |s| s. to_string ( ) ) . collect ( ) ;
18-
19- flags. push ( String :: from ( "-include" ) ) ;
20- flags. push (
21- TOPOBJDIR
22- . join ( "dist" )
23- . join ( "include" )
24- . join ( "mozilla-config.h" )
25- . to_str ( )
26- . unwrap ( )
27- . to_string ( ) ,
28- ) ;
29- flags
30- }
31-
32- #[ cfg( not( feature = "gecko" ) ) ]
33- const fn clang_args ( ) -> Vec < String > {
34- Vec :: new ( )
35- }
36-
37- fn bindgen ( ) {
38- let target_os = env:: var ( "CARGO_CFG_TARGET_OS" ) . expect ( "CARGO_CFG_TARGET_OS was not set" ) ;
39-
40- // Platforms currently not supported.
41- //
42- // See <https://github.com/mozilla/mtu/issues/82>.
43- if matches ! ( target_os. as_str( ) , "ios" | "tvos" | "visionos" ) {
44- return ;
45- }
46-
47- if target_os == "windows" {
48- return ;
49- }
50-
51- let bindings = if matches ! ( target_os. as_str( ) , "linux" | "android" ) {
52- bindgen:: Builder :: default ( )
53- . header_contents ( "rtnetlink.h" , "#include <linux/rtnetlink.h>" )
54- // Only generate bindings for the following types
55- . allowlist_type ( "rtattr|rtmsg|ifinfomsg|nlmsghdr" )
56- } else {
57- bindgen:: Builder :: default ( )
58- . header_contents (
59- "route.h" ,
60- "#include <sys/types.h>\n #include <sys/socket.h>\n #include <net/route.h>\n #include <net/if.h>" ,
61- )
62- // Only generate bindings for the following types and items
63- . allowlist_type ( "rt_msghdr|rt_metrics|if_data" )
64- . allowlist_item ( "RTAX_MAX|RTM_GET|RTM_VERSION|RTA_DST|RTA_IFP" )
65- } ;
66-
67- let bindings = bindings
68- . clang_args ( clang_args ( ) )
69- // Tell cargo to invalidate the built crate whenever any of the
70- // included header files changed.
71- . parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks :: new ( ) ) )
72- // Constants should be generated as &CStr instead of &[u8].
73- . generate_cstr ( true )
74- // Always emit explicit padding fields.
75- . explicit_padding ( true )
76- // Default trait should be derived when possible
77- . derive_default ( true )
78- // Finish the builder and generate the bindings.
79- . generate ( )
80- // Unwrap the Result and panic on failure.
81- . expect ( "Unable to generate bindings" ) ;
82-
83- // Write the bindings to the $OUT_DIR/$BINDINGS file.
84- let out_path = std:: path:: PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) . join ( BINDINGS ) ;
85- bindings
86- . write_to_file ( out_path. clone ( ) )
87- . expect ( "Couldn't write bindings!" ) ;
88- println ! ( "cargo:rustc-env=BINDINGS={}" , out_path. display( ) ) ;
89- }
90-
917fn main ( ) {
92- // Setup cfg aliases
938 cfg_aliases:: cfg_aliases! {
949 bsd: {
9510 any(
@@ -100,6 +15,4 @@ fn main() {
10015 )
10116 }
10217 }
103-
104- bindgen ( ) ;
10518}
0 commit comments