extendr / rextendr

An R package that helps scaffolding extendr-enabled packages or compiling Rust code dynamically
https://extendr.github.io/rextendr/
Other
184 stars 27 forks source link

Support switching `features` during runtime compilation #139

Closed Ilia-Kosenkov closed 3 years ago

Ilia-Kosenkov commented 3 years ago

Currently, extendr has at least one feature-guarded...well, feature: ndarray support https://github.com/extendr/extendr/blob/00fed0d8fce2ca0a3c4bf822f685d0d6ada0a1ae/extendr-api/src/prelude.rs#L56-L60

I realized it is currently impossible to write [features] to Cargo.toml, nor pass any explicit arguments to cargo during compilation.

Relevant changes should probably be made here https://github.com/extendr/rextendr/blob/31c3cd331b0923f17da22c0f27d2168c2014f1e7/R/source.R#L154-L159

Currently to_toml supports empty arrays by providing R vector of length 0, so enabling ndarray feature might look like:


to_toml(...,
    features = list(ndarray = integer(0))
)

Alternatively, we can export something like rextendr::toml_empty_array().

clauswilke commented 3 years ago

I feel that both

to_toml(...,
    features = list(ndarray = integer(0))
)

and

to_toml(...,
    features = list(ndarray = rextendr::toml_empty_array())
)

are ugly. How about replacing NAs with nothing, so you could write:

to_toml(...,
    features = list(ndarray = NA)
)
Ilia-Kosenkov commented 3 years ago

@clauswilke, yeah, we can do that. I will try to draft a PR for this.