@@ -24,6 +24,7 @@ enum Version {
2424 Openssl10x ,
2525 Libressl ,
2626 Boringssl ,
27+ AwsLc ,
2728}
2829
2930fn env_inner ( name : & str ) -> Option < OsString > {
@@ -71,6 +72,51 @@ fn check_ssl_kind() {
7172 // BoringSSL does not have any build logic, exit early
7273 std:: process:: exit ( 0 ) ;
7374 }
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+ }
74120}
75121
76122fn main ( ) {
@@ -79,6 +125,7 @@ fn main() {
79125 println ! ( "cargo:rustc-check-cfg=cfg(openssl)" ) ;
80126 println ! ( "cargo:rustc-check-cfg=cfg(libressl)" ) ;
81127 println ! ( "cargo:rustc-check-cfg=cfg(boringssl)" ) ;
128+ println ! ( "cargo:rustc-check-cfg=cfg(awslc)" ) ;
82129
83130 println ! ( "cargo:rustc-check-cfg=cfg(libressl250)" ) ;
84131 println ! ( "cargo:rustc-check-cfg=cfg(libressl251)" ) ;
@@ -201,7 +248,10 @@ fn main() {
201248 // try to match the behavior for common platforms. For a more robust option,
202249 // this likely needs to be deferred to the caller with an environment
203250 // 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+ {
205255 let cpp_lib = match env:: var ( "CARGO_CFG_TARGET_OS" ) . unwrap ( ) . as_ref ( ) {
206256 "macos" => "c++" ,
207257 _ => "stdc++" ,
@@ -231,8 +281,8 @@ fn main() {
231281fn postprocess ( include_dirs : & [ PathBuf ] ) -> Version {
232282 let version = validate_headers ( include_dirs) ;
233283
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 ) {
236286 #[ cfg( feature = "bindgen" ) ]
237287 run_bindgen:: run ( & include_dirs) ;
238288 }
@@ -296,14 +346,18 @@ See rust-openssl documentation for more information:
296346 let mut openssl_version = None ;
297347 let mut libressl_version = None ;
298348 let mut is_boringssl = false ;
349+ let mut is_awslc = false ;
350+ let mut bindgen_symbol_prefix: Option < String > = None ;
299351 for line in expanded. lines ( ) {
300352 let line = line. trim ( ) ;
301353
302354 let openssl_prefix = "RUST_VERSION_OPENSSL_" ;
303355 let new_openssl_prefix = "RUST_VERSION_NEW_OPENSSL_" ;
304356 let libressl_prefix = "RUST_VERSION_LIBRESSL_" ;
305357 let boringssl_prefix = "RUST_OPENSSL_IS_BORINGSSL" ;
358+ let awslc_prefix = "RUST_OPENSSL_IS_AWSLC" ;
306359 let conf_prefix = "RUST_CONF_" ;
360+ let symbol_prefix = "RUST_BINDGEN_SYMBOL_PREFIX_" ;
307361 if let Some ( version) = line. strip_prefix ( openssl_prefix) {
308362 openssl_version = Some ( parse_version ( version) ) ;
309363 } else if let Some ( version) = line. strip_prefix ( new_openssl_prefix) {
@@ -314,6 +368,11 @@ See rust-openssl documentation for more information:
314368 enabled. push ( conf) ;
315369 } else if line. starts_with ( boringssl_prefix) {
316370 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) ;
317376 }
318377 }
319378
@@ -329,6 +388,13 @@ See rust-openssl documentation for more information:
329388 return Version :: Boringssl ;
330389 }
331390
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+
332398 // We set this for any non-BoringSSL lib.
333399 println ! ( "cargo:rustc-cfg=openssl" ) ;
334400
0 commit comments