@@ -132,6 +132,34 @@ fn main() {
132
132
println ! ( "cargo:rustc-link-lib={}={}" , kind, lib) ;
133
133
}
134
134
135
+ // libssl in BoringSSL requires the C++ runtime, and static libraries do
136
+ // not carry dependency information. On unix-like platforms, the C++
137
+ // runtime and standard library are typically picked up by default via the
138
+ // C++ compiler, which has a platform-specific default. (See implementations
139
+ // of `GetDefaultCXXStdlibType` in Clang.) Builds may also choose to
140
+ // override this and specify their own with `-nostdinc++` and `-nostdlib++`
141
+ // flags. Some compilers also provide options like `-stdlib=libc++`.
142
+ //
143
+ // Typically, such information is carried all the way up the build graph,
144
+ // but Cargo is not an integrated cross-language build system, so it cannot
145
+ // safely handle any of these situations. As a result, we need to make
146
+ // guesses. Getting this wrong may result in symbol conflicts and memory
147
+ // errors, but this unsafety is inherent to driving builds with
148
+ // externally-built libraries using Cargo.
149
+ //
150
+ // For now, we guess that the build was made with the defaults. This too is
151
+ // difficult because Rust does not expose this information from Clang, but
152
+ // try to match the behavior for common platforms. For a more robust option,
153
+ // this likely needs to be deferred to the caller with an environment
154
+ // variable.
155
+ if version == Version :: Boringssl && kind == "static" && env:: var ( "CARGO_CFG_UNIX" ) . is_ok ( ) {
156
+ let cpp_lib = match env:: var ( "CARGO_CFG_TARGET_OS" ) . unwrap ( ) . as_ref ( ) {
157
+ "macos" => "c++" ,
158
+ _ => "stdc++" ,
159
+ } ;
160
+ println ! ( "cargo:rustc-link-lib={}" , cpp_lib) ;
161
+ }
162
+
135
163
// https://github.com/openssl/openssl/pull/15086
136
164
if version == Version :: Openssl3xx
137
165
&& kind == "static"
0 commit comments