Skip to content

Standardize on a single GOOS/GOARCH and deprecate node-syscall module. #1111

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

Merged
merged 23 commits into from
Apr 20, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
6e7e549
Support building `syscall` and `syscall/js` as `js/wasm`.
nevkontakte Oct 2, 2021
60f28c2
Fix `os` package test failures when built as `js/wasm`.
nevkontakte Oct 2, 2021
d6aec8e
Make sure GopherJS tests work correctly under when build as `js/wasm`.
nevkontakte Oct 3, 2021
7f838ba
Support `net` package when building for the target `js/wasm`.
nevkontakte Oct 17, 2021
1142005
Support `net/http` package when building for `js/wasm` target.
nevkontakte Oct 23, 2021
0ad407b
Only exclude std packages from CI if they are actually failing any te…
nevkontakte Nov 11, 2021
4170cbb
Drop GopherJS Fetch API-based http client implementation.
nevkontakte Feb 26, 2022
cdf693a
Convert prelude browser fs API stub into ES5 and reduce its size.
nevkontakte Mar 7, 2022
41de9e3
Use GOOS=js and GOARCH=ecmascript to build user code by default.
nevkontakte Mar 13, 2022
49f2893
Disable CGo when loading packages.
nevkontakte Mar 19, 2022
b94c4eb
Respect --tags flag in `gopherjs run` subcommand.
nevkontakte Mar 19, 2022
7d56422
Hide legacy `node-syscall` support behind a build tag.
nevkontakte Mar 20, 2022
305cb64
Remove unnecessary package tweaks for `crypto/rand`.
nevkontakte Mar 20, 2022
de83fe4
Remove unnecessary overlays and package tweaks for `internal/poll`.
nevkontakte Mar 20, 2022
f7681d2
Remove unnecessary standard library overlays.
nevkontakte Mar 20, 2022
59958da
Refactor TestNativesDontImportExtraPackages.
nevkontakte Mar 20, 2022
9813bf2
Remove GOROOT and GOPATH fields from `build.Options`.
nevkontakte Mar 20, 2022
9511320
Set `runtime.GOOS` and `GOARCH` to values chosen for GopherJS.
nevkontakte Mar 20, 2022
50f5dca
Fix compiler panics when building on Windows.
nevkontakte Mar 20, 2022
208100a
Catch and ignore the error if `fs` module can't be required.
nevkontakte Mar 27, 2022
3dfe12d
Set up a simple smoke test job on Windows and Mac OS.
nevkontakte Mar 27, 2022
adcfc77
Apply suggestions from code review
nevkontakte Apr 19, 2022
fe1dd62
Update VFS and minified prelude.
nevkontakte Apr 19, 2022
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
27 changes: 0 additions & 27 deletions .std_test_pkg_exclusions
Original file line number Diff line number Diff line change
@@ -1,48 +1,21 @@
crypto/tls
debug/gosym
embed/internal/embedtest
go/build
go/importer
go/internal/gccgoimporter
go/internal/gcimporter
go/internal/srcimporter
go/types
internal/abi
internal/syscall/unix
internal/syscall/windows
internal/syscall/windows/registry
internal/syscall/windows/sysdll
internal/testenv
internal/testlog
internal/trace
internal/x/net/nettest
log/syslog
net
net/http
net/http/cgi
net/http/httptest
net/http/httptrace
net/http/httputil
net/http/internal
net/http/pprof
net/internal/socktest
net/rpc
net/smtp
os
os/exec
os/signal
os/signal/internal/pty
plugin
runtime
runtime/cgo
runtime/debug
runtime/internal/atomic
runtime/internal/math
runtime/internal/sys
runtime/pprof
runtime/pprof/internal/profile
runtime/race
runtime/trace
syscall
testing/internal/testdeps
unsafe
80 changes: 34 additions & 46 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,12 @@ import (
"github.com/gopherjs/gopherjs/compiler"
"github.com/gopherjs/gopherjs/compiler/astutil"
"github.com/gopherjs/gopherjs/compiler/gopherjspkg"
"github.com/gopherjs/gopherjs/compiler/natives"

"github.com/neelance/sourcemap"
"github.com/shurcooL/httpfs/vfsutil"
"golang.org/x/tools/go/buildutil"

"github.com/gopherjs/gopherjs/build/cache"
_ "github.com/gopherjs/gopherjs/build/versionhack" // go/build release tags hack.
)

// DefaultGOROOT is the default GOROOT value for builds.
Expand All @@ -48,27 +47,20 @@ var DefaultGOROOT = func() string {
return build.Default.GOROOT
}()

// ImportCError is returned when GopherJS attempts to build a package that uses
// CGo.
type ImportCError struct {
pkgPath string
}

func (e *ImportCError) Error() string {
return e.pkgPath + `: importing "C" is not supported by GopherJS`
}

// NewBuildContext creates a build context for building Go packages
// with GopherJS compiler.
//
// Core GopherJS packages (i.e., "github.com/gopherjs/gopherjs/js", "github.com/gopherjs/gopherjs/nosync")
// are loaded from gopherjspkg.FS virtual filesystem if not present in GOPATH or
// go.mod.
func NewBuildContext(installSuffix string, buildTags []string) XContext {
gopherjsRoot := filepath.Join(DefaultGOROOT, "src", "github.com", "gopherjs", "gopherjs")
e := DefaultEnv()
e.InstallSuffix = installSuffix
e.BuildTags = buildTags
realGOROOT := goCtx(e)
return &chainedCtx{
primary: goCtx(installSuffix, buildTags),
secondary: embeddedCtx(&withPrefix{gopherjspkg.FS, gopherjsRoot}, installSuffix, buildTags),
primary: realGOROOT,
secondary: gopherjsCtx(e),
}
}

