@@ -36,15 +36,20 @@ const INCLUDES: &str = "
36
36
#include <openssl/x509_vfy.h>
37
37
#include <openssl/x509v3.h>
38
38
39
+ #if !defined(OPENSSL_IS_AWSLC)
39
40
// this must be included after ssl.h for libressl!
40
41
#include <openssl/srtp.h>
42
+ #endif
41
43
42
- #if !defined(LIBRESSL_VERSION_NUMBER) && ! defined(OPENSSL_IS_BORINGSSL)
43
- #include <openssl/cms .h>
44
+ #if !( defined(LIBRESSL_VERSION_NUMBER) || defined(OPENSSL_IS_BORINGSSL) || defined(OPENSSL_IS_AWSLC) )
45
+ #include <openssl/cmsrc/ssl/mod.rss .h>
44
46
#endif
45
47
46
- #if !defined(OPENSSL_IS_BORINGSSL)
48
+ #if !( defined(OPENSSL_IS_BORINGSSL) || defined(OPENSSL_IS_AWSLC) )
47
49
#include <openssl/comp.h>
50
+ #endif
51
+
52
+ #if !defined(OPENSSL_IS_BORINGSSL)
48
53
#include <openssl/ocsp.h>
49
54
#endif
50
55
@@ -60,7 +65,7 @@ const INCLUDES: &str = "
60
65
#include <openssl/quic.h>
61
66
#endif
62
67
63
- #if defined(LIBRESSL_VERSION_NUMBER) || defined(OPENSSL_IS_BORINGSSL)
68
+ #if defined(LIBRESSL_VERSION_NUMBER) || defined(OPENSSL_IS_BORINGSSL) || defined(OPENSSL_IS_AWSLC)
64
69
#include <openssl/poly1305.h>
65
70
#endif
66
71
@@ -216,6 +221,96 @@ pub fn run_boringssl(include_dirs: &[PathBuf]) {
216
221
. compile ( "boring_static_wrapper" ) ;
217
222
}
218
223
224
+ #[ cfg( feature = "bindgen" ) ]
225
+ pub fn run_awslc ( include_dirs : & [ PathBuf ] ) {
226
+ let out_dir = PathBuf :: from ( env:: var_os ( "OUT_DIR" ) . unwrap ( ) ) ;
227
+
228
+ fs:: File :: create ( out_dir. join ( "awslc_static_wrapper.h" ) )
229
+ . expect ( "Failed to create awslc_static_wrapper.h" )
230
+ . write_all ( INCLUDES . as_bytes ( ) )
231
+ . expect ( "Failed to write contents to awslc_static_wrapper.h" ) ;
232
+
233
+ let mut builder = bindgen:: builder ( )
234
+ . rust_target ( RustTarget :: Stable_1_47 )
235
+ . ctypes_prefix ( "::libc" )
236
+ . raw_line ( "use libc::*;" )
237
+ . derive_default ( false )
238
+ . enable_function_attribute_detection ( )
239
+ . default_macro_constant_type ( MacroTypeVariation :: Signed )
240
+ . rustified_enum ( "point_conversion_form_t" )
241
+ . allowlist_file ( r".*(/|\\)openssl((/|\\)[^/\\]+)+\.h" )
242
+ . wrap_static_fns ( true )
243
+ . wrap_static_fns_path ( out_dir. join ( "awslc_static_wrapper" ) . display ( ) . to_string ( ) )
244
+ . layout_tests ( false )
245
+ . header (
246
+ out_dir
247
+ . join ( "awslc_static_wrapper.h" )
248
+ . display ( )
249
+ . to_string ( ) ,
250
+ ) ;
251
+
252
+ for include_dir in include_dirs {
253
+ builder = builder
254
+ . clang_arg ( "-I" )
255
+ . clang_arg ( include_dir. display ( ) . to_string ( ) ) ;
256
+ }
257
+
258
+ builder
259
+ . generate ( )
260
+ . unwrap ( )
261
+ . write_to_file ( out_dir. join ( "bindgen.rs" ) )
262
+ . unwrap ( ) ;
263
+
264
+ cc:: Build :: new ( )
265
+ . file ( out_dir. join ( "awslc_static_wrapper.c" ) )
266
+ . includes ( include_dirs)
267
+ . compile ( "awslc_static_wrapper" ) ;
268
+ }
269
+
270
+ #[ cfg( not( feature = "bindgen" ) ) ]
271
+ pub fn run_awslc ( include_dirs : & [ PathBuf ] ) {
272
+ let out_dir = PathBuf :: from ( env:: var_os ( "OUT_DIR" ) . unwrap ( ) ) ;
273
+
274
+ fs:: File :: create ( out_dir. join ( "awslc_static_wrapper.h" ) )
275
+ . expect ( "Failed to create awslc_static_wrapper.h" )
276
+ . write_all ( INCLUDES . as_bytes ( ) )
277
+ . expect ( "Failed to write contents to awslc_static_wrapper.h" ) ;
278
+
279
+ let mut bindgen_cmd = process:: Command :: new ( "bindgen" ) ;
280
+ bindgen_cmd
281
+ . arg ( "-o" )
282
+ . arg ( out_dir. join ( "bindgen.rs" ) )
283
+ // Must be a valid version from
284
+ // https://docs.rs/bindgen/latest/bindgen/enum.RustTarget.html
285
+ . arg ( "--rust-target=1.47" )
286
+ . arg ( "--ctypes-prefix=::libc" )
287
+ . arg ( "--raw-line=use libc::*;" )
288
+ . arg ( "--no-derive-default" )
289
+ . arg ( "--enable-function-attribute-detection" )
290
+ . arg ( "--default-macro-constant-type=signed" )
291
+ . arg ( "--rustified-enum=point_conversion_form_t" )
292
+ . arg ( r"--allowlist-file=.*(/|\\)openssl((/|\\)[^/\\]+)+\.h" )
293
+ . arg ( "--experimental" )
294
+ . arg ( "--wrap-static-fns" )
295
+ . arg ( "--wrap-static-fns-path" )
296
+ . arg ( out_dir. join ( "awslc_static_wrapper" ) . display ( ) . to_string ( ) )
297
+ . arg ( out_dir. join ( "awslc_static_wrapper.h" ) )
298
+ . arg ( "--" )
299
+ . arg ( format ! ( "--target={}" , env:: var( "TARGET" ) . unwrap( ) ) ) ;
300
+
301
+ for include_dir in include_dirs {
302
+ bindgen_cmd. arg ( "-I" ) . arg ( include_dir. display ( ) . to_string ( ) ) ;
303
+ }
304
+
305
+ let result = bindgen_cmd. status ( ) . expect ( "bindgen failed to execute" ) ;
306
+ assert ! ( result. success( ) ) ;
307
+
308
+ cc:: Build :: new ( )
309
+ . file ( out_dir. join ( "awslc_static_wrapper.c" ) )
310
+ . includes ( include_dirs)
311
+ . compile ( "awslc_static_wrapper" ) ;
312
+ }
313
+
219
314
#[ cfg( feature = "bindgen" ) ]
220
315
#[ derive( Debug ) ]
221
316
struct OpensslCallbacks ;
0 commit comments