Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ let package = Package(
platforms: [.macOS(.v15), .iOS(.v18)],
products: [
.executable(name: "wasmkit-cli", targets: ["CLI"]),
.executable(name: "wasm-component-ld", targets: ["wasm-component-ld"]),
.library(name: "WasmKit", targets: ["WasmKit"]),
.library(name: "WasmKitWASI", targets: ["WasmKitWASI"]),
.library(name: "WASI", targets: ["WASI"]),
Expand All @@ -43,6 +44,23 @@ let package = Package(
dependencies: ["CLICommands"],
exclude: ["CMakeLists.txt"]
),
.executableTarget(
name: "wasm-component-ld",
path: "Sources/wasm-component-ld",
cSettings: [
.define("HAS_UNISTD", to: "1"),
.define("HAS_SYSUIO", to: "1"),
.define("HAS_SYSTIME", to: "1"),
.define("HAS_SYSRESOURCE", to: "1"),
.define("HAS_STRNDUP", to: "1"),
.define("HAS_FCNTL", to: "1"),
.define("HAS_LSTAT", to: "1"),
.define("HAS_GETENTROPY", to: "1"),
.define("HAS_TIMESPEC", to: "1"),
.define("_BSD_SOURCE", to: "1", .when(platforms: [.macOS])),
.unsafeFlags(["-std=c90", "-fno-modules"]),
]
),
.target(
name: "WasmKit",
dependencies: [
Expand Down
48 changes: 48 additions & 0 deletions Sources/wasm-component-ld/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#include <stdio.h>
#include <stdlib.h>

#include "w2c2_base.h"
#include "wasi/wasi.h"
#include "wasm-component-ld.h"

void
trap(
Trap trap
) {
fprintf(stderr, "TRAP: %s\n", trapDescription(trap));
abort();
}

wasmMemory*
wasiMemory(
void* instance
) {
return wasmcomponentld_memory((wasmcomponentldInstance*)instance);
}

extern char** environ;

int
main(
int argc,
char* argv[]
) {
if (!wasiInit(argc, argv, environ)) {
fprintf(stderr, "failed to init WASI\n");
return 1;
}

if (!wasiFileDescriptorAdd(-1, ".", NULL)) {
fprintf(stderr, "failed to add current-directory preopen\n");
return 1;
}

{
wasmcomponentldInstance instance;
wasmcomponentldInstantiate(&instance, NULL);
wasmcomponentld__start(&instance);
wasmcomponentldFreeInstance(&instance);
}

return 0;
}
Loading
Loading