| 
									
										
										
										
											2023-03-25 08:48:03 -07:00
										 |  |  | #!/usr/bin/env bash | 
					
						
							|  |  |  | # Copyright 2023 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. | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-17 22:13:52 -07:00
										 |  |  | case "$GOWASIRUNTIME" in | 
					
						
							| 
									
										
										
										
											2023-05-09 20:32:19 -07:00
										 |  |  | 	"wasmedge") | 
					
						
							| 
									
										
										
										
											2023-05-26 09:58:43 -07:00
										 |  |  | 		exec wasmedge --dir=/ --env PWD="$PWD" --env PATH="$PATH" ${GOWASIRUNTIMEARGS:-} "$1" "${@:2}" | 
					
						
							| 
									
										
										
										
											2023-05-09 20:32:19 -07:00
										 |  |  | 		;; | 
					
						
							| 
									
										
										
										
											2023-05-08 22:21:19 -07:00
										 |  |  | 	"wasmer") | 
					
						
							| 
									
										
										
										
											2023-05-26 09:58:43 -07:00
										 |  |  | 		exec wasmer run --dir=/ --env PWD="$PWD" --env PATH="$PATH" ${GOWASIRUNTIMEARGS:-} "$1" -- "${@:2}" | 
					
						
							| 
									
										
										
										
											2023-05-08 22:21:19 -07:00
										 |  |  | 		;; | 
					
						
							| 
									
										
										
										
											2023-07-25 15:54:16 -07:00
										 |  |  | 	"wazero") | 
					
						
							| 
									
										
											  
											
												net: implement wasip1 FileListener and FileConn
Implements net.FileListener and net.FileConn for wasip1.
net.FileListener can be used with a pre-opened socket. If the WASM
module knows the file descriptor, a listener can be constructed with:
    l, err := net.FileListener(os.NewFile(fd, ""))
If the WASM module does not know the file descriptor, but knows that at
least one of the preopens is a socket, it can find the file descriptor
and construct a listener like so:
    func findListener() (net.Listener, error) {
        // We start looking for pre-opened sockets at fd=3 because 0, 1,
        // and 2 are reserved for stdio. Pre-opened directories also
        // start at fd=3, so we skip fds that aren't sockets. Once we
        // reach EBADF we know there are no more pre-opens.
        for preopenFd := uintptr(3); ; preopenFd++ {
            l, err := net.FileListener(os.NewFile(preopenFd, ""))
            var se syscall.Errno
            switch errors.As(err, &se); se {
            case syscall.ENOTSOCK:
                continue
            case syscall.EBADF:
                err = nil
            }
            return l, err
        }
    }
A similar strategy can be used with net.FileConn and pre-opened
connection sockets.
The wasmtime runtime supports pre-opening listener sockets:
    $ wasmtime --tcplisten 127.0.0.1:8080 module.wasm
Change-Id: Iec6ae4ffa84b3753cce4f56a2817e150445db643
Reviewed-on: https://go-review.googlesource.com/c/go/+/493358
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Dmitri Shuralyov <dmitshur@golang.org>
TryBot-Bypass: Dmitri Shuralyov <dmitshur@google.com>
Reviewed-by: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Auto-Submit: Johan Brandhorst-Satzkorn <johan.brandhorst@gmail.com>
Reviewed-by: Dmitri Shuralyov <dmitshur@google.com>
											
										 
											2023-05-08 17:08:20 +10:00
										 |  |  | 		exec wazero run -mount /:/ -env-inherit -cachedir "${TMPDIR:-/tmp}"/wazero ${GOWASIRUNTIMEARGS:-} "$1" "${@:2}" | 
					
						
							| 
									
										
										
										
											2023-04-17 22:13:52 -07:00
										 |  |  | 		;; | 
					
						
							| 
									
										
										
										
											2023-07-25 15:54:16 -07:00
										 |  |  | 	"wasmtime" | "") | 
					
						
							| 
									
										
										
										
											2025-06-23 16:36:25 -07:00
										 |  |  | 		exec wasmtime run --dir=/ --env PWD="$PWD" --env PATH="$PATH" -W max-wasm-stack=8388608 ${GOWASIRUNTIMEARGS:-} "$1" "${@:2}" | 
					
						
							| 
									
										
										
										
											2023-07-25 15:54:16 -07:00
										 |  |  | 		;; | 
					
						
							| 
									
										
										
										
											2023-04-17 22:13:52 -07:00
										 |  |  | 	*) | 
					
						
							|  |  |  | 		echo "Unknown Go WASI runtime specified: $GOWASIRUNTIME" | 
					
						
							|  |  |  | 		exit 1 | 
					
						
							|  |  |  | 		;; | 
					
						
							|  |  |  | esac |