rhai icon indicating copy to clipboard operation
rhai copied to clipboard

Add web-time

Open 0byteme opened this issue 1 year ago • 12 comments

according to https://github.com/rhaiscript/rhai/issues/891, since instant is no longer maintained, we should use web-time to replace it. Actually I have built WASM to make sure it works in it, but it seems that I don't find unit tests for WASM.

0byteme avatar Aug 05 '24 11:08 0byteme

It is failing the no-std build... Can you check?

Also I wonder if it is possible to write tests for WASM...

schungx avatar Aug 05 '24 13:08 schungx

Also I wonder if it is possible to write tests for WASM...

I'm not sure if I can write tests for WASM, but I'll try it. BTW, I have fixed the no-std build.

0byteme avatar Aug 05 '24 15:08 0byteme

If we add web-time with optional = true then we can't pass the cargo build --target wasm32-unknown-unknown --no-default-features compile; Otherwise if we set optional = false, we can't pass cargo build --manifest-path=no_std/no_std_test/Cargo.toml --profile unix compile. It seems like there isn't perfect way to solve it.

0byteme avatar Aug 05 '24 16:08 0byteme

Why is the wasm build failing without default features?

schungx avatar Aug 05 '24 21:08 schungx

[target.'cfg(not(feature = "no_time"))'.dependencies]

Why did you change it to no_time instead? Before it is pulled in only for wasm which doesnt have Instant.

schungx avatar Aug 05 '24 21:08 schungx

[target.'cfg(not(feature = "no_time"))'.dependencies]

Why did you change it to no_time instead? Before it is pulled in only for wasm which doesnt have Instant.

You are correct. I have changed it to target.'cfg(all(target_family = "wasm", not(feature = "no_time")))'.dependencies, but it still fails the tests. It appears that when we add web-time as dependencies, it fails the no_std tests. I'm not certain if it's because of the implementation of web-time.

0byteme avatar Aug 06 '24 12:08 0byteme

It shoudnt... no-std is not supposed to pull in web-time, then it shouldnt be affected.

If it still fails that means web-time is still being brought in somehow...

schungx avatar Aug 09 '24 01:08 schungx

I'm pretty sure the issue is related to once_cell and web_time. I've created an example to reproduce the problem. Can run cargo c --features time or cargo c to see the issue. However, it works correctly if I switch from web_time to instant. I'm not sure why this is happening.

0byteme avatar Aug 19 '24 07:08 0byteme

Is it possible that web-time does not support no-std?

schungx avatar Aug 20 '24 00:08 schungx

It's not supported to be pulled if I don't add features time in this, but it still failed.

0byteme avatar Aug 21 '24 06:08 0byteme

It's not supported to be pulled if I don't add features time in this, but it still failed.

If only one dependency crate in the entire tree depends on std, then stdlib will be pulled in, causing compilation error in no-std.

schungx avatar Aug 21 '24 10:08 schungx

It turn out that feature = ... in target.'cfg(...)'.dependencies is not supported for selecting dependencies and will not work as expected. So actually rhai will always pull instant whenever it's wasm or not. But web-time don't support to work in no_std environment, so now we can't use web_time to replace instant.

0byteme avatar Aug 22 '24 07:08 0byteme