forked from Code-Hex/vz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
shared_directory_arm64.go
109 lines (93 loc) · 3.4 KB
/
shared_directory_arm64.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
//go:build darwin && arm64
// +build darwin,arm64
package vz
/*
#cgo darwin CFLAGS: -mmacosx-version-min=11 -x objective-c -fno-objc-arc
#cgo darwin LDFLAGS: -lobjc -framework Foundation -framework Virtualization
# include "virtualization_13_arm64.h"
*/
import "C"
import (
"runtime/cgo"
"unsafe"
"github.com/Code-Hex/vz/v3/internal/objc"
)
// LinuxRosettaAvailability represents an availability of Rosetta support for Linux binaries.
//
//go:generate go run ./cmd/addtags -tags=darwin,arm64 -file linuxrosettaavailability_string_arm64.go stringer -type=LinuxRosettaAvailability -output=linuxrosettaavailability_string_arm64.go
type LinuxRosettaAvailability int
const (
// LinuxRosettaAvailabilityNotSupported Rosetta support for Linux binaries is not available on the host system.
LinuxRosettaAvailabilityNotSupported LinuxRosettaAvailability = iota
// LinuxRosettaAvailabilityNotInstalled Rosetta support for Linux binaries is not installed on the host system.
LinuxRosettaAvailabilityNotInstalled
// LinuxRosettaAvailabilityInstalled Rosetta support for Linux is installed on the host system.
LinuxRosettaAvailabilityInstalled
)
//export linuxInstallRosettaWithCompletionHandler
func linuxInstallRosettaWithCompletionHandler(cgoHandleUintptr C.uintptr_t, errPtr unsafe.Pointer) {
cgoHandle := cgo.Handle(cgoHandleUintptr)
handler := cgoHandle.Value().(func(error))
if err := newNSError(errPtr); err != nil {
handler(err)
} else {
handler(nil)
}
}
// LinuxRosettaDirectoryShare directory share to enable Rosetta support for Linux binaries.
// see: https://developer.apple.com/documentation/virtualization/vzlinuxrosettadirectoryshare?language=objc
type LinuxRosettaDirectoryShare struct {
*pointer
*baseDirectoryShare
}
var _ DirectoryShare = (*LinuxRosettaDirectoryShare)(nil)
// NewLinuxRosettaDirectoryShare creates a new Rosetta directory share if Rosetta support
// for Linux binaries is installed.
//
// This is only supported on macOS 13 and newer, error will
// be returned on older versions.
func NewLinuxRosettaDirectoryShare() (*LinuxRosettaDirectoryShare, error) {
if err := macOSAvailable(13); err != nil {
return nil, err
}
nserrPtr := newNSErrorAsNil()
ds := &LinuxRosettaDirectoryShare{
pointer: objc.NewPointer(
C.newVZLinuxRosettaDirectoryShare(&nserrPtr),
),
}
if err := newNSError(nserrPtr); err != nil {
return nil, err
}
objc.SetFinalizer(ds, func(self *LinuxRosettaDirectoryShare) {
objc.Release(self)
})
return ds, nil
}
// LinuxRosettaDirectoryShareInstallRosetta download and install Rosetta support
// for Linux binaries if necessary.
//
// This is only supported on macOS 13 and newer, error will
// be returned on older versions.
func LinuxRosettaDirectoryShareInstallRosetta() error {
if err := macOSAvailable(13); err != nil {
return err
}
errCh := make(chan error, 1)
cgoHandle := cgo.NewHandle(func(err error) {
errCh <- err
})
C.linuxInstallRosetta(C.uintptr_t(cgoHandle))
return <-errCh
}
// LinuxRosettaDirectoryShareAvailability checks the availability of Rosetta support
// for the directory share.
//
// This is only supported on macOS 13 and newer, LinuxRosettaAvailabilityNotSupported will
// be returned on older versions.
func LinuxRosettaDirectoryShareAvailability() LinuxRosettaAvailability {
if err := macOSAvailable(13); err != nil {
return LinuxRosettaAvailabilityNotSupported
}
return LinuxRosettaAvailability(C.availabilityVZLinuxRosettaDirectoryShare())
}