Add no_std support
#39
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Through
no_stdsupport, we now also supportwasm32v1-none.Introduced a new
stdcrate feature that is enabled by default. Without it#[no_std]is enabled, but only on Web! This allows Web target to build without std, which is now supported bywasm-bindgenas well.Additionally, various changes had to be done to support
no_std:no_stddoes not supportthread_local!, we useonce_cellto polyfill this gap.once_cellis not a new dependency, it is already a dependency ofwasm-bindgen.feature = "std", we usethread_local!as before.target_feature = "atomics", we use astatic mutwithonce_cell::unsync::Lazy.#[thread_local]withonce_cell::unsync::Lazy.Some
f64instructions are not available onno_stdand had to be polyfilled. For this code fromlibmwas copied. Which is used by std as well.SystemTimeErrornow only implementsErrorwithfeature = "std".no_stdtesting requires to refrain from using the default test harness. The problem was that native tests still needed to use the default test harness. To solve this, integration tests were removed from root crate and two workspace members added, that manually define all integration tests as test targets. Thetests-webcrate hasharness = falseon all tests, whiletests-nativefunctions regularly. This allow us to use the default test harness for native tests while disabling it for Web.Additionally, every test target requires the
runcrate feature, which are enabled by default depending on the target by the root crate. This way regular testing can function correctly for each target as long as--all-featuresis not used. E.g.cargo test --workspaceandcargo test --workspace --target wasm32-unknown-unknownwill work correctly.The
tests-weblibrary is used to implement thepanic_handler,global_allocatorandcritical_section. It is always imported to reduce code duplication in all tests.Used
serde-json-coreto cover tests withno_stdas well.All links to std documentation had to be supplemented with manual link when
stdis not present.Improvements to CI:
--no-default-features.cargo publish.wasm-bindgenupdate allows us to refrain from having to passcfgflags to thewasm-bindgenproc-macros.llvm-toolsinstead of the official LLVM package.scripttag from coverage report.Small fixes that were stumbled upon:
web_time::webwithcfg(docsrs)on native as well.SerializeandDeserializeimplementation are now marked withdoc(cfg(feature = "serde")).stable.-Ctarget-feature=+nontrapping-fptointwas moved from the top-level to the "Usage" section.no_stdsupport forserde_test: serde-deprecated/test#36no_stdsupport forgetrandom: rust-random/getrandom#541.no_stdWasmf64instructions: rust-lang/stdarch#1677