Skip to content

Commit 5ac8cf3

Browse files
committed
linux support for net.Dial by stubbing out runtime polling
Signed-off-by: leongross <leon.gross@9elements.com>
1 parent 797ef15 commit 5ac8cf3

File tree

11 files changed

+134
-604
lines changed

11 files changed

+134
-604
lines changed

.gitmodules

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,6 @@
3232
[submodule "lib/macos-minimal-sdk"]
3333
path = lib/macos-minimal-sdk
3434
url = https://github.com/aykevl/macos-minimal-sdk.git
35-
[submodule "src/net"]
36-
path = src/net
37-
url = https://github.com/tinygo-org/net.git
38-
branch = dev
3935
[submodule "lib/wasi-cli"]
4036
path = lib/wasi-cli
4137
url = https://github.com/WebAssembly/wasi-cli

loader/goroot.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool {
267267
if needsSyscallPackage {
268268
paths["syscall/"] = true // include syscall/js
269269
}
270+
271+
// to enable network support for linux systems, reuse the Go version of the net package
272+
// and the according runtime functions
273+
// if runtime.GOOS == "linux" {
274+
// paths["runtime/netpoll/"] = true
275+
// }
270276
return paths
271277
}
272278

src/crypto/tls/common.go

Lines changed: 0 additions & 460 deletions
This file was deleted.

src/crypto/tls/ticket.go

Lines changed: 0 additions & 16 deletions
This file was deleted.

src/crypto/tls/tls.go

Lines changed: 0 additions & 114 deletions
This file was deleted.

src/net

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/runtime/netpoll.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright 2024 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
package runtime
6+
7+
// For debugging purposes this is used for all target architectures, but this is only valid for linux systems.
8+
// TODO: add linux specific build tags
9+
type pollDesc struct {
10+
runtimeCtx uintptr
11+
}
12+
13+
func (pd *pollDesc) wait(mode int, isFile bool) error {
14+
return nil
15+
}
16+
17+
const (
18+
pollNoError = 0 // no error
19+
pollErrClosing = 1 // descriptor is closed
20+
pollErrTimeout = 2 // I/O timeout
21+
pollErrNotPollable = 3 // general error polling descriptor
22+
)
23+
24+
//go:linkname poll_runtime_pollReset internal/poll.runtime_pollReset
25+
func poll_runtime_pollReset(pd *pollDesc, mode int) int {
26+
println("poll_runtime_pollReset not implemented", pd, mode)
27+
return pollNoError
28+
}
29+
30+
//go:linkname poll_runtime_pollWait internal/poll.runtime_pollWait
31+
func poll_runtime_pollWait(pd *pollDesc, mode int) int {
32+
println("poll_runtime_pollWait not implemented", pd, mode)
33+
return pollNoError
34+
}
35+
36+
//go:linkname poll_runtime_pollSetDeadline internal/poll.runtime_pollSetDeadline
37+
func poll_runtime_pollSetDeadline(pd *pollDesc, d int64, mode int) {
38+
println("poll_runtime_pollSetDeadline not implemented", pd, d, mode)
39+
}
40+
41+
//go:linkname poll_runtime_pollOpen internal/poll.runtime_pollOpen
42+
func poll_runtime_pollOpen(fd uintptr) (*pollDesc, int) {
43+
println("poll_runtime_pollOpen not implemented", fd)
44+
return &pollDesc{runtimeCtx: 0x13371337}, pollNoError
45+
}

src/runtime/netpoll_generic.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright 2024 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
//go:build (js && wasm) || wasip1 || windows
6+
7+
package runtime
8+
9+
// Network poller descriptor.
10+
//
11+
// No heap pointers.
12+
// For linux to call create Fds with a pollDesc, it needs a ctxRuntime pointer, so use the original pollDesc struct.
13+
// On linux we have a heap.
14+
type pollDesc struct{}
15+
16+
//go:linkname poll_runtime_pollReset internal/poll.runtime_pollReset
17+
func poll_runtime_pollReset(pd *pollDesc, mode int) int {
18+
println("poll_runtime_pollReset not implemented", pd, mode)
19+
return 1
20+
}
21+
22+
//go:linkname poll_runtime_pollWait internal/poll.runtime_pollWait
23+
func poll_runtime_pollWait(pd *pollDesc, mode int) int {
24+
println("poll_runtime_pollWait not implemented", pd, mode)
25+
return 1
26+
}
27+
28+
//go:linkname poll_runtime_pollSetDeadline internal/poll.runtime_pollSetDeadline
29+
func poll_runtime_pollSetDeadline(pd *pollDesc, d int64, mode int) {
30+
println("poll_runtime_pollSetDeadline not implemented", pd, d, mode)
31+
}

src/runtime/poll.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@ package runtime
44

55
//go:linkname poll_runtime_pollServerInit internal/poll.runtime_pollServerInit
66
func poll_runtime_pollServerInit() {
7-
panic("todo: runtime_pollServerInit")
7+
// fmt.Printf("poll_runtime_pollServerInit not implemented, skipping panic\n")
88
}
99

10-
//go:linkname poll_runtime_pollOpen internal/poll.runtime_pollOpen
11-
func poll_runtime_pollOpen(fd uintptr) (uintptr, int) {
12-
panic("todo: runtime_pollOpen")
13-
}
10+
// //go:linkname poll_runtime_pollOpen internal/poll.runtime_pollOpen
11+
// func poll_runtime_pollOpen(fd uintptr) (uintptr, int) {
12+
// // fmt.Printf("poll_runtime_pollOpen not implemented, skipping panic\n")
13+
// return 0, 0
14+
// }
1415

1516
//go:linkname poll_runtime_pollClose internal/poll.runtime_pollClose
1617
func poll_runtime_pollClose(ctx uintptr) {
17-
panic("todo: runtime_pollClose")
18+
// fmt.Printf("poll_runtime_pollClose not implemented, skipping panic\n")
1819
}
1920

2021
//go:linkname poll_runtime_pollUnblock internal/poll.runtime_pollUnblock
2122
func poll_runtime_pollUnblock(ctx uintptr) {
22-
panic("todo: runtime_pollUnblock")
23+
// fmt.Printf("poll_runtime_pollUnblock not implemented, skipping panic\n")
2324
}

src/runtime/sync.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,14 @@ package runtime
44

55
//go:linkname semacquire internal/poll.runtime_Semacquire
66
func semacquire(sema *uint32) {
7-
panic("todo: semacquire")
7+
// TODO the "net" pkg calls this, so panic() isn't an option. Right
8+
// now, just ignore the call.
9+
// panic("todo: semacquire")
810
}
911

1012
//go:linkname semrelease internal/poll.runtime_Semrelease
1113
func semrelease(sema *uint32) {
12-
panic("todo: semrelease")
14+
// TODO the "net" pkg calls this, so panic() isn't an option. Right
15+
// now, just ignore the call.
16+
// panic("todo: semrelease")
1317
}

0 commit comments

Comments
 (0)