Stream: general

Topic: wasmtime-go on my nix machine is getting compile errors


view this post on Zulip Ymo (Aug 14 2025 at 06:18):

Hi folks

image.png

I am geting the above error in my vscode build. i am not sure what could be going on. also from the command line go mod tidy reports no errors.

 go build -o test main.go
# command-line-arguments
./main.go:14:20: undefined: wasmtime.NewStore
./main.go:14:38: undefined: wasmtime.NewEngine
./main.go:19:24: undefined: wasmtime.Wat2Wasm
./main.go:30:26: undefined: wasmtime.NewModule
./main.go:35:19: undefined: wasmtime.WrapFunc
./main.go:41:28: undefined: wasmtime.NewInstance
./main.go:41:66: undefined: wasmtime.AsExtern

view this post on Zulip Pat Hickey (Aug 14 2025 at 14:50):

if you switch to version 34, does it work?

view this post on Zulip Ymo (Aug 14 2025 at 14:59):

No. i am getting the same error. Also i confirmed that the same exact code works fine in an ubuntu vm. i am prutty this has something to do with the fact that i am on nixos. its very finicky about dynamically loaded libraries. the weird thing is that is not so obvious

view this post on Zulip Pat Hickey (Aug 14 2025 at 15:10):

ok. sorry, cant help you with that, I don't use or know nix, nor wasmtime-go or go. maybe someone else will have an idea

view this post on Zulip Ymo (Aug 14 2025 at 15:27):

thank you for jumping on this !

do you know what is happening behind the scene ? like where/when does it need to load dynamicl libraries ? i was naive enough to assume shared libraries would not be needed at compile time. any hints on what is happening behind the scene would be much appreciated.

Regards

view this post on Zulip Ymo (Aug 14 2025 at 15:28):

like i know its failing because of shared libraries and i need to tell it where to find them via an environement variable maybe

view this post on Zulip Lann Martin (Aug 14 2025 at 15:40):

Are you using x86_64?

view this post on Zulip Ymo (Aug 14 2025 at 15:43):

Yes i am on an x86 machine

 neofetch
          ▗▄▄▄       ▗▄▄▄▄    ▄▄▄▖            ymo@memx
          ▜███▙       ▜███▙  ▟███▛            --------
           ▜███▙       ▜███▙▟███▛             OS: NixOS 25.05.20250801.59e6964 (Warbler) x86_64
            ▜███▙       ▜██████▛              Host: ASUSTeK COMPUTER INC. ROG CROSSHAIR VIII DARK HERO
     ▟█████████████████▙ ▜████▛     ▟▙        Kernel: 6.12.40
    ▟███████████████████▙ ▜███▙    ▟██▙       Uptime: 8 days, 20 hours, 8 mins
           ▄▄▄▄▖           ▜███▙  ▟███▛       Packages: 1074 (nix-system), 1099 (nix-user)
          ▟███▛             ▜██▛ ▟███▛        Shell: bash 5.3.0
         ▟███▛               ▜▛ ▟███▛         Resolution: 1920x1080, 2560x1440
▟███████████▛                  ▟██████████▙   DE: shi3
▜██████████▛                  ▟███████████▛   WM: i3
      ▟███▛ ▟▙               ▟███▛            Theme: Adwaita [GTK3]
     ▟███▛ ▟██▙             ▟███▛             Icons: Adwaita [GTK3]
    ▟███▛  ▜███▙           ▝▀▀▀▀              Terminal: kitty
    ▜██▛    ▜███▙ ▜██████████████████▛        Terminal Font: JetBrainsMono Nerd Font 10.0
     ▜▛     ▟████▙ ▜████████████████▛         CPU: AMD Ryzen 9 5950X (32) @ 5.084GHz
           ▟██████▙       ▜███▙               GPU: NVIDIA GeForce RTX 3060 Ti Lite Hash Rate
          ▟███▛▜███▙       ▜███▙              Memory: 20675MiB / 64203MiB

view this post on Zulip Lann Martin (Aug 14 2025 at 15:46):

Does ls $(go env GOPATH)/pkg/mod/github.com/bytecodealliance/wasmtime-go/v35@v35.0.0/build/linux-x86_64 show a libwasmtime.a?

view this post on Zulip Ymo (Aug 14 2025 at 15:46):

https://github.com/microsoft/wassette/blob/main/flake.nix

i am looking at how these folks are supporting wasmtime under the hood in nix for inspiration. trying to see what they are doing

Wassette: A security-oriented runtime that runs WebAssembly Components via MCP - microsoft/wassette

