Skip to content

Commit

Permalink
fix(build): disable atomics and use locks instead in OpenSSL v3 on `i…
Browse files Browse the repository at this point in the history
…686-linux-android`
  • Loading branch information
rami3l committed Apr 27, 2024
1 parent e29572a commit d214f4a
Showing 1 changed file with 37 additions and 33 deletions.
70 changes: 37 additions & 33 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,40 +31,44 @@ fn main() {
// Set linker options specific to Windows MSVC.
let target_os = env::var("CARGO_CFG_TARGET_OS");
let target_env = env::var("CARGO_CFG_TARGET_ENV");
if !(target_os.as_deref() == Ok("windows") && target_env.as_deref() == Ok("msvc")) {
return;
}
let target_pointer_width = env::var("CARGO_CFG_TARGET_POINTER_WIDTH");

// # Only search system32 for DLLs
//
// This applies to DLLs loaded at load time. However, this setting is ignored
// before Windows 10 RS1 (aka 1601).
// https://learn.microsoft.com/en-us/cpp/build/reference/dependentloadflag?view=msvc-170
println!("cargo:cargo:rustc-link-arg-bin=rustup-init=/DEPENDENTLOADFLAG:0x800");
if target_os.as_deref() == Ok("android") && target_pointer_width.as_deref() == Ok("32") {
// Disable atomics and use locks instead in OpenSSL v3 on `i686-linux-android`.
// See <https://github.com/sfackler/rust-openssl/issues/2043#issuecomment-1763528874>.
println!("cargo:rustc-link-arg=-DBROKEN_CLANG_ATOMICS")
} else if target_os.as_deref() == Ok("windows") && target_env.as_deref() == Ok("msvc") {
// # Only search system32 for DLLs
//
// This applies to DLLs loaded at load time. However, this setting is ignored
// before Windows 10 RS1 (aka 1601).
// https://learn.microsoft.com/en-us/cpp/build/reference/dependentloadflag?view=msvc-170
println!("cargo:cargo:rustc-link-arg-bin=rustup-init=/DEPENDENTLOADFLAG:0x800");

// # Delay load
//
// Delay load dlls that are not "known DLLs"[1].
// Known DLLs are always loaded from the system directory whereas other DLLs
// are loaded from the application directory. By delay loading the latter
// we can ensure they are instead loaded from the system directory.
// [1]: https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#factors-that-affect-searching
//
// This will work on all supported Windows versions but it relies on
// us using `SetDefaultDllDirectories` before any libraries are loaded.
// See also: src/bin/rustup-init.rs
let delay_load_dlls = ["bcrypt", "powrprof", "secur32"];
for dll in delay_load_dlls {
println!("cargo:rustc-link-arg-bin=rustup-init=/delayload:{dll}.dll");
}
// When using delayload, it's necessary to also link delayimp.lib
// https://learn.microsoft.com/en-us/cpp/build/reference/dependentloadflag?view=msvc-170
println!("cargo:rustc-link-arg-bin=rustup-init=delayimp.lib");
// # Delay load
//
// Delay load dlls that are not "known DLLs"[1].
// Known DLLs are always loaded from the system directory whereas other DLLs
// are loaded from the application directory. By delay loading the latter
// we can ensure they are instead loaded from the system directory.
// [1]: https://learn.microsoft.com/en-us/windows/win32/dlls/dynamic-link-library-search-order#factors-that-affect-searching
//
// This will work on all supported Windows versions but it relies on
// us using `SetDefaultDllDirectories` before any libraries are loaded.
// See also: src/bin/rustup-init.rs
let delay_load_dlls = ["bcrypt", "powrprof", "secur32"];
for dll in delay_load_dlls {
println!("cargo:rustc-link-arg-bin=rustup-init=/delayload:{dll}.dll");
}
// When using delayload, it's necessary to also link delayimp.lib
// https://learn.microsoft.com/en-us/cpp/build/reference/dependentloadflag?view=msvc-170
println!("cargo:rustc-link-arg-bin=rustup-init=delayimp.lib");

// # Turn linker warnings into errors
//
// Rust hides linker warnings meaning mistakes may go unnoticed.
// Turning them into errors forces them to be displayed (and the build to fail).
// If we do want to ignore specific warnings then `/IGNORE:` should be used.
println!("cargo:cargo:rustc-link-arg-bin=rustup-init=/WX");
// # Turn linker warnings into errors
//
// Rust hides linker warnings meaning mistakes may go unnoticed.
// Turning them into errors forces them to be displayed (and the build to fail).
// If we do want to ignore specific warnings then `/IGNORE:` should be used.
println!("cargo:cargo:rustc-link-arg-bin=rustup-init=/WX");
}
}

0 comments on commit d214f4a

Please sign in to comment.