diff --git a/build.rs b/build.rs index 4da408a..8f87548 100644 --- a/build.rs +++ b/build.rs @@ -39,9 +39,10 @@ lazy_static::lazy_static! { static ref V8_FORCE_MONOLITH_DOWNLOAD: bool = env::var("V8_FORCE_DOWNLOAD_V8_MONOLITH").map(|v| v == "yes").unwrap_or(false); } -fn run_cmd(cmd: &str, args: &[&str]) { +fn run_cmd_with_env(cmd: &str, args: &[&str], env: &[(&str, &str)]) { let failure_message = format!("Failed running command: {} {}", cmd, args.join(" ")); if !Command::new(cmd) + .envs(env.iter().map(|v| v.clone())) .args(args) .status() .expect(&failure_message) @@ -51,6 +52,10 @@ fn run_cmd(cmd: &str, args: &[&str]) { } } +fn run_cmd(cmd: &str, args: &[&str]) { + run_cmd_with_env(cmd, args, &[]) +} + fn main() { println!("cargo:rerun-if-changed=v8_c_api/src/v8_c_api.h"); println!("cargo:rerun-if-changed=v8_c_api/src/v8_c_api.cpp"); @@ -69,7 +74,11 @@ fn main() { run_cmd("unzip", &[&V8_HEADERS_PATH, "-d", *V8_HEADERS_DIRECTORY]); } - run_cmd("make", &["-C", "v8_c_api/"]); + if PROFILE.as_str() == "debug" { + run_cmd_with_env("make", &["-C", "v8_c_api/"], &[("DEBUG", "1")]); + } else { + run_cmd("make", &["-C", "v8_c_api/"]); + } let output_dir = env::var("OUT_DIR").expect("Can not find out directory"); diff --git a/v8_c_api/src/Makefile b/v8_c_api/src/Makefile index 222ae65..fc2d1f4 100644 --- a/v8_c_api/src/Makefile +++ b/v8_c_api/src/Makefile @@ -1,6 +1,13 @@ +GCC_FLAGS=-std=c++17 -DV8_COMPRESS_POINTERS -DV8_ENABLE_SANDBOX +ifeq ($(DEBUG),1) + GCC_FLAGS+=-O0 -DV8_ENABLE_CHECKS +else + GCC_FLAGS+=-O2 +endif + build: - g++ -I./v8include -fPIC -c -o2 -g v8_c_api.cpp -o c8_c_api.o -std=c++17 -DV8_COMPRESS_POINTERS -DV8_ENABLE_SANDBOX + g++ -I./v8include -fPIC -c -g v8_c_api.cpp -o c8_c_api.o $(GCC_FLAGS) ar r libv8.a c8_c_api.o clean: - rm -rf *.o *.a \ No newline at end of file + rm -rf *.o *.a