Skip to content

Commit

Permalink
Gather comments from headers (#141)
Browse files Browse the repository at this point in the history
* add emit warnings

* snaps comments from the source!

* Update bindings [skip ci]

* Added callbacks processing to trim comments

* hide behind feature-gate

* this didn't do anything anyways, let us try without it

* Update bindings [skip ci]

* Remove comment

Co-authored-by: Hiroaki Yutani <[email protected]>

---------

Co-authored-by: CGMossa <[email protected]>
Co-authored-by: Michael Milton <[email protected]>
Co-authored-by: Hiroaki Yutani <[email protected]>
  • Loading branch information
4 people authored Mar 1, 2023
1 parent 9d21fc2 commit 02d1427
Show file tree
Hide file tree
Showing 15 changed files with 3,365 additions and 115 deletions.
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

0 comments on commit 02d1427

Please sign in to comment.