1
1
use std:: {
2
- collections:: HashSet ,
3
2
env,
4
3
path:: { Path , PathBuf } ,
5
4
process:: Command ,
6
5
str,
7
6
} ;
8
7
9
- use bindgen:: callbacks:: { MacroParsingBehavior , ParseCallbacks } ;
10
8
use regex:: Regex ;
11
9
12
- extern crate bindgen;
13
-
14
- // https://github.com/rust-lang/rust-bindgen/issues/687#issuecomment-450750547
15
- #[ derive( Debug ) ]
16
- struct IgnoreMacros ( HashSet < String > ) ;
17
-
18
- impl ParseCallbacks for IgnoreMacros {
19
- fn will_parse_macro ( & self , name : & str ) -> MacroParsingBehavior {
20
- if self . 0 . contains ( name) {
21
- MacroParsingBehavior :: Ignore
22
- } else {
23
- MacroParsingBehavior :: Default
24
- }
25
- }
26
- }
27
-
28
10
const MIN_PHP_API_VER : u32 = 20200930 ;
29
11
const MAX_PHP_API_VER : u32 = 20200930 ;
30
12
@@ -33,6 +15,18 @@ fn main() {
33
15
println ! ( "cargo:rerun-if-changed=src/wrapper/wrapper.h" ) ;
34
16
println ! ( "cargo:rerun-if-changed=src/wrapper/wrapper.c" ) ;
35
17
18
+ let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) . join ( "bindings.rs" ) ;
19
+
20
+ // check for docs.rs and use stub bindings if required
21
+ if env:: var ( "DOCS_RS" ) . is_ok ( ) {
22
+ println ! ( "cargo:warning=docs.rs detected - using stub bindings" ) ;
23
+ println ! ( "cargo:rustc-cfg=php_debug" ) ;
24
+
25
+ std:: fs:: copy ( "docsrs_bindings.rs" , out_path)
26
+ . expect ( "Unable to copy docs.rs stub bindings to output directory." ) ;
27
+ return ;
28
+ }
29
+
36
30
// use php-config to fetch includes
37
31
let includes_cmd = Command :: new ( "php-config" )
38
32
. arg ( "--includes" )
@@ -85,31 +79,10 @@ fn main() {
85
79
)
86
80
. compile ( "wrapper" ) ;
87
81
88
- let ignore_math_h_macros = IgnoreMacros (
89
- vec ! [
90
- // math.h:914 - enum which uses #define for values
91
- "FP_NAN" . into( ) ,
92
- "FP_INFINITE" . into( ) ,
93
- "FP_ZERO" . into( ) ,
94
- "FP_SUBNORMAL" . into( ) ,
95
- "FP_NORMAL" . into( ) ,
96
- // math.h:237 - enum which uses #define for values
97
- "FP_INT_UPWARD" . into( ) ,
98
- "FP_INT_DOWNWARD" . into( ) ,
99
- "FP_INT_TOWARDZERO" . into( ) ,
100
- "FP_INT_TONEARESTFROMZERO" . into( ) ,
101
- "FP_INT_TONEAREST" . into( ) ,
102
- ]
103
- . into_iter ( )
104
- . collect ( ) ,
105
- ) ;
106
-
107
- let out_path = PathBuf :: from ( env:: var ( "OUT_DIR" ) . unwrap ( ) ) ;
108
82
let mut bindgen = bindgen:: Builder :: default ( )
109
83
. header ( "src/wrapper/wrapper.h" )
110
84
. clang_args ( includes. split ( ' ' ) )
111
85
. parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks ) )
112
- . parse_callbacks ( Box :: new ( ignore_math_h_macros) )
113
86
. rustfmt_bindings ( true )
114
87
. no_copy ( "_zend_value" )
115
88
. layout_tests ( env:: var ( "EXT_PHP_RS_TEST" ) . is_ok ( ) ) ;
@@ -124,7 +97,7 @@ fn main() {
124
97
bindgen
125
98
. generate ( )
126
99
. expect ( "Unable to generate bindings for PHP" )
127
- . write_to_file ( out_path. join ( "bindings.rs" ) )
100
+ . write_to_file ( out_path)
128
101
. expect ( "Unable to write bindings file." ) ;
129
102
130
103
let configure = Configure :: get ( ) ;
0 commit comments