Open leongross opened 6 months ago
@leongross Here's a start; I think this is on the right track...
loader/goroot.go file controls which std lib pkgs get overridden for tinygo, based on target. To build on x86_64, we need to not use the tinygo "net" pkg, but rather use the std lib pkg. I hacked loader/goroot.go to use std lib "net" pkg:
diff --git a/loader/goroot.go b/loader/goroot.go
index ea2f705d..629f1880 100644
--- a/loader/goroot.go
+++ b/loader/goroot.go
@@ -241,14 +241,14 @@ func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool {
"internal/reflectlite/": false,
"internal/task/": false,
"machine/": false,
- "net/": true,
- "net/http/": false,
+ //"net/": true,
+ //"net/http/": false,
}
I then tried building a test app using (note the -tags netgo). It built, but getting linker errors:
$ ~/go/bin/tinygo build -tags netgo main.go
ld.lld-17: error: undefined symbol: internal/poll.runtime_pollReset
>>> referenced by fd_poll_runtime.go:68 (/usr/local/go/src/internal/poll/fd_poll_runtime.go:68)
>>> /home/sfeldma/.cache/tinygo/thinlto/llvmcache-9D46EBAE39229B9F538CA31649783F334AB281E6:((*internal/poll.pollDesc).prepare)
ld.lld-17: error: undefined symbol: internal/poll.runtime_pollWait
>>> referenced by fd_poll_runtime.go:84 (/usr/local/go/src/internal/poll/fd_poll_runtime.go:84)
>>> /home/sfeldma/.cache/tinygo/thinlto/llvmcache-9D46EBAE39229B9F538CA31649783F334AB281E6:((*internal/poll.pollDesc).wait)
ld.lld-17: error: undefined symbol: internal/poll.runtime_pollSetDeadline
>>> referenced by fd_poll_runtime.go:161 (/usr/local/go/src/internal/poll/fd_poll_runtime.go:161)
>>> /home/sfeldma/.cache/tinygo/thinlto/llvmcache-9D46EBAE39229B9F538CA31649783F334AB281E6:(internal/poll.setDeadlineImpl)
ld.lld-17: error: undefined symbol: getrandom
>>> referenced by os_linux.go:125 (/home/sfeldma/work/tinygo/src/runtime/os_linux.go:125)
>>> /home/sfeldma/.cache/tinygo/thinlto/llvmcache-9D46EBAE39229B9F538CA31649783F334AB281E6:((*net.Resolver).exchange)
error: failed to link /tmp/tinygo3732967082/main: exit status 1
So the next thing to figure out is why internal/poll didnt' get picked up.
Here's the test app:
package main
import (
"fmt"
"net"
)
func main() {
conn, err := net.Dial("tcp", "localhost")
if err != nil {
fmt.Println(err)
}
conn.Close()
}
Also, on a parallel topic, there is an effort to use the full "net" pkg with embedded targets. See https://github.com/tinygo-org/tinygo/pull/4187.
I did some work to enable the sys/unix
package syscalls https://github.com/tinygo-org/tinygo/pull/4310. @scottfeldman feel free to have look there as well
There was a discussion in the tinygo slack channel on the functionality of the net package on non-embedded platforms such as regular Linux platforms on x86_64. What are the current limitations / issues that we have to overcome that we can use the net package for scenarios where tinygo should be run on desktop/servers that run Linux? As soon as we figured out the issues, I'd be happy to help with the implementation.