Skip to content

Commit 7c15fc8

Browse files
committed
Support Wasi
1 parent d5b10b5 commit 7c15fc8

File tree

3 files changed

+20
-16
lines changed

3 files changed

+20
-16
lines changed

LinkerTest/Linker_Linked.br.wasm

6 Bytes
Binary file not shown.

LinkerTest/Linker_Linked.br.wat

+1-1
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@
114114
(global $./Resources/LinkTest/index.br1.$Brisk$Constant:moduleFunctionOffset i32 (i32.const 0))
115115
(global $./Resources/LinkTest/index.br1.print320 (mut i32) (i32.const 0))
116116
(export "memory" (memory 0))
117-
(start $_start)
117+
(export "_start" (func $_start))
118118
(elem (;0;) (i32.const 0) func $./print32.br0.fd_write)
119119
(elem (;1;) (i32.const 1) func $./print32.br0.writeCharacterCode)
120120
(elem (;2;) (i32.const 2) func $./print32.br0.print32))

linker/BuildFile.gr

+19-15
Original file line numberDiff line numberDiff line change
@@ -604,21 +604,23 @@ export let createStartSection = (wasmBinary, dependencyChain, wasmData) => {
604604
...wasmBinary.localNames
605605
]
606606
// TODO: Support WASI
607-
wasmBinary.startSection = listToBuffer(
608-
Encoder.encodeUIntLeb128(wasmData.funcCount)
609-
)
610-
// // Push The Start Export to be Wasi Compatible
611-
// let startExport = Buffer.make(0)
612-
// // Export Name
613-
// appendBufferByteList(Encoder.encodeString("_start"), startExport)
614-
// // Export Type
615-
// appendBufferByteList(
616-
// [
617-
// 0x00, // Function Export Kind
618-
// ...Encoder.encodeUIntLeb128(wasmData.funcCount)
619-
// ],
620-
// startExport
607+
// wasmBinary.startSection = listToBuffer(
608+
// Encoder.encodeUIntLeb128(wasmData.funcCount)
621609
// )
610+
// Push The Start Export to be Wasi Compatible
611+
let startExport = Buffer.make(0)
612+
// Export Name
613+
appendBufferByteList(Encoder.encodeString("_start"), startExport)
614+
// Export Type
615+
appendBufferByteList(
616+
[
617+
0x00, // Function Export Kind
618+
...Encoder.encodeUIntLeb128(wasmData.funcCount)
619+
],
620+
startExport
621+
)
622+
// Export Start
623+
wasmBinary.exportSection = [startExport, ...wasmBinary.exportSection]
622624
}
623625
export let createElementSection = (wasmBinary, dependencyChain, wasmData) => {
624626
let mut elementOffset = 0
@@ -850,7 +852,9 @@ export let buildBinary = wasmBinaryContent => {
850852
Buffer.addBuffer(memorySection, wasmBinary)
851853
Buffer.addBuffer(globalSection, wasmBinary)
852854
Buffer.addBuffer(exportSection, wasmBinary)
853-
Buffer.addBuffer(startSection, wasmBinary)
855+
if (Buffer.length(wasmBinaryContent.startSection) != 0) {
856+
Buffer.addBuffer(startSection, wasmBinary)
857+
}
854858
Buffer.addBuffer(elementSection, wasmBinary)
855859
Buffer.addBuffer(codeSection, wasmBinary)
856860
// let wasmBinary = createDataSection(wasmBinary, dependencyChain, wasmData)

0 commit comments

Comments
 (0)