Skip to content

Improve Mac OS (darwin) support. #1024

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 1 commit into from
May 3, 2021
Merged
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: 21 additions & 4 deletions build/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,11 @@ func importWithSrcDir(bctx build.Context, path string, srcDir string, mode build
switch path {
case "os":
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.
// Prefer dirent_js.go version, since it targets a similar environment to
// ours. Arguably this file should be excluded by the build tags (see
// https://github.com/gopherjs/gopherjs/issues/693).
pkg.GoFiles = exclude(pkg.GoFiles, "dirent_linux.go")
// Prefer the dirent_${GOOS}.go version, to make the build pass on both linux
// and darwin.
// In the long term, our builds should produce the same output regardless
// of the host OS: https://github.com/gopherjs/gopherjs/issues/693.
pkg.GoFiles = exclude(pkg.GoFiles, "dirent_js.go")
case "runtime":
pkg.GoFiles = []string{} // Package sources are completely replaced in natives.
case "runtime/internal/sys":
Expand All @@ -194,6 +195,16 @@ func importWithSrcDir(bctx build.Context, path string, srcDir string, mode build
case "crypto/rand":
pkg.GoFiles = []string{"rand.go", "util.go"}
pkg.TestGoFiles = exclude(pkg.TestGoFiles, "rand_linux_test.go") // Don't want linux-specific tests (since linux-specific package files are excluded too).
case "crypto/x509":
// GopherJS doesn't support loading OS root certificates regardless of the
// OS. The substitution below allows to avoid build dependency on Mac OS
// implementation, which won't be used anyway.
//
// Just like above, https://github.com/gopherjs/gopherjs/issues/693 is
// probably the best long-term option.
pkg.GoFiles = include(
exclude(pkg.GoFiles, fmt.Sprintf("root_%s.go", bctx.GOOS)),
"root_unix.go", "root_js.go")
}

if len(pkg.CgoFiles) > 0 {
Expand Down Expand Up @@ -249,6 +260,12 @@ Outer:
return s
}

func include(files []string, includes ...string) []string {
files = exclude(files, includes...) // Ensure there won't be duplicates.
files = append(files, includes...)
return files
}

// ImportDir is like Import but processes the Go package found in the named
// directory.
func ImportDir(dir string, mode build.ImportMode, installSuffix string, buildTags []string) (*PackageData, error) {
Expand Down
9 changes: 9 additions & 0 deletions compiler/linkname.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,15 @@ func parseGoLinknames(fset *token.FileSet, pkgPath string, file *ast.File) ([]Go

obj := file.Scope.Lookup(localName)
if obj == nil {
if pkgPath == "syscall" {
// Syscall uses go:cgo_import_dynamic pragma to import symbols from
// dynamic libraries when build with GOOS=darwin, which GopherJS doesn't
// support. Silently ignore such directives.
//
// In the long term https://github.com/gopherjs/gopherjs/issues/693 is a
// preferred solution.
return nil
}
return fmt.Errorf("//go:linkname local symbol %q is not found in the current source file", localName)
}

Expand Down
4 changes: 0 additions & 4 deletions compiler/natives/src/syscall/syscall_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ func funcPC(f func()) uintptr {
return SYS_CHDIR
case js.InternalObject(libc_rmdir_trampoline):
return SYS_RMDIR
case js.InternalObject(libc___getdirentries64_trampoline):
return SYS_GETDIRENTRIES64
case js.InternalObject(libc_getattrlist_trampoline):
return SYS_GETATTRLIST
case js.InternalObject(libc_symlink_trampoline):
return SYS_SYMLINK
case js.InternalObject(libc_readlink_trampoline):
Expand Down