Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing Network Crate #646

Open
zamderax opened this issue Aug 24, 2024 · 1 comment
Open

Missing Network Crate #646

zamderax opened this issue Aug 24, 2024 · 1 comment
Labels
A-framework Affects the framework crates and the translator for them

Comments

@zamderax
Copy link

NSNetService in Foundation has all been deprecated:

It's been succeeded by the Network Framework:
https://developer.apple.com/documentation/network?language=objc

I can only see a NetworkExtension autogenerated crate; which is completely different than Network

Question:

  1. How can I generate the Network crate/feature since it's missing
  2. Alternatively, can I call these methods without the Network crate on version 0.5.2?
@zamderax zamderax changed the title https://developer.apple.com/documentation/network?language=objc Aug 24, 2024
@madsmtm
Copy link
Owner

madsmtm commented Aug 30, 2024

Yeah, see #556, more work is needed to figure out how memory management should work.

can I call these methods without the Network crate on version 0.5.2?

You should be able to, you'll have to write the extern "C" definitions yourself, but it's a lot of work. For an API like nw_browser_create, to take a random example, the C header contains:

NW_RETURNS_RETAINED nw_browser_t
nw_browser_create(nw_browse_descriptor_t descriptor,
				  _Nullable nw_parameters_t parameters);

So in Rust you'd write something like:

// --- Declare protocols that is used in Network

extern_protocol!(
    unsafe trait OS_nw_browser: NSObjectProtocol {}
    unsafe impl ProtocolType for dyn OS_nw_browser {}
);
type nw_browser_t = ProtocolObject<dyn OS_nw_browser>;

extern_protocol!(
    unsafe trait OS_nw_parameters: NSObjectProtocol {}
    unsafe impl ProtocolType for dyn OS_nw_parameters {}
);
type nw_parameters_t = ProtocolObject<dyn OS_nw_parameters>;

extern_protocol!(
    unsafe trait OS_nw_browse_descriptor: NSObjectProtocol {}
    unsafe impl ProtocolType for dyn OS_nw_browse_descriptor {}
);
type nw_browse_descriptor_t = ProtocolObject<dyn OS_nw_browse_descriptor>;

// --- Declare the actual function prototype

extern "C" {
    fn nw_browser_create(
        descriptor: &nw_browse_descriptor_t,
        parameters: Option<&nw_parameters_t>,
    ) -> *mut nw_browser_t;
}

// --- Usage

// SAFETY: Uses `Retained::from_raw` because of `NW_RETURNS_RETAINED`.
let browser = unsafe { Retained::from_raw(nw_browser_create(descriptor, parameters)) };

I think, at least, I doubt I'm familiar enough with the Network framework to help you out further, though feel free to ask!

@madsmtm madsmtm added the A-framework Affects the framework crates and the translator for them label Sep 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-framework Affects the framework crates and the translator for them
2 participants