@@ -16,6 +16,7 @@ pub(crate) struct Config {
1616
1717pub ( crate ) struct Features {
1818 pub ( crate ) fips : bool ,
19+ pub ( crate ) fips_precompiled : bool ,
1920 pub ( crate ) fips_link_precompiled : bool ,
2021 pub ( crate ) pq_experimental : bool ,
2122 pub ( crate ) rpk : bool ,
@@ -35,6 +36,7 @@ pub(crate) struct Env {
3536 pub ( crate ) android_ndk_home : Option < PathBuf > ,
3637 pub ( crate ) cmake_toolchain_file : Option < PathBuf > ,
3738 pub ( crate ) cpp_runtime_lib : Option < OsString > ,
39+ pub ( crate ) docs_rs : bool ,
3840}
3941
4042impl Config {
@@ -47,11 +49,7 @@ impl Config {
4749 let target_os = env:: var ( "CARGO_CFG_TARGET_OS" ) . unwrap ( ) ;
4850
4951 let features = Features :: from_env ( ) ;
50- let env = Env :: from_env (
51- & host,
52- & target,
53- features. fips || features. fips_link_precompiled ,
54- ) ;
52+ let env = Env :: from_env ( & host, & target, features. is_fips_like ( ) ) ;
5553
5654 let mut is_bazel = false ;
5755 if let Some ( src_path) = & env. source_path {
@@ -80,6 +78,10 @@ impl Config {
8078 panic ! ( "`fips` and `rpk` features are mutually exclusive" ) ;
8179 }
8280
81+ if self . features . fips_precompiled && self . features . rpk {
82+ panic ! ( "`fips-precompiled` and `rpk` features are mutually exclusive" ) ;
83+ }
84+
8385 let is_precompiled_native_lib = self . env . path . is_some ( ) ;
8486 let is_external_native_lib_source =
8587 !is_precompiled_native_lib && self . env . source_path . is_none ( ) ;
@@ -96,30 +98,47 @@ impl Config {
9698 || self . features . underscore_wildcards ;
9799
98100 let patches_required = features_with_patches_enabled && !self . env . assume_patched ;
99- let build_from_sources_required = self . features . fips_link_precompiled || patches_required;
100101
101- if is_precompiled_native_lib && build_from_sources_required {
102- panic ! ( "precompiled BoringSSL was provided, so FIPS configuration or optional patches can't be applied" ) ;
102+ if is_precompiled_native_lib && patches_required {
103+ println ! (
104+ "cargo:warning=precompiled BoringSSL was provided, so patches will be ignored"
105+ ) ;
106+ }
107+
108+ // todo(rmehra): should this even be a restriction? why not let people link a custom bcm.o?
109+ // precompiled boringssl will include libcrypto.a
110+ if is_precompiled_native_lib && self . features . fips_link_precompiled {
111+ panic ! ( "precompiled BoringSSL was provided, so FIPS configuration can't be applied" ) ;
112+ }
113+
114+ if !is_precompiled_native_lib && self . features . fips_precompiled {
115+ panic ! ( "`fips-precompiled` feature requires `BORING_BSSL_FIPS_PATH` to be set" ) ;
103116 }
104117 }
105118}
106119
107120impl Features {
108121 fn from_env ( ) -> Self {
109122 let fips = env:: var_os ( "CARGO_FEATURE_FIPS" ) . is_some ( ) ;
123+ let fips_precompiled = env:: var_os ( "CARGO_FEATURE_FIPS_PRECOMPILED" ) . is_some ( ) ;
110124 let fips_link_precompiled = env:: var_os ( "CARGO_FEATURE_FIPS_LINK_PRECOMPILED" ) . is_some ( ) ;
111125 let pq_experimental = env:: var_os ( "CARGO_FEATURE_PQ_EXPERIMENTAL" ) . is_some ( ) ;
112126 let rpk = env:: var_os ( "CARGO_FEATURE_RPK" ) . is_some ( ) ;
113127 let underscore_wildcards = env:: var_os ( "CARGO_FEATURE_UNDERSCORE_WILDCARDS" ) . is_some ( ) ;
114128
115129 Self {
116130 fips,
131+ fips_precompiled,
117132 fips_link_precompiled,
118133 pq_experimental,
119134 rpk,
120135 underscore_wildcards,
121136 }
122137 }
138+
139+ pub ( crate ) fn is_fips_like ( & self ) -> bool {
140+ self . fips || self . fips_precompiled || self . fips_link_precompiled
141+ }
123142}
124143
125144impl Env {
@@ -133,9 +152,10 @@ impl Env {
133152 let target_var = |name : & str | {
134153 let kind = if host == target { "HOST" } else { "TARGET" } ;
135154
136- var ( & format ! ( "{}_{}" , name, target) )
137- . or_else ( || var ( & format ! ( "{}_{}" , name, target_with_underscores) ) )
138- . or_else ( || var ( & format ! ( "{}_{}" , kind, name) ) )
155+ // TODO(rmehra): look for just `name` first, as most people just set that
156+ var ( & format ! ( "{name}_{target}" ) )
157+ . or_else ( || var ( & format ! ( "{name}_{target_with_underscores}" ) ) )
158+ . or_else ( || var ( & format ! ( "{kind}_{name}" ) ) )
139159 . or_else ( || var ( name) )
140160 } ;
141161
@@ -166,6 +186,7 @@ impl Env {
166186 android_ndk_home : target_var ( "ANDROID_NDK_HOME" ) . map ( Into :: into) ,
167187 cmake_toolchain_file : target_var ( "CMAKE_TOOLCHAIN_FILE" ) . map ( Into :: into) ,
168188 cpp_runtime_lib : target_var ( "BORING_BSSL_RUST_CPPLIB" ) ,
189+ docs_rs : var ( "DOCS_RS" ) . is_some ( ) ,
169190 }
170191 }
171192}
0 commit comments