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

windows-bindgen: functions not generated from winmd after upgrade to 0.57 #3100

Closed
youyuanwu opened this issue Jun 14, 2024 · 5 comments
Closed
Labels
question Further information is requested

Comments

@youyuanwu
Copy link

Summary

After upgrading to version 0.57, functions previously marked with feature "Win32_Foundation" no longer exists. The function refers to the type windows::Win32::Foundation::BOOLEAN.

See: Azure/service-fabric-rs#38 for example.

Crate manifest

No response

Crate code

No response

@youyuanwu youyuanwu added the bug Something isn't working label Jun 14, 2024
@kennykerr kennykerr added question Further information is requested and removed bug Something isn't working labels Jun 14, 2024
@kennykerr
Copy link
Collaborator

This is likely related to #2735 and is by design.

@youyuanwu
Copy link
Author

@kennykerr This does not happen for 0.56 but only in 0.57. Seems to be not caused from the commit you mentioned.

This caused those functions not generated and not accessible.
I want to use those functions, how to make windows-bindgen generate them? Is there a new flag in 0.57 to enable Win32_Foundation?

@kennykerr
Copy link
Collaborator

Taking this winmd file: https://github.com/Azure/service-fabric-metadata/blob/main/.windows/winmd/Microsoft.ServiceFabric.winmd

I see the definition for IFabricAsyncOperationContext includes these four methods:

[Guid(2216108223u, 51688, 20079, 156, 63, 107, 127, 74, 199, 59, 205)]
[Agile]
public interface IFabricAsyncOperationContext : IUnknown
{
	BOOLEAN IsCompleted();

	BOOLEAN CompletedSynchronously();

	[SpecialName]
	unsafe HRESULT get_Callback([Out][RetVal] IFabricAsyncOperationCallback* callback);

	HRESULT Cancel();
}

And running this command:

[dependencies.windows-bindgen]
version = "0.57"
fn main() {
    windows_bindgen::bindgen([
        "--in",
        "/git/Microsoft.ServiceFabric.winmd",
        "--out",
        "src/bindings.rs",
        "--filter",
        "Microsoft",
        "--config",
        "implement",
    ])
    .unwrap();
}

This generates bindings that includes:

impl IFabricAsyncOperationContext {
    pub unsafe fn IsCompleted(&self) -> windows::Win32::Foundation::BOOLEAN {
        (windows_core::Interface::vtable(self).IsCompleted)(
            windows_core::Interface::as_raw(self),
        )
    }
    pub unsafe fn CompletedSynchronously(&self) -> windows::Win32::Foundation::BOOLEAN {
        (windows_core::Interface::vtable(self).CompletedSynchronously)(
            windows_core::Interface::as_raw(self),
        )
    }
    pub unsafe fn Callback(&self) -> windows_core::Result<IFabricAsyncOperationCallback> {
        let mut result__ = core::mem::zeroed();
        (windows_core::Interface::vtable(self).Callback)(
            windows_core::Interface::as_raw(self),
            &mut result__,
        )
        .and_then(|| windows_core::Type::from_abi(result__))
    }
    pub unsafe fn Cancel(&self) -> windows_core::Result<()> {
        (windows_core::Interface::vtable(self).Cancel)(windows_core::Interface::as_raw(
            self,
        ))
        .ok()
    }
}

Compiling the bindings with the following dependencies seems to work fine:

[dependencies.windows]
version = "0.57"
features = [
    "Win32_Foundation",
]

[dependencies.windows-core]
version = "0.57"

In future, please include a repro of this sort. That being said, what's missing?

@youyuanwu
Copy link
Author

Bindgen config=implement generates correct functions.
But I am using this:

--in  ./windows/Microsoft.ServiceFabric.winmd
--out crates/libs/com/src/Microsoft.rs

--filter
    Microsoft
  
--config
  package=true

package=true generates the code with functions missing in this issue.

@kennykerr
Copy link
Collaborator

kennykerr commented Jun 19, 2024

Ah, the package config option is only meant for the windows and windows-sys crates. If you use the options I suggested above then you'll get all the bindings just in a single source file. It's a lot simpler. The package config option is really just meant to deal with the vast size of the Windows API and as such has a few really peculiar characteristics that don't apply to other crates.

youyuanwu added a commit to Azure/service-fabric-rs that referenced this issue Jun 28, 2024
windows-rs version 0.57 has various improvements for generated com
bindings and the code size reduces.

We have been using win-bindgen with config=package, which is not
publicly supported, and we are advised to switch to config=implement
that is supported external to windows-rs. See
microsoft/windows-rs#3100 for details.

The generated code are reorganized due to the generation config mode,
and the mod structures are remapped so that there is no unwanted nesting
of mods, for example, FabricRuntime is no longer inside FabricCommon but
they are siblings now. The generation of the code and remapping of the
mods are still hacky, and we still need
Azure/service-fabric-metadata#1 to improve
this.

Previously all mods are generated once, but now, each mod like
FabricCommon and FabricRuntime is generated separately from the winmd
file per pass. The generation speed maybe slowed but in practice it is
not observable.

This upgrade will cause break in down stream because of the mod layout
change. But it is easy to fix: just change the imports(use) with
different path.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants