Utilities/wasm: Enable on Windows

This commit is contained in:
ayeteadoe 2025-08-08 12:10:39 -07:00 committed by Andrew Kaster
commit a95e0d2777
Notes: github-actions[bot] 2025-08-24 19:00:20 +00:00
5 changed files with 22 additions and 7 deletions

View file

@ -9,10 +9,11 @@
#include <AK/StackInfo.h>
#include <LibWasm/AbstractMachine/Configuration.h>
#include <LibWasm/AbstractMachine/Interpreter.h>
#include <LibWasm/Export.h>
namespace Wasm {
struct BytecodeInterpreter final : public Interpreter {
struct WASM_API BytecodeInterpreter final : public Interpreter {
explicit BytecodeInterpreter(StackInfo const& stack_info)
: m_stack_info(stack_info)
{

View file

@ -7,6 +7,7 @@ set(SOURCES
Printer/Printer.cpp
)
# FIXME: Add Windows support
if (NOT WIN32)
list(APPEND SOURCES WASI/Wasi.cpp)
endif()

View file

@ -6,6 +6,7 @@
#pragma once
#include <LibWasm/Export.h>
#include <LibWasm/Types.h>
namespace Wasm {
@ -16,7 +17,7 @@ class Value;
ByteString instruction_name(OpCode const& opcode);
Optional<OpCode> instruction_from_name(StringView name);
struct Printer {
struct WASM_API Printer {
explicit Printer(Stream& stream, size_t initial_indent = 0)
: m_stream(stream)
, m_indent(initial_indent)

View file

@ -1,7 +1,10 @@
if(WIN32)
# FIXME: Add support for LibLine on Windows
lagom_utility(js SOURCES js.cpp LIBS LibCrypto LibJS LibUnicode LibMain LibTextCodec LibGC Threads::Threads)
lagom_utility(wasm SOURCES wasm.cpp LIBS LibFileSystem LibWasm LibMain)
else()
lagom_utility(js SOURCES js.cpp LIBS LibCrypto LibJS LibLine LibUnicode LibMain LibTextCodec LibGC Threads::Threads)
lagom_utility(wasm SOURCES wasm.cpp LIBS LibFileSystem LibWasm LibLine LibMain)
endif()
# FIXME: Increase support for building targets on Windows
@ -34,7 +37,6 @@ if (ASSERT_FAIL_HAS_INT OR EMSCRIPTEN)
target_compile_definitions(test262-runner PRIVATE ASSERT_FAIL_HAS_INT)
endif()
lagom_utility(wasm SOURCES wasm.cpp LIBS LibFileSystem LibWasm LibLine LibMain)
lagom_utility(xml SOURCES xml.cpp LIBS LibFileSystem LibMain LibXML LibURL)
if (NOT CMAKE_SKIP_INSTALL_RULES)

View file

@ -10,19 +10,23 @@
#include <AK/MemoryStream.h>
#include <AK/StackInfo.h>
#include <LibCore/ArgsParser.h>
#include <LibCore/EventLoop.h>
#include <LibCore/File.h>
#include <LibCore/MappedFile.h>
#include <LibFileSystem/FileSystem.h>
#if !defined(AK_OS_WINDOWS)
# include <LibLine/Editor.h>
#endif
#include <LibMain/Main.h>
#include <LibWasm/AbstractMachine/AbstractMachine.h>
#include <LibWasm/AbstractMachine/BytecodeInterpreter.h>
#include <LibWasm/Printer/Printer.h>
#include <LibWasm/Types.h>
#if !defined(AK_OS_WINDOWS)
# include <LibWasm/Wasi.h>
#endif
#include <math.h>
#include <signal.h>
#include <unistd.h>
static OwnPtr<Stream> g_stdout {};
static OwnPtr<Wasm::Printer> g_printer {};
@ -277,7 +281,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
bool print_compiled = false;
bool attempt_instantiate = false;
bool export_all_imports = false;
bool wasi = false;
[[maybe_unused]] bool wasi = false;
ByteString exported_function_to_execute;
Vector<ParsedValue> values_to_push;
Vector<ByteString> modules_to_link_in;
@ -291,7 +295,9 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
parser.add_option(attempt_instantiate, "Attempt to instantiate the module", "instantiate", 'i');
parser.add_option(exported_function_to_execute, "Attempt to execute the named exported function from the module (implies -i)", "execute", 'e', "name");
parser.add_option(export_all_imports, "Export noop functions corresponding to imports", "export-noop");
#if !defined(AK_OS_WINDOWS)
parser.add_option(wasi, "Enable WASI", "wasi", 'w');
#endif
parser.add_option(Core::ArgsParser::Option {
.argument_mode = Core::ArgsParser::OptionArgumentMode::Required,
.help_string = "Directory mappings to expose via WASI",
@ -356,6 +362,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
if (attempt_instantiate || print_compiled) {
Wasm::AbstractMachine machine;
#if !defined(AK_OS_WINDOWS)
Optional<Wasm::Wasi::Implementation> wasi_impl;
if (wasi) {
@ -383,6 +390,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
return paths; },
});
}
#endif
Core::EventLoop main_loop;
// First, resolve the linked modules
@ -416,6 +424,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
for (auto& instance : linked_instances)
linker.link(*instance);
#if !defined(AK_OS_WINDOWS)
if (wasi) {
HashMap<Wasm::Linker::Name, Wasm::ExternValue> wasi_exports;
for (auto& entry : linker.unresolved_imports()) {
@ -432,6 +441,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
linker.link(wasi_exports);
}
#endif
if (export_all_imports) {
HashMap<Wasm::Linker::Name, Wasm::ExternValue> exports;