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] diff --git a/build.rs b/build.rs index 90c60a0e..de064061 100644 --- a/build.rs +++ b/build.rs @@ -191,7 +191,7 @@ fn get_r_home() -> io::Result { } } -// 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()) { @@ -373,10 +373,11 @@ fn get_non_api() -> std::collections::HashSet { // 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", @@ -385,6 +386,8 @@ fn get_non_api() -> std::collections::HashSet { // 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)) @@ -520,12 +523,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()); @@ -602,8 +605,14 @@ struct TrimCommentsCallbacks; #[cfg(feature = "use-bindgen")] impl bindgen::callbacks::ParseCallbacks for TrimCommentsCallbacks { fn process_comment(&self, comment: &str) -> Option { - 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()) } } 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: ///
typedef struct {