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

Reliably detecting `rtools` when compiling rust code at runtime #108

Closed Ilia-Kosenkov closed 3 years ago

Ilia-Kosenkov commented 3 years ago

{rextendr} supports two different scenarios:

In all cases, on Windows compilation depends on rtools (especially now, with the new version we no longer need msys2). When rust is part of the package, rtools path is injected when the package is built, as part of a regular R compilation process. When rust is compiled at runtime, we have to do everything ourselves. Currently, we use RTOOLS40_HOME, set up by the rtools installer, to determine if rtools is present on the system. However, there are other signs of rtools installation, including folder structure at the default path (C:\rtools40) and registry entry.

We have a dependency on {pkgbuild}, which has a set of nice methods pkgbuild::has_rtools(), pkgbuild::rtools_path(), which allow offloading rtools lookup to the package that specializes in it. Moreover, there is a pkgbuild::rtools_needed(), which retrieves a string with the required rtools version that can be put into the error message.

{pkgbuild} imports {withr}, so we can safely import {withr} ourselves and use it to set up environment variables locally instead of relying on on.exit().

I have a working prototype here https://github.com/Ilia-Kosenkov/rextendr/tree/find-rtools, which I suggest to consider after #106 is merged.

clauswilke commented 3 years ago

Sounds good to me.