Skip to content

Commit

Permalink
Support for Virtio graphics
Browse files Browse the repository at this point in the history
  • Loading branch information
azenla committed Jun 10, 2023
1 parent 40860e5 commit ef1d9a2
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 9 deletions.
3 changes: 2 additions & 1 deletion Sources/diavirt/CannedMac.swift
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,8 @@ func createCannedMac() -> DAVirtualMachineConfiguration {
pixelsPerInch: 80
)
]
)
),
virtioGraphicsDevice: .init(scanouts: [])
)
],
directorySharingDevices: [
Expand Down
28 changes: 27 additions & 1 deletion Sources/diavirt/ConfigurationBuilder.swift
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,17 @@ extension DAVirtioNetworkDevice {

extension DAGraphicsDevice {
func build() throws -> VZGraphicsDeviceConfiguration {
try (macGraphicsDevice?.build())!
var device: VZGraphicsDeviceConfiguration?

if let macGraphicsDevice {
device = try macGraphicsDevice.build()
}

if let virtioGraphicsDevice {
device = try virtioGraphicsDevice.build()
}

return device!
}
}

Expand All @@ -469,6 +479,22 @@ extension DAMacGraphicsDisplay {
}
}

extension DAVirtioGraphicsDevice {
func build() throws -> VZVirtioGraphicsDeviceConfiguration {
let device = VZVirtioGraphicsDeviceConfiguration()
let scanouts = try scanouts.map { scanout in try scanout.build() }
device.scanouts = scanouts
return device
}
}

extension DAVirtioGraphicsScanout {
func build() throws -> VZVirtioGraphicsScanoutConfiguration {
VZVirtioGraphicsScanoutConfiguration(widthInPixels: widthInPixels,
heightInPixels: heightInPixels)
}
}

extension DADirectorySharingDevice {
func build() throws -> VZDirectorySharingDeviceConfiguration {
let share = try directoryShare.build()
Expand Down
10 changes: 10 additions & 0 deletions Sources/diavirt/ConfigurationModel.swift
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ struct DANATNetworkAttachment: Codable {}

struct DAGraphicsDevice: Codable {
let macGraphicsDevice: DAMacGraphicsDevice?
let virtioGraphicsDevice: DAVirtioGraphicsDevice?
}

struct DAMacGraphicsDevice: Codable {
Expand All @@ -152,6 +153,15 @@ struct DAMacGraphicsDisplay: Codable {
let pixelsPerInch: Int
}

struct DAVirtioGraphicsScanout: Codable {
let widthInPixels: Int
let heightInPixels: Int
}

struct DAVirtioGraphicsDevice: Codable {
let scanouts: [DAVirtioGraphicsScanout]
}

struct DADirectorySharingDevice: Codable {
let virtioFileSystemDevice: DAVirtioFileSystemDevice?
let directoryShare: DADirectoryShare
Expand Down
9 changes: 7 additions & 2 deletions Sources/diavirt/EntryPoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -111,14 +111,19 @@ struct DiavirtCommand: ParsableCommand {
}

Task {
try await Global.machine!.create()
do {
try await Global.machine!.create()
} catch {
DiavirtCommand.exit(withError: error)
}

Global.machine?.start()
Global.stateObserverHandle = Global.machine!.watchForState { state in
Task {
if state == .error {
DiavirtCommand.exit(withError: ExitCode.failure)
} else if state == .stopped {
DiavirtCommand.exit(withError: ExitCode.success)
// DiavirtCommand.exit(withError: ExitCode.success)
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions diavirt.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MACOSX_DEPLOYMENT_TARGET = 14.0;
MTL_ENABLE_DEBUG_INFO = INCLUDE_SOURCE;
MTL_FAST_MATH = YES;
ONLY_ACTIVE_ARCH = YES;
Expand Down Expand Up @@ -293,7 +293,7 @@
GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE;
GCC_WARN_UNUSED_FUNCTION = YES;
GCC_WARN_UNUSED_VARIABLE = YES;
MACOSX_DEPLOYMENT_TARGET = 12.0;
MACOSX_DEPLOYMENT_TARGET = 14.0;
MTL_ENABLE_DEBUG_INFO = NO;
MTL_FAST_MATH = YES;
SDKROOT = macosx;
Expand Down
6 changes: 3 additions & 3 deletions diavirt.xcodeproj/xcshareddata/xcschemes/diavirt.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
useCustomWorkingDirectory = "YES"
customWorkingDirectory = "$(PROJECT_DIR)/work/mac"
customWorkingDirectory = "$(PROJECT_DIR)/work/alpine"
ignoresPersistentStateOnLaunch = "NO"
debugDocumentVersioning = "YES"
debugServiceExtension = "internal"
Expand All @@ -53,11 +53,11 @@
</BuildableProductRunnable>
<CommandLineArguments>
<CommandLineArgument
argument = "-w"
argument = "-v"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
argument = "-v"
argument = "-w"
isEnabled = "YES">
</CommandLineArgument>
</CommandLineArguments>
Expand Down

0 comments on commit ef1d9a2

Please sign in to comment.