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

Can not compile windows-rs when enabling UI_ViewManagement feature #3425

Open
JunkuiZhang opened this issue Jan 8, 2025 · 6 comments
Open
Labels
bug Something isn't working

Comments

@JunkuiZhang
Copy link

Summary

When I enable the UI_ViewManagement feature to compile windows-rs, I encounter some errors. I'm not sure if there are additional steps I should take. Could you kindly advise?

   Compiling windows v0.59.0
error[E0412]: cannot find type `IApplicationViewFullscreenStatics` in this scope
    --> C:\Users\36477\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-0.59.0\src\Windows\UI\ViewManagement\mod.rs:414:56
     |
414  |     fn IApplicationViewFullscreenStatics<R, F: FnOnce(&IApplicationViewFullscreenStatics) -> windows_core::Result<R>>(callback: F) -> windows_core::Result<R> {
     |                                                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a struct with a similar name exists: `IApplicationViewSwitcherStatics`
...
1198 | windows_core::imp::define_interface!(IApplicationViewSwitcherStatics, IApplicationViewSwitcherStatics_Vtbl, 0x975f2f1e_e656_4c5e_a0a1_717c6ffa7d64);
     | --------------------------------------------------------------------------------------------------------------------------------------------------- similarly named struct `IApplicationViewSwitcherStatics` defined here

error[E0412]: cannot find type `IApplicationViewFullscreenStatics` in this scope
    --> C:\Users\36477\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-0.59.0\src\Windows\UI\ViewManagement\mod.rs:415:73
     |
414  |     fn IApplicationViewFullscreenStatics<R, F: FnOnce(&IApplicationViewFullscreenStatics) -> windows_core::Result<R>>(callback: F) -> windows_core::Result<R> {
     |        --------------------------------- an associated function by that name is available on `Self` here
415  |         static SHARED: windows_core::imp::FactoryCache<ApplicationView, IApplicationViewFullscreenStatics> = windows_core::imp::FactoryCache::new();
     |                                                                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: a struct with a similar name exists: `IApplicationViewSwitcherStatics`
...
1198 | windows_core::imp::define_interface!(IApplicationViewSwitcherStatics, IApplicationViewSwitcherStatics_Vtbl, 0x975f2f1e_e656_4c5e_a0a1_717c6ffa7d64);
     | --------------------------------------------------------------------------------------------------------------------------------------------------- similarly named struct `IApplicationViewSwitcherStatics` defined here

error[E0412]: cannot find type `IApplicationViewStatics` in this scope
    --> C:\Users\36477\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-0.59.0\src\Windows\UI\ViewManagement\mod.rs:422:46
     |
422  |     fn IApplicationViewStatics<R, F: FnOnce(&IApplicationViewStatics) -> windows_core::Result<R>>(callback: F) -> windows_core::Result<R> {
     |                                              ^^^^^^^^^^^^^^^^^^^^^^^ help: a struct with a similar name exists: `IApplicationViewStatics2`
...
1165 | windows_core::imp::define_interface!(IApplicationViewStatics2, IApplicationViewStatics2_Vtbl, 0xaf338ae5_cf64_423c_85e5_f3e72448fb23);
     | ------------------------------------------------------------------------------------------------------------------------------------- similarly named struct `IApplicationViewStatics2` defined here

error[E0412]: cannot find type `IApplicationViewStatics` in this scope
    --> C:\Users\36477\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-0.59.0\src\Windows\UI\ViewManagement\mod.rs:423:73
     |
422  |     fn IApplicationViewStatics<R, F: FnOnce(&IApplicationViewStatics) -> windows_core::Result<R>>(callback: F) -> windows_core::Result<R> {
     |        ----------------------- an associated function by that name is available on `Self` here
423  |         static SHARED: windows_core::imp::FactoryCache<ApplicationView, IApplicationViewStatics> = windows_core::imp::FactoryCache::new();
     |                                                                         ^^^^^^^^^^^^^^^^^^^^^^^ help: a struct with a similar name exists: `IApplicationViewStatics2`
...
1165 | windows_core::imp::define_interface!(IApplicationViewStatics2, IApplicationViewStatics2_Vtbl, 0xaf338ae5_cf64_423c_85e5_f3e72448fb23);
     | ------------------------------------------------------------------------------------------------------------------------------------- similarly named struct `IApplicationViewStatics2` defined here

error[E0609]: no field `TryUnsnapToFullscreen` on type `&_`
   --> C:\Users\36477\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-0.59.0\src\Windows\UI\ViewManagement\mod.rs:343:52
    |
343 |             (windows_core::Interface::vtable(this).TryUnsnapToFullscreen)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__)
    |                                                    ^^^^^^^^^^^^^^^^^^^^^ unknown field

error[E0609]: no field `Value` on type `&_`
   --> C:\Users\36477\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-0.59.0\src\Windows\UI\ViewManagement\mod.rs:359:52
    |
359 |             (windows_core::Interface::vtable(this).Value)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__)
    |                                                    ^^^^^ unknown field

error[E0609]: no field `TryUnsnap` on type `&_`
   --> C:\Users\36477\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-0.59.0\src\Windows\UI\ViewManagement\mod.rs:365:52
    |
365 |             (windows_core::Interface::vtable(this).TryUnsnap)(windows_core::Interface::as_raw(this), &mut result__).map(|| result__)
    |                                                    ^^^^^^^^^ unknown field

Some errors have detailed explanations: E0412, E0609.
For more information about an error, try `rustc --explain E0412`.
error: could not compile `windows` (lib) due to 7 previous errors

Crate manifest

[package]
name = "rust-test"
version = "0.1.0"
edition = "2021"

[dependencies]
windows = { version = "0.59", features = ["UI_ViewManagement"] }

Crate code

fn main() {
    println!("Hello");
}
@JunkuiZhang JunkuiZhang added the bug Something isn't working label Jan 8, 2025
@kennykerr
Copy link
Collaborator

Thanks for reporting this bug.

The code generator is failing to add the required #[cfg(feature = "deprecated")] to the static factories.

I'll get this fixed, but as a workaround you can add the "deprecated" feature to get this to work.

windows = { version = "0.59", features = ["UI_ViewManagement", "deprecated"] }

@JunkuiZhang
Copy link
Author

Thank you so much for your prompt response! So, does that mean the next version, such as "0.60," will fix this bug?

Additionally, I noticed that some function parameter signatures have changed, introducing types like windows_core::Ref<'_, SomeType>. Could you kindly share the best practices for handling this type? Would the following approach be appropriate?

// in function:
pdataobj: windows_core::Ref<'_, IDataObject>,
...
let Some(data) = pdataobj.as_ref() else {
    return;
}
// do something with `data`

@JunkuiZhang
Copy link
Author

I also noticed some inconsistencies when using the feature search tool at https://microsoft.github.io/windows-rs/features/#/0.59.0/search/StorageFile. When I searched for StorageFile, the results suggested that I should enable the "Storage" feature. However, when I tried to compile, the compiler indicated that I needed to enable the "Storage_Streams" feature instead.

error[E0432]: unresolved import `windows::Storage::StorageFile`
    --> crates\fs\src/fs.rs:465:44
     |
465  |             Storage::{StorageDeleteOption, StorageFile},
     |                                            ^^^^^^^^^^^
     |                                            |
     |                                            no `StorageFile` in `Storage`
     |                                            help: a similar name exists in the module: `IStorageFile2`
     |
note: found an item that was configured out
    --> C:\Users\36477\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-0.59.0\src\Windows\Storage\mod.rs:4255:12
     |
4255 | pub struct StorageFile(windows_core::IUnknown);
     |            ^^^^^^^^^^^
note: the item is gated behind the `Storage_Streams` feature
    --> C:\Users\36477\.cargo\registry\src\index.crates.io-6f17d22bba15001f\windows-0.59.0\src\Windows\Storage\mod.rs:4252:7
     |
4252 | #[cfg(feature = "Storage_Streams")]
     |       ^^^^^^^^^^^^^^^^^^^^^^^^^^^

Also, the same thing happens for StorageFolder, compiler told me to enable "Storage_Search" instead of "Storage".

@kennykerr
Copy link
Collaborator

kennykerr commented Jan 8, 2025

Ref and OutRef were added to make it easier to correctly deal with Win32/COM style parameter semantics. #3025 #3386 #3394

You can typically rely on param.ok()? to handle input parameters most easily.
https://docs.rs/windows-core/0.59.0/windows_core/struct.Ref.html

The feature search index still needs to be updated - will get to that soon.

@JunkuiZhang
Copy link
Author

Thank you very much for your patient explanation. Your work is truly outstanding.

BTW, the new async feature is incompatible with the async-trait crate. Here's an example:

#[async_trait::async_trait]
impl Fs for WindowsFs {
    async fn trash_file(&self, path: &str) -> Result<()> {
        let file = StorageFile::GetFileFromPathAsync(&HSTRING::from(path))?.await?; 
        file.DeleteAsync(StorageDeleteOption::Default)?.await?;
        Ok(())
    }
}

The above code fails to compile with the following error:

error: future cannot be sent between threads safely
  --> src/main.rs:31:58
   |
31 |       async fn trash_file(&self, path: &str) -> Result<()> {
   |  __________________________________________________________^
32 | |         let file = StorageFile::GetFileFromPathAsync(&HSTRING::from(path))?.await?;
33 | |         file.DeleteAsync(StorageDeleteOption::Default)?.await?;
34 | |         Ok(())
35 | |     }
   | |_____^ future created by async block is not `Send`
   |
   = help: within `{async block@src/main.rs:31:58: 35:6}`, the trait `Send` is not implemented for `NonNull<c_void>`, which is required by `{async block@src/main.rs:31:58: 35:6}: Send`
note: future is not `Send` as this value is used across an await
  --> src/main.rs:33:57
   |
32 |         let file = StorageFile::GetFileFromPathAsync(&HSTRING::from(path))?.await?;
   |             ---- has type `StorageFile` which is not `Send`
33 |         file.DeleteAsync(StorageDeleteOption::Default)?.await?;
   |                                                         ^^^^^ await occurs here, with `file` maybe used later
   = note: required for the cast from `Pin<Box<{async block@src/main.rs:31:58: 35:6}>>` to `Pin<Box<dyn Future<Output = Result<(), anyhow::Error>> + Send>>`

The error message indicates that IUnknown in StorageFile<IUnknown> doesn't implement Send. Is this intentional?

@kennykerr
Copy link
Collaborator

IUnknown cannot be Send/Sync because its implementation is open-ended and not known to be thread-safe at compile time.

Let's keep this issue focused on build issues related to feature selection, otherwise it will be hard to track fixes. Feel free to create new issues for other questions or concerns.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants