Skip to content

Commit

Permalink
Create language_std helper function
Browse files Browse the repository at this point in the history
A helper function to configure the build's language standard and to
automatically enable or disable C++ support. This allows moving some
more code out of `main`, but it is also preparing for running more than
one build, for splitting the `secp256k1` library.
  • Loading branch information
jvff committed Jul 14, 2021
1 parent dbc90de commit 7a72f7e
Showing 1 changed file with 20 additions and 8 deletions.
28 changes: 20 additions & 8 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,9 @@ fn main() -> Result<()> {
let target = env::var("TARGET").expect("TARGET was not set");
let mut base_config = cc::Build::new();

language_std(&mut base_config, "c++17");

base_config
.cpp(true)
.include("depend/zcash/src")
.include("depend/zcash/src/rust/include/")
.include("depend/zcash/src/secp256k1/include")
Expand Down Expand Up @@ -99,13 +100,6 @@ fn main() -> Result<()> {
}
}

let tool = base_config.get_compiler();
if tool.is_like_msvc() {
base_config.flag("/std:c++17");
} else if tool.is_like_clang() || tool.is_like_gnu() {
base_config.flag("-std=c++17");
}

if target.contains("windows") {
base_config.define("WIN32", "1");
}
Expand Down Expand Up @@ -161,3 +155,21 @@ fn is_64bit_compilation() -> bool {
false
}
}

/// Configure the language standard used in the build.
///
/// Configures the appropriate flag based on the compiler that's used.
///
/// This will also enable or disable the `cpp` flag if the standard is for C++. The code determines
/// this based on whether `std` starts with `c++` or not.
fn language_std(build: &mut cc::Build, std: &str) {
build.cpp(std.starts_with("c++"));

let flag = if build.get_compiler().is_like_msvc() {
"/std:"
} else {
"-std="
};

build.flag(&[flag, std].concat());
}

0 comments on commit 7a72f7e

Please sign in to comment.