mirror of
https://github.com/danbulant/oxc
synced 2026-05-25 12:51:57 +00:00
Fix 2 mistakes in the `#[cfg]` for custom allocators in `oxlint` CLI. 1. `#![cfg(not(miri))]` at top of file was disabling the entire module if running miri, rather than just disabling custom allocator. 2. If both `target_os = "windows"` and `not(target_env = "msvc")`, it would try to register both mimalloc and jemalloc as global allocator. I am actually not sure if it's possible to compile for Windows without using MSVC, but it seems like a good idea not to assume.
43 lines
1.4 KiB
Rust
43 lines
1.4 KiB
Rust
// NB: Miri does not support custom allocators
|
|
#[cfg(all(feature = "allocator", not(miri), not(target_env = "msvc"), not(target_os = "windows")))]
|
|
#[global_allocator]
|
|
static GLOBAL: jemallocator::Jemalloc = jemallocator::Jemalloc;
|
|
|
|
#[cfg(all(feature = "allocator", not(miri), target_os = "windows"))]
|
|
#[global_allocator]
|
|
static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc;
|
|
|
|
use oxlint::{CliRunResult, LintRunner, Runner};
|
|
|
|
fn main() -> CliRunResult {
|
|
init_tracing();
|
|
init_miette();
|
|
|
|
let command = oxlint::lint_command().run();
|
|
command.handle_threads();
|
|
LintRunner::new(command).run()
|
|
}
|
|
|
|
// Initialize the data which relies on `is_atty` system calls so they don't block subsequent threads.
|
|
fn init_miette() {
|
|
miette::set_hook(Box::new(|_| Box::new(miette::MietteHandlerOpts::new().build()))).unwrap();
|
|
}
|
|
|
|
/// To debug `oxc_resolver`:
|
|
/// `OXC_LOG=oxc_resolver oxlint --import-plugin`
|
|
fn init_tracing() {
|
|
use tracing_subscriber::{filter::Targets, prelude::*};
|
|
|
|
// Usage without the `regex` feature.
|
|
// <https://github.com/tokio-rs/tracing/issues/1436#issuecomment-918528013>
|
|
tracing_subscriber::registry()
|
|
.with(std::env::var("OXC_LOG").map_or_else(
|
|
|_| Targets::new(),
|
|
|env_var| {
|
|
use std::str::FromStr;
|
|
Targets::from_str(&env_var).unwrap()
|
|
},
|
|
))
|
|
.with(tracing_subscriber::fmt::layer())
|
|
.init();
|
|
}
|