madsmtm / objc2

Bindings to Apple's frameworks in Rust
https://docs.rs/objc2/
MIT License
281 stars 35 forks source link

Add support for Virtualization framework #613

Closed retrage closed 1 week ago

retrage commented 2 weeks ago

This PR proposes to add Virtualization Framework support for macOS 12.0 or later. I'm developing a Virtualization Framework-based VMM in Rust that deeply depends on the fork of objc2 with Virtualization Framework support.

According to the official document, macOS 11.0 starts supporting the framework, and macOS 12.0 has additional APIs to support macOS guests. Since my VMM is designed to run macOS guests, the objc2-virtualization must support the APIs for macOS 12.0 or later. So I have hardcoded the minimum supported macOS version to 12.0 in framework-crates/objc2-virtualization/translation-config.toml. This may not be appropriate for other use cases.

This PR depends on https://github.com/madsmtm/objc2-generated/pull/10.

retrage commented 2 weeks ago

I noticed that some of the APIs are only available for aarch64 (they have #ifdef __arm64__ guards). How can I deal with them? Is it OK to include them for all target architectures, or do they need to be guarded with #[cfg(target_arch = "aarch64")]?

retrage commented 2 weeks ago

The "Verify header translator output" should succeed if the header-translator target is changed as follows:

diff --git a/crates/header-translator/src/main.rs b/crates/header-translator/src/main.rs
index e0003505..7be0c427 100644
--- a/crates/header-translator/src/main.rs
+++ b/crates/header-translator/src/main.rs
@@ -90,7 +90,7 @@ fn main() -> Result<(), BoxError> {
         // These are found using the `get_llvm_targets.fish` helper script
         let llvm_targets: &[_] = match &sdk.platform {
             Platform::MacOsX => &[
-                "x86_64-apple-macosx10.12.0",
+                "arm64-apple-macosx10.12.0",
                 // "arm64-apple-macosx11.0.0",
                 // "i686-apple-macosx10.12.0",
             ],
madsmtm commented 1 week ago

Hmm, I'm a bit weary about doing so, but I think it'll be fine for now, please commit that change as well.

In the future I'm planning to automatically generate cfg-guards for target-specific APIs, but it's a hard problem.

retrage commented 1 week ago

25d88ee switches the target.