Skip to content

Commit

Permalink
feat(cli): add debug build flag
Browse files Browse the repository at this point in the history
  • Loading branch information
ObserverOfTime authored and amaanq committed May 17, 2024
1 parent 20b4353 commit 6368017
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 24 deletions.
3 changes: 2 additions & 1 deletion cli/loader/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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
Expand Down
33 changes: 10 additions & 23 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,8 @@ struct Build {
pub path: Option<String>,
#[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)]
Expand Down Expand Up @@ -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()?;
Expand Down Expand Up @@ -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")]
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 6368017

Please sign in to comment.