Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
frederikrothenberger committed Jul 9, 2024
1 parent 41559f0 commit 1587eee
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 0 deletions.
1 change: 1 addition & 0 deletions demos/vc_issuer/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions demos/vc_issuer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ strfmt = "0.2"
lazy_static = "1.4"
include_dir = "0.7"

[target.'cfg(all(target_arch = "wasm32", target_vendor = "unknown", target_os = "unknown"))'.dependencies]
getrandom = { version = "0.2", features = ["custom"] }

[dev-dependencies]
assert_matches = "1.5.0"
candid_parser = "0.1"
Expand Down
8 changes: 8 additions & 0 deletions demos/vc_issuer/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/// A small module that makes get_random work on wasm32-unknown-unknown.
/// The dependency on get_random comes from the captcha library.
#[cfg(all(
target_arch = "wasm32",
target_vendor = "unknown",
target_os = "unknown"
))]
mod wasm_get_random;
21 changes: 21 additions & 0 deletions demos/vc_issuer/src/wasm_get_random.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! This module exists to work around a problem with `getrandom` 0.2, which is a dependency
//! of `rand` 0.8
//!
//! For the `wasm32-unknown-unknown` target, `getrandom` 0.2 will refuse to compile. This is an
//! intentional policy decision on the part of the getrandom developers. As a consequence, it
//! would not be possible to compile anything which depends on `rand` 0.8 to wasm for use in
//! canister code.
//!
//! Depending on this crate converts the compile time error into a runtime error, by
//! registering a custom `getrandom` implementation which always fails. This matches the
//! behavior of `getrandom` 0.1.
//!
//! See the [getrandom
//! documentation](https://docs.rs/getrandom/latest/getrandom/macro.register_custom_getrandom.html)
//! for more details on custom implementations.

/// A getrandom implementation that always fails
pub fn always_fail(_buf: &mut [u8]) -> Result<(), getrandom::Error> {
Err(getrandom::Error::UNSUPPORTED)
}
getrandom::register_custom_getrandom!(always_fail);

0 comments on commit 1587eee

Please sign in to comment.