@@ -7,9 +7,12 @@ package vz
7
7
#cgo darwin CFLAGS: -mmacosx-version-min=11 -x objective-c -fno-objc-arc
8
8
#cgo darwin LDFLAGS: -lobjc -framework Foundation -framework Virtualization
9
9
# include "virtualization_13_arm64.h"
10
+ # include "virtualization_14_arm64.h"
10
11
*/
11
12
import "C"
12
13
import (
14
+ "fmt"
15
+ "os"
13
16
"runtime/cgo"
14
17
"unsafe"
15
18
@@ -79,6 +82,16 @@ func NewLinuxRosettaDirectoryShare() (*LinuxRosettaDirectoryShare, error) {
79
82
return ds , nil
80
83
}
81
84
85
+ // SetOptions enables translation caching and configure the socket communication type for Rosetta.
86
+ //
87
+ // This is only supported on macOS 14 and newer. Older versions do nothing.
88
+ func (ds * LinuxRosettaDirectoryShare ) SetOptions (options LinuxRosettaCachingOptions ) {
89
+ if err := macOSAvailable (14 ); err != nil {
90
+ return
91
+ }
92
+ C .setOptionsVZLinuxRosettaDirectoryShare (objc .Ptr (ds ), objc .Ptr (options ))
93
+ }
94
+
82
95
// LinuxRosettaDirectoryShareInstallRosetta download and install Rosetta support
83
96
// for Linux binaries if necessary.
84
97
//
@@ -107,3 +120,115 @@ func LinuxRosettaDirectoryShareAvailability() LinuxRosettaAvailability {
107
120
}
108
121
return LinuxRosettaAvailability (C .availabilityVZLinuxRosettaDirectoryShare ())
109
122
}
123
+
124
+ // LinuxRosettaCachingOptions for a directory sharing device configuration.
125
+ type LinuxRosettaCachingOptions interface {
126
+ objc.NSObject
127
+
128
+ linuxRosettaCachingOptions ()
129
+ }
130
+
131
+ type baseLinuxRosettaCachingOptions struct {}
132
+
133
+ func (* baseLinuxRosettaCachingOptions ) linuxRosettaCachingOptions () {}
134
+
135
+ // LinuxRosettaUnixSocketCachingOptions is an struct that represents caching options
136
+ // for a UNIX domain socket.
137
+ //
138
+ // This struct configures Rosetta to communicate with the Rosetta daemon using a UNIX domain socket.
139
+ type LinuxRosettaUnixSocketCachingOptions struct {
140
+ * pointer
141
+
142
+ * baseLinuxRosettaCachingOptions
143
+ }
144
+
145
+ var _ LinuxRosettaCachingOptions = (* LinuxRosettaUnixSocketCachingOptions )(nil )
146
+
147
+ // NewLinuxRosettaUnixSocketCachingOptions creates a new Rosetta caching options object for
148
+ // a UNIX domain socket with the path you specify.
149
+ //
150
+ // The path of the Unix Domain Socket to be used to communicate with the Rosetta translation daemon.
151
+ //
152
+ // This is only supported on macOS 14 and newer, error will
153
+ // be returned on older versions.
154
+ func NewLinuxRosettaUnixSocketCachingOptions (path string ) (* LinuxRosettaUnixSocketCachingOptions , error ) {
155
+ if err := macOSAvailable (14 ); err != nil {
156
+ return nil , err
157
+ }
158
+ maxPathLen := maximumPathLengthLinuxRosettaUnixSocketCachingOptions ()
159
+ if maxPathLen < len (path ) {
160
+ return nil , fmt .Errorf ("path length exceeds maximum allowed length of %d" , maxPathLen )
161
+ }
162
+ if _ , err := os .Stat (path ); err != nil {
163
+ return nil , fmt .Errorf ("invalid path: %w" , err )
164
+ }
165
+
166
+ cs := charWithGoString (path )
167
+ defer cs .Free ()
168
+
169
+ nserrPtr := newNSErrorAsNil ()
170
+ usco := & LinuxRosettaUnixSocketCachingOptions {
171
+ pointer : objc .NewPointer (
172
+ C .newVZLinuxRosettaUnixSocketCachingOptionsWithPath (cs .CString (), & nserrPtr ),
173
+ ),
174
+ }
175
+ if err := newNSError (nserrPtr ); err != nil {
176
+ return nil , err
177
+ }
178
+ objc .SetFinalizer (usco , func (self * LinuxRosettaUnixSocketCachingOptions ) {
179
+ objc .Release (self )
180
+ })
181
+ return usco , nil
182
+ }
183
+
184
+ func maximumPathLengthLinuxRosettaUnixSocketCachingOptions () int {
185
+ return int (uint32 (C .maximumPathLengthVZLinuxRosettaUnixSocketCachingOptions ()))
186
+ }
187
+
188
+ // LinuxRosettaAbstractSocketCachingOptions is caching options for an abstract socket.
189
+ //
190
+ // Use this object to configure Rosetta to communicate with the Rosetta daemon using an abstract socket.
191
+ type LinuxRosettaAbstractSocketCachingOptions struct {
192
+ * pointer
193
+
194
+ * baseLinuxRosettaCachingOptions
195
+ }
196
+
197
+ var _ LinuxRosettaCachingOptions = (* LinuxRosettaAbstractSocketCachingOptions )(nil )
198
+
199
+ // NewLinuxRosettaAbstractSocketCachingOptions creates a new LinuxRosettaAbstractSocketCachingOptions.
200
+ //
201
+ // The name of the Abstract Socket to be used to communicate with the Rosetta translation daemon.
202
+ //
203
+ // This is only supported on macOS 14 and newer, error will
204
+ // be returned on older versions.
205
+ func NewLinuxRosettaAbstractSocketCachingOptions (name string ) (* LinuxRosettaAbstractSocketCachingOptions , error ) {
206
+ if err := macOSAvailable (14 ); err != nil {
207
+ return nil , err
208
+ }
209
+ maxNameLen := maximumNameLengthVZLinuxRosettaAbstractSocketCachingOptions ()
210
+ if maxNameLen < len (name ) {
211
+ return nil , fmt .Errorf ("name length exceeds maximum allowed length of %d" , maxNameLen )
212
+ }
213
+
214
+ cs := charWithGoString (name )
215
+ defer cs .Free ()
216
+
217
+ nserrPtr := newNSErrorAsNil ()
218
+ asco := & LinuxRosettaAbstractSocketCachingOptions {
219
+ pointer : objc .NewPointer (
220
+ C .newVZLinuxRosettaAbstractSocketCachingOptionsWithName (cs .CString (), & nserrPtr ),
221
+ ),
222
+ }
223
+ if err := newNSError (nserrPtr ); err != nil {
224
+ return nil , err
225
+ }
226
+ objc .SetFinalizer (asco , func (self * LinuxRosettaAbstractSocketCachingOptions ) {
227
+ objc .Release (self )
228
+ })
229
+ return asco , nil
230
+ }
231
+
232
+ func maximumNameLengthVZLinuxRosettaAbstractSocketCachingOptions () int {
233
+ return int (uint32 (C .maximumNameLengthVZLinuxRosettaAbstractSocketCachingOptions ()))
234
+ }
0 commit comments