Skip to content

Commit 1c6bdc3

Browse files
committed
build: conditionalize ANSI support to Windows only
The `enable-ansi-support` crate is only required on Windows to enable ANSI escape codes in the terminal. On other operating systems, this functionality is native. This change restricts the dependency to Windows targets and wraps its usage in a `#[cfg(target_os = "windows")]` block, reducing the dependency footprint for non-Windows builds.
1 parent 630516b commit 1c6bdc3

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ der-parser = "10.0.0"
5353
digest = "0.10.7"
5454
dsa = "0.6.3"
5555
ecdsa = "0.16.9"
56-
enable-ansi-support = "0.3.1"
5756
env_logger = "0.11.10"
5857
figment = "0.10.19"
5958
globwalk = "0.9.1"

cli/Cargo.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ figment = { workspace = true, features = ["toml"] }
5757
globwalk = { workspace = true }
5858
home = { workspace = true }
5959
itertools = { workspace = true }
60-
enable-ansi-support = { workspace = true }
6160
env_logger = { workspace = true, optional = true, features = ["auto-color"] }
6261
log = { workspace = true, optional = true }
6362
protobuf = { workspace = true }
@@ -85,4 +84,7 @@ wild = "2.2.1"
8584
[dev-dependencies]
8685
assert_cmd = "2.2.2"
8786
assert_fs = "1.1.4"
88-
predicates = { workspace = true }
87+
predicates = { workspace = true }
88+
89+
[target.'cfg(windows)'.dependencies]
90+
enable-ansi-support = "0.3.1"

cli/src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ const EXIT_ERROR: i32 = 1;
2929
const CONFIG_FILE: &str = ".yara-x.toml";
3030

3131
fn main() -> anyhow::Result<()> {
32-
// Enable support for ANSI escape codes in Windows. In other platforms
33-
// this is a no-op.
32+
// Enable support for ANSI escape codes in Windows.
33+
#[cfg(target_os = "windows")]
3434
if let Err(err) = enable_ansi_support::enable_ansi_support() {
3535
println!("could not enable ANSI support: {err}")
3636
}

0 commit comments

Comments
 (0)