Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add function signature attributes #176

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
21 changes: 15 additions & 6 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down Expand Up @@ -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",
Expand All @@ -385,6 +386,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))
Expand Down Expand Up @@ -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());

Expand Down Expand Up @@ -602,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())
}
}

Expand Down
2 changes: 1 addition & 1 deletion wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down