@@ -24,6 +24,7 @@ enum Version {
24
24
Openssl10x ,
25
25
Libressl ,
26
26
Boringssl ,
27
+ AwsLc ,
27
28
}
28
29
29
30
fn env_inner ( name : & str ) -> Option < OsString > {
@@ -71,6 +72,51 @@ fn check_ssl_kind() {
71
72
// BoringSSL does not have any build logic, exit early
72
73
std:: process:: exit ( 0 ) ;
73
74
}
75
+
76
+ let is_aws_lc = cfg ! ( feature = "aws-lc" ) ;
77
+
78
+ if is_aws_lc {
79
+ println ! ( "cargo:rustc-cfg=awslc" ) ;
80
+ println ! ( "cargo:awslc=true" ) ;
81
+
82
+ // The aws-lc-sys crate uses a link name that embeds
83
+ // the version number of crate. Examples (crate-name => links name):
84
+ // * aws-lc-sys => aws_lc_0_26_0
85
+ // This is done to avoid issues if the cargo dependency graph for an application
86
+ // were to resolve to multiple versions for the same crate.
87
+ //
88
+ // Due to this we need to determine what version of the AWS-LC has been selected (fips or non-fips)
89
+ // and then need to parse out the pieces we are interested in ignoring the version componenet of the name.
90
+ const AWS_LC_ENV_VAR_PREFIX : & str = "DEP_AWS_LC_" ;
91
+
92
+ let mut version = None ;
93
+ for ( name, _) in std:: env:: vars ( ) {
94
+ if let Some ( name) = name. strip_prefix ( AWS_LC_ENV_VAR_PREFIX ) {
95
+ if let Some ( name) = name. strip_suffix ( "_INCLUDE" ) {
96
+ version = Some ( name. to_owned ( ) ) ;
97
+ break ;
98
+ }
99
+ }
100
+ }
101
+ let version = version. expect ( "aws-lc version detected" ) ;
102
+
103
+ // Read the OpenSSL configuration statements and emit rust-cfg for each.
104
+ if let Ok ( vars) = std:: env:: var ( format ! ( "{AWS_LC_ENV_VAR_PREFIX}{version}_CONF" ) ) {
105
+ for var in vars. split ( ',' ) {
106
+ println ! ( "cargo:rustc-cfg=osslconf=\" {var}\" " ) ;
107
+ }
108
+ println ! ( "cargo:conf={vars}" ) ;
109
+ }
110
+
111
+ // Emit the include header directory from the aws-lc(-fips)-sys crate so that it can be used if needed
112
+ // by crates consuming openssl-sys.
113
+ if let Ok ( val) = std:: env:: var ( format ! ( "{AWS_LC_ENV_VAR_PREFIX}{version}_INCLUDE" ) ) {
114
+ println ! ( "cargo:include={val}" ) ;
115
+ }
116
+
117
+ // AWS-LC does not have any build logic, exit early
118
+ std:: process:: exit ( 0 ) ;
119
+ }
74
120
}
75
121
76
122
fn main ( ) {
@@ -79,6 +125,7 @@ fn main() {
79
125
println ! ( "cargo:rustc-check-cfg=cfg(openssl)" ) ;
80
126
println ! ( "cargo:rustc-check-cfg=cfg(libressl)" ) ;
81
127
println ! ( "cargo:rustc-check-cfg=cfg(boringssl)" ) ;
128
+ println ! ( "cargo:rustc-check-cfg=cfg(awslc)" ) ;
82
129
83
130
println ! ( "cargo:rustc-check-cfg=cfg(libressl250)" ) ;
84
131
println ! ( "cargo:rustc-check-cfg=cfg(libressl251)" ) ;
@@ -201,7 +248,10 @@ fn main() {
201
248
// try to match the behavior for common platforms. For a more robust option,
202
249
// this likely needs to be deferred to the caller with an environment
203
250
// variable.
204
- if version == Version :: Boringssl && kind == "static" && env:: var ( "CARGO_CFG_UNIX" ) . is_ok ( ) {
251
+ if ( version == Version :: Boringssl || version == Version :: AwsLc )
252
+ && kind == "static"
253
+ && env:: var ( "CARGO_CFG_UNIX" ) . is_ok ( )
254
+ {
205
255
let cpp_lib = match env:: var ( "CARGO_CFG_TARGET_OS" ) . unwrap ( ) . as_ref ( ) {
206
256
"macos" => "c++" ,
207
257
_ => "stdc++" ,
@@ -231,8 +281,8 @@ fn main() {
231
281
fn postprocess ( include_dirs : & [ PathBuf ] ) -> Version {
232
282
let version = validate_headers ( include_dirs) ;
233
283
234
- // Never run bindgen for BoringSSL, if it was needed we already ran it.
235
- if version != Version :: Boringssl {
284
+ // Never run bindgen for BoringSSL or AWS-LC , if it was needed we already ran it.
285
+ if ! ( version == Version :: Boringssl || version == Version :: AwsLc ) {
236
286
#[ cfg( feature = "bindgen" ) ]
237
287
run_bindgen:: run ( & include_dirs) ;
238
288
}
@@ -296,14 +346,18 @@ See rust-openssl documentation for more information:
296
346
let mut openssl_version = None ;
297
347
let mut libressl_version = None ;
298
348
let mut is_boringssl = false ;
349
+ let mut is_awslc = false ;
350
+ let mut bindgen_symbol_prefix: Option < String > = None ;
299
351
for line in expanded. lines ( ) {
300
352
let line = line. trim ( ) ;
301
353
302
354
let openssl_prefix = "RUST_VERSION_OPENSSL_" ;
303
355
let new_openssl_prefix = "RUST_VERSION_NEW_OPENSSL_" ;
304
356
let libressl_prefix = "RUST_VERSION_LIBRESSL_" ;
305
357
let boringssl_prefix = "RUST_OPENSSL_IS_BORINGSSL" ;
358
+ let awslc_prefix = "RUST_OPENSSL_IS_AWSLC" ;
306
359
let conf_prefix = "RUST_CONF_" ;
360
+ let symbol_prefix = "RUST_BINDGEN_SYMBOL_PREFIX_" ;
307
361
if let Some ( version) = line. strip_prefix ( openssl_prefix) {
308
362
openssl_version = Some ( parse_version ( version) ) ;
309
363
} else if let Some ( version) = line. strip_prefix ( new_openssl_prefix) {
@@ -314,6 +368,11 @@ See rust-openssl documentation for more information:
314
368
enabled. push ( conf) ;
315
369
} else if line. starts_with ( boringssl_prefix) {
316
370
is_boringssl = true ;
371
+ } else if line. starts_with ( awslc_prefix) {
372
+ is_awslc = true ;
373
+ } else if line. starts_with ( symbol_prefix) {
374
+ let sym_prefix = String :: from ( line. strip_prefix ( symbol_prefix) . unwrap ( ) ) ;
375
+ bindgen_symbol_prefix = Some ( sym_prefix) ;
317
376
}
318
377
}
319
378
@@ -329,6 +388,13 @@ See rust-openssl documentation for more information:
329
388
return Version :: Boringssl ;
330
389
}
331
390
391
+ if is_awslc {
392
+ println ! ( "cargo:rustc-cfg=awslc" ) ;
393
+ println ! ( "cargo:awslc=true" ) ;
394
+ run_bindgen:: run_awslc ( include_dirs, bindgen_symbol_prefix) ;
395
+ return Version :: AwsLc ;
396
+ }
397
+
332
398
// We set this for any non-BoringSSL lib.
333
399
println ! ( "cargo:rustc-cfg=openssl" ) ;
334
400
0 commit comments