From 633f5a0cf7e2377acb1876b048c206b01497f13a Mon Sep 17 00:00:00 2001 From: Mossa Date: Thu, 9 May 2024 21:39:15 +0200 Subject: [PATCH] feature: added `non-api` feature that would allo non-api items to be part of the generated bindings. These bindings are not cached. --- Cargo.toml | 4 ++++ build.rs | 10 +++++++--- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 86e49018..d3678214 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -28,7 +28,11 @@ default = ["runtime"] # Turn on the 'use-bindgen' feature to generate bindings on the fly for your platform. use-bindgen = ["bindgen", "clang"] +# retain non-API bindings from R (requires build-time generation of bindings) +non-api = ["use-bindgen"] + runtime = ["clang/runtime", "bindgen/runtime"] + # Enables generation of layout-tests in bindgen layout_tests = ["use-bindgen"] diff --git a/build.rs b/build.rs index 2654fef6..6476718a 100644 --- a/build.rs +++ b/build.rs @@ -377,7 +377,7 @@ fn set_r_version_vars(ver: &RVersionInfo) { println!("cargo:r_version_devel={}", ver.devel); // Becomes DEP_R_R_VERSION_DEVEL for clients } -#[cfg(feature = "use-bindgen")] +#[cfg(all(feature = "use-bindgen", not(feature = "non-api")))] 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, @@ -392,8 +392,7 @@ fn get_non_api() -> std::collections::HashSet { ]; // nonAPI.txt is generated by - // - // Rscript -e 'cat(tools:::nonAPI, "\n")' | uniq | sort + // Rscript -e 'cat(tools:::nonAPI, sep = "\n")' | tr -d '\r' | sort -u | tee ./nonAPI.txt let non_api = include_str!("./nonAPI.txt") .lines() .filter(|e| !REQUIRED_NON_API.contains(e)) @@ -402,6 +401,11 @@ fn get_non_api() -> std::collections::HashSet { std::collections::HashSet::from_iter(non_api) } +#[cfg(all(feature = "use-bindgen", feature = "non-api"))] +fn get_non_api() -> std::collections::HashSet { + Default::default() +} + #[cfg(feature = "use-bindgen")] /// Generate bindings by calling bindgen. fn generate_bindings(r_paths: &InstallationPaths, version_info: &RVersionInfo) {