Squashed 'third_party/autocxx/' content from commit 629e8fa53
git-subtree-dir: third_party/autocxx
git-subtree-split: 629e8fa531a633164c0b52e2a3cab536d4cd0849
Signed-off-by: Brian Silverman <bsilver16384@gmail.com>
Change-Id: I62a03b0049f49adf029e0204639cdb5468dde1a1
diff --git a/gen/build/src/lib.rs b/gen/build/src/lib.rs
new file mode 100644
index 0000000..c1df580
--- /dev/null
+++ b/gen/build/src/lib.rs
@@ -0,0 +1,51 @@
+// Copyright 2020 Google LLC
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+
+#![forbid(unsafe_code)]
+
+use autocxx_engine::{BuilderContext, RebuildDependencyRecorder};
+use indexmap::set::IndexSet as HashSet;
+use std::{io::Write, sync::Mutex};
+
+pub type Builder = autocxx_engine::Builder<'static, CargoBuilderContext>;
+
+#[doc(hidden)]
+pub struct CargoBuilderContext;
+
+impl BuilderContext for CargoBuilderContext {
+ fn setup() {
+ env_logger::builder()
+ .format(|buf, record| writeln!(buf, "cargo:warning=MESSAGE:{}", record.args()))
+ .init();
+ }
+ fn get_dependency_recorder() -> Option<Box<dyn RebuildDependencyRecorder>> {
+ Some(Box::new(CargoRebuildDependencyRecorder::new()))
+ }
+}
+
+#[derive(Debug)]
+struct CargoRebuildDependencyRecorder {
+ printed_already: Mutex<HashSet<String>>,
+}
+
+impl CargoRebuildDependencyRecorder {
+ fn new() -> Self {
+ Self {
+ printed_already: Mutex::new(HashSet::new()),
+ }
+ }
+}
+
+impl RebuildDependencyRecorder for CargoRebuildDependencyRecorder {
+ fn record_header_file_dependency(&self, filename: &str) {
+ let mut already = self.printed_already.lock().unwrap();
+ if already.insert(filename.into()) {
+ println!("cargo:rerun-if-changed={}", filename);
+ }
+ }
+}