Skip to content

Commit b90dbcb

Browse files
committed
build, compiler/typesutil: Don't use vendor directory to resolve js, nosync.
These core GopherJS packages are already embedded into the GopherJS build system via the gopherjspkg virtual filesystem. The gopherjspkg package can be safely vendored. Therefore, there's no need to try to use vendor directory to resolve those packages. This change makes it possible to use a vendored copy of GopherJS in a project, and use it to build any Go code. Fixes gopherjs#415.
1 parent c121b3d commit b90dbcb

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

build/build.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,17 +144,16 @@ func importWithSrcDir(bctx build.Context, path string, srcDir string, mode build
144144
case "crypto/x509", "os/user":
145145
// These stdlib packages have cgo and non-cgo versions (via build tags); we want the latter.
146146
bctx.CgoEnabled = false
147+
case "github.com/gopherjs/gopherjs/js", "github.com/gopherjs/gopherjs/nosync":
148+
// These packages are already embedded via gopherjspkg.FS virtual filesystem (which can be
149+
// safely vendored). Don't try to use vendor directory to resolve them.
150+
mode |= build.IgnoreVendor
147151
}
148152
pkg, err := bctx.Import(path, srcDir, mode)
149153
if err != nil {
150154
return nil, err
151155
}
152156

153-
// TODO: Resolve issue #415 and remove this temporary workaround.
154-
if strings.HasSuffix(pkg.ImportPath, "/vendor/github.com/gopherjs/gopherjs/js") {
155-
return nil, fmt.Errorf("vendoring github.com/gopherjs/gopherjs/js package is not supported, see https://github.com/gopherjs/gopherjs/issues/415")
156-
}
157-
158157
switch path {
159158
case "os":
160159
pkg.GoFiles = excludeExecutable(pkg.GoFiles) // Need to exclude executable implementation files, because some of them contain package scope variables that perform (indirectly) syscalls on init.

compiler/typesutil/typesutil.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,9 @@
11
package typesutil
22

3-
import (
4-
"go/types"
5-
"strings"
6-
)
3+
import "go/types"
74

85
func IsJsPackage(pkg *types.Package) bool {
9-
return pkg != nil && (pkg.Path() == "github.com/gopherjs/gopherjs/js" || strings.HasSuffix(pkg.Path(), "/vendor/github.com/gopherjs/gopherjs/js"))
6+
return pkg != nil && pkg.Path() == "github.com/gopherjs/gopherjs/js"
107
}
118

129
func IsJsObject(t types.Type) bool {

0 commit comments

Comments
 (0)