view this post on Zulip Ymo (Aug 14 2025 at 15:49):

Lann Martin said:

Does ls $(go env GOPATH)/pkg/mod/github.com/bytecodealliance/wasmtime-go/v35@v35.0.0/build/linux-x86_64 show a libwasmtime.a?

its not at all here is what i did

 nix-shell -p wasmtime go_1_24

~ via ❄️  impure (shell)
 ls $(go env GOPATH)/pkg/mod/github.com/bytecodealliance/wasmtime-go/v35@v35.0.0/build/linux-x86_64
"/home/ymo/go/pkg/mod/github.com/bytecodealliance/wasmtime-go/v35@v35.0.0/build/linux-x86_64": No such file or directory (os error 2)

view this post on Zulip bjorn3 (Aug 14 2025 at 15:49):

And after you build inside the same nix-shell?

view this post on Zulip bjorn3 (Aug 14 2025 at 15:50):

I'm not a Nix user, but I can imagine nix-shell uses a separate cache dir for every nix-shell invocation.

view this post on Zulip Lann Martin (Aug 14 2025 at 15:51):

Does nix-shell bind mount over $HOME or something? :thinking:

view this post on Zulip Lann Martin (Aug 14 2025 at 15:52):

You might actually need to find generic resources on using cgo with nix. You're definitely off the beaten path here.

view this post on Zulip Lann Martin (Aug 14 2025 at 15:53):

On my system after a go get github.com/bytecodealliance/wasmtime-go/v35 the prebuilt object file appears as above

view this post on Zulip Lann Martin (Aug 14 2025 at 15:54):

Oh nix could also override GOMODCACHE I guess, in which case it might be $(go env GOMODCACHE)/github.com/bytecodealliance/wasmtime-go/v35@v35.0.0/build/linux-x86_64

view this post on Zulip Ymo (Aug 14 2025 at 15:56):

ok with your help i think i have at least found where its expecting those libs
❯ ls /home/ymo/3rdp/dev/golang/golang-rel/golatest-packages/pkg/mod/github.com/bytecodealliance/wasmtime-go/v35@v35.0.0/build/linux-x86_64/
empty.go libwasmtime.a

view this post on Zulip Lann Martin (Aug 14 2025 at 15:57):

The prebuilt lib is referenced in a cgo directive: // #cgo linux,amd64 LDFLAGS:-L${SRCDIR}/build/linux-x86_64

view this post on Zulip Lann Martin (Aug 14 2025 at 15:57):

I would guess that SRCDIR there isn't resolving as the author expects
edit: but SRCDIR does seem to be the recommended way to do that

view this post on Zulip Ymo (Aug 14 2025 at 15:57):

so at least i know the static library is there. now why is it not linking ? why is the go compiler reporting those methods as missing

 find   /home/ymo/3rdp/dev/golang/golang-rel/golatest-packages/pkg/mod/github.com/bytecodealliance/wasmtime-go/v35@v35.0.0/build/linux-x86_64/
/home/ymo/3rdp/dev/golang/golang-rel/golatest-packages/pkg/mod/github.com/bytecodealliance/wasmtime-go/v35@v35.0.0/build/linux-x86_64/
/home/ymo/3rdp/dev/golang/golang-rel/golatest-packages/pkg/mod/github.com/bytecodealliance/wasmtime-go/v35@v35.0.0/build/linux-x86_64/libwasmtime.a
/home/ymo/3rdp/dev/golang/golang-rel/golatest-packages/pkg/mod/github.com/bytecodealliance/wasmtime-go/v35@v35.0.0/build/linux-x86_64/empty.go

view this post on Zulip Chris Fallin (Aug 14 2025 at 16:02):

FWIW, I used Nix for a year or so for my dev env and got very frustrated and gave up: I found it would do things like modify compiler path-search logic to be "pure" / use only paths specified as dependencies, so libraries installed the usual way (in global paths) wouldn't be visible. I'd suggest asking around in a Nix-specific forum -- we're unlikely to be able to help here if it works normally on a non-Nix distro

view this post on Zulip Ymo (Aug 14 2025 at 16:04):

i got it. i am just nerdsniped at this point and cant let go. i dont want to burden the team on unbeaten path. if someone wants to throw anything at me i appreciate. i dont expect people to support this at all.

view this post on Zulip Ymo (Aug 14 2025 at 16:04):

i will report my findings here if that is ok

view this post on Zulip Ymo (Aug 14 2025 at 16:34):

