Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Misc. build improvements #125

Merged
merged 2 commits into from
Aug 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 5 additions & 3 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,12 @@ exclude = [
]

[features]
no_bssl = []
default = ["boringssl-vendored"]

boringssl-vendored = []

[package.metadata.docs.rs]
features = ["no_bssl"]
default-features = false

[build-dependencies]
cmake = "0.1"
Expand All @@ -35,7 +37,7 @@ ring = "0.16"
lazy_static = "1"

[target."cfg(windows)".dependencies]
winapi = {version = "0.3", features = ["wincrypt"] }
winapi = { version = "0.3", features = ["wincrypt"] }

[dev-dependencies]
mio = "0.6"
Expand Down
23 changes: 10 additions & 13 deletions src/build.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use cmake;

// Additional parameters for Android build of BoringSSL.
const CMAKE_PARAMS_ANDROID: &[(&str, &[(&str, &str)])] = &[
("aarch64", &[
Expand Down Expand Up @@ -55,12 +53,12 @@ const CMAKE_PARAMS_IOS: &[(&str, &[(&str, &str)])] = &[
]),
];

/// Generate the platform-specific output path for lib
/// Returns the platform-specific output path for lib.
///
/// MSVC generator on Windows place static libs in a target sub-folder,
/// so adjust library location based on platform and build target.
/// See issue: https://github.com/alexcrichton/cmake-rs/issues/18
fn platform_output_path(lib: &str) -> String {
fn get_boringssl_platform_output_path(lib: &str) -> String {
if cfg!(windows) {
if cfg!(debug_assertions) {
return format!("{}/Debug", lib);
Expand All @@ -72,9 +70,9 @@ fn platform_output_path(lib: &str) -> String {
};
}

// Returns a new cmake::Config for building BoringSSL.
//
// It will add platform-specific parameters if needed.
/// Returns a new cmake::Config for building BoringSSL.
///
/// It will add platform-specific parameters if needed.
fn get_boringssl_cmake_config() -> cmake::Config {
let arch = std::env::var("CARGO_CFG_TARGET_ARCH").unwrap();
let os = std::env::var("CARGO_CFG_TARGET_OS").unwrap();
Expand Down Expand Up @@ -123,23 +121,22 @@ fn get_boringssl_cmake_config() -> cmake::Config {
}

fn main() {
if !cfg!(feature = "no_bssl") {
if cfg!(feature = "boringssl-vendored") {
let bssl_dir = std::env::var("QUICHE_BSSL_PATH").unwrap_or_else(|_| {
get_boringssl_cmake_config()
.cflag("-fPIC")
.build_target("bssl")
.build()
.display()
.to_string()
});

let crypto_dir =
format!("{}/build/{}", bssl_dir, platform_output_path("crypto"));
let crypto_path = get_boringssl_platform_output_path("crypto");
let crypto_dir = format!("{}/build/{}", bssl_dir, crypto_path);
println!("cargo:rustc-link-search=native={}", crypto_dir);
println!("cargo:rustc-link-lib=static=crypto");

let ssl_dir =
format!("{}/build/{}", bssl_dir, platform_output_path("ssl"));
let ssl_path = get_boringssl_platform_output_path("ssl");
let ssl_dir = format!("{}/build/{}", bssl_dir, ssl_path);
println!("cargo:rustc-link-search=native={}", ssl_dir);
println!("cargo:rustc-link-lib=static=ssl");
}
Expand Down