cairo
cairo copied to clipboard
No std support
This PR aims to make as much as the cairo-lang libs no_std compatible.
In order to keep coherence across the crates, I opted for the cairo-lang-std approach.
I added a crate that will export a custom "std" lib, either from the rust "std" one or from the "core" one (+ hashbrown).
This approach reduces the amount of conditional compilation (#[cfg(feature = "std")] vs #[cfg(not(feature = "std"))] ) to be expressed in the subsequent crates.
The drawback is that we have to import all our basics from this cairo-lang-std crate, rather than using core. Regardless, I think that it's the best option for such a diverse workspace.
I also added an ensure_no_std crate. It imports the different libs that support no-std and compiles, with them as dependencies. If even a single symbol across the dependencies is provided by the std lib, the compilation will fail. It is to be used in the CI in order to make sure no regressions are introduced.
It has to be compile with:
cargo +nightly build --target wasm32-unknown-unknown
meaning it cannot be part of the workspace. I added a .cargo/config.toml and a rust-toolchain.toml so running cargo build will be enough.
In it's current state cairo-lang-std, cairo-lang-utils and cairo-lang-casm are compilable in no-std.
Why did you remove the version?
This answer describes what happens if you combine path and version. If you are importing the same version as the workspace version, it is not useful at all. And it could lead to errors if not updated. When I believe we always want to use the file from our current workspace commit.
Depending on git commits is probelamtci, and messes with resolution a lot of times. Why isn't a version enough?
indexmap has a problem with no-std in its 1.X.X version. It is described here. So we have to use code that is on version 2.0.0-pre, it could be achieved using version or the branch main. But they are not respecting semantic versioning yet for this version (because it's still -pre). So they could include breaking changes over time, that is why I preferred to fix on a commit that does what I need and is no-std compatible until they release a fixed 2.0.0 tag.
Format this better?
Yes my toml formating tool does this. Which is not the case of most people. I have to change it
indexmaphas a problem withno-stdin its1.X.Xversion. It is described here. So we have to use code that is on version2.0.0-pre, it could be achieved usingversionor the branchmain. But they are not respectingsemantic versioningyet for this version (because it's still-pre). So they could include breaking changes over time, that is why I preferred to fix on a commit that does what I need and isno-stdcompatible until they release a fixed2.0.0tag.
The issue is that using git-based dependencies makes the compiler unpublishable to crates.io which many projects depend on :(
The issue is that using git-based dependencies makes the compiler unpublishable to crates.io which many projects depend on :(
The only solution I see is for indexmap to publish a tag 2.0.0-pre. I will try to talk with them and understand what is the feasibility of this.
@mkaput On my demand indexmap released the 2.0.0 version
@spapinistarkware wdyt?
@spapinistarkware Yes I wasn't sure about the naming, but I don't know what will happen in the future for those crates.
We could always deprepate thoses and create new ones, with the correct name for their content.
Or do you prefer a more vague crate name, like cairo-lang-casm-types maybe ?