ok so solved my problem .. yaaay. i know now that i was missing gcc in my shell. duh !
now the weird thing is i cant see why the go build tool is not reporting that gcc is missing in the system. nor vscode for that matter ...

i tried passing -vx to the build command but even with this i dont see the error

 go build -vx   -o test .
flag provided but not defined: -vx
usage: go build [-o output] [build flags] [packages]
Run 'go help build' for details.

tools-wasm.devbr/wasmtime on  main [!?] via 🐹 v1.24.5
 go build -x   -o test .
WORK=/tmp/go-build3474305375
cd /home/ymo/work/wspace-yassinm/tools/tools-wasm/tools-wasm.devbr
git status --porcelain
cd /home/ymo/work/wspace-yassinm/tools/tools-wasm/tools-wasm.devbr
git -c log.showsignature=false log -1 --format=%H:%ct
cd /home/ymo/work/wspace-yassinm/tools/tools-wasm/tools-wasm.devbr; git -c log.showsignature=false log --no-decorate -n1 '--format=format:%H %ct %D' 4a2008a00285d9095bd5b0753520bd085b195f62 --
0.002s # cd /home/ymo/work/wspace-yassinm/tools/tools-wasm/tools-wasm.devbr; git -c log.showsignature=false log --no-decorate -n1 '--format=format:%H %ct %D' 4a2008a00285d9095bd5b0753520bd085b195f62 --
cd /home/ymo/work/wspace-yassinm/tools/tools-wasm/tools-wasm.devbr; git for-each-ref --format %(refname) refs/tags --merged 4a2008a00285d9095bd5b0753520bd085b195f62
0.001s # cd /home/ymo/work/wspace-yassinm/tools/tools-wasm/tools-wasm.devbr; git for-each-ref --format %(refname) refs/tags --merged 4a2008a00285d9095bd5b0753520bd085b195f62
cd /home/ymo/work/wspace-yassinm/tools/tools-wasm/tools-wasm.devbr; git -c log.showsignature=false log --no-decorate -n1 '--format=format:%H %ct %D' 4a2008a00285 --
0.002s # cd /home/ymo/work/wspace-yassinm/tools/tools-wasm/tools-wasm.devbr; git -c log.showsignature=false log --no-decorate -n1 '--format=format:%H %ct %D' 4a2008a00285 --
cd /home/ymo/work/wspace-yassinm/tools/tools-wasm/tools-wasm.devbr; git cat-file blob 4a2008a00285d9095bd5b0753520bd085b195f62:go.mod
0.002s # cd /home/ymo/work/wspace-yassinm/tools/tools-wasm/tools-wasm.devbr; git cat-file blob 4a2008a00285d9095bd5b0753520bd085b195f62:go.mod
mkdir -p $WORK/b001/
cat >/tmp/go-build3474305375/b001/importcfg << 'EOF' # internal
# import config
packagefile fmt=/home/ymo/.cache/go-build/54/54b5a9818058da35904c3c28580e80dfe500fdeefa2875e74f9b51bc3c475758-d
packagefile github.com/bytecodealliance/wasmtime-go/v34=/home/ymo/.cache/go-build/e7/e700c3361120863ad44ffa87f2a7b8077b1d32b8b4dc1f0b3f286fdd70838fbd-d
packagefile runtime=/home/ymo/.cache/go-build/78/78949c7e395974e1877d087e2432519b35169408d7338fe5aa6da19acd4f38e7-d
EOF
cd /home/ymo/work/wspace-yassinm/tools/tools-wasm/tools-wasm.devbr/wasmtime
/nix/store/y4awwzp30ka130wmjrpaqjmjdf9p010w-go-1.24.5/share/go/pkg/tool/linux_amd64/compile -o $WORK/b001/_pkg_.a -trimpath "$WORK/b001=>" -p main -lang=go1.24 -complete -buildid F9FZcqu2B1F6j8n8VIps/F9FZcqu2B1F6j8n8VIps -goversion go1.24.5 -c=4 -nolocalimports -importcfg $WORK/b001/importcfg -pack ./main.go
# gowasm
./main.go:14:20: undefined: wasmtime.NewStore
./main.go:14:38: undefined: wasmtime.NewEngine
./main.go:19:24: undefined: wasmtime.Wat2Wasm
./main.go:30:26: undefined: wasmtime.NewModule
./main.go:35:19: undefined: wasmtime.WrapFunc
./main.go:41:28: undefined: wasmtime.NewInstance
./main.go:41:66: undefined: wasmtime.AsExtern

Last updated: Dec 06 2025 at 05:03 UTC