extendr / rextendr

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

`rust_sitrep()` seems to fail to instruct the user if target is not gnu and matches toolchain arch on Windows #326

Open yanyu2015 opened 6 months ago

yanyu2015 commented 6 months ago

system:win11 R version:4.3.2

> rust_sitrep()
Rust infrastructure sitrep:
✔ "rustup": 1.26.0 (5af9b9484 2023-04-05)
✔ "cargo": 1.74.1 (ecb9851af 2023-10-18)
ℹ host: x86_64-pc-windows-msvc
ℹ toolchain: stable-x86_64-pc-windows-msvc
ℹ target: x86_64-pc-windows-msvc

When I use the code in the example, I encounter the following error

> rust_function("fn add(a:f64, b:f64) -> f64 { a + b }")
ℹ build directory: C:/Users/admin/AppData/Local/Temp/RtmpKMywd4/file75383e69395d
    Updating crates.io index
   Compiling proc-macro2 v1.0.70
   Compiling unicode-ident v1.0.12
   Compiling libR-sys v0.6.0
   Compiling paste v1.0.14
   Compiling extendr-api v0.6.0
   Compiling once_cell v1.19.0
error: could not compile `once_cell` (lib) due to 242 previous errors
warning: build failed, waiting for other jobs to finish...

    |
454 |     impl<T: PartialEq> PartialEq for OnceCell<T> {
    |                        ^^^^^^^^^ not found in this scope

✖ error[E0405]: cannot find trait `PartialEq` in this scope
   --> D:\ds\Rusts\o\.cargo\registry\src\index.crates.io-6f17d22bba15001f\once_cell-1.19.0\src\lib.rs:454:13
    |
454 |     impl<T: PartialEq> PartialEq for OnceCell<T> {
    |             ^^^^^^^^^ not found in this scope

It should be noted that rust is installed in the path D:\ds\Rusts\o\, and I have also configured the path.

Ilia-Kosenkov commented 6 months ago

Strange that rust_sitrep() does not report that you are missing a target. It should look something like this image What is the version of {rextendr} that you use?

After I removed the required target (to get the screenshot above), I got like a million compilation errors in your example, which is expected. To solve this, run

rustup target add x86_64-pc-windows-gnu
rextendr::rust_sitrep()
#> Rust infrastructure sitrep:
#> ✔ "rustup": 1.26.0 (5af9b9484 2023-04-05)
#> ✔ "cargo": 1.72.1 (103a7ff2e 2023-08-15)
#> ℹ host: x86_64-pc-windows-msvc
#> ℹ toolchains: stable-i686-pc-windows-gnu, stable-x86_64-pc-windows-msvc
#>   (default), nightly-x86_64-pc-windows-gnu, nightly-x86_64-pc-windows-msvc,
#>   1.60.0-x86_64-pc-windows-msvc, 1.64.0-x86_64-pc-windows-gnu,
#>   1.64.0-x86_64-pc-windows-msvc, and 1.71.1-x86_64-pc-windows-msvc
#> ℹ targets: x86_64-pc-windows-gnu and x86_64-pc-windows-msvc

rextendr::rust_function("fn add(a:f64, b:f64) -> f64 { a + b }")
#> ℹ build directory: 'C:/Users/.../AppData/Local/Temp/RtmpqiLYgf/file6dc45f862d81'
#> ✔ Writing 'C:/Users/.../AppData/Local/Temp/RtmpqiLYgf/file6dc45f862d81/target/extendr_wrappers.R'

add(42, 100500)
#> [1] 100542
Ilia-Kosenkov commented 6 months ago

It also could be because you do not have a default toolchain set through rustup? You can try then first with

rustup default stable-msvc

followed by R

rextendr::rust_sitrep()
yanyu2015 commented 6 months ago

Now it can work properly. (After completing the above configuration, it may need to wait a moment before running rust_sitrep() to avoid potential issues of not finding rustup. Thank you.

Ilia-Kosenkov commented 6 months ago

I hope this helped. To {rextendr} people -- I will keep this issue open & assigned to me because I want to investigate why there was no 'error' message when the default toolchain was not selected. We should be able to detect this and inform the user.