Run a virtual iPhone on an Apple Silicon Mac.
Swift
vphone-cli: Add network to `vm info`/`vm list` JSON
zqxwced37c06b61d2b
diff --git a/sources/VPhoneCore/VPhoneBundleReport.swift b/sources/VPhoneCore/VPhoneBundleReport.swiftindex 871d8953..2f83032c 100644--- a/sources/VPhoneCore/VPhoneBundleReport.swift+++ b/sources/VPhoneCore/VPhoneBundleReport.swift@@ -5,6 +5,7 @@ public struct VPhoneBundleReport: Codable, Equatable, Sendable {public let cpuCount: Intpublic let memoryMB: Intpublic let diskSizeBytes: Int64+ public let network: VPhoneVirtualMachineManifest.NetworkConfigpublic let restoreInfo: VPhoneRestoreInfo?public let udid: String?@@ -13,6 +14,7 @@ public struct VPhoneBundleReport: Codable, Equatable, Sendable {self.cpuCount = Int(bundle.manifest.cpuCount)self.memoryMB = Int(bundle.manifest.memorySize / (1024 * 1024))self.diskSizeBytes = bundle.diskSizeBytes+ self.network = bundle.manifest.networkConfigself.restoreInfo = VPhoneRestoreInfo.load(fromBundle: bundle)self.udid = VPhoneRestoreOps.resolveUDID(bundle: bundle)}diff --git a/sources/VPhoneCore/VPhoneVirtualMachineManifest.swift b/sources/VPhoneCore/VPhoneVirtualMachineManifest.swiftindex 3d16a2c4..370a3a62 100644--- a/sources/VPhoneCore/VPhoneVirtualMachineManifest.swift+++ b/sources/VPhoneCore/VPhoneVirtualMachineManifest.swift@@ -102,7 +102,7 @@ public struct VPhoneVirtualMachineManifest: Codable, Sendable {}}- public struct NetworkConfig: Codable, Sendable {+ public struct NetworkConfig: Codable, Equatable, Sendable {public let mode: NetworkModepublic let macAddress: String/// Host interface identifier to bridge (bridged mode only); nil otherwise.diff --git a/sources/vphone-cli/VPhoneVMCLI.swift b/sources/vphone-cli/VPhoneVMCLI.swiftindex 5b8330fb..7d2ac38d 100644--- a/sources/vphone-cli/VPhoneVMCLI.swift+++ b/sources/vphone-cli/VPhoneVMCLI.swift@@ -90,7 +90,7 @@ struct VPhoneVMInfoCommand: ParsableCommand {print("cpu: \(report.cpuCount)")print("mem: \(report.memoryMB) MB")print("disk: \(report.diskSizeBytes) bytes")- print("net: \(describeNetwork(bundle.manifest.networkConfig))")+ print("net: \(describeNetwork(report.network))")if let udid = report.udid { print("udid: \(udid)") }if let info = report.restoreInfo {print("iOS: \(info.ios.version) (\(info.ios.build))")diff --git a/tests/VPhoneCoreTests/BundleReportTests.swift b/tests/VPhoneCoreTests/BundleReportTests.swiftindex 45653b44..95a8563a 100644--- a/tests/VPhoneCoreTests/BundleReportTests.swift+++ b/tests/VPhoneCoreTests/BundleReportTests.swift@@ -13,6 +13,24 @@ struct BundleReportTests {#expect(report.name == "myvm")#expect(report.cpuCount == 6)#expect(report.memoryMB == 4096)+ #expect(report.network.mode == .nat)+ }++ @Test func carriesNetworkConfig() throws {+ let net = VPhoneVirtualMachineManifest.NetworkConfig(+ mode: .bridged, macAddress: "00:11:22:33:44:55", bridgeInterface: "en0")+ let manifest = VPhoneVirtualMachineManifest(+ cpuCount: 2, memorySize: 2 * 1024 * 1024 * 1024,+ networkConfig: net,+ romImages: .init(avpBooter: "a", avpSEPBooter: "b"))+ let report = VPhoneBundleReport(+ bundle: VPhoneBundle(url: URL(fileURLWithPath: "/tmp/b"), manifest: manifest))+ #expect(report.network.mode == .bridged)+ #expect(report.network.bridgeInterface == "en0")++ let back = try JSONDecoder().decode(+ VPhoneBundleReport.self, from: try JSONEncoder().encode(report))+ #expect(back.network == net)}@Test func encodesToJSON() throws {