tinygo icon indicating copy to clipboard operation
tinygo copied to clipboard

Netdev not set on AMD64+Linux

Open eaglexiang opened this issue 6 months ago • 6 comments

I'm a nooby of tinygo and exploring the possibility of Go developing on embeded platforms. Demo blew was built sucessfully but reported Netdev not set while running:

package main

import (
	"log"
	"net/http"
)

func main() {
	err := http.ListenAndServe(":8080", nil)
	if err != nil {
		log.Fatal(err)
	}
}

I'm just trying the smallest demo on my own PC (WSL Ubuntu with AMD64), how can I solve this problem? Actually we have several applications worked based on Go, my target is migrating them to embeded platforms.

eaglexiang avatar Aug 06 '25 03:08 eaglexiang

⋊> ~/tmp tinygo version
tinygo version 0.38.0 linux/amd64 (using go version go1.23.0 and LLVM version 19.1.2)
⋊> ~/tmp tinygo build .
⋊> ~/tmp ./tmp
2025/08/06 11:36:17 Netdev not set

eaglexiang avatar Aug 06 '25 03:08 eaglexiang

This is a big problem.. Could we use syscall?

j3l11234 avatar Sep 05 '25 13:09 j3l11234

Please give this a shot and let me know if it works: https://github.com/niemeyer/muslnet

It's just a few hours old, so there are probably bugs lurking there. Also just IPv4 for now.

niemeyer avatar Sep 23 '25 22:09 niemeyer

Please give this a shot and let me know if it works: https://github.com/niemeyer/muslnet

It's just a few hours old, so there are probably bugs lurking there. Also just IPv4 for now.

I changed code to:

package main

import (
	"log"
	"net/http"

	"github.com/niemeyer/muslnet"
	"tinygo.org/x/drivers/netdev"
)

func main() {
	netdev.UseNetdev(muslnet.New())

	err := http.ListenAndServe(":8080", nil)
	if err != nil {
		log.Fatal(err)
	}
}

and got:

tinygo build .                                                                                                                                                                                                          14:05:39
# runtime/cgo
../../.gvm/pkgsets/go1.23.0/global/pkg/mod/golang.org/[email protected]/src/runtime/cgo/cgo.go:14:6: not implemented: build constraints in #cgo line
../../.gvm/pkgsets/go1.23.0/global/pkg/mod/golang.org/[email protected]/src/runtime/cgo/cgo.go:15:6: not implemented: build constraints in #cgo line
../../.gvm/pkgsets/go1.23.0/global/pkg/mod/golang.org/[email protected]/src/runtime/cgo/cgo.go:16:6: not implemented: build constraints in #cgo line
../../.gvm/pkgsets/go1.23.0/global/pkg/mod/golang.org/[email protected]/src/runtime/cgo/cgo.go:17:6: not implemented: build constraints in #cgo line
../../.gvm/pkgsets/go1.23.0/global/pkg/mod/golang.org/[email protected]/src/runtime/cgo/cgo.go:18:6: not implemented: build constraints in #cgo line
../../.gvm/pkgsets/go1.23.0/global/pkg/mod/golang.org/[email protected]/src/runtime/cgo/cgo.go:19:6: not implemented: build constraints in #cgo line
../../.gvm/pkgsets/go1.23.0/global/pkg/mod/golang.org/[email protected]/src/runtime/cgo/cgo.go:20:6: not implemented: build constraints in #cgo line
../../.gvm/pkgsets/go1.23.0/global/pkg/mod/golang.org/[email protected]/src/runtime/cgo/cgo.go:21:6: not implemented: build constraints in #cgo line
../../.gvm/pkgsets/go1.23.0/global/pkg/mod/golang.org/[email protected]/src/runtime/cgo/cgo.go:22:6: not implemented: build constraints in #cgo line
../../.gvm/pkgsets/go1.23.0/global/pkg/mod/golang.org/[email protected]/src/runtime/cgo/cgo.go:23:6: not implemented: build constraints in #cgo line
../../.gvm/pkgsets/go1.23.0/global/pkg/mod/golang.org/[email protected]/src/runtime/cgo/cgo.go:24:6: not implemented: build constraints in #cgo line
../../.gvm/pkgsets/go1.23.0/global/pkg/mod/golang.org/[email protected]/src/runtime/cgo/cgo.go:31:6: not implemented: build constraints in #4765 

eaglexiang avatar Sep 26 '25 06:09 eaglexiang

I'm seeing a similar issue. With just a plain import "net/http", a tinygo-compiled binary generates a Netdev not set error from inside the ListenAndServe function. Importing the netdev and muslnet packages, I get a clean compile (unlike @eaglexiang), but running gives me a panic:

Listening on :8080
panic: As4 called on IP zero value
zsh: IOT instruction (core dumped)  ./mirror-tinygo hg+https://hg.sr.ht/~ser git+https://github.com/xxxserxxx

My (relevant, clipped) code & environment are:

        github.com/niemeyer/muslnet v0.0.0-20250923220305-4b81d3c72602 // indirect
        tinygo.org/x/drivers v0.33.0 // indirect
	netdev.UseNetdev(muslnet.New())
	fmt.Printf("Listening on %s\n", listen)
	if err := http.ListenAndServe(listen, handl); err != nil {
		log.Fatal(err)
		os.Exit(1)
	}

and I'm on:

  • Linux 6.16.8-arch3-1 #1 SMP PREEMPT_DYNAMIC x86_64
  • go version go1.25.1 X:nodwarf5 linux/amd64
  • tinygo version 0.39.0 linux/amd64 (using go version go1.25.1 X:nodwarf5 and LLVM version 19.1.2)

The whole project source (which is just a non-complex Go vanity mirror) is on Sourcehut, but I haven't checked in these changes for tinygo -- I was planning on keeping a side-branch specifically for differences necessary for building and running with tinygo, if I could get it working. My target is native -- vs WASM or whatnot.

xxxserxxx avatar Sep 29 '25 14:09 xxxserxxx

@xxxserxxx The panic is due to the ":8080". Put in the IP address (say, "0.0.0.0:8080") and it should work.

I will amend the tests and fix the issue when I have a moment.

@eaglexiang No idea there. These errors are coming from a place outside of muslnet, so this is probably environment-related. Please let me know if you debug and find some more information.

niemeyer avatar Sep 29 '25 14:09 niemeyer