Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Rust] Can't get minimal example to run #3637

Closed
Freymaurer opened this issue Dec 3, 2023 · 7 comments
Closed

[Rust] Can't get minimal example to run #3637

Freymaurer opened this issue Dec 3, 2023 · 7 comments

Comments

@Freymaurer
Copy link

Description

I should start with i have never done anything with/in rust before.

Here is what i did trying to setup fable-rust.

  1. Install DOWNLOAD RUSTUP-INIT.EXE (64-BIT
  2. create new folder
  3. dotnet new tool-manifest
  4. dotnet install fable
  5. create Cargo.toml (See Repro code)
  6. create test.fsx (See Repro code)
  7. run dotnet fable test.fsx --lang rust -e rs --noCache, creating test.rs.
  8. cargo clean
  9. cargo build

get the following error:
image

Repro code

//test.fsx
#r "nuget: Fable.Core, 4.2.0"

[<EntryPoint>]
let main argv =
  printfn "Hello World!"
  0
[package]
name = "fable-rust-sample"
version = "0.1.0"
edition = "2021" 

[[bin]]
name = "test"
path = "test.rs"

[dependencies]
fable_library_rust = { path = "./fable_modules/fable-library-rust" }

Copying the code from test.fsx into fable repl does not print "Hello World!" either.

Expected and actual results

I would expect "Hello World!" console output.

Related information

  • Fable version: 4.6.0
  • Operating system: Windows 11
@smoothdeveloper
Copy link
Contributor

@Freymaurer can you replace the script with a consoleapp fsproj?

dotnet new consoleapp -lang f#

in the same directory and moving your code

then adjusting the Cargo.toml like the screenshot below, then

dotnet fable . --lang rust

then

cargo run

image

@MangelMaxime
Copy link
Member

We also have a setup guide for Rust here and it is indeed using fsproj.

I know that in past fsx support was difficult because it is not real project and also it has less love/tests for it because the main usage of F# is via project file.

@Freymaurer
Copy link
Author

Ah yes i see, it worked with a .fsproj. Will there be .fsx support in the future? Just asking out of interest

@Freymaurer
Copy link
Author

One more issue i found when testing async:

//Program.fs
let asynWaitNPrint(wait: int) = async {
  do! Async.Sleep(wait)
  printfn "Hello World!"
  return 0
}

[<EntryPoint>]
let main argv =
  asynWaitNPrint 1000
  |> Async.RunSynchronously

Calling the output with cargo run results in:

   Compiling fable-rust-sample v0.1.0 (C:\Users\Kevin\Desktop\fable_transpile\rust)
error[E0432]: unresolved import `fable_library_rust::Async_`
  --> Program.fs.rs:16:33
   |
16 |         use fable_library_rust::Async_::Async;
   |                                 ^^^^^^ could not find `Async_` in `fable_library_rust`

error[E0432]: unresolved import `fable_library_rust::Async_`
  --> Program.fs.rs:17:33
   |
17 |         use fable_library_rust::Async_::runSynchronously;
   |                                 ^^^^^^ could not find `Async_` in `fable_library_rust`

error[E0432]: unresolved import `fable_library_rust::Async_`
  --> Program.fs.rs:18:33
   |
18 |         use fable_library_rust::Async_::sleep;
   |                                 ^^^^^^ could not find `Async_` in `fable_library_rust`

error[E0432]: unresolved import `fable_library_rust::AsyncBuilder_`
  --> Program.fs.rs:19:33
   |
19 |         use fable_library_rust::AsyncBuilder_::bind;
   |                                 ^^^^^^^^^^^^^ could not find `AsyncBuilder_` in `fable_library_rust`

error[E0432]: unresolved import `fable_library_rust::AsyncBuilder_`
  --> Program.fs.rs:20:33
   |
20 |         use fable_library_rust::AsyncBuilder_::delay;
   |                                 ^^^^^^^^^^^^^ could not find `AsyncBuilder_` in `fable_library_rust`

error[E0432]: unresolved import `fable_library_rust::AsyncBuilder_`
  --> Program.fs.rs:21:33
   |
21 |         use fable_library_rust::AsyncBuilder_::r_return;
   |                                 ^^^^^^^^^^^^^ could not find `AsyncBuilder_` in `fable_library_rust`

For more information about this error, try `rustc --explain E0432`.
error: could not compile `fable-rust-sample` (bin "Program") due to 6 previous errors

looking like this in vs code

image

@Freymaurer Freymaurer reopened this Dec 3, 2023
@ncave
Copy link
Collaborator

ncave commented Dec 3, 2023

@Freymaurer A lot of fable-libraty-rust implementations are opt-in and feature flagged, to minimize default library size and compilation time. For Async, you need to add this feature in your Cargo.toml:

[dependencies]
fable_library_rust = { path = "./fable_modules/fable-library-rust", features = ["threaded"] }

The full list of features is available here.

But yes, async support is still somewhat sketchy at the moment, for example Async.Sleep() is not implemented yet.
Contributions are very welcome, and no contribution is too small.

@Freymaurer
Copy link
Author

I see, yeah i wanted to add Rust support to Fable.Pyxpecto, as it supports js, ts, py and .net in the latest beta release.

Sadly i have 0 knowledge about rust and would be of no real help implementing. Just wanted to increase support.

@Freymaurer
Copy link
Author

I think this issue can be closed for now :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants