Skip to content

Commit 3d75652

Browse files
authored
Merge pull request #1024 from nevkontakte/master
Improve Mac OS (darwin) support.
2 parents a4630ec + ebf9edb commit 3d75652

File tree

3 files changed

+30
-8
lines changed

3 files changed

+30
-8
lines changed

build/build.go

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,11 @@ func importWithSrcDir(bctx build.Context, path string, srcDir string, mode build
175175
switch path {
176176
case "os":
177177
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.
178-
// Prefer dirent_js.go version, since it targets a similar environment to
179-
// ours. Arguably this file should be excluded by the build tags (see
180-
// https://github.com/gopherjs/gopherjs/issues/693).
181-
pkg.GoFiles = exclude(pkg.GoFiles, "dirent_linux.go")
178+
// Prefer the dirent_${GOOS}.go version, to make the build pass on both linux
179+
// and darwin.
180+
// In the long term, our builds should produce the same output regardless
181+
// of the host OS: https://github.com/gopherjs/gopherjs/issues/693.
182+
pkg.GoFiles = exclude(pkg.GoFiles, "dirent_js.go")
182183
case "runtime":
183184
pkg.GoFiles = []string{} // Package sources are completely replaced in natives.
184185
case "runtime/internal/sys":
@@ -194,6 +195,16 @@ func importWithSrcDir(bctx build.Context, path string, srcDir string, mode build
194195
case "crypto/rand":
195196
pkg.GoFiles = []string{"rand.go", "util.go"}
196197
pkg.TestGoFiles = exclude(pkg.TestGoFiles, "rand_linux_test.go") // Don't want linux-specific tests (since linux-specific package files are excluded too).
198+
case "crypto/x509":
199+
// GopherJS doesn't support loading OS root certificates regardless of the
200+
// OS. The substitution below allows to avoid build dependency on Mac OS
201+
// implementation, which won't be used anyway.
202+
//
203+
// Just like above, https://github.com/gopherjs/gopherjs/issues/693 is
204+
// probably the best long-term option.
205+
pkg.GoFiles = include(
206+
exclude(pkg.GoFiles, fmt.Sprintf("root_%s.go", bctx.GOOS)),
207+
"root_unix.go", "root_js.go")
197208
}
198209

199210
if len(pkg.CgoFiles) > 0 {
@@ -249,6 +260,12 @@ Outer:
249260
return s
250261
}
251262

263+
func include(files []string, includes ...string) []string {
264+
files = exclude(files, includes...) // Ensure there won't be duplicates.
265+
files = append(files, includes...)
266+
return files
267+
}
268+
252269
// ImportDir is like Import but processes the Go package found in the named
253270
// directory.
254271
func ImportDir(dir string, mode build.ImportMode, installSuffix string, buildTags []string) (*PackageData, error) {

compiler/linkname.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,15 @@ func parseGoLinknames(fset *token.FileSet, pkgPath string, file *ast.File) ([]Go
101101

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

compiler/natives/src/syscall/syscall_darwin.go

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,6 @@ func funcPC(f func()) uintptr {
2020
return SYS_CHDIR
2121
case js.InternalObject(libc_rmdir_trampoline):
2222
return SYS_RMDIR
23-
case js.InternalObject(libc___getdirentries64_trampoline):
24-
return SYS_GETDIRENTRIES64
25-
case js.InternalObject(libc_getattrlist_trampoline):
26-
return SYS_GETATTRLIST
2723
case js.InternalObject(libc_symlink_trampoline):
2824
return SYS_SYMLINK
2925
case js.InternalObject(libc_readlink_trampoline):

0 commit comments

Comments
 (0)