every product now builds for wasm32-unknown-wasip1 under both the full and
embedded swift sdk, verified from clean scratch paths. host behavior is
unchanged (119 tests passing). the package's declared platforms, tools version,
and dependency ranges are untouched, so this is purely additive for existing
consumers.
runtime verification against published test vectors shows the crypto products
produce byte-identical output natively and under wasm (see the harness below).
platform layer (RAW):
- CRAW: skip <sys/mman.h> on wasi. wasi-libc raises a hard #error without mmap
emulation, and nothing here needs mmap, so the include is guarded
- CRAW: add a __wasi__ branch to __craw_get_entropy_bytes using getentropy.
wasi defines __wasi__ but not __unix__, so the function previously compiled
to no branch at all: no entropy source and no return statement
- CRAW: give __craw_get_system_errno a real (void) prototype. the old
prototype-less declaration crashed the wasm backend pass "Add prototypes to
prototypes-less functions" whenever a swift file called it
- RAW: import WASILibc alongside Glibc/Darwin where memcpy and memcmp are used
- RAW: add a wasi branch to MemoryGuarded. wasi fixes the page size at 64 kib
and ships no mlock/munlock implementations, so the allocation stays page
aligned and zeroed but is not pinned
embedded swift tier:
- RAW_byte: move the Codable conformance into a !hasFeature(Embedded)
extension, since Codable is unavailable in embedded swift
- Array accessors: drop "any Error" string interpolation in fatalError, which
embedded swift cannot specialize
crypto targets:
- __crawdog_argon2: define __CRAWDOG_ARGON2_NO_THREADS from source when
building for wasi (wasip1 has no pthreads), so argon2 runs single-threaded
there without requiring a manifest-level build setting
- __crawdog_crypt_blowfish: exclude the signal/setitimer benchmark shim on
wasi, which provides no setitimer even under emulation
tests:
- add a wasm branch to readTSC (wasm has no cycle counter; use clock())
- (void) prototypes for allTestsRelatedTo25519 and __crawdog_argon2testf. the
former was declared () but defined with (int argc, char **argv) while being
called with no arguments
- skip the blowfish benchmark test on wasi, since its shim cannot exist there
adds two unlisted harnesses. neither is referenced by Package.swift, so SwiftPM
ignores them and normal builds are unaffected:
- Tests/__wasm_probe/probe.swift links and executes RAW as a wasm module
- Tests/__wasm_crypto_probe/main.swift emits digests from sha1, sha256, sha512,
md5, blake2b, hmac-sha256, argon2id, chacha20-poly1305, bcrypt, hex and
base64; compiled natively and for wasm, the two outputs are byte-identical
and match published vectors (FIPS 180, RFC 1321, RFC 4231, RFC 7693)