From c8c3c1993d0fe2ed7b8aad34f16683c8be6af14b Mon Sep 17 00:00:00 2001
From: mossa <cgmossa@gmail.com>
Date: Mon, 14 Aug 2023 20:42:42 +0200
Subject: [PATCH 1/7] Update `bindgen`.

---
 Cargo.toml | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/Cargo.toml b/Cargo.toml
index e031936e..239aeb0d 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -19,7 +19,7 @@ repository = "https://github.com/extendr/libR-sys"
 [dependencies]
 
 [build-dependencies]
-bindgen = { version = "0.64", optional = true }
+bindgen = { version = "0.66", optional = true, features = ["experimental"] }
 clang = { version = "2", optional = true, features = ["runtime", "clang_3_7"] }
 
 [features]

From 55cfcb789f6bd9c7a01d43b56df75261e69ffe0d Mon Sep 17 00:00:00 2001
From: mossa <cgmossa@gmail.com>
Date: Mon, 14 Aug 2023 20:42:59 +0200
Subject: [PATCH 2/7] minor edit

---
 build.rs | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/build.rs b/build.rs
index 90c60a0e..24db2331 100644
--- a/build.rs
+++ b/build.rs
@@ -191,7 +191,7 @@ fn get_r_home() -> io::Result<PathBuf> {
     }
 }
 
-// Get the path to the R library
+/// Returns the path to the R library.
 fn get_r_library(r_home: &Path) -> PathBuf {
     let pkg_target_arch = env::var("CARGO_CFG_TARGET_ARCH").unwrap();
     match (cfg!(windows), pkg_target_arch.as_str()) {

From f127f3a1803804e4ca8d13ab3cc8b23742c1e77e Mon Sep 17 00:00:00 2001
From: mossa <cgmossa@gmail.com>
Date: Mon, 14 Aug 2023 20:43:20 +0200
Subject: [PATCH 3/7] This is how I got the non-api stuff

---
 build.rs | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/build.rs b/build.rs
index 24db2331..84ed7d29 100644
--- a/build.rs
+++ b/build.rs
@@ -385,6 +385,8 @@ fn get_non_api() -> std::collections::HashSet<String> {
     // nonAPI.txt is generated by
     //
     //     Rscript -e 'cat(tools:::nonAPI, "\n")' | uniq | sort
+    // Another attempt"
+    //     Rscript -e 'tools:::nonAPI |> unique() |> sort() |> paste0(collapse = "\n") |> cat(file = "nonAPI.txt")'
     let non_api = include_str!("./nonAPI.txt")
         .lines()
         .filter(|e| !REQUIRED_NON_API.contains(e))

From 7216871a7cbcf5c99b1f7ab1c6ead09f5b41d5b9 Mon Sep 17 00:00:00 2001
From: mossa <cgmossa@gmail.com>
Date: Mon, 14 Aug 2023 20:43:51 +0200
Subject: [PATCH 4/7] This is for -> ! detection

---
 build.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/build.rs b/build.rs
index 84ed7d29..33d09c86 100644
--- a/build.rs
+++ b/build.rs
@@ -522,6 +522,7 @@ fn generate_bindings(r_paths: &InstallationPaths, version_info: &RVersionInfo) {
         .generate_comments(true)
         .parse_callbacks(Box::new(TrimCommentsCallbacks))
         .clang_arg("-fparse-all-comments")
+        .enable_function_attribute_detection()
         .generate()
         // Unwrap the Result and panic on failure.
         .expect("Unable to generate bindings");

From bad94dc16fbf82f252dbc81ccc4ad52346c18b70 Mon Sep 17 00:00:00 2001
From: mossa <cgmossa@gmail.com>
Date: Mon, 14 Aug 2023 20:44:09 +0200
Subject: [PATCH 5/7] Change in bindgen

---
 build.rs | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/build.rs b/build.rs
index 33d09c86..b5aad5f8 100644
--- a/build.rs
+++ b/build.rs
@@ -522,13 +522,12 @@ fn generate_bindings(r_paths: &InstallationPaths, version_info: &RVersionInfo) {
         .generate_comments(true)
         .parse_callbacks(Box::new(TrimCommentsCallbacks))
         .clang_arg("-fparse-all-comments")
+        .emit_diagnostics()
         .enable_function_attribute_detection()
         .generate()
         // Unwrap the Result and panic on failure.
         .expect("Unable to generate bindings");
 
-    bindings.emit_warnings();
-
     // Write the bindings to the $OUT_DIR/bindings.rs file.
     let out_path = PathBuf::from(env::var_os("OUT_DIR").unwrap());
 

From 15eefb23cd1dafb2aafc032be001c2a0d21773ab Mon Sep 17 00:00:00 2001
From: mossa <cgmossa@gmail.com>
Date: Mon, 14 Aug 2023 20:44:35 +0200
Subject: [PATCH 6/7] Fixes warnings with `cargo doc`.

---
 build.rs | 13 ++++++++++---
 1 file changed, 10 insertions(+), 3 deletions(-)

diff --git a/build.rs b/build.rs
index b5aad5f8..de064061 100644
--- a/build.rs
+++ b/build.rs
@@ -373,10 +373,11 @@ fn get_non_api() -> std::collections::HashSet<String> {
     // Several non-APIs are required for extendr-engine, so we explicitly allow
     // these here. If extendr-engine (or other crate) requires more non-APIs,
     // add it here with caution.
-    const REQUIRED_NON_API: [&str; 6] = [
+    const REQUIRED_NON_API: [&str; 7] = [
         "R_CStackLimit",
         "R_CleanTempDir",
         "R_RunExitFinalizers",
+        "Rf_initEmbeddedR",
         "Rf_endEmbeddedR",
         "Rf_initialize_R",
         "setup_Rmainloop",
@@ -604,8 +605,14 @@ struct TrimCommentsCallbacks;
 #[cfg(feature = "use-bindgen")]
 impl bindgen::callbacks::ParseCallbacks for TrimCommentsCallbacks {
     fn process_comment(&self, comment: &str) -> Option<String> {
-        let trim_comment = comment.trim();
-        Some(trim_comment.to_string())
+        // trim comments
+        let comment = comment.trim();
+
+        // replace bare brackets
+        let comment = comment.replace("[", r"`[");
+        let comment = comment.replace("]", r"]`");
+
+        Some(comment.into())
     }
 }
 

From edc357d4af4a8c71b6ff81a082f18bdd9eefab9c Mon Sep 17 00:00:00 2001
From: mossa <cgmossa@gmail.com>
Date: Mon, 14 Aug 2023 20:44:50 +0200
Subject: [PATCH 7/7] fixes warning with `cargo doc`

---
 wrapper.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/wrapper.h b/wrapper.h
index da6a06cc..3e8362da 100644
--- a/wrapper.h
+++ b/wrapper.h
@@ -44,7 +44,7 @@ typedef ptrdiff_t R_xlen_t_rust;
 // R 4.3 redefined `Rcomplex` to a union for compatibility with Fortran.
 // But the old definition is compatible both the union version
 // and the struct version.
-// See: https://github.com/extendr/extendr/issues/524
+// See: <https://github.com/extendr/extendr/issues/524>
 /// <div rustbindgen replaces="Rcomplex"></div>
 typedef struct
 {