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/examples/pod/Cargo.toml b/examples/pod/Cargo.toml
new file mode 100644
index 0000000..71bd5a0
--- /dev/null
+++ b/examples/pod/Cargo.toml
@@ -0,0 +1,21 @@
+# Copyright 2021 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.
+
+[package]
+name = "autocxx-pod-example"
+version = "0.1.0"
+authors = ["Adrian Taylor <adetaylor@chromium.org>"]
+edition = "2021"
+
+[dependencies]
+cxx = "1.0.54"
+autocxx = { path = "../..", version="0.22.0" }
+
+[build-dependencies]
+autocxx-build = { path = "../../gen/build", version="0.22.0" }
+miette = { version="4.3", features = [ "fancy" ] }
diff --git a/examples/pod/build.rs b/examples/pod/build.rs
new file mode 100644
index 0000000..a6bd95c
--- /dev/null
+++ b/examples/pod/build.rs
@@ -0,0 +1,17 @@
+// Copyright 2021 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.
+
+fn main() -> miette::Result<()> {
+    let path = std::path::PathBuf::from("src");
+    let mut b = autocxx_build::Builder::new("src/main.rs", &[&path]).build()?;
+    b.flag_if_supported("-std=c++14")
+        .compile("autocxx-pod-example");
+    println!("cargo:rerun-if-changed=src/main.rs");
+    println!("cargo:rerun-if-changed=src/cpp.h");
+    Ok(())
+}
diff --git a/examples/pod/src/cpp.h b/examples/pod/src/cpp.h
new file mode 100644
index 0000000..94d1466
--- /dev/null
+++ b/examples/pod/src/cpp.h
@@ -0,0 +1,27 @@
+// Copyright 2021 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.
+
+#pragma once
+#include <iostream>
+
+struct Point {
+  int x;
+  int y;
+};
+
+class Rect {
+public:
+  Point top_left;
+  Point bottom_right;
+  int width() const { return bottom_right.x - top_left.x; }
+  int height() const { return bottom_right.y - top_left.y; }
+};
+
+inline void print_point(Point p) {
+  std::cout << "(" << p.x << ", " << p.y << ")\n";
+}
diff --git a/examples/pod/src/main.rs b/examples/pod/src/main.rs
new file mode 100644
index 0000000..7a8b659
--- /dev/null
+++ b/examples/pod/src/main.rs
@@ -0,0 +1,40 @@
+// Copyright 2021 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.
+
+use autocxx::prelude::*;
+
+include_cpp! {
+    // C++ headers we want to include.
+    #include "cpp.h"
+    // Safety policy. We are marking that this whole C++ inclusion is unsafe
+    // which means the functions themselves do not need to be marked
+    // as unsafe. Other policies are possible.
+    safety!(unsafe)
+    // What types and functions we want to generate
+    generate_pod!("Rect")
+    generate!("print_point")
+}
+
+use ffi::{Point, Rect};
+
+// A simple example dealing with plain-old-data types.
+
+fn main() {
+    let r = Rect {
+        top_left: Point { x: 3, y: 3 },
+        bottom_right: Point { x: 12, y: 15 },
+    };
+    // r.width() and r.height() return an autocxx::c_int
+    // which we need to unpackage. It is hoped that one day cxx will
+    // natively support 'int' and friends, and that won't be necessary.
+    let center = Point {
+        x: r.top_left.x + r.width().0 / 2,
+        y: r.top_left.y + r.height().0 / 2,
+    };
+    ffi::print_point(center);
+}