mirror of
https://github.com/girlbossceo/hardened_malloc-rs.git
synced 2025-04-29 14:19:25 -04:00
chore: cleanup build.rs, remove unnecessary prefix
This commit is contained in:
parent
9174cb5543
commit
24ba28ca8c
1 changed files with 87 additions and 107 deletions
70
build.rs
70
build.rs
|
@ -9,7 +9,7 @@ fn update_submodules() {
|
|||
let program = "git";
|
||||
let args = ["submodule", "update", "--init", "--recursive"];
|
||||
println!(
|
||||
"[hardened_malloc-sys]: Running command: \"{} {}\" in directory: {:?}",
|
||||
"Running command: \"{} {}\" in directory: {:?}",
|
||||
program,
|
||||
args.join(" "),
|
||||
current_dir(),
|
||||
|
@ -17,43 +17,33 @@ fn update_submodules() {
|
|||
let ret = Command::new(program).args(args).status();
|
||||
|
||||
match ret.map(|status| (status.success(), status.code())) {
|
||||
Ok((true, _)) => println!("[hardened_malloc-sys]: Updating submodules exited successfully"),
|
||||
Ok((false, Some(exit_code))) => panic!(
|
||||
"[hardened_malloc-sys]: Updating submodules failed with error code {}",
|
||||
exit_code
|
||||
),
|
||||
Ok((false, None)) => panic!(
|
||||
"[hardened_malloc-sys]: Updating submodules exited with no error code, possibly killed by system, exiting."
|
||||
),
|
||||
Err(e) => panic!("[hardened_malloc-sys]: Updating submodules failed with error: {}", e),
|
||||
Ok((true, _)) => println!("updating submodules exited successfully"),
|
||||
Ok((false, Some(exit_code))) => panic!("updating submodules failed with error code {}", exit_code),
|
||||
Ok((false, None)) => {
|
||||
panic!("updating submodules exited with no error code, possibly killed by system, exiting.")
|
||||
},
|
||||
Err(e) => panic!("updating submodules failed with error: {}", e),
|
||||
}
|
||||
}
|
||||
|
||||
fn check_compiler(compiler: &str) {
|
||||
fn check_compiler(compiler: &'static str) -> &'static str {
|
||||
let args = "-v";
|
||||
|
||||
println!(
|
||||
"[hardened_malloc-sys]: Checking if compiler {} exists",
|
||||
compiler
|
||||
);
|
||||
println!("checking if compiler {} exists", compiler);
|
||||
|
||||
let ret = Command::new(compiler).arg(args).status();
|
||||
|
||||
match ret.map(|status| (status.success(), status.code())) {
|
||||
Ok((true, _)) => println!("[hardened_malloc-sys]: Compiler check exited successfully"),
|
||||
Ok((false, Some(exit_code))) => panic!(
|
||||
"[hardened_malloc-sys]: Compiler check failed with error code {}",
|
||||
exit_code
|
||||
),
|
||||
Ok((false, None)) => panic!(
|
||||
"[hardened_malloc-sys]: Compiler check exited with no error code, possibly killed by system"
|
||||
),
|
||||
Err(e) => panic!("[hardened_malloc-sys]: Compiler check failed with error: {}", e),
|
||||
Ok((true, _)) => println!("compiler check exited successfully"),
|
||||
Ok((false, Some(exit_code))) => panic!("compiler check failed with error code {}", exit_code),
|
||||
Ok((false, None)) => panic!("compiler check exited with no error code, possibly killed by system"),
|
||||
Err(e) => panic!("compiler check failed with error: {}", e),
|
||||
}
|
||||
compiler
|
||||
}
|
||||
|
||||
fn main() {
|
||||
#[cfg(all(feature = "gcc", feature="clang"))]
|
||||
#[cfg(all(feature = "gcc", feature = "clang"))]
|
||||
compile_error!("gcc OR clang must be enabled, not both.");
|
||||
|
||||
println!("cargo:rerun-if-changed=build.rs");
|
||||
|
@ -64,7 +54,6 @@ fn main() {
|
|||
println!("cargo:rerun-if-changed=src/hardened_malloc/.git/refs/tags");
|
||||
|
||||
let out_dir = env::var("OUT_DIR").unwrap();
|
||||
let current_working_directory = current_dir().unwrap();
|
||||
|
||||
if !Path::new("src/hardened_malloc/Makefile").exists() {
|
||||
println!("src/hardened_malloc/Makefile does not exist, running submodule sync");
|
||||
|
@ -72,28 +61,26 @@ fn main() {
|
|||
}
|
||||
|
||||
let compiler = if cfg!(feature = "gcc") {
|
||||
check_compiler("gcc");
|
||||
"gcc"
|
||||
check_compiler("gcc")
|
||||
} else {
|
||||
check_compiler("clang");
|
||||
"clang"
|
||||
check_compiler("clang")
|
||||
};
|
||||
|
||||
let variant = if cfg!(feature = "light") {
|
||||
"light"
|
||||
} else {
|
||||
"default" // "default" is hardened_malloc's default.mk. this crate's feature uses "standard" for "default"
|
||||
"default" // "default" is hardened_malloc's default.mk. this crate's feature
|
||||
// uses "standard" for "default"
|
||||
};
|
||||
|
||||
let build_args = [
|
||||
"VARIANT=".to_owned() + variant,
|
||||
"V=".to_owned() + "1",
|
||||
"OUT=".to_owned() + &out_dir,
|
||||
"CC=".to_owned() + compiler,
|
||||
format!("VARIANT={}", variant),
|
||||
format!("V={}", "1"),
|
||||
format!("OUT={}", &out_dir),
|
||||
format!("CC={}", compiler),
|
||||
];
|
||||
|
||||
//TODO: handle support for explicit make flags like N_ARENA=1 and such
|
||||
|
||||
let mut make_command = Command::new("make");
|
||||
|
||||
println!("running {:?} with args {:?}", make_command, build_args);
|
||||
|
@ -103,25 +90,18 @@ fn main() {
|
|||
.args(build_args)
|
||||
.output()
|
||||
.unwrap_or_else(|error| {
|
||||
panic!("[hardened_malloc-sys]: Failed to run 'make {}': ", error);
|
||||
panic!("failed to run 'make {}': ", error);
|
||||
});
|
||||
|
||||
if !make_output.status.success() {
|
||||
panic!(
|
||||
"[hardened_malloc-sys]: building hardened_malloc failed:\n{:?}\n{}\n{}",
|
||||
"building hardened_malloc failed:\n{:?}\n{}\n{}",
|
||||
make_command,
|
||||
String::from_utf8_lossy(&make_output.stdout),
|
||||
String::from_utf8_lossy(&make_output.stderr)
|
||||
);
|
||||
}
|
||||
|
||||
println!(
|
||||
"[hardened_malloc-sys]: current working directory: {}",
|
||||
current_working_directory.display()
|
||||
);
|
||||
|
||||
println!("[hardened_malloc-sys]: OUT_DIR={}", out_dir);
|
||||
|
||||
if cfg!(feature = "light") {
|
||||
println!("cargo:rustc-link-lib=dylib=hardened_malloc-light");
|
||||
println!("cargo:rustc-link-search={}", out_dir);
|
||||
|
|
Loading…
Add table
Reference in a new issue