8000 net: enable native golang linux networking by leongross · Pull Request #4498 · tinygo-org/tinygo · GitHub
[go: up one dir, main page]

Skip to content

net: enable native golang linux networking #4498

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

Open
wants to merge 14 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
linux support for net.Dial by stubbing out runtime polling
Signed-off-by: leongross <leon.gross@9elements.com>
  • Loading branch information
leongross committed Nov 27, 2024
commit 329fef6b4a6394ebe7e5ec49e5cacfa15f61b006
4 changes: 0 additions & 4 deletions .gitmodules
8000
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@
[submodule "lib/macos-minimal-sdk"]
path = lib/macos-minimal-sdk
url = https://github.com/aykevl/macos-minimal-sdk.git
[submodule "src/net"]
path = src/net
url = https://github.com/tinygo-org/net.git
branch = dev
[submodule "lib/wasi-cli"]
path = lib/wasi-cli
url = https://github.com/WebAssembly/wasi-cli
6 changes: 6 additions & 0 deletions loader/goroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ func pathsToOverride(goMinor int, needsSyscallPackage bool) map[string]bool {
if needsSyscallPackage {
paths["syscall/"] = true // include syscall/js
}

// to enable network support for linux systems, reuse the Go version of the net package
// and the according runtime functions
// if runtime.GOOS == "linux" {
// paths["runtime/netpoll/"] = true
// }
return paths
}

Expand Down
460 changes: 0 additions & 460 deletions src/crypto/tls/common.go

This file was deleted.

16 changes: 0 additions & 16 deletions src/crypto/tls/ticket.go

This file was deleted.

114 changes: 0 additions & 114 deletions src/crypto/tls/tls.go

This file was deleted.

1 change: 0 additions & 1 deletion src/net
Submodule net deleted from a23705
45 changes: 45 additions & 0 deletions src/runtime/netpoll.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package runtime

// For debugging purposes this is used for all target architectures, but this is only valid for linux systems.
// TODO: add linux specific build tags
type pollDesc struct {
runtimeCtx uintptr
}

func (pd *pollDesc) wait(mode int, isFile bool) error {
return nil
}

const (
pollNoError = 0 // no error
pollErrClosing = 1 // descriptor is closed
pollErrTimeout = 2 // I/O timeout
pollErrNotPollable = 3 // general error polling descriptor
)

//go:linkname poll_runtime_pollReset internal/poll.runtime_pollReset
func poll_runtime_pollReset(pd *pollDesc, mode int) int {
println("poll_runtime_pollReset not implemented", pd, mode)
return pollNoError
}

//go:linkname poll_runtime_pollWait internal/poll.runtime_pollWait
func poll_runtime_pollWait(pd *pollDesc, mode int) int {
println("poll_runtime_pollWait not implemented", pd, mode)
return pollNoError
}

//go:linkname poll_runtime_pollSetDeadline internal/poll.runtime_pollSetDeadline
func poll_runtime_pollSetDeadline(pd *pollDesc, d int64, mode int) {
println("poll_runtime_pollSetDeadline not implemented", pd, d, mode)
}

//go:linkname poll_runtime_pollOpen internal/poll.runtime_pollOpen
func poll_runtime_pollOpen(fd uintptr) (*pollDesc, int) {
println("poll_runtime_pollOpen not implemented", fd)
return &pollDesc{runtimeCtx: 0x13371337}, pollNoError
}
31 changes: 31 additions & 0 deletions src/runtime/netpoll_generic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
// Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

8000 //go:build (js && wasm) || wasip1 || windows

package runtime

// Network poller descriptor.
//
// No heap pointers.
// For linux to call create Fds with a pollDesc, it needs a ctxRuntime pointer, so use the original pollDesc struct.
// On linux we have a heap.
type pollDesc struct{}

//go:linkname poll_runtime_pollReset internal/poll.runtime_pollReset
func poll_runtime_pollReset(pd *pollDesc, mode int) int {
println("poll_runtime_pollReset not implemented", pd, mode)
return 1
}

//go:linkname poll_runtime_pollWait internal/poll.runtime_pollWait
func poll_runtime_pollWait(pd *pollDesc, mode int) int {
println("poll_runtime_pollWait not implemented", pd, mode)
return 1
}

//go:linkname poll_runtime_pollSetDeadline internal/poll.runtime_pollSetDeadline
func poll_runtime_pollSetDeadline(pd *pollDesc, d int64, mode int) {
println("poll_runtime_pollSetDeadline not implemented", pd, d, mode)
}
15 changes: 8 additions & 7 deletions src/runtime/poll.go
panic("todo: runtime_pollClose")
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,21 @@ package runtime

//go:linkname poll_runtime_pollServerInit internal/poll.runtime_pollServerInit
func poll_runtime_pollServerInit() {
panic("todo: runtime_pollServerInit")
// fmt.Printf("poll_runtime_pollServerInit not implemented, skipping panic\n")
Copy link
Member
@aykevl aykevl Nov 8, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you put in debugging code, please remove it before sending in a PR. It makes the diff bigger and more work to review.
Generally, take a look at the PR diff and see if there's any part of it that is not necessary and can be removed (such as the changes to .gitmodules and the signal changes that are still part of this PR).
(Also, how do you know that you can just remove this panic?)

}

//go:linkname poll_runtime_pollOpen internal/poll.runtime_pollOpen
func poll_runtime_pollOpen(fd uintptr) (uintptr, int) {
panic("todo: runtime_pollOpen")
}
// //go:linkname poll_runtime_pollOpen internal/poll.runtime_pollOpen
// func poll_runtime_pollOpen(fd uintptr) (uintptr, int) {
// // fmt.Printf("poll_runtime_pollOpen not implemented, skipping panic\n")
// return 0, 0
// }

//go:linkname poll_runtime_pollClose internal/poll.runtime_pollClose
func poll_runtime_pollClose(ctx uintptr) {
// fmt.Printf("poll_runtime_pollClose not implemented, skipping panic\n")
}

//go:linkname poll_runtime_pollUnblock internal/poll.runtime_pollUnblock
func poll_runtime_pollUnblock(ctx uintptr) {
panic("todo: runtime_pollUnblock")
// fmt.Printf("poll_runtime_pollUnblock not implemented, skipping panic\n")
}
8 changes: 6 additions & 2 deletions src/runtime/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@ package runtime

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

//go:linkname semrelease internal/poll.runtime_Semrelease
func semrelease(sema *uint32) {
panic("todo: semrelease")
// TODO the "net" pkg calls this, so panic() isn't an option. Right
// now, just ignore the call.
// panic("todo: semrelease")
}
38 changes: 38 additions & 0 deletions src/syscall/forklock_tinygo.go
A532
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//go:build tinygo

package syscall

// This is the original ForkLock:
//
// var ForkLock sync.RWMutex
//
// This requires importing sync, but importing sync causes an import loop:
//
// package tinygo.org/x/drivers/examples/net/tcpclient
// imports bytes
// imports io
// imports sync
// imports internal/task
// imports runtime/interrupt
// imports device/arm
// imports syscall
// imports sync: import cycle not allowed
//
// So for now, make our own stubbed-out ForkLock that doesn't use sync..

type forklock struct{}

func (f forklock) RLock() {}
func (f forklock) RUnlock() {}

var ForkLock forklock

func CloseOnExec(fd int) {
system.CloseOnExec(fd)
}

func SetNonblock(fd int, nonblocking bool) (err error) {
return system.SetNonblock(fd, nonblocking)
}

type SysProcAttr struct{}
0