Skip to content

Add WAMR (failing on tests) #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
100 changes: 100 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -352,3 +352,103 @@ tasks.withType<NodeJsExec>().all {
)
}
}


// WAMR tasks
val wamrVersion = "2.2.0"
val wamrDirectoryName = "iwasm-gc-eh-$wamrVersion"

val unzipWAMR = run {
val wamrDirectory = "https://github.com/bytecodealliance/wasm-micro-runtime/releases/download/WAMR-$wamrVersion"
val wamrSuffix = when (currentOsType) {
OsType(OsName.LINUX, OsArch.X86_64) -> "x86_64-ubuntu-20.04"
OsType(OsName.MAC, OsArch.X86_64),
OsType(OsName.MAC, OsArch.ARM64) -> "x86_64-macos-13"
OsType(OsName.WINDOWS, OsArch.X86_32),
OsType(OsName.WINDOWS, OsArch.X86_64) -> "x86_64-windows-latest"
else -> error("unsupported os type $currentOsType")
}

val wamrArtifactiName = "$wamrDirectoryName-$wamrSuffix.tar.gz"
val wamrLocation = "$wamrDirectory/$wamrArtifactiName"

val downloadedTools = File(layout.buildDirectory.asFile.get(), "tools")

val downloadWamr = tasks.register("wamrDownload", Download::class) {
src(wamrLocation)
dest(File(downloadedTools, wamrArtifactiName))
overwrite(false)
}

tasks.register("wamrUnzip", Copy::class) {
dependsOn(downloadWamr)
from(tarTree(downloadWamr.get().dest))
into(downloadedTools.resolve(wamrDirectoryName) )
}
}

fun Project.createWamrExec(
nodeMjsFile: RegularFileProperty,
taskName: String,
taskGroup: String?,
startFunction: String
): TaskProvider<Exec> {
val outputDirectory = nodeMjsFile.map { it.asFile.parentFile }
val wasmFileName = nodeMjsFile.map { "${it.asFile.nameWithoutExtension}.wasm" }

return tasks.register(taskName, Exec::class) {
dependsOn(unzipWAMR)
inputs.property("wasmFileName", wasmFileName)

taskGroup?.let { group = it }
description = "Executes tests with WAMR"

executable = unzipWAMR.get().destinationDir.resolve("iwasm").absolutePath

doFirst {
val newArgs = mutableListOf<String>()

newArgs.add("--function")
newArgs.add(startFunction)

newArgs.add(wasmFileName.get())

args(newArgs)
workingDir(outputDirectory)
}
}
}

tasks.withType<KotlinJsTest>().all {
val wamrRunTask = createWamrExec(
inputFileProperty,
name.replace("Node", "WAMR"),
group,
"_initialize"
)

wamrRunTask.configure {
dependsOn (
project.provider { [email protected] }
)
}

tasks.withType<KotlinTestReport> {
dependsOn(wamrRunTask)
}
}

tasks.withType<NodeJsExec>().all {
val wamrRunTask = createWamrExec(
inputFileProperty,
name.replace("Node", "WAMR"),
group,
"dummy"
)

wamrRunTask.configure {
dependsOn (
project.provider { [email protected] }
)
}
}
4 changes: 2 additions & 2 deletions src/wasmWasiMain/kotlin/MonotonicTime.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@ fun wasiRealTime(): Long = wasiGetTime(REALTIME)

fun wasiMonotonicTime(): Long = wasiGetTime(MONOTONIC)

// We need it to run WasmEdge with the _initialize function
// We need it to run WasmEdge/WAMR with the _initialize function
@WasmExport
fun dummy() {}
fun dummy() {}