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

wasip1/wasm #2

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
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
1 change: 0 additions & 1 deletion src/cmd/dist/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -1731,7 +1731,6 @@ var cgoEnabled = map[string]bool{
// See go.dev/issue/56679.
var broken = map[string]bool{
"linux/sparc64": true, // An incomplete port. See CL 132155.
"wasip1/wasm": true, // An incomplete port. See CL 479627.
"openbsd/ppc64": true, // An incomplete port: go.dev/issue/56001.
"openbsd/mips64": true, // Broken: go.dev/issue/58110.
}
Expand Down
3 changes: 2 additions & 1 deletion src/crypto/rand/rand.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ import "io"
// On OpenBSD and macOS, Reader uses getentropy(2).
// On other Unix-like systems, Reader reads from /dev/urandom.
// On Windows systems, Reader uses the RtlGenRandom API.
// On Wasm, Reader uses the Web Crypto API.
// On JS/Wasm, Reader uses the Web Crypto API.
// On WASIP1/Wasm, Reader uses random_get from wasi_snapshot_preview1.
var Reader io.Reader

// Read is a helper function that calls Reader.Read using io.ReadFull.
Expand Down
27 changes: 27 additions & 0 deletions src/crypto/rand/rand_wasip1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// 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.

//go:build wasip1

package rand

import "syscall"

func init() {
Reader = &reader{}
}

type reader struct{}

func (r *reader) Read(b []byte) (int, error) {
// This uses the wasi_snapshot_preview1 random_get syscall defined in
// https://github.com/WebAssembly/WASI/blob/23a52736049f4327dd335434851d5dc40ab7cad1/legacy/preview1/docs.md#-random_getbuf-pointeru8-buf_len-size---result-errno.
// The definition does not explicitly guarantee that the entire buffer will
// be filled, but this appears to be the case in all runtimes tested.
err := syscall.RandomGet(b)
if err != nil {
return 0, err
}
return len(b), nil
}
2 changes: 1 addition & 1 deletion src/crypto/x509/root_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build aix || dragonfly || freebsd || (js && wasm) || linux || netbsd || openbsd || solaris
//go:build aix || dragonfly || freebsd || (js && wasm) || linux || netbsd || openbsd || solaris || wasip1

package x509

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build js && wasm
//go:build wasm

package x509

Expand Down
2 changes: 1 addition & 1 deletion src/debug/elf/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -900,7 +900,7 @@ func TestCompressedSection(t *testing.T) {
func TestNoSectionOverlaps(t *testing.T) {
// Ensure cmd/link outputs sections without overlaps.
switch runtime.GOOS {
case "aix", "android", "darwin", "ios", "js", "plan9", "windows":
case "aix", "android", "darwin", "ios", "js", "plan9", "windows", "wasip1":
t.Skipf("cmd/link doesn't produce ELF binaries on %s", runtime.GOOS)
}
_ = net.ResolveIPAddr // force dynamic linkage
Expand Down
2 changes: 1 addition & 1 deletion src/go/types/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// Only run where builders (build.golang.org) have
// access to compiled packages for import.
//
//go:build !android && !ios && !js
//go:build !android && !ios && !js && !wasip1

package types_test

Expand Down
4 changes: 4 additions & 0 deletions src/io/ioutil/ioutil_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
. "io/ioutil"
"os"
"path/filepath"
"runtime"
"testing"
)

Expand Down Expand Up @@ -70,6 +71,9 @@ func TestReadOnlyWriteFile(t *testing.T) {
if os.Getuid() == 0 {
t.Skipf("Root can write to read-only files anyway, so skip the read-only test.")
}
if runtime.GOOS == "wasip1" {
t.Skip("file permissions are not supported by wasip1")
}

// We don't want to use TempFile directly, since that opens a file for us as 0600.
tempDir, err := TempDir("", t.Name())
Expand Down
2 changes: 1 addition & 1 deletion src/log/syslog/syslog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !windows && !plan9 && !js
//go:build !windows && !plan9 && !js && !wasip1

package syslog

Expand Down
2 changes: 1 addition & 1 deletion src/mime/type_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build unix || (js && wasm)
//go:build unix || (js && wasm) || wasip1

package mime

Expand Down
2 changes: 1 addition & 1 deletion src/net/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js
//go:build !js && !wasip1

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/conn_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
// This file implements API tests across platforms and will never have a build
// tag.

//go:build !js
//go:build !js && !wasip1

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/dial_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js
//go:build !js && !wasip1

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/dnsclient_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js
//go:build !js && !wasip1

// DNS client: see RFC 1035.
// Has to be linked into package net for Dial.
Expand Down
2 changes: 1 addition & 1 deletion src/net/dnsconfig_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js && !windows
//go:build !js && !wasip1 && !windows

// Read system DNS config from /etc/resolv.conf

Expand Down
2 changes: 1 addition & 1 deletion src/net/dnsname_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js
//go:build !js && !wasip1

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/error_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

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

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/error_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js
//go:build !js && !wasip1

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/error_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build unix || js
//go:build unix || js || wasip1

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/external_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js
//go:build !js && !wasip1

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/file_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

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

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js
//go:build !js && !wasip1

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/hook_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build unix || (js && wasm)
//go:build unix || (js && wasm) || wasip1

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/http/roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js || !wasm
//go:build !js

package http

Expand Down
3 changes: 1 addition & 2 deletions src/net/http/transport_default_other.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !(js && wasm)
// +build !js !wasm
//go:build !wasm

package http

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build js && wasm
// +build js,wasm
//go:build (js && wasm) || wasip1

package http

Expand Down
2 changes: 1 addition & 1 deletion src/net/interface_stub.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

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

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/interface_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js
//go:build !js && !wasip1

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/internal/socktest/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js && !plan9
//go:build !js && !plan9 && !wasip1

package socktest_test

Expand Down
2 changes: 1 addition & 1 deletion src/net/internal/socktest/main_unix_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js && !plan9 && !windows
//go:build !js && !plan9 && !wasip1 && !windows

package socktest_test

Expand Down
2 changes: 1 addition & 1 deletion src/net/internal/socktest/switch_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build unix || (js && wasm)
//go:build unix || (js && wasm) || wasip1

package socktest

Expand Down
2 changes: 1 addition & 1 deletion src/net/internal/socktest/sys_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build unix || (js && wasm)
//go:build unix || (js && wasm) || wasip1

package socktest

Expand Down
2 changes: 1 addition & 1 deletion src/net/ip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js
//go:build !js && !wasip1

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/iprawsock_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

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

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/iprawsock_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js
//go:build !js && !wasip1

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/ipsock_posix.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

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

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/listen_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js && !plan9
//go:build !js && !plan9 && !wasip1

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/lookup_fake.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

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

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/lookup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js
//go:build !js && !wasip1

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/main_conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build !js && !plan9
//go:build !js && !plan9 && !wasip1

package net

Expand Down
2 changes: 1 addition & 1 deletion src/net/main_noconf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build (js && wasm) || plan9
//go:build (js && wasm) || plan9 || wasip1

package net

Expand Down
Loading