Expand Down Expand Up @@ -103,7 +95,7 @@ func statFile(path string) (os.FileInfo, error) {
func Import(path string, mode build.ImportMode, installSuffix string, buildTags []string) (*PackageData, error) {
wd, err := os.Getwd()
if err != nil {
// Getwd may fail if we're in GOARCH=js mode. That's okay, handle
// Getwd may fail if we're in GOOS=js mode. That's okay, handle
// it by falling back to empty working directory. It just means
// Import will not be able to resolve relative import paths.
wd = ""
Expand Down Expand Up @@ -180,15 +172,7 @@ func parseAndAugment(xctx XContext, pkg *PackageData, isTest bool, fileSet *toke
importPath = importPath[:len(importPath)-5]
}

nativesContext := embeddedCtx(&withPrefix{fs: natives.FS, prefix: DefaultGOROOT}, "", nil)

if importPath == "syscall" {
// Special handling for the syscall package, which uses OS native
// GOOS/GOARCH pair. This will no longer be necessary after
// https://github.com/gopherjs/gopherjs/issues/693.
nativesContext.bctx.GOARCH = build.Default.GOARCH
nativesContext.bctx.BuildTags = append(nativesContext.bctx.BuildTags, "js")
}
nativesContext := overlayCtx(xctx.Env())

if nativesPkg, err := nativesContext.Import(importPath, "", 0); err == nil {
names := nativesPkg.GoFiles
Expand Down Expand Up @@ -321,8 +305,6 @@ func parseAndAugment(xctx XContext, pkg *PackageData, isTest bool, fileSet *toke

// Options controls build process behavior.
type Options struct {
GOROOT string
GOPATH string
Verbose bool
Quiet bool
Watch bool
Expand Down Expand Up @@ -366,6 +348,10 @@ type PackageData struct {
bctx *build.Context // The original build context this package came from.
}

func (p PackageData) String() string {
return fmt.Sprintf("%s [is_test=%v]", p.ImportPath, p.IsTest)
}

// InternalBuildContext returns the build context that produced the package.
//
// WARNING: This function is a part of internal API and will be removed in
Expand Down Expand Up @@ -439,30 +425,26 @@ type Session struct {

// NewSession creates a new GopherJS build session.
func NewSession(options *Options) (*Session, error) {
if options.GOROOT == "" {
options.GOROOT = DefaultGOROOT
}
if options.GOPATH == "" {
options.GOPATH = build.Default.GOPATH
}
options.Verbose = options.Verbose || options.Watch

// Go distribution version check.
if err := compiler.CheckGoVersion(options.GOROOT); err != nil {
return nil, err
}

s := &Session{
options: options,
UpToDateArchives: make(map[string]*compiler.Archive),
}
s.xctx = NewBuildContext(s.InstallSuffix(), s.options.BuildTags)
env := s.xctx.Env()

// Go distribution version check.
if err := compiler.CheckGoVersion(env.GOROOT); err != nil {
return nil, err
}

s.buildCache = cache.BuildCache{
GOOS: s.xctx.GOOS(),
GOARCH: "js",
GOROOT: options.GOROOT,
GOPATH: options.GOPATH,
BuildTags: options.BuildTags,
GOOS: env.GOOS,
GOARCH: env.GOARCH,
GOROOT: env.GOROOT,
GOPATH: env.GOPATH,
BuildTags: append([]string{}, env.BuildTags...),
Minify: options.Minify,
TestedPackage: options.TestedPackage,
}
Expand Down Expand Up @@ -496,7 +478,7 @@ func (s *Session) InstallSuffix() string {

// GoRelease returns Go release version this session is building with.
func (s *Session) GoRelease() string {
return compiler.GoRelease(s.options.GOROOT)
return compiler.GoRelease(s.xctx.Env().GOROOT)
}

// BuildFiles passed to the GopherJS tool as if they were a package.
Expand All @@ -513,7 +495,7 @@ func (s *Session) BuildFiles(filenames []string, pkgObj string, packagePath stri
// This ephemeral package doesn't have a unique import path to be used as a
// build cache key, so we never cache it.
SrcModTime: time.Now().Add(time.Hour),
bctx: &goCtx(s.InstallSuffix(), s.options.BuildTags).bctx,
bctx: &goCtx(s.xctx.Env()).bctx,
}

for _, file := range filenames {
Expand Down Expand Up @@ -667,6 +649,12 @@ func (s *Session) ImportResolverFor(pkg *PackageData) func(string) (*compiler.Ar
}
}

// SourceMappingCallback returns a call back for compiler.SourceMapFilter
// configured for the current build session.
func (s *Session) SourceMappingCallback(m *sourcemap.Map) func(generatedLine, generatedColumn int, originalPos token.Position) {
return NewMappingCallback(m, s.xctx.Env().GOROOT, s.xctx.Env().GOPATH, s.options.MapToLocalDisk)
}

// WriteCommandPackage writes the final JavaScript output file at pkgObj path.
func (s *Session) WriteCommandPackage(archive *compiler.Archive, pkgObj string) error {
if err := os.MkdirAll(filepath.Dir(pkgObj), 0777); err != nil {
Expand All @@ -692,7 +680,7 @@ func (s *Session) WriteCommandPackage(archive *compiler.Archive, pkgObj string)
fmt.Fprintf(codeFile, "//# sourceMappingURL=%s.map\n", filepath.Base(pkgObj))
}()

sourceMapFilter.MappingCallback = NewMappingCallback(m, s.options.GOROOT, s.options.GOPATH, s.options.MapToLocalDisk)
sourceMapFilter.MappingCallback = s.SourceMappingCallback(m)
}

deps, err := compiler.ImportDependencies(archive, func(path string) (*compiler.Archive, error) {
Expand Down
Loading