contextfree / winrt-rust

Use and (eventually) make Windows Runtime APIs with Rust
Apache License 2.0
142 stars 10 forks source link

Can't import winrt::windows::data or ::ui #41

Closed ghost closed 6 years ago

ghost commented 6 years ago
rustc 1.18.0 (03fc9d622 2017-06-06)
cargo 0.19.0 (28d1d60d4 2017-05-16)

My Cargo.toml:

[package]
name = "hello_world"
version = "0.0.1"
authors = [ "Adam Baxter <github@voltagex.org>" ]

[dependencies]
winrt = "0.2.1"

[features]
windows-ui = []
windows-data = []

main.rs:

extern crate winrt;
use winrt::*; // import various helper types
use winrt::windows::data::xml::dom::*;
use winrt::windows::ui::notifications::*;

fn main() {
    let rt = RuntimeContext::init();
    println!("Hello, world!");

} 

(to be replaced with a toast notification as soon as I can make it work)

PS C:\git\rust\hello> cargo build --verbose
       Fresh winapi v0.2.8
       Fresh winapi-build v0.1.1
       Fresh ole32-sys v0.2.0
       Fresh runtimeobject-sys v0.2.0
       Fresh oleaut32-sys v0.2.0
       Fresh winrt v0.2.1
   Compiling hello_world v0.0.1 (file:///C:/git/rust/hello)
     Running `rustc --crate-name hello_world src\main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=1d57d6994d17b2e4 -C extra-filename=-1d57d6994d17b2e4 --out-dir C:\git\rust\hello\target\debug\deps -L dependency=C:\git\rust\hello\target\debug\deps
--extern winrt=C:\git\rust\hello\target\debug\deps\libwinrt-9ac1a1eab3936cb9.rlib`
error[E0432]: unresolved import `winrt::windows::data::xml::dom::*`
 --> src\main.rs:3:5
  |
3 | use winrt::windows::data::xml::dom::*;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Could not find `data` in `windows`

error[E0432]: unresolved import `winrt::windows::ui::notifications::*`
 --> src\main.rs:4:5
  |
4 | use winrt::windows::ui::notifications::*;
  |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Could not find `ui` in `windows`

error: aborting due to 2 previous errors

error: Could not compile `hello_world`.

Caused by:
  process didn't exit successfully: `rustc --crate-name hello_world src\main.rs --crate-type bin --emit=dep-info,link -C debuginfo=2 -C metadata=1d57d6994d17b2e4 -C extra-filename=-1d57d6994d17b2e4 --out-dir C:\git\rust\hello\target\debug\deps -L dependency=C:\git\rust\h
ello\target\debug\deps --extern winrt=C:\git\rust\hello\target\debug\deps\libwinrt-9ac1a1eab3936cb9.rlib` (exit code: 101)
PS C:\git\rust\hello>
Boddlnagg commented 6 years ago

This seems to be the same as #38. Is there any way in which we could make this clearer in the documentation?

ghost commented 6 years ago

Sorry for the duplicate issue. Is there no way to make features depend on each other automagically?

Failing that, perhaps the example should include (at least a fragment of) a Cargo.toml file - perhaps in a comment at the top of the file?

Edit: I thought I was enabling the features in my Cargo.toml, but I was not. I think a more full-featured example would help the newbies, such as myself.

Boddlnagg commented 6 years ago

@voltagex I tried to improve the wording of the README in this PR branch: https://github.com/Boddlnagg/winrt-rust/tree/multifile-gen. It now includes a fragment of Cargo.toml. What do you think, is this better?

Surely there is lots of room for improvement still ...

GabrielMajeri commented 6 years ago

Is there no way to make features depend on each other automagically?

winapi-rs uses a custom build.rs file that turns on features based on the dependency graph. Perhaps a similar file could be used in this case too.

However, their build.rs file is manually written. I don't know if the Windows Metadata files also contain dependency information, and manually writting all the dependencies might take quite a while.

Boddlnagg commented 6 years ago

@GuildMasterInfinite Interesting! However, in WinRT, the number of features is rather small (17), and problems with interdependencies are already worked around by cfg'ing out parts of the API (e.g., if a function in Windows.System refers to a data structure defined in Windows.Storage, that function will not be available unless Windows.Storage is also enabled via the windows-storage feature).

I don't see any way to make the handling of features any easier, except maybe:

By the way, when you're writing a C# application for WinRT, you also have to manually reference all the WinMD files that are directly needed. Since WinMD files map 1:1 to our Cargo features, you have to essentially do the same thing when using this crate.

Boddlnagg commented 6 years ago

I consider this issue to be solved.