Skip to content

Commit

Permalink
feature: non-api adds non-API items to bindings (#237)
Browse files Browse the repository at this point in the history
* feature: added `non-api` feature that would
allo non-api items to be part of the
generated bindings. These bindings
are not cached.

* an empty blocklist result in all items being blocked

* ci: add `non-api` option to tests

---------

Co-authored-by: CGMossa <[email protected]>
  • Loading branch information
CGMossa and CGMossa authored May 11, 2024
1 parent 542d266 commit 09d76ad
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 9 deletions.
1 change: 1 addition & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,7 @@ jobs:
run: |
. ./ci-cargo.ps1
ci-cargo test -vv --features use-bindgen,layout_tests $(if ($env:RUST_TARGET -ne '') {"--target=$env:RUST_TARGET"} ) '--' --nocapture -ActionName "Running bindgen tests for target: $env:RUST_TARGET"
ci-cargo test -vv --features use-bindgen,non-api,layout_tests $(if ($env:RUST_TARGET -ne '') {"--target=$env:RUST_TARGET"} ) '--' --nocapture -ActionName "Running bindgen tests for target: $env:RUST_TARGET (with non-API)"
env:
RUST_TARGET: ${{ matrix.config.target }}

Expand Down
4 changes: 4 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,11 @@ default = ["runtime"]
# Turn on the 'use-bindgen' feature to generate bindings on the fly for your platform.
use-bindgen = ["bindgen", "regex"]

# retain non-API bindings from R (requires build-time generation of bindings)
non-api = ["use-bindgen"]

runtime = ["bindgen/runtime"]

# Enables generation of layout-tests in bindgen
layout_tests = ["use-bindgen"]

Expand Down
4 changes: 2 additions & 2 deletions bindings/bindings-windows-x86_64-R4.5-devel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ pub const R_MINOR: &[u8; 4] = b"5.0\0";
pub const R_STATUS: &[u8; 29] = b"Under development (unstable)\0";
pub const R_YEAR: &[u8; 5] = b"2024\0";
pub const R_MONTH: &[u8; 3] = b"05\0";
pub const R_DAY: &[u8; 3] = b"08\0";
pub const R_SVN_REVISION: u32 = 86528;
pub const R_DAY: &[u8; 3] = b"10\0";
pub const R_SVN_REVISION: u32 = 86529;
pub const R_GE_definitions: u32 = 13;
pub const R_GE_deviceClip: u32 = 14;
pub const R_GE_group: u32 = 15;
Expand Down
18 changes: 11 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<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,
Expand All @@ -392,8 +392,7 @@ fn get_non_api() -> std::collections::HashSet<String> {
];

// 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))
Expand All @@ -405,13 +404,18 @@ fn get_non_api() -> std::collections::HashSet<String> {
#[cfg(feature = "use-bindgen")]
/// Generate bindings by calling bindgen.
fn generate_bindings(r_paths: &InstallationPaths, version_info: &RVersionInfo) {
let blocklist = get_non_api().into_iter().collect::<Vec<_>>().join("|");

// The bindgen::Builder is the main entry point
// to bindgen, and lets you build up options for
// the resulting bindings.
let mut bindgen_builder = bindgen::Builder::default()
.blocklist_item(blocklist)
let mut bindgen_builder = bindgen::Builder::default();

#[cfg(all(feature = "use-bindgen", not(feature = "non-api")))]
{
let blocklist = get_non_api().into_iter().collect::<Vec<_>>().join("|");
bindgen_builder = bindgen_builder.blocklist_item(blocklist);
}

bindgen_builder = bindgen_builder
.emit_diagnostics()
.translate_enum_integer_types(true)
.merge_extern_blocks(true)
Expand Down

0 comments on commit 09d76ad

Please sign in to comment.