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

Missing target causes an error #192

Closed CGMossa closed 7 months ago

CGMossa commented 2 years ago

Calling rust_function causes this error if target x86_64-pc-windows-gnu.

This is fixed with rustup target add x86_64-pc-windows-gnu.

Maybe we can remedy this somehow?

> # create a Rust function
> rust_function("fn add(a:f64, b:f64) -> f64 { a + b }")
ℹ build directory: C:/Users/angus/AppData/Local/Temp/RtmpMNe9BF/file311051b2883
Opening fd 2
    Updating crates.io index
 Downloading crates ...
  Downloaded syn v1.0.93
   Compiling winapi v0.3.9
   Compiling proc-macro2 v1.0.38
   Compiling unicode-xid v0.2.3
   Compiling syn v1.0.93
   Compiling extendr-engine v0.2.0
   Compiling lazy_static v1.4.0
error: could not compile `lazy_static` due to 20 previous errors
warning: build failed, waiting for other jobs to finish...
error: build failed
Error in `invoke_cargo()`:
! Rust code could not be compiled successfully. Aborting.
✖ error[E0463]: can't find crate for `core`
  |
  = note: the `x86_64-pc-windows-gnu` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-pc-windows-gnu`
✖ error[E0463]: can't find crate for `compiler_builtins`
✖ error[E0463]: can't find crate for `core`
 --> C:\Users\angus\.cargo\registry\src\github.com-1ecc6299db9ec823\lazy_static-1.4.0\src\inline_lazy.rs:8:1
  |
8 | extern crate core;
  | ^^^^^^^^^^^^^^^^^^ can't find crate
  |
  = note: the `x86_64-pc-windows-gnu` target may not be installed
  = help: consider downloading the target with `rustup target add x86_64-pc-windows-gnu`
✖ error[E0463]: can't find crate for `std`
 --> C:\Users\angus\.cargo\registry\src\github.com-1ecc6299db9ec823\lazy_static-1.4.0\src\inline_lazy.rs:9:1
  |
9 | extern crate std;
  | ^^^^^^^^^^^^^^^^^ can't find crate
[redacted]
CGMossa commented 2 years ago

I also found that devtools should be Imports and not just Suggests.

Ilia-Kosenkov commented 2 years ago

This can be related to #168. We can at least provide the information about what is available and what is missing. Not sure we should interfere with the installation process.

yutannihilation commented 2 years ago

Thanks for catching. I already updated the setup instruction, so I hope not so many people will see this error, but I think it's nice if we can display more friendly error.

I also found that devtools should be Imports and not just Suggests.

JFYI, rextendr requires users to install devtools when it's necessary, so I don't think so.

https://github.com/extendr/rextendr/blob/7e25565091ac4e4fa0f086ff919736d4584f4fec/R/rextendr_document.R#L19

JosiahParry commented 1 year ago

I ran into this problem today when installing on my work machine (windows). Solved by following the instruction rustup target add x86_64-pc-windows-gnu

JosiahParry commented 1 year ago

We could, in theory, catch that specific message, but that feels icky.

JosiahParry commented 1 year ago

Is this resolved by rust_sitrep()? Perhaps if error is encountered in rust_function() or rust_source() the error message can recommend running rust_sitrep()?

Ilia-Kosenkov commented 1 year ago

Sounds reasonable. Also we should update docs (README) to mention rust_sitrep(). Up for the task? :)

JosiahParry commented 7 months ago

See https://github.com/extendr/rextendr?tab=readme-ov-file#usage.