yury / cidre

Apple frameworks bindings for rust
MIT License
49 stars 2 forks source link

How to use macos_13_0 with the sc feature? #18

Closed kusaanko closed 3 weeks ago

kusaanko commented 4 weeks ago

I want to set the deployment target to macos_13_0 and use ScreenCaptureKit.

cidre = { git = "https://github.com/yury/cidre", rev = "d37e5ac9baf5ecc2966a22e6ad9dfb11b99a262a", features = [
    "private",

    "blocks",
    "async",

    "app",
    "am",
    "at",
    "ca",
    "ci",
    "cl",
    "cm",
    "cmio",
    "ct",
    "av",
    "av_kit",
    "cf",
    "cg",
    "iio",
    "ns",
    "nl",
    "vt",
    "sc",
    "mc",
    "mtl",
    "mlc",
    "cv",
    "objc",
    "mps",
    "mpsg",
    "dispatch",
    "da",
    "simd",
    "cat",
    "vn",
    "sn",
    "ui",
    "ut",
    "un",
    "io",
    "nw",
    "core_motion",
    "core_audio",
    "wc",
    "wk",
    "gc",
    "xpc",
    "vdsp",

    "macos_13_0"], default-features = false}
error: cannot find macro `define_weak_cls` in this scope
   --> /Users/cactus/.cargo/git/checkouts/cidre-e660120dbd7e907a/d8499b1/cidre/src/sc/screenshot_manager.rs:10:5
    |
10  |     define_cls!(SC_SCREENSHOT_MANAGER);
    |     ^^^^^^^^^^
    |
   ::: /Users/cactus/.cargo/git/checkouts/cidre-e660120dbd7e907a/d8499b1/cidre/src/objc.rs:309:1
    |
