-
Notifications
You must be signed in to change notification settings - Fork 57
Cleanup of conditional dependencies to support a wider range of compilation targets #138
Conversation
`chrono` is conflictive with embedded scenarios, as relies on `libc` functions that are not supported on all architectures, even if libstd is available for those architectures. This commit takes the assumption that the timestamp present in the type `TangleMessage` is a leftover from pre-chrysalis. It's the only place where `chrono` is needed. Therefore, the following actions have been taken: - Convert `TangleMessage<F>` into just a type alias of `BinaryMessage<F, TangleAddress>` - Remove `chrono` from `streams-app` dependencies
espidf targets have libstd available through ESP-IDF framework. This framework provides most but not all of the POSIX standard API. In particular, ESP-IDF does not provide a means to fork threads, and cannot implement `pthread_atfork` (see espressif/rust-esp32-example#23). This means `rand::thread_rng()` is not available on those targets, as it is based on storing the rng in the thread-local storage, accessed through a thread handle. For these targets, this commit specializes the random_key and random_nonce generators to use `StdRng::from_entropy()` instead. In practice, given the coldness of these 2 functions, the same level of security and performance is to be expected. Note that currently `getrandom` does not support `espidf` targets and requires a small patch.
those 2 commits are causing problems with the node.js bindings -
Here's some uncompleted fork, that tried to get the lib working with WASI / WASM, but discontinued efforts: This might be interesting too, something with the core cargo toml dependencies + features declaration is doing weird things, especially with tokio / mio, maybe some helpful hint inside here: I remember actually fixing this issue by tweaking around with the dependencies, overwriting / patching some with that [patch] toml syntax, downgrading a few crates, and using the new feature resolver v2 function on the rust nightly channel .. https://doc.rust-lang.org/nightly/cargo/reference/features.html#feature-resolver-version-2 But with so many different tries and outdated clones of the streams repo, i cannot remember which exact changes fixed that following build error, that keeps hunting us again and again :D @jlvandenhout deso@nuc /tmp/foo (master *) $ cargo build --target wasm32-unknown-unknown
Compiling mio v0.7.7
error[E0432]: unresolved import `crate::sys::IoSourceState`
--> /tmp/cargo-home/registry/src/github.com-1ecc6299db9ec823/mio-0.7.7/src/io_source.rs:12:5
|
12 | use crate::sys::IoSourceState;
| ^^^^^^^^^^^^^^^^^^^^^^^^^ no `IoSourceState` in `sys` Otherwise, +1 for your no-std efforts, can't wait to spin up my xargo / cargo xtensa llvm esp32 custom target ^^
Ive been using this nice crate for it, ive got the Qemu installed but i tend to run it directly on the hardware
|
Hey @sascha1337 sorry for the late reply! We were focused on releasing 1.2.0 and this PR got backburnered. I've sync'ed this branch with develop, and the wasm build works now. |
iota-streams-app/Cargo.toml
Outdated
anyhow = { version = "1.0.26", default-features = false } | ||
chrono = { version = "0.4.11", default-features = false, optional = true } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
chrono ... wasm... tokio... the never ending loop :(
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
About the timestamp removal. Im all up for it, but when we add it back later (I believe in stardust we get one again?) what is the plan?
Or will we be timestamp agnostic, and let the user use iota.rs to fetch timestamps?
@@ -11,14 +11,14 @@ description = "A rust implementation of the IOTA Streams applications" | |||
[features] | |||
default = ["std", "client"] | |||
# Enable `std` feature in dependencies | |||
std = ["iota-streams-core/std", "iota-streams-core-edsig/std", "iota-streams-ddml/std", "chrono/std", "chrono/clock", "hex/std"] | |||
std = ["iota-streams-core/std", "iota-streams-core-edsig/std", "iota-streams-ddml/std", "hex/std"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should add rand/std as well, otherwise rand doesnt support it with default-features = false. To be correct :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, actually, you helped me realize that rand does not need to be a dependency on iota-streams-app
. As per rand/std
, in iota-streams-core
it is already done as you suggest: https://github.com/iotaledger/streams/pull/138/files#diff-3350ed2612e4263878a1a2e5ba8025625b76c0ec06cc80b7211f586991da47f3R14
Not sure about Stardust, but definitely will in Coordicide. What I'm not convinced of is if this timestamp will be relevant from Streams point of view... Will Streams use the timestamp of the TX for any logic? what will the semantics of this timestamp be? will it be relevant for the subscriber of the Stream? In any case, in the present this timestamp is not there, and it is not used, and just adds up to the general confusion. That's why I propose to remove it and deal with it once it makes sense |
instead of iota-streams-app/Cargo.toml
I think it's safe to say that as we currently have it implemented it really doesn't provide much benefit. The only way I could see the timestamp being relevant/beneficial is if it was added to the header so that we can sort multiple messages at a given index by this timestamp, which arguably we shouldn't need to do because (I'm not 100% sure on the stardust side specifically but in corrdicide yes) will contain their own timestamping process that we should be able to use since the timestamps will be embedded into the Tangle Message anyways. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see no issues with this one, I think we're good to merge it.
Description
During preparation of arnauorriols/iota-streams-esp32, several changes have had to be done in Streams to be able to run it in the ESP32 target, with and without
std
feature enabled. This PR includes all such changes. The following is the list of the most relevant:wasm-bindgen
feature ofrand
only enabled whenwasm-client
feature ofapp-channels
is enabled (it was always enabled)Debug
in a bunch of types, notablyBucketTransport
,TangleMessage
andKeccak1600
chrono
dependency. I've taken the assumption that thetimestamp
inTangleMessage
was a leftoverfrom pre-chrysalis, so I've removed it completely. Now
TangleMessage<F>
is an alias ofBinaryMessage<F, TangleAddress>
futures
dependency pulled only when a*-client
feature is enabled (it was always enabled)StdRng::from_entropy()
instead ofthread_rng
whentarget_os == espidf
Type of change
How the change has been tested
cargo check --no-default-features && cargo check && cargo check --all-features
cargo clippy --no-default-features && cargo clippy && cargo clippy --all-features
Change checklist