Skip to content
Open
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
25 changes: 23 additions & 2 deletions loader/goroot.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
"encoding/hex"
"encoding/json"
"errors"
"go/build"
"io"
"io/fs"
"os"
Expand Down Expand Up @@ -48,7 +49,7 @@ func GetCachedGoroot(config *compileopts.Config) (string, error) {
overrides := pathsToOverride(config.GoMinorVersion, needsSyscallPackage(config.BuildTags()))

// Resolve the merge links within the goroot.
merge, err := listGorootMergeLinks(goroot, tinygoroot, overrides)
merge, err := listGorootMergeLinks(goroot, tinygoroot, overrides, config)
if err != nil {
return "", err
}
Expand Down Expand Up @@ -143,10 +144,22 @@ func GetCachedGoroot(config *compileopts.Config) (string, error) {
}

// listGorootMergeLinks searches goroot and tinygoroot for all symlinks that must be created within the merged goroot.
func listGorootMergeLinks(goroot, tinygoroot string, overrides map[string]bool) (map[string]string, error) {
func listGorootMergeLinks(goroot, tinygoroot string, overrides map[string]bool, config *compileopts.Config) (map[string]string, error) {
goSrc := filepath.Join(goroot, "src")
tinygoSrc := filepath.Join(tinygoroot, "src")
merges := make(map[string]string)

// buildContext is used to evaluate //go:build constraints on TinyGo
// source files. A TinyGo file that doesn't match the current target
// (e.g. a *_wasip2.go file in a wasip1 build) must not be treated as
// "TinyGo owns this directory" — otherwise wasip1 builds would lose
// upstream Go files at the same level.
bctx := build.Default
bctx.GOOS = config.GOOS()
bctx.GOARCH = config.GOARCH()
bctx.BuildTags = config.BuildTags()
bctx.Compiler = "gc"
Comment on lines +152 to +161
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Why is this needed? (And why do normal build tags not work?)


for dir, merge := range overrides {
if !merge {
// Use the TinyGo version.
Expand All @@ -168,6 +181,14 @@ func listGorootMergeLinks(goroot, tinygoroot string, overrides map[string]bool)

// Link this file.
name := e.Name()
// Only count this file as a TinyGo override of the directory
// when its build tags match the current target. Files with a
// non-matching //go:build are invisible to this build anyway
// (the compiler would skip them), so they shouldn't cause
// upstream files to be dropped from the merge.
if matched, _ := bctx.MatchFile(tinygoDir, name); !matched {
continue
}
merges[filepath.Join("src", dir, name)] = filepath.Join(tinygoDir, name)

hasTinyGoFiles = true
Expand Down
24 changes: 24 additions & 0 deletions src/internal/poll/errors_wasip.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
//go:build wasip1 || wasip2

// Shared error sentinels for the wasip1 and wasip2 internal/poll
// implementations. The error values are part of the public API surface
// upstream net relies on; sharing them keeps fd_wasip1.go and
// fd_wasip2.go free of redundant declarations.

package poll

import "errors"

// ErrFileClosing is returned when a Read or Write is started on a closed FD.
var ErrFileClosing = errors.New("use of closed file")

// ErrNetClosing is returned for network operations on a closed FD.
var ErrNetClosing = errors.New("use of closed network connection")

// ErrDeadlineExceeded is returned by Read/Write when a deadline expired.
// Matches the error returned by os.IsTimeout-style helpers.
var ErrDeadlineExceeded = errors.New("i/o timeout")

// ErrNoDeadline is returned if SetDeadline is called on an FD whose
// underlying type does not support deadlines.
var ErrNoDeadline = errors.New("file type does not support deadline")
15 changes: 0 additions & 15 deletions src/internal/poll/fd_wasip1.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,12 @@
package poll

import (
"errors"
"internal/task"
"syscall"
"time"
"unsafe"
)

// ErrFileClosing is returned when a Read or Write is started on a closed FD.
var ErrFileClosing = errors.New("use of closed file")

// ErrNetClosing is returned for network operations on a closed FD.
var ErrNetClosing = errors.New("use of closed network connection")

// ErrDeadlineExceeded is returned by Read/Write when a deadline expired.
// Matches the error returned by os.IsTimeout-style helpers.
var ErrDeadlineExceeded = errors.New("i/o timeout")

// ErrNoDeadline is returned if SetDeadline is called on an FD whose
// underlying type does not support deadlines.
var ErrNoDeadline = errors.New("file type does not support deadline")

// pollMode constants must mirror runtime/netpoll_wasip1.go's pollRead/
// pollWrite values.
const (
Expand Down
Loading
Loading