mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-22 09:18:55 +00:00
Utilities/wasm: Enable on Windows
This commit is contained in:
parent
070392307a
commit
a95e0d2777
Notes:
github-actions[bot]
2025-08-24 19:00:20 +00:00
Author: https://github.com/ayeteadoe
Commit: a95e0d2777
Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/5769
Reviewed-by: https://github.com/ADKaster ✅
Reviewed-by: https://github.com/R-Goc
5 changed files with 22 additions and 7 deletions
|
@ -9,10 +9,11 @@
|
||||||
#include <AK/StackInfo.h>
|
#include <AK/StackInfo.h>
|
||||||
#include <LibWasm/AbstractMachine/Configuration.h>
|
#include <LibWasm/AbstractMachine/Configuration.h>
|
||||||
#include <LibWasm/AbstractMachine/Interpreter.h>
|
#include <LibWasm/AbstractMachine/Interpreter.h>
|
||||||
|
#include <LibWasm/Export.h>
|
||||||
|
|
||||||
namespace Wasm {
|
namespace Wasm {
|
||||||
|
|
||||||
struct BytecodeInterpreter final : public Interpreter {
|
struct WASM_API BytecodeInterpreter final : public Interpreter {
|
||||||
explicit BytecodeInterpreter(StackInfo const& stack_info)
|
explicit BytecodeInterpreter(StackInfo const& stack_info)
|
||||||
: m_stack_info(stack_info)
|
: m_stack_info(stack_info)
|
||||||
{
|
{
|
||||||
|
|
|
@ -7,6 +7,7 @@ set(SOURCES
|
||||||
Printer/Printer.cpp
|
Printer/Printer.cpp
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# FIXME: Add Windows support
|
||||||
if (NOT WIN32)
|
if (NOT WIN32)
|
||||||
list(APPEND SOURCES WASI/Wasi.cpp)
|
list(APPEND SOURCES WASI/Wasi.cpp)
|
||||||
endif()
|
endif()
|
||||||
|
|
|
@ -6,6 +6,7 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <LibWasm/Export.h>
|
||||||
#include <LibWasm/Types.h>
|
#include <LibWasm/Types.h>
|
||||||
|
|
||||||
namespace Wasm {
|
namespace Wasm {
|
||||||
|
@ -16,7 +17,7 @@ class Value;
|
||||||
ByteString instruction_name(OpCode const& opcode);
|
ByteString instruction_name(OpCode const& opcode);
|
||||||
Optional<OpCode> instruction_from_name(StringView name);
|
Optional<OpCode> instruction_from_name(StringView name);
|
||||||
|
|
||||||
struct Printer {
|
struct WASM_API Printer {
|
||||||
explicit Printer(Stream& stream, size_t initial_indent = 0)
|
explicit Printer(Stream& stream, size_t initial_indent = 0)
|
||||||
: m_stream(stream)
|
: m_stream(stream)
|
||||||
, m_indent(initial_indent)
|
, m_indent(initial_indent)
|
||||||
|
|
|
@ -1,7 +1,10 @@
|
||||||
if(WIN32)
|
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(js SOURCES js.cpp LIBS LibCrypto LibJS LibUnicode LibMain LibTextCodec LibGC Threads::Threads)
|
||||||
|
lagom_utility(wasm SOURCES wasm.cpp LIBS LibFileSystem LibWasm LibMain)
|
||||||
else()
|
else()
|
||||||
lagom_utility(js SOURCES js.cpp LIBS LibCrypto LibJS LibLine LibUnicode LibMain LibTextCodec LibGC Threads::Threads)
|
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()
|
endif()
|
||||||
|
|
||||||
# FIXME: Increase support for building targets on Windows
|
# 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)
|
target_compile_definitions(test262-runner PRIVATE ASSERT_FAIL_HAS_INT)
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
lagom_utility(wasm SOURCES wasm.cpp LIBS LibFileSystem LibWasm LibLine LibMain)
|
|
||||||
lagom_utility(xml SOURCES xml.cpp LIBS LibFileSystem LibMain LibXML LibURL)
|
lagom_utility(xml SOURCES xml.cpp LIBS LibFileSystem LibMain LibXML LibURL)
|
||||||
|
|
||||||
if (NOT CMAKE_SKIP_INSTALL_RULES)
|
if (NOT CMAKE_SKIP_INSTALL_RULES)
|
||||||
|
|
|
@ -10,19 +10,23 @@
|
||||||
#include <AK/MemoryStream.h>
|
#include <AK/MemoryStream.h>
|
||||||
#include <AK/StackInfo.h>
|
#include <AK/StackInfo.h>
|
||||||
#include <LibCore/ArgsParser.h>
|
#include <LibCore/ArgsParser.h>
|
||||||
|
#include <LibCore/EventLoop.h>
|
||||||
#include <LibCore/File.h>
|
#include <LibCore/File.h>
|
||||||
#include <LibCore/MappedFile.h>
|
#include <LibCore/MappedFile.h>
|
||||||
#include <LibFileSystem/FileSystem.h>
|
#include <LibFileSystem/FileSystem.h>
|
||||||
#include <LibLine/Editor.h>
|
#if !defined(AK_OS_WINDOWS)
|
||||||
|
# include <LibLine/Editor.h>
|
||||||
|
#endif
|
||||||
#include <LibMain/Main.h>
|
#include <LibMain/Main.h>
|
||||||
#include <LibWasm/AbstractMachine/AbstractMachine.h>
|
#include <LibWasm/AbstractMachine/AbstractMachine.h>
|
||||||
#include <LibWasm/AbstractMachine/BytecodeInterpreter.h>
|
#include <LibWasm/AbstractMachine/BytecodeInterpreter.h>
|
||||||
#include <LibWasm/Printer/Printer.h>
|
#include <LibWasm/Printer/Printer.h>
|
||||||
#include <LibWasm/Types.h>
|
#include <LibWasm/Types.h>
|
||||||
#include <LibWasm/Wasi.h>
|
#if !defined(AK_OS_WINDOWS)
|
||||||
|
# include <LibWasm/Wasi.h>
|
||||||
|
#endif
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <unistd.h>
|
|
||||||
|
|
||||||
static OwnPtr<Stream> g_stdout {};
|
static OwnPtr<Stream> g_stdout {};
|
||||||
static OwnPtr<Wasm::Printer> g_printer {};
|
static OwnPtr<Wasm::Printer> g_printer {};
|
||||||
|
@ -277,7 +281,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
|
||||||
bool print_compiled = false;
|
bool print_compiled = false;
|
||||||
bool attempt_instantiate = false;
|
bool attempt_instantiate = false;
|
||||||
bool export_all_imports = false;
|
bool export_all_imports = false;
|
||||||
bool wasi = false;
|
[[maybe_unused]] bool wasi = false;
|
||||||
ByteString exported_function_to_execute;
|
ByteString exported_function_to_execute;
|
||||||
Vector<ParsedValue> values_to_push;
|
Vector<ParsedValue> values_to_push;
|
||||||
Vector<ByteString> modules_to_link_in;
|
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(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(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");
|
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');
|
parser.add_option(wasi, "Enable WASI", "wasi", 'w');
|
||||||
|
#endif
|
||||||
parser.add_option(Core::ArgsParser::Option {
|
parser.add_option(Core::ArgsParser::Option {
|
||||||
.argument_mode = Core::ArgsParser::OptionArgumentMode::Required,
|
.argument_mode = Core::ArgsParser::OptionArgumentMode::Required,
|
||||||
.help_string = "Directory mappings to expose via WASI",
|
.help_string = "Directory mappings to expose via WASI",
|
||||||
|
@ -356,6 +362,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
|
||||||
|
|
||||||
if (attempt_instantiate || print_compiled) {
|
if (attempt_instantiate || print_compiled) {
|
||||||
Wasm::AbstractMachine machine;
|
Wasm::AbstractMachine machine;
|
||||||
|
#if !defined(AK_OS_WINDOWS)
|
||||||
Optional<Wasm::Wasi::Implementation> wasi_impl;
|
Optional<Wasm::Wasi::Implementation> wasi_impl;
|
||||||
|
|
||||||
if (wasi) {
|
if (wasi) {
|
||||||
|
@ -383,6 +390,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
|
||||||
return paths; },
|
return paths; },
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
Core::EventLoop main_loop;
|
Core::EventLoop main_loop;
|
||||||
// First, resolve the linked modules
|
// First, resolve the linked modules
|
||||||
|
@ -416,6 +424,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
|
||||||
for (auto& instance : linked_instances)
|
for (auto& instance : linked_instances)
|
||||||
linker.link(*instance);
|
linker.link(*instance);
|
||||||
|
|
||||||
|
#if !defined(AK_OS_WINDOWS)
|
||||||
if (wasi) {
|
if (wasi) {
|
||||||
HashMap<Wasm::Linker::Name, Wasm::ExternValue> wasi_exports;
|
HashMap<Wasm::Linker::Name, Wasm::ExternValue> wasi_exports;
|
||||||
for (auto& entry : linker.unresolved_imports()) {
|
for (auto& entry : linker.unresolved_imports()) {
|
||||||
|
@ -432,6 +441,7 @@ ErrorOr<int> ladybird_main(Main::Arguments arguments)
|
||||||
|
|
||||||
linker.link(wasi_exports);
|
linker.link(wasi_exports);
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
if (export_all_imports) {
|
if (export_all_imports) {
|
||||||
HashMap<Wasm::Linker::Name, Wasm::ExternValue> exports;
|
HashMap<Wasm::Linker::Name, Wasm::ExternValue> exports;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue