Skip to content

Should now error on wasm (not on emscripten or wasi) without wasmbind? #1301

@alexkazik

Description

@alexkazik

I've written a program for wasm and everything worked.
After some time I decided to disable all default features on the dependencies.
I had to enable some features to get it to compile ("clock" for chrono).
But then it worked (it compiled and seem to work).

Though a call to Local::now() did now panics (was fine before, it calls something in std which always panics on my target).
Now it's clear to me that I should have enabled the feature wasmbind.

But it would've been better if the now() function just was not available in my configuration.

Removing the line feature = "wasmbind", in Utc::now() seems to have that effect.

The result is that on wasm (no emscripten or wasi) with wasmbind the replaced function is used. And if not on wasm or with emscripten or wasi the std function is used. And on wasm (no emscripten or wasi) without wasmbind the function is not available.

Of course Utc::today(), Local::now() and Local::today() have also to be disabled in that case, the following does just that.

#[cfg(any(
    not(target_arch = "wasm32"),
    feature = "wasmbind",
    all(target_arch = "wasm32", any(target_os = "emscripten", target_os = "wasi")),
))]

This would be of course a breaking change.

And there are probably other targets which also always panic (though I don't know).

I can try to write a PR if that is wanted.

Edit:
As an alternative or first step, all the mentioned functions could be marked as deprecated with a comment which says that it will always panic (of course only for the problematic configuration).

Example:

#[cfg_attr(
    all(
        target_arch = "wasm32",
        not(feature = "wasmbind"),
        not(any(target_os = "emscripten", target_os = "wasi"))
    ),
    deprecated(since = "?", note = "will always panic")
)]

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions