I am working through the learning_gfx_hal project and running into what I perceive as namespace issues and how Cargo.toml can help or hinder. Admittedly I trying to bite off a lot at the moment
- I am through 2/3 of the Programming Rust by Blandy
- I am working on understanding gfx_hal with the learning gfx hal tutorial.
- Splitting out the types created in the tutorial into separate code for reuse.
The organization of my code is
Cargo.toml
src/gfx_types // where I am defining types one per file:
src/gfx_types/hal_state.rs
src/gfx_types/winit_state.rs
src/gfx_type/mod.rs
src/main.rs
examples/build_windows.rs
examples/Cargo.toml
Top level Cargo.toml:
[package]
name = "learning_gfx_hal"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[features]
default = []
metal = ["gfx-backend-metal"]
dx12 = ["gfx-backend-dx12"]
vulkan = ["gfx-backend-vulkan"]
#[workspace]
#members = [
# "src/gfx_types",
#]
[dependencies]
winit = "0.22.2"
log = "0.4.8"
simple_logger = "1.6.0"
gfx-hal = "0.5.3"
arrayvec = "0.5.1"
bitflags = "1.2.1"
#gfx_types = {path = "src/gfx_types/"}
[dependencies.gfx-backend-vulkan]
version = "0.5.8"
optional = true
[target.'cfg(target_os = "macos")'.dependencies.gfx-backend-metal]
version = "0.4.0"
optional = true
[target.'cfg(target_os = "windows")'.dependencies.gfx-backend-dx12]
src/gfx_types/Cargo.toml
[packlage]
name ="gfx_types"
version = "0.1.0"
workspace = "../.."
edition = "2018"
[lib]
name = "gfx_types"
path = "mod.rs"
examples/Cargo.toml currently
[packlage]
name ="gfx_types"
version = "0.1.0"
workspace = "../.."
edition = "2018"
src/gfx_types/mod.rs :
pub mod winit_state;
pub mod hal_state;
main.rs finds the types in the mod gfx_types just fine but I don't have much luck with the code in examples seeing the gfx_types mod.
main.rs
mod gfx_types;
fn main() {
let winit_state = winit_state::WinitState::default();
}
examples/build_windows.rs :
mod gfx_types;
use winit::event::Event;
use winit::event::WindowEvent;
use winit::event_loop::ControlFlow;
fn main() {
use gfx_types::winit_state;
let winit_state = winit_state::WinitState::default();
let running = true;
while running {
winit_state.events_loop.run(move |event, _, control_flow| {
*control_flow = ControlFlow::Poll;
match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => {
*control_flow = ControlFlow::Exit
},
_ => (),
}
})
}
}
Error mod gfx_types is not found. I have looked a numerous examples including gfx_hal/examples but I am not getting it. Most attempts are errors in the Example/Cargo.toml file.
I understand that the top level Cargo.toml is the root crate bu how do I bind gfx_types to the root crate namespace?
Sorry if my terminology is a little off but I am coming from other comp. languages.
Thanks,
Frank