extism / go-pdk

Extism Plug-in Development Kit (PDK) for Go
https://pkg.go.dev/github.com/extism/go-pdk
BSD 3-Clause "New" or "Revised" License
60 stars 11 forks source link

Bug: Can't compile the samples on Windows #11

Closed mhmd-azeez closed 10 months ago

mhmd-azeez commented 1 year ago

I tried compiling the samples in example folder of this repo on Windows, but it seems like the C FFI is not working as expected. The examples build just fine on Windows Subsystem for Linux.

Versions:

Windows: Windows 11 - 22H2 (OS Build 22621.1848) Go: go1.20.5 windows/amd64 TinyGo: 0.28.1 windows/amd64 (using go version go1.20.5 and LLVM version 15.0.0)

Logs

Mo in ~ λ go version
go version go1.20.5 windows/amd64
Mo in ~ λ tinygo version
tinygo version 0.28.1 windows/amd64 (using go version go1.20.5 and LLVM version 15.0.0)
Mo in D:\Explore\go\go-pdk\example on main ● ~1 λ tinygo build -o main.wasm .\main.go
wasm-ld: error: C:\Users\Mo\AppData\Local\Temp\tinygo3081171661\main.o: undefined symbol: extism_load_u64
wasm-ld: error: C:\Users\Mo\AppData\Local\Temp\tinygo3081171661\main.o: undefined symbol: extism_load_u8
wasm-ld: error: C:\Users\Mo\AppData\Local\Temp\tinygo3081171661\main.o: undefined symbol: extism_alloc
wasm-ld: error: C:\Users\Mo\AppData\Local\Temp\tinygo3081171661\main.o: undefined symbol: extism_store_u64
wasm-ld: error: C:\Users\Mo\AppData\Local\Temp\tinygo3081171661\main.o: undefined symbol: extism_store_u8
wasm-ld: error: C:\Users\Mo\AppData\Local\Temp\tinygo3081171661\main.o: undefined symbol: extism_var_get
wasm-ld: error: C:\Users\Mo\AppData\Local\Temp\tinygo3081171661\main.o: undefined symbol: extism_length
wasm-ld: error: C:\Users\Mo\AppData\Local\Temp\tinygo3081171661\main.o: undefined symbol: extism_input_length
wasm-ld: error: C:\Users\Mo\AppData\Local\Temp\tinygo3081171661\main.o: undefined symbol: extism_input_load_u64
wasm-ld: error: C:\Users\Mo\AppData\Local\Temp\tinygo3081171661\main.o: undefined symbol: extism_input_load_u8
wasm-ld: error: C:\Users\Mo\AppData\Local\Temp\tinygo3081171661\main.o: undefined symbol: extism_var_set
wasm-ld: error: C:\Users\Mo\AppData\Local\Temp\tinygo3081171661\main.o: undefined symbol: extism_config_get
wasm-ld: error: C:\Users\Mo\AppData\Local\Temp\tinygo3081171661\main.o: undefined symbol: extism_length
wasm-ld: error: C:\Users\Mo\AppData\Local\Temp\tinygo3081171661\main.o: undefined symbol: extism_output_set
failed to run tool: wasm-ld
error: failed to link C:\Users\Mo\AppData\Local\Temp\tinygo3081171661\main: exit status 1
JayJamieson commented 10 months ago

Can't reproduce, I cloned repo and installed tinygo and needed to install wasm-opt too.

I can build countvowels successfully with tinygo build -o example/tiny_countvowels.wasm -target wasi ./example/countvowels

I can build http successfully with tinygo build -o example/tiny_http.wasm -target wasi ./example/http

C:\Users\jay\github\go-pdk>go version
go version go1.20.7 windows/amd64

C:\Users\jay\github\go-pdk>tinygo version
tinygo version 0.30.0 windows/amd64 (using go version go1.20.7 and LLVM version 16.0.1)

Edit:

Can you try upgrading tinygo version to latest? It's only two versions but worth a try.

JayJamieson commented 10 months ago

Ah interesting, I can reproduce similar errors with tinygo build example\countvowels\main.go.

ld.lld: error: undefined symbol: github.com/extism/go-pdk.extism_input_load_u8_
>>> referenced by main
>>>               C:\Users\jay\AppData\Local\Temp\tinygo2640000697\main.o

ld.lld: error: undefined symbol: github.com/extism/go-pdk.extism_store_u8_
>>> referenced by main
>>>               C:\Users\jay\AppData\Local\Temp\tinygo2640000697\main.o

ld.lld: error: undefined symbol: github.com/extism/go-pdk.extism_load_u8_
>>> referenced by main
>>>               C:\Users\jay\AppData\Local\Temp\tinygo2640000697\main.o

ld.lld: error: undefined symbol: github.com/extism/go-pdk.extism_free
>>> referenced by main
>>>               C:\Users\jay\AppData\Local\Temp\tinygo2640000697\main.o

ld.lld: error: undefined symbol: github.com/extism/go-pdk.extism_load_u64
>>> referenced by main
>>>               C:\Users\jay\AppData\Local\Temp\tinygo2640000697\main.o

ld.lld: error: undefined symbol: github.com/extism/go-pdk.extism_store_u64
>>> referenced by main
>>>               C:\Users\jay\AppData\Local\Temp\tinygo2640000697\main.o

ld.lld: error: undefined symbol: github.com/extism/go-pdk.extism_input_length
>>> referenced by main
>>>               C:\Users\jay\AppData\Local\Temp\tinygo2640000697\main.o

ld.lld: error: undefined symbol: github.com/extism/go-pdk.extism_input_load_u64
>>> referenced by main
>>>               C:\Users\jay\AppData\Local\Temp\tinygo2640000697\main.o

ld.lld: error: undefined symbol: github.com/extism/go-pdk.extism_alloc
>>> referenced by main
>>>               C:\Users\jay\AppData\Local\Temp\tinygo2640000697\main.o

ld.lld: error: undefined symbol: github.com/extism/go-pdk.extism_output_set
>>> referenced by main
>>>               C:\Users\jay\AppData\Local\Temp\tinygo2640000697\main.o

ld.lld: error: undefined symbol: github.com/extism/go-pdk.extism_config_get
>>> referenced by main
>>>               C:\Users\jay\AppData\Local\Temp\tinygo2640000697\main.o

ld.lld: error: undefined symbol: github.com/extism/go-pdk.extism_length
>>> referenced by main
>>>               C:\Users\jay\AppData\Local\Temp\tinygo2640000697\main.o

ld.lld: error: undefined symbol: github.com/extism/go-pdk.extism_var_get
>>> referenced by main
>>>               C:\Users\jay\AppData\Local\Temp\tinygo2640000697\main.o

ld.lld: error: undefined symbol: github.com/extism/go-pdk.extism_var_set
>>> referenced by main
>>>               C:\Users\jay\AppData\Local\Temp\tinygo2640000697\main.o
failed to run tool: ld.lld
error: failed to link C:\Users\jay\AppData\Local\Temp\tinygo2640000697\main.exe: exit status 1
mhmd-azeez commented 10 months ago

With the latest version of TinyGo and latest version of the examples in the repo, you can build the examples on windows too:

PS D:\dylibso\go-pdk\example\countvowels> tinygo version
tinygo version 0.30.0 windows/amd64 (using go version go1.21.1 and LLVM version 16.0.1)
PS D:\dylibso\go-pdk\example\countvowels> tinygo build -target wasi -o c.wasm .\tiny_main.go
PS D:\dylibso\go-pdk\example\countvowels> extism call .\c.wasm count_vowels --input "Hello World!" --wasi
{"count": 3, "config": "<unset by host>", "a": "this is var a"}