fsbolero / TryFSharpOnWasm

F# Compiler running in WebAssembly with Bolero
Apache License 2.0
38 stars 4 forks source link

Client site error when trying to build by myself. #10

Open ingted opened 1 year ago

ingted commented 1 year ago

image

ingted commented 1 year ago

The build was successful but no matter I stay in Bolero 0.14 or 0.20 there are always missing /tmp/mscorlib issue after downloading phase is finished.

Tarmil commented 1 year ago

Yeah this project hasn't been updated in a long time, so it won't work with a recent version of Blazor. It won't be easy to upgrade unfortunately, because both Blazor and and FSharp.Compiler.Service have had significant changes since then.

harrisse commented 1 year ago

I was able to get past this error by copying files from the browser cache to .net wasm's file system, but wasn't able to get the compiler to recognize any symbols from referenced dlls, e.g. The namespace 'FSharp' is not defined.

And file copying code in case it's useful to anyone else:

export async function loadCachedFiles(loadFile) {
    const cache = await caches.open('blazor-resources-/')
    const keys = await cache.keys()
    for (let i = 0; i < keys.length; i++) {
        const key = keys[i];
        const match = await cache.match(key)
        const buffer = await match.arrayBuffer()
        const stream = DotNet.createJSStreamReference(buffer);
        await loadFile.invokeMethodAsync('Invoke', key.url, stream);
    }
}
type Invocable2<'a, 'b> (f: 'a * 'b -> unit) =
    [<JSInvokable>]
    member this.Invoke(arg1, arg2) =
        f (arg1, arg2)

type Message =
    | Init 
    | LoadFile of Path: string * IJSStreamReference
    | FileLoaded of Path: string

let update message model =
    | Init ->
        let subscribe dispatch =
            let loadFile = Invocable2<string, IJSStreamReference> (LoadFile >> dispatch)
            JS.Module.Task.asyncVoid editorJS "loadCachedFiles" [| loadFile |]
            |> ignore
        model, Cmd.ofSub subscribe
    | LoadFile (path, stream) ->
        let copyFile () =
            task {
                let path = Regex.Replace(path, "^.*_framework/|.sha256.*$", "")
                let path = Path.Combine(Path.GetTempPath(), path)
                use! inStream = stream.OpenReadStreamAsync(Int64.MaxValue)
                use outStream = File.OpenWrite(path)
                let! _ = inStream.CopyToAsync(outStream)
                return path
            }
        model, Cmd.OfTask.either copyFile () FileLoaded Error
    | FileLoaded path -> ...