Internals: Add WASI (wasm32-wasip1) build support (#8216) (#8217)

This commit is contained in:
Aliaksei Chapyzhenka
2026-08-25 19:13:07 -04:00
committed by GitHub
parent b23b53227d
commit 5e4151e3e0
4 changed files with 19 additions and 2 deletions
+15 -1
View File
@@ -82,7 +82,9 @@ VL_DEFINE_DEBUG_FUNCTIONS;
# endif
#else
# include <sys/time.h>
# include <sys/wait.h> // Needed on FreeBSD for WIFEXITED
# ifndef __wasi__
# include <sys/wait.h> // Needed on FreeBSD for WIFEXITED
# endif
# include <unistd.h> // usleep
#endif
// clang-format on
@@ -445,6 +447,12 @@ string V3Os::trueRandom(size_t size) VL_MT_SAFE {
if (VL_UNCOVERABLE(!BCRYPT_SUCCESS(hr))) {
v3fatal("Could not acquire random data. Try specifying a key instead."); // LCOV_EXCL_LINE
}
#elif defined(__wasi__)
// WASI has no /dev/urandom. getentropy() rejects sizes over 256 bytes,
// which is more than any caller asks for, and errors rather than truncates.
if (VL_UNCOVERABLE(getentropy(data, size))) {
v3fatal("Could not acquire random data. Try specifying a key instead."); // LCOV_EXCL_LINE
}
#else
std::ifstream is{"/dev/urandom", std::ios::in | std::ios::binary};
// This read uses the size of the buffer.
@@ -492,6 +500,11 @@ void V3Os::u_sleep(int64_t usec) {
// METHODS (sub command)
int V3Os::system(const string& command) {
#ifdef __wasi__
// WASI has no process spawning
v3fatal("Running subcommands is not supported on this platform: " << command);
return -1;
#else
UINFO(1, "Running system: " << command);
const int ret = ::system(command.c_str());
if (VL_UNCOVERABLE(ret == -1)) {
@@ -504,6 +517,7 @@ int V3Os::system(const string& command) {
UINFO(1, command << " returned exit code of " << exit_code);
UASSERT(exit_code >= 0, "exit code must not be negative");
return exit_code;
#endif
}
void V3Os::selfTest() {