Skip to content

Commit e9efdc3

Browse files
authored
Merge pull request #1389 from google/fix-double-init
Fix double init of EnvLogger
2 parents 657540f + fea2009 commit e9efdc3

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

gen/build/src/lib.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,26 @@
1010

1111
use autocxx_engine::{BuilderContext, RebuildDependencyRecorder};
1212
use indexmap::set::IndexSet as HashSet;
13-
use std::{io::Write, sync::Mutex};
13+
use std::{
14+
borrow::Borrow,
15+
io::Write,
16+
sync::{LazyLock, Mutex},
17+
};
1418

1519
pub type Builder = autocxx_engine::Builder<'static, CargoBuilderContext>;
1620

1721
#[doc(hidden)]
1822
pub struct CargoBuilderContext;
1923

24+
static ENV_LOGGER: LazyLock<()> = LazyLock::new(|| {
25+
env_logger::builder()
26+
.format(|buf, record| writeln!(buf, "cargo:warning=MESSAGE:{}", record.args()))
27+
.init();
28+
});
29+
2030
impl BuilderContext for CargoBuilderContext {
2131
fn setup() {
22-
env_logger::builder()
23-
.format(|buf, record| writeln!(buf, "cargo:warning=MESSAGE:{}", record.args()))
24-
.init();
32+
ENV_LOGGER.borrow();
2533
}
2634
fn get_dependency_recorder() -> Option<Box<dyn RebuildDependencyRecorder>> {
2735
Some(Box::new(CargoRebuildDependencyRecorder::new()))

0 commit comments

Comments
 (0)