Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std net package does not supported in wasm/wasi #2704

Open
Cylkal opened this issue Mar 11, 2022 · 7 comments
Open

std net package does not supported in wasm/wasi #2704

Cylkal opened this issue Mar 11, 2022 · 7 comments
Labels
enhancement New feature or request wasm WebAssembly

Comments

@Cylkal
Copy link

Cylkal commented Mar 11, 2022

Problem description

code example:

package main

import (
	"net"
	"time"
)

func main() {
	_, _ = net.DialTimeout("tcp", ":80", time.Second)
}

compile command:
tinygo build -o demo.wasm -target=wasi ./test.go

out:

# command-line-arguments
test.go:9:13: DialTimeout not declared by package net

Background

When I want to import package golang.org/x/crypto/ssh, trying to connect to ssh server in a wasm module, some err occurs while compile:

# golang.org/x/crypto/ssh
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/tcpip.go:71:54: TCPAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/tcpip.go:104:39: TCPAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/tcpip.go:183:51: TCPAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/tcpip.go:289:13: TCPAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/tcpip.go:389:54: TCPAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/client.go:173:19: DialTimeout not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/server.go:299:28: TCPAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/streamlocal.go:47:28: UnixAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/streamlocal.go:85:15: UnixAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/streamlocal.go:89:15: UnixAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/streamlocal.go:99:30: UnixAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/streamlocal.go:112:14: UnixAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/tcpip.go:27:21: ResolveTCPAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/tcpip.go:191:14: TCPAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/tcpip.go:231:17: UnixAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/tcpip.go:235:17: UnixAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/tcpip.go:355:20: TCPAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/tcpip.go:372:16: UnixAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/tcpip.go:376:16: UnixAddr not declared by package net
../../../../go/pkg/mod/golang.org/x/crypto@v0.0.0-20210813211128-0a44fdfbc16e/ssh/tcpip.go:391:16: TCPAddr not declared by package net

As we can see, ssh import net package which does not support many methods or types it reqiuired.

Is there any plan to support the official net library?

@dankegel
Copy link
Contributor

WASI does seem to have the beginnings of support for sockets, see
https://radu-matei.com/blog/towards-sockets-networking-wasi/
WebAssembly/WASI#312
bytecodealliance/wasmtime#70
https://github.com/WebAssembly/wasi-sockets
and there has been a tiny bit of discussion about it in tinygo slack,
https://gophers.slack.com/archives/CDJD3SUP6/p1645868342147429
but as yet nobody has wired it up.

@sago35
Copy link
Member

sago35 commented Mar 11, 2022

I have not tried this, but the following may be helpful.

tinynet implements a subnet of the Go net package. Because it is based on unisockets, it supports more platforms (WASM/JS, WASM/WASI, TinyGo, Go etc.) than the official net package.

https://github.com/alphahorizonio/tinynet

@deadprogram deadprogram added enhancement New feature or request wasm WebAssembly labels Apr 23, 2022
@dipankardas011
Copy link

same issue here is my error log

# golang.org/x/crypto/ssh
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/tcpip.go:289:13: undefined: net.TCPAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/tcpip.go:71:54: undefined: net.TCPAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/tcpip.go:104:39: undefined: net.TCPAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/tcpip.go:183:51: undefined: net.TCPAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/tcpip.go:389:54: undefined: net.TCPAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/client.go:177:19: undefined: net.DialTimeout
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/server.go:300:28: undefined: net.TCPAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/streamlocal.go:47:28: undefined: net.UnixAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/streamlocal.go:85:15: undefined: net.UnixAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/streamlocal.go:89:15: undefined: net.UnixAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/streamlocal.go:99:30: undefined: net.UnixAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/streamlocal.go:112:14: undefined: net.UnixAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/tcpip.go:27:21: undefined: net.ResolveTCPAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/tcpip.go:191:14: undefined: net.TCPAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/tcpip.go:231:17: undefined: net.UnixAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/tcpip.go:235:17: undefined: net.UnixAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/tcpip.go:355:20: undefined: net.TCPAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/tcpip.go:372:16: undefined: net.UnixAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/tcpip.go:376:16: undefined: net.UnixAddr
../home/tinygo/go/pkg/mod/golang.org/x/crypto@v0.0.0-20220722155217-630584e8d5aa/ssh/tcpip.go:391:16: undefined: net.TCPAddr

@dipankardas011
Copy link

Is it worked on?
if not where should I work to help its development?

@aykevl
Copy link
Member

aykevl commented May 31, 2023

See: #3704 (I haven't followed the development very closely).

@dipankardas011
Copy link

Also one more query does tinygo support cobra cli package? I know its not the right place but whom to ask😕

@aykevl
Copy link
Member

aykevl commented Jun 1, 2023

@dipankardas011 you can test so for yourself, it only takes a few seconds 😉

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request wasm WebAssembly
Projects
None yet
Development

No branches or pull requests

6 participants