@@ -44,26 +44,29 @@ fn run() -> Result<()> {
44
44
let out_dir =
45
45
PathBuf :: from ( env:: var_os ( "OUT_DIR" ) . ok_or ( "Missing OUT_DIR environment variable" ) ?) ;
46
46
47
- let build_dir = out_dir. join ( "build" ) ;
48
- let build_dir = build_dir. to_str ( ) . ok_or_else ( || {
49
- format ! ( "Build dir path is required to be valid UTF-8, got {build_dir:?}" )
50
- } ) ?;
47
+ let sysroot = find_clang_sysroot ( & target) ?;
51
48
52
- if let Err ( e) = remove_dir_all ( build_dir) {
53
- if e. kind ( ) != ErrorKind :: NotFound {
54
- println ! ( "cargo:warning=Unable to clear {build_dir:?}. This may lead to flaky builds that might not incorporate configurations changes: {e}" ) ;
55
- }
56
- }
49
+ let docs = env:: var_os ( "DOCS_RS" ) . is_some ( ) ;
50
+ if !docs {
51
+ let build_dir = out_dir. join ( "build" ) ;
52
+ let build_dir = build_dir. to_str ( ) . ok_or_else ( || {
53
+ format ! ( "Build dir path is required to be valid UTF-8, got {build_dir:?}" )
54
+ } ) ?;
57
55
58
- let sysroot = find_clang_sysroot ( & target) ?;
56
+ if let Err ( e) = remove_dir_all ( build_dir) {
57
+ if e. kind ( ) != ErrorKind :: NotFound {
58
+ println ! ( "cargo:warning=Unable to clear {build_dir:?}. This may lead to flaky builds that might not incorporate configurations changes: {e}" ) ;
59
+ }
60
+ }
59
61
60
- copy_recursive ( & src_dir, build_dir. as_ref ( ) , & [ ".git" . as_ref ( ) ] ) ?;
62
+ copy_recursive ( & src_dir, build_dir. as_ref ( ) , & [ ".git" . as_ref ( ) ] ) ?;
61
63
62
- println ! ( "cargo:rerun-if-changed=wrapper.h" ) ;
63
- println ! ( "cargo:rerun-if-changed=wrapper.c" ) ;
64
+ println ! ( "cargo:rerun-if-changed=wrapper.h" ) ;
65
+ println ! ( "cargo:rerun-if-changed=wrapper.c" ) ;
64
66
65
- Build :: new ( & target) . run ( & target, build_dir) ?;
66
- build_wrapper ( & target) . map_err ( |e| format ! ( "Unable to compile mupdf wrapper:\n {e}" ) ) ?;
67
+ Build :: new ( & target) . run ( & target, build_dir) ?;
68
+ build_wrapper ( & target) . map_err ( |e| format ! ( "Unable to compile mupdf wrapper:\n {e}" ) ) ?;
69
+ }
67
70
68
71
generate_bindings ( & target, & out_dir. join ( "bindings.rs" ) , sysroot)
69
72
. map_err ( |e| format ! ( "Unable to generate mupdf bindings using bindgen:\n {e}" ) ) ?;
@@ -165,15 +168,61 @@ fn generate_bindings(target: &Target, path: &Path, sysroot: Option<String>) -> R
165
168
builder = builder
166
169
. clang_arg ( "-Imupdf/include" )
167
170
. header ( "wrapper.h" )
168
- . header ( "wrapper.c" )
171
+ . header ( "wrapper.c" ) ;
172
+
173
+ builder = builder
174
+ . allowlist_recursively ( false )
175
+ . allowlist_type ( "wchar_t" )
176
+ . allowlist_type ( "FILE" )
177
+ . opaque_type ( "FILE" ) ;
178
+
179
+ builder = builder
169
180
. allowlist_item ( "fz_.*" )
170
181
. allowlist_item ( "FZ_.*" )
171
182
. allowlist_item ( "pdf_.*" )
172
183
. allowlist_item ( "PDF_.*" )
184
+ . allowlist_type ( "cmap_splay" )
173
185
. allowlist_item ( "ucdn_.*" )
174
186
. allowlist_item ( "UCDN_.*" )
175
187
. allowlist_item ( "Memento_.*" )
176
- . allowlist_item ( "mupdf_.*" )
188
+ . allowlist_item ( "mupdf_.*" ) ;
189
+
190
+ // remove va_list functions as for all of these versions using ... exist
191
+ builder = builder
192
+ . blocklist_function ( "Memento_vasprintf" ) // Memento_asprintf
193
+ . blocklist_function ( "fz_vthrow" ) // fz_throw
194
+ . blocklist_function ( "fz_vwarn" ) // fz_warn
195
+ . blocklist_function ( "fz_vlog_error_printf" ) // fz_log_error_printf
196
+ . blocklist_function ( "fz_append_vprintf" ) // fz_append_printf
197
+ . blocklist_function ( "fz_write_vprintf" ) // fz_write_printf
198
+ . blocklist_function ( "fz_vsnprintf" ) // fz_snprintf
199
+ . blocklist_function ( "fz_format_string" ) ; // mupdf_format_string
200
+
201
+ // build config
202
+ builder = builder
203
+ . blocklist_var ( "FZ_VERSION.*" )
204
+ . blocklist_var ( "FZ_ENABLE_.*" )
205
+ . blocklist_var ( "FZ_PLOTTERS_.*" ) ;
206
+
207
+ // internal implementation details, considered private
208
+ builder = builder
209
+ . blocklist_item ( "fz_jmp_buf" )
210
+ . blocklist_function ( "fz_var_imp" )
211
+ . blocklist_function ( "fz_push_try" )
212
+ . blocklist_function ( "fz_do_.*" )
213
+ . blocklist_var ( "FZ_JMPBUF_ALIGN" )
214
+ . blocklist_type ( "fz_error_stack_slot" )
215
+ . blocklist_type ( "fz_error_context" )
216
+ . blocklist_type ( "fz_warn_context" )
217
+ . blocklist_type ( "fz_aa_context" )
218
+ . blocklist_type ( "fz_activity_.*" )
219
+ . blocklist_function ( "fz_register_activity_logger" )
220
+ . opaque_type ( "fz_context" )
221
+ . blocklist_type ( "fz_new_context_imp" )
222
+ . blocklist_type ( "fz_lock" )
223
+ . blocklist_type ( "fz_unlock" ) ;
224
+
225
+ builder = builder
177
226
. parse_callbacks ( Box :: new ( bindgen:: CargoCallbacks :: new ( ) ) )
178
227
. parse_callbacks ( Box :: new ( DocsCallbacks :: default ( ) ) ) ;
179
228
@@ -182,10 +231,7 @@ fn generate_bindings(target: &Target, path: &Path, sysroot: Option<String>) -> R
182
231
builder = builder. parse_callbacks ( Box :: new ( ZerocopyDeriveCallbacks ) ) ;
183
232
}
184
233
185
- builder
186
- . size_t_is_usize ( true )
187
- . generate ( ) ?
188
- . write_to_file ( path) ?;
234
+ builder. use_core ( ) . generate ( ) ?. write_to_file ( path) ?;
189
235
190
236
Ok ( ( ) )
191
237
}
0 commit comments