Back to all reviewers

prefer compile-time configuration

tree-sitter/tree-sitter
Based on 7 comments
Rust

Use compile-time configuration checks with `cfg!` macros instead of runtime environment variable parsing when the configuration decision can be determined at build time. This improves performance by eliminating runtime checks and makes the code's behavior more predictable.

Configurations Rust

Reviewer Prompt

Use compile-time configuration checks with cfg! macros instead of runtime environment variable parsing when the configuration decision can be determined at build time. This improves performance by eliminating runtime checks and makes the code’s behavior more predictable.

Prefer this:

if cfg!(target_family = "wasm") {
    let sysroot = std::path::Path::new("bindings/rust/wasm-sysroot");
    c_config.include(sysroot);
}

#[cfg(target_env = "msvc")]
c_config.flag("-utf-8");

#[cfg(feature = "std")]
use std::fs;

Instead of this:

if std::env::var("TARGET").unwrap() == "wasm32-unknown-unknown" {
    let sysroot_dir = std::path::Path::new("bindings/rust/wasm-sysroot");
    c_config.include(sysroot_dir);
}

Use cfg! for target platform checks, #[cfg(feature = "...")] for optional features, and #[cfg(target_env = "...")] for toolchain-specific behavior. Reserve runtime environment variable checks for user-configurable settings that must be determined at runtime, not build-time architectural decisions.

7
Comments Analyzed
Rust
Primary Language
Configurations
Category

Source Discussions