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

Gather comments from headers #141

Merged
merged 8 commits into from
Mar 1, 2023
Merged
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
243 changes: 236 additions & 7 deletions bindings/bindings-linux-aarch64-R4.1.rs

Large diffs are not rendered by default.

244 changes: 237 additions & 7 deletions bindings/bindings-linux-aarch64-R4.2.rs

Large diffs are not rendered by default.

249 changes: 240 additions & 9 deletions bindings/bindings-linux-aarch64-R4.3-devel.rs

Large diffs are not rendered by default.

243 changes: 236 additions & 7 deletions bindings/bindings-linux-x86_64-R4.1.rs

Large diffs are not rendered by default.

244 changes: 237 additions & 7 deletions bindings/bindings-linux-x86_64-R4.2.rs

Large diffs are not rendered by default.

249 changes: 240 additions & 9 deletions bindings/bindings-linux-x86_64-R4.3-devel.rs

Large diffs are not rendered by default.

244 changes: 237 additions & 7 deletions bindings/bindings-macos-aarch64-R4.2.rs

Large diffs are not rendered by default.

243 changes: 236 additions & 7 deletions bindings/bindings-macos-x86_64-R4.1.rs

Large diffs are not rendered by default.

244 changes: 237 additions & 7 deletions bindings/bindings-macos-x86_64-R4.2.rs

Large diffs are not rendered by default.

340 changes: 327 additions & 13 deletions bindings/bindings-macos-x86_64-R4.3-devel.rs

Large diffs are not rendered by default.

226 changes: 219 additions & 7 deletions bindings/bindings-windows-x86-R4.1.rs

Large diffs are not rendered by default.

226 changes: 219 additions & 7 deletions bindings/bindings-windows-x86_64-R4.1.rs

Large diffs are not rendered by default.

226 changes: 219 additions & 7 deletions bindings/bindings-windows-x86_64-R4.2.rs

Large diffs are not rendered by default.

231 changes: 222 additions & 9 deletions bindings/bindings-windows-x86_64-R4.3-devel.rs

Large diffs are not rendered by default.

28 changes: 23 additions & 5 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ fn get_r_version(
Ok(v) => Ok(v),
// If the envvar is not present, then use the actual R binary to get the version.
Err(EnvVarError::EnvVarNotPresent) => get_r_version_from_r(r_paths),
// In the case of any error other than the absense of envvar, stop with
// In the case of any error other than the absence of envvar, stop with
// that error because it means the envvar is set and something is wrong.
e @ Err(_) => e,
}
Expand Down Expand Up @@ -389,7 +389,7 @@ fn generate_bindings(r_paths: &InstallationPaths, version_info: &RVersionInfo) {
.unwrap();

// Extract all the AST entities into `e`, as well as listing up all the
// include files in a chain into `inclide_files`.
// include files in a chain into `include_files`.
let mut include_files = std::collections::HashSet::new();
let e = tu
.get_entity()
Expand Down Expand Up @@ -429,7 +429,7 @@ fn generate_bindings(r_paths: &InstallationPaths, version_info: &RVersionInfo) {
}
}

// Do some regex-fu agaist the text content of all the include files. This
// Do some regex-fu against the text content of all the include files. This
// handles these 3 cases:
//
// case 1) numeric literals
Expand All @@ -455,7 +455,7 @@ fn generate_bindings(r_paths: &InstallationPaths, version_info: &RVersionInfo) {
}
}

// This cannot be detected because the #define-ed constats are aliased in another #define
// This cannot be detected because the #define-ed constants are aliased in another #define
// c.f. https://github.com/wch/r-source/blob/9f284035b7e503aebe4a804579e9e80a541311bb/src/include/R_ext/GraphicsEngine.h#L93
allowlist.insert("R_GE_version".to_string());

Expand Down Expand Up @@ -484,6 +484,7 @@ fn generate_bindings(r_paths: &InstallationPaths, version_info: &RVersionInfo) {
"Generating bindings for target: {}, os: {}, architecture: {}",
target, target_os, target_arch
);

// Point to the correct headers
bindgen_builder = bindgen_builder.clang_args(&[
format!("-I{}", r_paths.include.display()),
Expand All @@ -508,18 +509,23 @@ fn generate_bindings(r_paths: &InstallationPaths, version_info: &RVersionInfo) {

// Finish the builder and generate the bindings.
let bindings = bindgen_builder
.generate_comments(true)
.parse_callbacks(Box::new(RCallbacks))
.clang_arg("-fparse-all-comments")
.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());

bindings
.write_to_file(out_path.join("bindings.rs"))
.expect("Couldn't write bindings to default output path!");

// Also write the bindings to a folder specified by LIBRSYS_BINDINGS_OUTPUT_PATH, if defined
// Also write the bindings to a folder specified by `LIBRSYS_BINDINGS_OUTPUT_PATH`, if defined
if let Some(alt_target) = env::var_os(ENVVAR_BINDINGS_OUTPUT_PATH) {
let out_path = PathBuf::from(alt_target);
// if folder doesn't exist, try to create it
Expand Down Expand Up @@ -580,6 +586,18 @@ fn retrieve_prebuild_bindings(version_info: &RVersionInfo) {
println!("cargo:rerun-if-changed={}", from.display());
}

/// Provide extra cleaning of the processed elements in the headers.
#[derive(Debug)]
struct RCallbacks;

#[cfg(feature = "use-bindgen")]
impl bindgen::callbacks::ParseCallbacks for RCallbacks {
fn process_comment(&self, comment: &str) -> Option<String> {
let trim_comment = comment.trim();
Some(trim_comment.to_string())
}
}

fn main() {
let r_paths = probe_r_paths();

Expand Down