309 | macro_rules! define_cls {
    | ----------------------- similarly named macro `define_cls` defined here
    |
    = help: have you added the `#[macro_use]` on the module/import?
help: a macro with a similar name exists
    |
10  |     define_cls!(SC_SCREENSHOT_MANAGER);
    |     ~~~~~~~~~~
help: consider importing this macro through its public re-export
    |
1   + use crate::define_weak_cls;
    |

error: cannot find macro `define_weak_cls` in this scope
   --> /Users/cactus/.cargo/git/checkouts/cidre-e660120dbd7e907a/d8499b1/cidre/src/sc/content_sharing_picker.rs:66:5
    |
66  |     define_cls!(SC_CONTENT_SHARING_PICKER);
    |     ^^^^^^^^^^
    |
   ::: /Users/cactus/.cargo/git/checkouts/cidre-e660120dbd7e907a/d8499b1/cidre/src/objc.rs:309:1
    |
309 | macro_rules! define_cls {
    | ----------------------- similarly named macro `define_cls` defined here
    |
    = help: have you added the `#[macro_use]` on the module/import?
help: a macro with a similar name exists
    |
66  |     define_cls!(SC_CONTENT_SHARING_PICKER);
    |     ~~~~~~~~~~
help: consider importing this macro through its public re-export
    |
1   + use crate::define_weak_cls;
    |

error[E0425]: cannot find value `SC_CONTENT_SHARING_PICKER_CONFIGURATION` in this scope
   --> /Users/cactus/.cargo/git/checkouts/cidre-e660120dbd7e907a/d8499b1/cidre/src/sc/content_sharing_picker.rs:27:5
    |
27  |     SC_CONTENT_SHARING_PICKER_CONFIGURATION,
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a static with a similar name exists: `SC__CONTENT__SHARING__PICKER__CONFIGURATION`
...
135 | #[api::weak]
    | ------------ similarly named static `SC__CONTENT__SHARING__PICKER__CONFIGURATION` defined here

error[E0599]: no function or associated item named `capture_sample_buf_ch` found for struct `ScreenshotManager` in the current scope
   --> /Users/cactus/.cargo/git/checkouts/cidre-e660120dbd7e907a/d8499b1/cidre/src/sc/screenshot_manager.rs:28:15
    |
28  |         Self::capture_sample_buf_ch(filter, cfg, Some(&mut block));
    |               ^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `ScreenshotManager`
    |
   ::: /Users/cactus/.cargo/git/checkouts/cidre-e660120dbd7e907a/d8499b1/cidre/src/objc.rs:458:9
    |
458 |         $vis struct $NewType($BaseType);
    |         -------------------------------- function or associated item `capture_sample_buf_ch` not found for this struct
    |
help: there is an associated function `capture_sample_buf` with a similar name
   --> /Users/cactus/.cargo/git/checkouts/cidre-e660120dbd7e907a/d8499b1/cidre/src/sc/screenshot_manager.rs:23:5
    |
23  | /     pub async fn capture_sample_buf(
24  | |         filter: &sc::ContentFilter,
25  | |         cfg: &sc::StreamCfg,
26  | |     ) -> Result<arc::R<cm::SampleBuf>, arc::R<ns::Error>> {
    | |_________________________________________________________^

error[E0599]: no function or associated item named `capture_image_ch` found for struct `ScreenshotManager` in the current scope
   --> /Users/cactus/.cargo/git/checkouts/cidre-e660120dbd7e907a/d8499b1/cidre/src/sc/screenshot_manager.rs:48:15
    |
48  |         Self::capture_image_ch(filter, cfg, Some(&mut block));
    |               ^^^^^^^^^^^^^^^^ function or associated item not found in `ScreenshotManager`
    |
   ::: /Users/cactus/.cargo/git/checkouts/cidre-e660120dbd7e907a/d8499b1/cidre/src/objc.rs:458:9
    |
458 |         $vis struct $NewType($BaseType);
    |         -------------------------------- function or associated item `capture_image_ch` not found for this struct
    |
help: there is an associated function `capture_image` with a similar name
   --> /Users/cactus/.cargo/git/checkouts/cidre-e660120dbd7e907a/d8499b1/cidre/src/sc/screenshot_manager.rs:43:5
    |
43  | /     pub async fn capture_image(
44  | |         filter: &sc::ContentFilter,
45  | |         cfg: &sc::StreamCfg,
46  | |     ) -> Result<arc::R<cg::Image>, arc::R<ns::Error>> {
    | |_____________________________________________________^

error[E0599]: no function or associated item named `cls` found for struct `Picker` in the current scope
   --> /Users/cactus/.cargo/git/checkouts/cidre-e660120dbd7e907a/d8499b1/cidre/src/sc/content_sharing_picker.rs:68:5
    |
68  |     #[objc::msg_send(sharedPicker)]
    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ function or associated item not found in `Picker`
    |
   ::: /Users/cactus/.cargo/git/checkouts/cidre-e660120dbd7e907a/d8499b1/cidre/src/objc.rs:458:9
    |
458 |         $vis struct $NewType($BaseType);
    |         -------------------------------- function or associated item `cls` not found for this struct
    |
    = note: this error originates in the attribute macro `objc::msg_send` (in Nightly builds, run with -Z macro-backtrace for more info)
help: there is a method `class` with a similar name
    |
68  |     class
    |

error[E0133]: call to unsafe function `shareable_content::Window::is_active` is unsafe and requires unsafe function or block
  --> /Users/cactus/.cargo/git/checkouts/cidre-e660120dbd7e907a/d8499b1/cidre/src/sc/shareable_content.rs:87:34
   |
87 |             .field("is_active", &self.is_active())
   |                                  ^^^^^^^^^^^^^^^^ call to unsafe function
   |
   = note: consult the function's documentation for information on how to avoid undefined behavior

How do I fix the problem? Is the features usage correct?

yury commented 4 weeks ago

Frankly speaking, I haven’t tested the app on macOS 13 yet. I’ve made some improvements, but it’s not ready for release.

As for the feature set, I believe you should expand it to include all the features. You don’t necessarily need private access (that’s my attempt to use an outdated API to install apps on iOS devices).

I’ll delve deeper into this issue tomorrow.

yury commented 3 weeks ago

latest version should be good.

This is good default for you:

[dependencies]

cidre = { path = "../cidre/cidre", features = [
    "blocks",
    "async",
    "dispatch",
    "av",
    "cm",
    "ns",
    "sc",
    "macos_13_0"
], default-features = false}
kusaanko commented 3 weeks ago

It works! Thank you so much.

But I got a clippy warning. Could you fix this warning?

warning: transmute from a reference to a pointer
   --> src/****.rs:224:5
    |
224 | /     cidre::define_obj_type!(
225 | |         SCKitAudioRecorder + cidre::sc::stream::OutputImpl,
226 | |         SCKitAudioRecorderInner,
227 | |         AUDIO_RECORDER
228 | |     );
    | |_____^
    |
    = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#useless_transmute
    = note: `#[warn(clippy::useless_transmute)]` on by default
    = note: this warning originates in the macro `cidre::define_obj_type` (in Nightly builds, run with -Z macro-backtrace for more info)
objc.rs(417, 26): Actual error occurred here

https://github.com/yury/cidre/blob/83a6f8b5ef5ce36af6c109b9a9f67d4951aa4bba/cidre/src/objc.rs#L417

yury commented 3 weeks ago

Fixed

kusaanko commented 3 weeks ago

Great job! Thank you.