1- // use bindgen::Formatter;
2- // use regex::Regex;
3- // use std::env;
4- // use std::fs::File;
5- // use std::io::Write;
6- // use std::path::PathBuf;
1+ use bindgen:: Formatter ;
2+ use regex:: Regex ;
3+ use std:: env;
4+ use std:: fs:: File ;
5+ use std:: io:: Write ;
6+ use std:: path:: PathBuf ;
77
88fn main ( ) {
99 // To "fix" it not working on github and to reduce build requirements - this will not be called
1010 // in every build.
11- /*
1211 should_replace1 ( ) ;
1312 should_replace2 ( ) ;
1413
@@ -23,27 +22,27 @@ fn main() {
2322 . default_enum_style ( bindgen:: EnumVariation :: Rust {
2423 non_exhaustive : false ,
2524 } )
26- .allowlist_type("BWAPI::.*")
27- // .whitelist_type("BWAPI::.*GameTable")
28- // .whitelist_type("BWAPI::.*Enum")
25+ . allowlist_type ( "BWAPI::(GameTable|.*Enum|MouseButton|Key|UnitData|RegionData|GameData)" )
26+ . allowlist_type ( "BWAPIC::(UnitCommand|.*Enum)" )
2927 . ignore_methods ( )
3028 . ignore_functions ( )
3129 . opaque_type ( "std::.*" )
3230 . formatter ( Formatter :: Rustfmt )
3331 // .derive_default(true)
34- .derive_eq(true)
32+ // .derive_eq(true)
3533 . derive_hash ( true )
3634 // .disable_name_namespacing()
3735 // The input header we would like to generate
3836 // bindings for.
3937 . header ( "wrapper.h" )
38+ // .clang_arg("--target=i686-unknown-linux-gnu")
4039 // Finish the builder and generate the bindings.
4140 . generate ( )
4241 // Unwrap the Result and panic on failure.
4342 . expect ( "Unable to generate bindings" ) ;
4443
4544 // Write the bindings to the $OUT_DIR/bindings.rs file.
46- todo!("Target src/");
45+ // todo!("Target src/");
4746 let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
4847 let result = bindings. to_string ( ) ;
4948 let mut file = File :: create ( out_path. join ( "bindings.rs" ) ) . unwrap ( ) ;
@@ -52,29 +51,34 @@ fn main() {
5251 assert_ne ! ( changed, result, "Could not add FromPrimitive to bindings!" ) ;
5352 file. write_all ( changed. as_bytes ( ) )
5453 . expect ( "Couldn't write bindings!" ) ;
55- */
5654}
5755
58- // fn should_replace1() {
59- // // GIVEN
60- // let test = "# [ derive ( Debug , Copy , Clone , PartialEq , Eq , Hash ) ] pub enum std_deque__bindgen_ty_1";
56+ fn should_replace1 ( ) {
57+ // GIVEN
58+ let test = "# [ derive ( Debug , Copy , Clone , PartialEq , Eq , Hash ) ] pub enum std_deque__bindgen_ty_1" ;
6159
62- // // WHEN
63- // let re = Regex::new(r"#\s*\[\s*derive\s*\((?P<d>[^)]+)\)\s*\]\s*pub\s+enum").unwrap();
64- // let changed = re.replace_all(test, "#[derive($d, FromPrimitive)]\npub enum");
60+ // WHEN
61+ let re = Regex :: new ( r"#\s*\[\s*derive\s*\((?P<d>[^)]+)\)\s*\]\s*pub\s+enum" ) . unwrap ( ) ;
62+ let changed = re. replace_all ( test, "#[derive($d, FromPrimitive)]\n pub enum" ) ;
6563
66- // // THEN
67- // assert_eq!("#[derive( Debug , Copy , Clone , PartialEq , Eq , Hash , FromPrimitive)]\npub enum std_deque__bindgen_ty_1", changed);
68- // }
64+ // THEN
65+ assert_eq ! (
66+ "#[derive( Debug , Copy , Clone , PartialEq , Eq , Hash , FromPrimitive)]\n pub enum std_deque__bindgen_ty_1" ,
67+ changed
68+ ) ;
69+ }
6970
70- // fn should_replace2() {
71- // // GIVEN
72- // let test = "# [ derive ( Debug , Copy , Clone , PartialEq , Eq , Hash ) ] pub enum BWAPI_Text_Size_Enum # [ derive ( Debug , Copy , Clone , PartialEq , Eq , Hash ) ] pub enum BWAPIC_CommandType_Enum ";
71+ fn should_replace2 ( ) {
72+ // GIVEN
73+ let test = "# [ derive ( Debug , Copy , Clone , PartialEq , Eq , Hash ) ] pub enum BWAPI_Text_Size_Enum # [ derive ( Debug , Copy , Clone , PartialEq , Eq , Hash ) ] pub enum BWAPIC_CommandType_Enum " ;
7374
74- // // WHEN
75- // let re = Regex::new(r"#\s*\[\s*derive\s*\((?P<d>[^)]+)\)\s*\]\s*pub\s+enum").unwrap();
76- // let changed = re.replace_all(test, "#[derive($d, FromPrimitive)]\npub enum");
75+ // WHEN
76+ let re = Regex :: new ( r"#\s*\[\s*derive\s*\((?P<d>[^)]+)\)\s*\]\s*pub\s+enum" ) . unwrap ( ) ;
77+ let changed = re. replace_all ( test, "#[derive($d, FromPrimitive)]\n pub enum" ) ;
7778
78- // // THEN
79- // assert_eq!("#[derive( Debug , Copy , Clone , PartialEq , Eq , Hash , FromPrimitive)]\npub enum BWAPI_Text_Size_Enum #[derive( Debug , Copy , Clone , PartialEq , Eq , Hash , FromPrimitive)]\npub enum BWAPIC_CommandType_Enum ", changed);
80- // }
79+ // THEN
80+ assert_eq ! (
81+ "#[derive( Debug , Copy , Clone , PartialEq , Eq , Hash , FromPrimitive)]\n pub enum BWAPI_Text_Size_Enum #[derive( Debug , Copy , Clone , PartialEq , Eq , Hash , FromPrimitive)]\n pub enum BWAPIC_CommandType_Enum " ,
82+ changed
83+ ) ;
84+ }
0 commit comments