From 636801770eea172d140e64b691815ff11f6b556f Mon Sep 17 00:00:00 2001 From: ObserverOfTime Date: Thu, 11 Apr 2024 18:32:38 +0300 Subject: [PATCH] feat(cli): add debug build flag --- cli/loader/src/lib.rs | 3 ++- cli/src/main.rs | 33 ++++++++++----------------------- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/cli/loader/src/lib.rs b/cli/loader/src/lib.rs index 3371e1f7a2..dcf6407cfd 100644 --- a/cli/loader/src/lib.rs +++ b/cli/loader/src/lib.rs @@ -569,6 +569,7 @@ impl Loader { .cargo_warnings(false) .target(BUILD_TARGET) .host(BUILD_HOST) + .debug(self.debug_build) .file(&config.parser_path) .includes(&config.header_paths); @@ -608,7 +609,7 @@ impl Loader { command.args(cc_config.get_files()); command.arg("-link").arg(out); } else { - command.args(["-Werror=implicit-function-declaration", "-g"]); + command.arg("-Werror=implicit-function-declaration"); if cfg!(any(target_os = "macos", target_os = "ios")) { command.arg("-dynamiclib"); // TODO: remove when supported diff --git a/cli/src/main.rs b/cli/src/main.rs index 94df3322ba..8315b3410e 100644 --- a/cli/src/main.rs +++ b/cli/src/main.rs @@ -114,11 +114,8 @@ struct Build { pub path: Option, #[arg(long, help = "Make the parser reuse the same allocator as the library")] pub reuse_allocator: bool, - #[arg( - long, - help = "Build the parser with `TREE_SITTER_INTERNAL_BUILD` defined" - )] - pub internal_build: bool, + #[arg(long, short = '0', help = "Compile a parser in debug mode")] + pub debug: bool, } #[derive(Args)] @@ -502,15 +499,14 @@ fn run() -> Result<()> { .with_extension(env::consts::DLL_EXTENSION) }; - let flags: &[&str] = - match (build_options.reuse_allocator, build_options.internal_build) { - (true, true) => { - &["TREE_SITTER_REUSE_ALLOCATOR", "TREE_SITTER_INTERNAL_BUILD"] - } - (true, false) => &["TREE_SITTER_REUSE_ALLOCATOR"], - (false, true) => &["TREE_SITTER_INTERNAL_BUILD"], - (false, false) => &[], - }; + let flags: &[&str] = match (build_options.reuse_allocator, build_options.debug) { + (true, true) => &["TREE_SITTER_REUSE_ALLOCATOR", "TREE_SITTER_DEBUG"], + (true, false) => &["TREE_SITTER_REUSE_ALLOCATOR"], + (false, true) => &["TREE_SITTER_DEBUG"], + (false, false) => &[], + }; + + loader.use_debug_build(build_options.debug); let config = Config::load(None)?; let loader_config = config.get()?; @@ -563,11 +559,6 @@ fn run() -> Result<()> { let cancellation_flag = util::cancel_on_signal(); let mut parser = Parser::new(); - if parse_options.debug { - // For augmenting debug logging in external scanners - env::set_var("TREE_SITTER_DEBUG", "1"); - } - loader.use_debug_build(parse_options.debug_build); #[cfg(feature = "wasm")] @@ -663,10 +654,6 @@ fn run() -> Result<()> { Commands::Test(test_options) => { let config = Config::load(test_options.config_path)?; - if test_options.debug { - // For augmenting debug logging in external scanners - env::set_var("TREE_SITTER_DEBUG", "1"); - } loader.use_debug_build(test_options.debug_build);