Osspial / vk-rs

Collection of Rust libraries for the Vulkan API
MIT License
24 stars 4 forks source link

use_libc_types() causes "type name undefined" compile errors #3

Closed jamsch0 closed 8 years ago

jamsch0 commented 8 years ago

When using use_libc_types(true) the compiler complains that uint32_t, c_void, etc. aren't defined or aren't in scope. After checking through the generated bindings the issue seems to be that the use libc::*; is inside the types module, and all of the function definitions inside the cmds module are therefore referring to unknown types.

This is ok with the default settings because the defined types are public and therefore are visible to the cmds module.

I think a possible workaround in the meantime is to use extern_types_override, although I haven't tried it yet.

Osspial commented 8 years ago

Unfortunately, this is unavoidable behavior as far as I can see.

What use_libc_types does is, instead of creating type definitions inside of the Vulkan module, uses the types provided by the libc crate. If the libc crate isn't a part of your project, rustc will rightfully throw an error because the types don't actually exist in your project. Because libc isn't provided as part of the rust standard library, I don't see any way to avoid this while still providing the ability to use the official typedefs.

To get this feature working, simply add libc to your crate's dependencies and import libc at your crate's root. I should probably document this behavior better, so I'll leave this issue open until I get around to doing that.

jamsch0 commented 8 years ago

This is what I had written:

extern crate libc;

use libc::*;

mod vk {
    include!(concat!(env!("OUT_DIR"), "vk_bindings.rs"));
}

fn main() {
    // ...
}

I assume that's what you mean? If so, I'm still getting compiler errors. I also tried moving the use libc::*; inside mod vk {}.

Osspial commented 8 years ago

Huh. Could you post a gist of your vk_bindings.rs? Unfortunately, I don't currently have access to a computer that can run rustc so I can't directly look at the generated file.

jamsch0 commented 8 years ago

Sure

Osspial commented 8 years ago

OK, I see the issue. The libc types are being properly imported in the type definition module, but they aren't being imported in the cmds module for the function definitions. Try using extern_type_overrides with the libc types for now (with use_libc_types disabled) - that should make it compile at least until I can get a proper fix in. That should happen by the 20th, probably a few days earlier. Sorry I can't get it fixed until then!

Also, I should probably write some tests for non-default configurations so this sort of issue doesn't happen again.

jamsch0 commented 8 years ago

Yes, that's what I surmised in my initial post. No worries about the timescale for the fix, the workaround should work just fine in the meantime!

I'm more interested in getting bindings for the debug extensions working, I've posted my findings so far in #2.

Osspial commented 8 years ago

Resolved in 766bcf633f3dda504ac001362b12d407c4814b13