Closed Cpyte-Engine-Developer closed 1 year ago
Try enabling the hashbrown
feature via Cargo, e.g.
pyo3 = { version = "0.18", features = ["hashbrown"] }
I already tried it, but it doesn't work
We need more details then - how does your Cargo.toml
and your code look, and what error do you get from the compiler?
Code
/// some usings
thread_local!(static EVENT_LOOP: Rc<RefCell<EventLoop<()>>> = Rc::new(RefCell::new(EventLoop::new())));
#[pyclass]
#[derive(Debug)]
pub struct Game {
renderer: Renderer,
scene_graph: SceneGraph,
start_time: Instant,
}
#[pymethods]
impl Game {
#[new]
pub fn new(entity_dict: HashMap<String, Entity>) -> Self { // the trait bound hashbrown::HashMap<std::string::String, entity::Entity>: pyo3::PyClass is not satisfied ...
let event_loop = EVENT_LOOP.with(|event_loop| Rc::clone(event_loop));
let mut scene_graph = SceneGraph::new();
scene_graph.insert_many(entity_dict);
let renderer = Renderer::new(&event_loop.borrow(), &mut scene_graph, SampleCountFlags::_1);
let start_time = Instant::now();
Self {
renderer,
scene_graph,
start_time,
}
}
pub fn run(&mut self) {
EVENT_LOOP.with(|event_loop| {
event_loop
.borrow_mut()
.run_return(|event, _, control_flow| {
*control_flow = ControlFlow::Poll;
match event {
Event::WindowEvent {
event: WindowEvent::CloseRequested,
..
} => *control_flow = ControlFlow::Exit,
Event::MainEventsCleared => {
let exec_time = self.start_time.elapsed().as_secs_f32();
self.scene_graph.on_update(exec_time);
self.renderer.draw_frame(&self.scene_graph, exec_time);
}
_ => {}
}
})
})
}
}
unsafe impl Send for Game {}
Cargo.toml:
[package]
name = "cpyte-engine"
version = "0.1.0"
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[lib]
name = "cpyte_engine"
crate-type = ["cdylib"]
[dependencies]
pyo3 = { version = "0.18.3", features = ["extension-module", "hashbrown"] }
vulkanalia = { version = "0.15.0", features = ["libloading", "window"] }
anyhow = "1.0.58"
lazy_static = "1.4.0"
image = "0.24.2"
pretty_env_logger = "0.4.0"
thiserror = "1.0.31"
winit = "0.26.1"
log = "0.4.17"
itertools = "0.9.0"
collada = "0.14.0"
fbxcel-dom = "0.0.9"
gltf = "1.0.0"
tobj = "3.2.3"
hashbrown = "0.12.3"
rand = "0.8.5"
memoffset = "0.8.0"
nalgebra = "0.32.2"
numpy = { version = "0.18.0", features = ["nalgebra"] }
I think you are running into a sharp edge of Cargo's dependency resolution which often also affects users of rust-numpy
: pyo3
supports hashbrown = { version = ">= 0.9, < 0.14", optional = true }
which includes version 0.12.3
on which you depend directly. However, by default Cargo will make your project depend on two versions of hashbrown
because 0.12.3
which is ^0.12.3
which is >= 0.12.3, < 0.13
and >= 0.9, < 0.14
not exactly the same range of versions.
For example, if you look at the output of running cargo tree
on the above project, you will find:
> cargo tree
cpyte-engine v0.1.0
├── anyhow v1.0.71
├── collada v0.14.0
│ ├── RustyXML v0.3.0
│ ├── log v0.4.17
│ │ └── cfg-if v1.0.0
│ ├── quaternion v0.4.1
│ │ └── vecmath v1.0.0
│ │ └── piston-float v1.0.1
│ └── vecmath v1.0.0 (*)
[..]
├── hashbrown v0.12.3
│ └── ahash v0.7.6 (*)
[..]
├── numpy v0.18.0
│ ├── libc v0.2.143
│ ├── nalgebra v0.32.2 (*)
│ ├── ndarray v0.15.6
│ │ ├── matrixmultiply v0.3.7 (*)
│ │ ├── num-complex v0.4.3 (*)
│ │ ├── num-integer v0.1.45 (*)
│ │ ├── num-traits v0.2.15 (*)
│ │ └── rawpointer v0.2.1
│ ├── num-complex v0.4.3 (*)
│ ├── num-integer v0.1.45 (*)
│ ├── num-traits v0.2.15 (*)
│ ├── pyo3 v0.18.3
│ │ ├── cfg-if v1.0.0
│ │ ├── hashbrown v0.13.2
│ │ │ └── ahash v0.8.3
│ │ │ ├── cfg-if v1.0.0
│ │ │ ├── getrandom v0.2.9 (*)
│ │ │ └── once_cell v1.17.1
│ │ │ [build-dependencies]
│ │ │ └── version_check v0.9.4
[..]
i.e. a dependency on both hashbrown
version 0.12.3
and 0.13.2
. (And a transitive dependency on version 0.11.2
via fbxcel-dom
which further complicates dependency resolution.)
The not-so-great error message indicates that you want to take a 0.12.3
-HashMap
as an argument but pyo3
supports only 0.13.2
-HashMap
s.
I think the easiest solution would be to change your requirement to
hashbrown = "0.13"
which would remove 0.12.3
from your dependency closure and settle the direct dependency and the transitive one via pyo3
on 0.13.2
.
It is unrelated to your dependency issues, but note that
unsafe impl Send for Game {}
seems questionable. If your type really is not Send
able, then using
#[pyclass(unsendable)]
struct Game {
[..]
would seem to be sound solution.
As a further remark, running cargo-outdated
on your dependency tree indicates quite a few possibility to upgrade your dependencies thereby reducing duplicate transitive dependencies as everything settles on the newest versions:
> cargo outdated -R
Name Project Compat Latest Kind Platform
---- ------- ------ ------ ---- --------
collada 0.14.0 --- 0.15.0 Normal ---
fbxcel-dom 0.0.9 --- 0.0.10 Normal ---
hashbrown 0.12.3 --- 0.13.2 Normal ---
itertools 0.9.0 --- 0.10.5 Normal ---
tobj 3.2.5 --- 4.0.0 Normal ---
vulkanalia 0.15.0 --- 0.19.0 Normal ---
winit 0.26.1 --- 0.28.5 Normal ---
Of course, bumping those versions might require additional changes to your code base...
I tried change hashbrown version, but it doesn't work. Error is same.
May be just try re-export hashbrown types
I tried change hashbrown version, but it doesn't work. Error is same.
It did fix your example for me. Could you post the output of cargo tree
for your project here?
May be just try re-export hashbrown types
Re-exporting them is possible but one usually needs these integration exactly because the crate in question enters the dependency tree from elsewhere, hence re-exporting would only help with a few of these cases and managing the dependency tree is often necessary in any case.
cargo tree:
cpyte-engine v0.1.0 (/home/arman/Documents/engines/cpyte-engine)
├── anyhow v1.0.58
├── collada v0.14.0
│ ├── RustyXML v0.3.0
│ ├── log v0.4.17
│ │ └── cfg-if v1.0.0
│ ├── quaternion v0.4.1
│ │ └── vecmath v1.0.0
│ │ └── piston-float v1.0.1
│ └── vecmath v1.0.0 (*)
├── fbxcel-dom v0.0.9
│ ├── anyhow v1.0.58
│ ├── fbxcel v0.8.1
│ │ ├── byteorder v1.4.3
│ │ ├── indextree v4.4.0
│ │ ├── libflate v1.2.0
│ │ │ ├── adler32 v1.2.0
│ │ │ ├── crc32fast v1.3.2
│ │ │ │ └── cfg-if v1.0.0
│ │ │ └── libflate_lz77 v1.1.0
│ │ │ └── rle-decode-fast v1.0.3
│ │ ├── log v0.4.17 (*)
│ │ └── string-interner v0.14.0
│ │ ├── cfg-if v1.0.0
│ │ └── hashbrown v0.11.2
│ │ └── ahash v0.7.6
│ │ ├── getrandom v0.2.7
│ │ │ ├── cfg-if v1.0.0
│ │ │ └── libc v0.2.126
│ │ └── once_cell v1.17.1
│ │ [build-dependencies]
│ │ └── version_check v0.9.4
│ ├── log v0.4.17 (*)
│ ├── mint v0.5.9
│ ├── rgb v0.8.33
│ │ └── bytemuck v1.10.0
│ └── string-interner v0.14.0 (*)
├── gltf v1.0.0
│ ├── base64 v0.12.3
│ ├── byteorder v1.4.3
│ ├── gltf-json v1.0.0
│ │ ├── gltf-derive v1.0.0 (proc-macro)
│ │ │ ├── inflections v1.1.1
│ │ │ ├── proc-macro2 v1.0.40
│ │ │ │ └── unicode-ident v1.0.1
│ │ │ ├── quote v1.0.20
│ │ │ │ └── proc-macro2 v1.0.40 (*)
│ │ │ └── syn v1.0.98
│ │ │ ├── proc-macro2 v1.0.40 (*)
│ │ │ ├── quote v1.0.20 (*)
│ │ │ └── unicode-ident v1.0.1
│ │ ├── serde v1.0.138
│ │ ├── serde_derive v1.0.138 (proc-macro)
│ │ │ ├── proc-macro2 v1.0.40 (*)
│ │ │ ├── quote v1.0.20 (*)
│ │ │ └── syn v1.0.98 (*)
│ │ └── serde_json v1.0.85
│ │ ├── itoa v1.0.3
│ │ ├── ryu v1.0.11
│ │ └── serde v1.0.138
│ ├── image v0.23.14
│ │ ├── bytemuck v1.10.0
│ │ ├── byteorder v1.4.3
│ │ ├── color_quant v1.1.0
│ │ ├── jpeg-decoder v0.1.22
│ │ ├── num-iter v0.1.43
│ │ │ ├── num-integer v0.1.45
│ │ │ │ └── num-traits v0.2.15
│ │ │ │ [build-dependencies]
│ │ │ │ └── autocfg v1.1.0
│ │ │ │ [build-dependencies]
│ │ │ │ └── autocfg v1.1.0
│ │ │ └── num-traits v0.2.15 (*)
│ │ │ [build-dependencies]
│ │ │ └── autocfg v1.1.0
│ │ ├── num-rational v0.3.2
│ │ │ ├── num-integer v0.1.45 (*)
│ │ │ └── num-traits v0.2.15 (*)
│ │ │ [build-dependencies]
│ │ │ └── autocfg v1.1.0
│ │ ├── num-traits v0.2.15 (*)
│ │ └── png v0.16.8
│ │ ├── bitflags v1.3.2
│ │ ├── crc32fast v1.3.2 (*)
│ │ ├── deflate v0.8.6
│ │ │ ├── adler32 v1.2.0
│ │ │ └── byteorder v1.4.3
│ │ └── miniz_oxide v0.3.7
│ │ └── adler32 v1.2.0
│ └── lazy_static v1.4.0
├── hashbrown v0.13.2
│ └── ahash v0.8.3
│ ├── cfg-if v1.0.0
│ └── once_cell v1.17.1
│ [build-dependencies]
│ └── version_check v0.9.4
├── image v0.24.2
│ ├── bytemuck v1.10.0
│ ├── byteorder v1.4.3
│ ├── color_quant v1.1.0
│ ├── exr v1.4.2
│ │ ├── bit_field v0.10.1
│ │ ├── deflate v1.0.0
│ │ │ └── adler32 v1.2.0
│ │ ├── flume v0.10.13
│ │ │ ├── futures-core v0.3.21
│ │ │ ├── futures-sink v0.3.21
│ │ │ ├── nanorand v0.7.0
│ │ │ │ └── getrandom v0.2.7 (*)
│ │ │ ├── pin-project v1.0.11
│ │ │ │ └── pin-project-internal v1.0.11 (proc-macro)
│ │ │ │ ├── proc-macro2 v1.0.40 (*)
│ │ │ │ ├── quote v1.0.20 (*)
│ │ │ │ └── syn v1.0.98 (*)
│ │ │ └── spin v0.9.3
│ │ │ └── lock_api v0.4.7
│ │ │ └── scopeguard v1.1.0
│ │ │ [build-dependencies]
│ │ │ └── autocfg v1.1.0
│ │ ├── half v1.8.2
│ │ ├── inflate v0.4.5
│ │ │ └── adler32 v1.2.0
│ │ ├── lebe v0.5.1
│ │ ├── smallvec v1.9.0
│ │ └── threadpool v1.8.1
│ │ └── num_cpus v1.13.1
│ │ └── libc v0.2.126
│ ├── gif v0.11.4
│ │ ├── color_quant v1.1.0
│ │ └── weezl v0.1.6
│ ├── jpeg-decoder v0.2.6
│ │ └── rayon v1.5.3
│ │ ├── crossbeam-deque v0.8.1
│ │ │ ├── cfg-if v1.0.0
│ │ │ ├── crossbeam-epoch v0.9.9
│ │ │ │ ├── cfg-if v1.0.0
│ │ │ │ ├── crossbeam-utils v0.8.10
│ │ │ │ │ ├── cfg-if v1.0.0
│ │ │ │ │ └── once_cell v1.17.1
│ │ │ │ ├── memoffset v0.6.5
│ │ │ │ │ [build-dependencies]
│ │ │ │ │ └── autocfg v1.1.0
│ │ │ │ ├── once_cell v1.17.1
│ │ │ │ └── scopeguard v1.1.0
│ │ │ │ [build-dependencies]
│ │ │ │ └── autocfg v1.1.0
│ │ │ └── crossbeam-utils v0.8.10 (*)
│ │ ├── either v1.7.0
│ │ └── rayon-core v1.9.3
│ │ ├── crossbeam-channel v0.5.5
│ │ │ ├── cfg-if v1.0.0
│ │ │ └── crossbeam-utils v0.8.10 (*)
│ │ ├── crossbeam-deque v0.8.1 (*)
│ │ ├── crossbeam-utils v0.8.10 (*)
│ │ └── num_cpus v1.13.1 (*)
│ │ [build-dependencies]
│ │ └── autocfg v1.1.0
│ ├── num-iter v0.1.43 (*)
│ ├── num-rational v0.4.1
│ │ ├── num-integer v0.1.45 (*)
│ │ └── num-traits v0.2.15 (*)
│ │ [build-dependencies]
│ │ └── autocfg v1.1.0
│ ├── num-traits v0.2.15 (*)
│ ├── png v0.17.5
│ │ ├── bitflags v1.3.2
│ │ ├── crc32fast v1.3.2 (*)
│ │ ├── deflate v1.0.0 (*)
│ │ └── miniz_oxide v0.5.3
│ │ └── adler v1.0.2
│ ├── scoped_threadpool v0.1.9
│ └── tiff v0.7.2
│ ├── flate2 v1.0.24
│ │ ├── crc32fast v1.3.2 (*)
│ │ └── miniz_oxide v0.5.3 (*)
│ ├── jpeg-decoder v0.2.6 (*)
│ └── weezl v0.1.6
├── itertools v0.9.0
│ └── either v1.7.0
├── lazy_static v1.4.0
├── log v0.4.17 (*)
├── memoffset v0.8.0
│ [build-dependencies]
│ └── autocfg v1.1.0
├── nalgebra v0.32.2
│ ├── approx v0.5.1
│ │ └── num-traits v0.2.15 (*)
│ ├── matrixmultiply v0.3.2
│ │ └── rawpointer v0.2.1
│ ├── nalgebra-macros v0.2.0 (proc-macro)
│ │ ├── proc-macro2 v1.0.40 (*)
│ │ ├── quote v1.0.20 (*)
│ │ └── syn v1.0.98 (*)
│ ├── num-complex v0.4.3
│ │ └── num-traits v0.2.15 (*)
│ ├── num-rational v0.4.1 (*)
│ ├── num-traits v0.2.15 (*)
│ ├── simba v0.8.1
│ │ ├── approx v0.5.1 (*)
│ │ ├── num-complex v0.4.3 (*)
│ │ ├── num-traits v0.2.15 (*)
│ │ ├── paste v1.0.12 (proc-macro)
│ │ └── wide v0.7.8
│ │ ├── bytemuck v1.10.0
│ │ └── safe_arch v0.6.0
│ │ └── bytemuck v1.10.0
│ └── typenum v1.16.0
├── numpy v0.18.0
│ ├── libc v0.2.126
│ ├── nalgebra v0.32.2 (*)
│ ├── ndarray v0.15.6
│ │ ├── matrixmultiply v0.3.2 (*)
│ │ ├── num-complex v0.4.3 (*)
│ │ ├── num-integer v0.1.45 (*)
│ │ ├── num-traits v0.2.15 (*)
│ │ └── rawpointer v0.2.1
│ ├── num-complex v0.4.3 (*)
│ ├── num-integer v0.1.45 (*)
│ ├── num-traits v0.2.15 (*)
│ ├── pyo3 v0.18.3
│ │ ├── cfg-if v1.0.0
│ │ ├── hashbrown v0.12.3
│ │ │ └── ahash v0.7.6 (*)
│ │ ├── indoc v1.0.6 (proc-macro)
│ │ ├── libc v0.2.126
│ │ ├── memoffset v0.8.0 (*)
│ │ ├── parking_lot v0.12.1
│ │ │ ├── lock_api v0.4.7 (*)
│ │ │ └── parking_lot_core v0.9.3
│ │ │ ├── cfg-if v1.0.0
│ │ │ ├── libc v0.2.126
│ │ │ └── smallvec v1.9.0
│ │ ├── pyo3-ffi v0.18.3
│ │ │ └── libc v0.2.126
│ │ │ [build-dependencies]
│ │ │ └── pyo3-build-config v0.18.3
│ │ │ ├── once_cell v1.17.1
│ │ │ └── target-lexicon v0.12.4
│ │ │ [build-dependencies]
│ │ │ └── target-lexicon v0.12.4
│ │ ├── pyo3-macros v0.18.3 (proc-macro)
│ │ │ ├── proc-macro2 v1.0.40 (*)
│ │ │ ├── pyo3-macros-backend v0.18.3
│ │ │ │ ├── proc-macro2 v1.0.40 (*)
│ │ │ │ ├── quote v1.0.20 (*)
│ │ │ │ └── syn v1.0.98 (*)
│ │ │ ├── quote v1.0.20 (*)
│ │ │ └── syn v1.0.98 (*)
│ │ └── unindent v0.1.9
│ │ [build-dependencies]
│ │ └── pyo3-build-config v0.18.3 (*)
│ └── rustc-hash v1.1.0
├── pretty_env_logger v0.4.0
│ ├── env_logger v0.7.1
│ │ ├── atty v0.2.14
│ │ │ └── libc v0.2.126
│ │ ├── humantime v1.3.0
│ │ │ └── quick-error v1.2.3
│ │ ├── log v0.4.17 (*)
│ │ ├── regex v1.6.0
│ │ │ ├── aho-corasick v0.7.18
│ │ │ │ └── memchr v2.5.0
│ │ │ ├── memchr v2.5.0
│ │ │ └── regex-syntax v0.6.27
│ │ └── termcolor v1.1.3
│ └── log v0.4.17 (*)
├── pyo3 v0.18.3 (*)
├── rand v0.8.5
│ ├── libc v0.2.126
│ ├── rand_chacha v0.3.1
│ │ ├── ppv-lite86 v0.2.17
│ │ └── rand_core v0.6.4
│ │ └── getrandom v0.2.7 (*)
│ └── rand_core v0.6.4 (*)
├── thiserror v1.0.31
│ └── thiserror-impl v1.0.31 (proc-macro)
│ ├── proc-macro2 v1.0.40 (*)
│ ├── quote v1.0.20 (*)
│ └── syn v1.0.98 (*)
├── tobj v3.2.3
│ └── ahash v0.7.6 (*)
├── vulkanalia v0.15.0
│ ├── libloading v0.7.3
│ │ └── cfg-if v1.0.0
│ ├── raw-window-handle v0.3.4
│ │ ├── libc v0.2.126
│ │ └── raw-window-handle v0.4.3
│ │ └── cty v0.2.2
│ └── vulkanalia-sys v0.15.0
│ └── bitflags v1.3.2
└── winit v0.26.1
├── bitflags v1.3.2
├── instant v0.1.12
│ └── cfg-if v1.0.0
├── lazy_static v1.4.0
├── libc v0.2.126
├── log v0.4.17 (*)
├── mio v0.8.4
│ ├── libc v0.2.126
│ └── log v0.4.17 (*)
├── parking_lot v0.11.2
│ ├── instant v0.1.12 (*)
│ ├── lock_api v0.4.7 (*)
│ └── parking_lot_core v0.8.5
│ ├── cfg-if v1.0.0
│ ├── instant v0.1.12 (*)
│ ├── libc v0.2.126
│ └── smallvec v1.9.0
├── percent-encoding v2.1.0
├── raw-window-handle v0.4.3 (*)
├── smithay-client-toolkit v0.15.4
│ ├── bitflags v1.3.2
│ ├── calloop v0.9.3
│ │ ├── log v0.4.17 (*)
│ │ └── nix v0.22.3
│ │ ├── bitflags v1.3.2
│ │ ├── cfg-if v1.0.0
│ │ ├── libc v0.2.126
│ │ └── memoffset v0.6.5 (*)
│ ├── dlib v0.5.0
│ │ └── libloading v0.7.3 (*)
│ ├── lazy_static v1.4.0
│ ├── log v0.4.17 (*)
│ ├── memmap2 v0.3.1
│ │ └── libc v0.2.126
│ ├── nix v0.22.3 (*)
│ ├── wayland-client v0.29.4
│ │ ├── bitflags v1.3.2
│ │ ├── downcast-rs v1.2.0
│ │ ├── libc v0.2.126
│ │ ├── nix v0.22.3 (*)
│ │ ├── scoped-tls v1.0.0
│ │ ├── wayland-commons v0.29.4
│ │ │ ├── nix v0.22.3 (*)
│ │ │ ├── once_cell v1.17.1
│ │ │ ├── smallvec v1.9.0
│ │ │ └── wayland-sys v0.29.4
│ │ │ ├── dlib v0.5.0 (*)
│ │ │ └── lazy_static v1.4.0
│ │ │ [build-dependencies]
│ │ │ └── pkg-config v0.3.25
│ │ └── wayland-sys v0.29.4 (*)
│ │ [build-dependencies]
│ │ └── wayland-scanner v0.29.4
│ │ ├── proc-macro2 v1.0.40 (*)
│ │ ├── quote v1.0.20 (*)
│ │ └── xml-rs v0.8.4
│ ├── wayland-cursor v0.29.4
│ │ ├── nix v0.22.3 (*)
│ │ ├── wayland-client v0.29.4 (*)
│ │ └── xcursor v0.3.4
│ │ └── nom v7.1.1
│ │ ├── memchr v2.5.0
│ │ └── minimal-lexical v0.2.1
│ └── wayland-protocols v0.29.4
│ ├── bitflags v1.3.2
│ ├── wayland-client v0.29.4 (*)
│ └── wayland-commons v0.29.4 (*)
│ [build-dependencies]
│ └── wayland-scanner v0.29.4 (*)
│ [build-dependencies]
│ └── pkg-config v0.3.25
├── wayland-client v0.29.4 (*)
├── wayland-protocols v0.29.4 (*)
└── x11-dl v2.19.1
├── lazy_static v1.4.0
└── libc v0.2.126
[build-dependencies]
└── pkg-config v0.3.25
Somehow you now ended up with the transitive dependency via pyo3
resolving to 0.12.3
:
[..]
│ ├── pyo3 v0.18.3
│ │ ├── cfg-if v1.0.0
│ │ ├── hashbrown v0.12.3
│ │ │ └── ahash v0.7.6 (*)
[..]
Did you run cargo update --package .. --precise
on the project? Could you just for the sake of it retrying after deleting your Cargo.lock
file?
No, I don't run cargo update --package .. --precise
I tried to delete Cargo.lock and run maturin develop
. And it works. Thanks
Hello, please add capability create methods with hashbrown types as parameters. It make code easier.