emoon / rust_minifb

Cross platfrom window and framebuffer crate for Rust
MIT License
1.01k stars 97 forks source link

Reduce dependencies #237

Closed emoon closed 2 years ago

emoon commented 3 years ago

Currently when building for Linux one get a dependency list like this

  Compiling libc v0.2.74
   Compiling cfg-if v0.1.10
   Compiling proc-macro2 v1.0.19
   Compiling unicode-xid v0.2.1
   Compiling memchr v2.3.3
   Compiling pkg-config v0.3.18
   Compiling bitflags v1.2.1
   Compiling version_check v0.9.2
   Compiling lazy_static v1.4.0
   Compiling glob v0.3.0
   Compiling log v0.4.13
   Compiling xml-rs v0.8.3
   Compiling unicode-width v0.1.8
   Compiling regex-syntax v0.6.22
   Compiling cfg-if v1.0.0
   Compiling termcolor v1.1.2
   Compiling humantime v2.1.0
   Compiling bindgen v0.56.0
   Compiling strsim v0.8.0
   Compiling nix v0.17.0
   Compiling getrandom v0.1.14
   Compiling ansi_term v0.11.0
   Compiling vec_map v0.8.2
   Compiling rustc-hash v1.1.0
   Compiling peeking_take_while v0.1.2
   Compiling void v1.0.2
   Compiling lazycell v1.3.0
   Compiling shlex v0.1.1
   Compiling smallvec v1.4.2
   Compiling once_cell v1.4.0
   Compiling ppv-lite86 v0.2.8
   Compiling maybe-uninit v2.0.0
   Compiling byteorder v1.3.4
   Compiling downcast-rs v1.2.0
   Compiling cc v1.0.58
   Compiling crc32fast v1.2.0
   Compiling adler32 v1.2.0
   Compiling remove_dir_all v0.5.3
   Compiling libloading v0.6.7
   Compiling textwrap v0.11.0
   Compiling thread_local v1.1.0
   Compiling miniz_oxide v0.3.7
   Compiling nom v5.1.2
   Compiling clang-sys v1.0.3
   Compiling wayland-sys v0.27.0
   Compiling x11-dl v2.18.5
   Compiling aho-corasick v0.7.15
   Compiling deflate v0.8.6
   Compiling quote v1.0.7
   Compiling minifb v0.19.2 (/home/emoon/code/projects/rust_minifb)
   Compiling wayland-scanner v0.27.0
   Compiling png v0.16.7
   Compiling atty v0.2.14
   Compiling which v3.1.1
   Compiling raw-window-handle v0.3.3
   Compiling clap v2.33.3
   Compiling rand_core v0.5.1
   Compiling wayland-client v0.27.0
   Compiling wayland-protocols v0.27.0
   Compiling rand_chacha v0.2.2
   Compiling regex v1.4.3
   Compiling cexpr v0.4.0
   Compiling xcursor v0.3.2
   Compiling rand v0.7.3
   Compiling tempfile v3.1.0
   Compiling env_logger v0.8.2
   Compiling wayland-commons v0.27.0
   Compiling wayland-cursor v0.27.0
   Compiling xkbcommon-sys v0.7.5
   Compiling xkb v0.2.1

Which is WAY too much stuff being dragged in... like clang-sys This needs to be fixed

rspencer01 commented 3 years ago

The command cargo tree gives me

minifb v0.19.3 (/.../rust_minifb)
├── raw-window-handle v0.3.3
│   └── libc v0.2.95
├── tempfile v3.2.0
│   ├── cfg-if v1.0.0
│   ├── libc v0.2.95
│   ├── rand v0.8.3
│   │   ├── libc v0.2.95
│   │   ├── rand_chacha v0.3.0
│   │   │   ├── ppv-lite86 v0.2.10
│   │   │   └── rand_core v0.6.2
│   │   │       └── getrandom v0.2.3
│   │   │           ├── cfg-if v1.0.0
│   │   │           └── libc v0.2.95
│   │   └── rand_core v0.6.2 (*)
│   └── remove_dir_all v0.5.3
├── wayland-client v0.28.5
│   ├── bitflags v1.2.1
│   ├── downcast-rs v1.2.0
│   ├── libc v0.2.95
│   ├── nix v0.20.0
│   │   ├── bitflags v1.2.1
│   │   ├── cfg-if v1.0.0
│   │   └── libc v0.2.95
│   ├── wayland-commons v0.28.5
│   │   ├── nix v0.20.0 (*)
│   │   ├── once_cell v1.7.2
│   │   ├── smallvec v1.6.1
│   │   └── wayland-sys v0.28.5
│   │       [build-dependencies]
│   │       └── pkg-config v0.3.19
│   └── wayland-sys v0.28.5 (*)
│   [build-dependencies]
│   └── wayland-scanner v0.28.5
│       ├── proc-macro2 v1.0.27
│       │   └── unicode-xid v0.2.2
│       ├── quote v1.0.9
│       │   └── proc-macro2 v1.0.27 (*)
│       └── xml-rs v0.8.3
├── wayland-cursor v0.28.5
│   ├── nix v0.20.0 (*)
│   ├── wayland-client v0.28.5 (*)
│   └── xcursor v0.3.3
│       └── nom v6.1.2
│           └── memchr v2.4.0
│           [build-dependencies]
│           └── version_check v0.9.3
├── wayland-protocols v0.28.5
│   ├── bitflags v1.2.1
│   ├── wayland-client v0.28.5 (*)
│   └── wayland-commons v0.28.5 (*)
│   [build-dependencies]
│   └── wayland-scanner v0.28.5 (*)
├── x11-dl v2.18.5
│   ├── lazy_static v1.4.0
│   ├── libc v0.2.95
│   └── maybe-uninit v2.0.0
│   [build-dependencies]
│   └── pkg-config v0.3.19
├── xkb v0.2.1
│   ├── bitflags v1.2.1
│   ├── libc v0.2.95
│   └── xkbcommon-sys v0.7.5
│       └── libc v0.2.95
│       [build-dependencies]
│       ├── bindgen v0.56.0
│       │   ├── bitflags v1.2.1
│       │   ├── cexpr v0.4.0
│       │   │   └── nom v5.1.2
│       │   │       └── memchr v2.4.0
│       │   │       [build-dependencies]
│       │   │       └── version_check v0.9.3
│       │   ├── clang-sys v1.2.0
│       │   │   ├── glob v0.3.0
│       │   │   ├── libc v0.2.95
│       │   │   └── libloading v0.7.0
│       │   │       └── cfg-if v1.0.0
│       │   │   [build-dependencies]
│       │   │   └── glob v0.3.0
│       │   ├── clap v2.33.3
│       │   │   ├── ansi_term v0.11.0
│       │   │   ├── atty v0.2.14
│       │   │   │   └── libc v0.2.95
│       │   │   ├── bitflags v1.2.1
│       │   │   ├── strsim v0.8.0
│       │   │   ├── textwrap v0.11.0
│       │   │   │   └── unicode-width v0.1.8
│       │   │   ├── unicode-width v0.1.8
│       │   │   └── vec_map v0.8.2
│       │   ├── env_logger v0.8.3
│       │   │   ├── atty v0.2.14 (*)
│       │   │   ├── humantime v2.1.0
│       │   │   ├── log v0.4.14
│       │   │   │   └── cfg-if v1.0.0
│       │   │   ├── regex v1.5.4
│       │   │   │   ├── aho-corasick v0.7.18
│       │   │   │   │   └── memchr v2.4.0
│       │   │   │   ├── memchr v2.4.0
│       │   │   │   └── regex-syntax v0.6.25
│       │   │   └── termcolor v1.1.2
│       │   ├── lazy_static v1.4.0
│       │   ├── lazycell v1.3.0
│       │   ├── log v0.4.14 (*)
│       │   ├── peeking_take_while v0.1.2
│       │   ├── proc-macro2 v1.0.27 (*)
│       │   ├── quote v1.0.9 (*)
│       │   ├── regex v1.5.4 (*)
│       │   ├── rustc-hash v1.1.0
│       │   ├── shlex v0.1.1
│       │   └── which v3.1.1
│       │       └── libc v0.2.95
│       └── pkg-config v0.3.19
└── xkbcommon-sys v0.7.5 (*)
[build-dependencies]
└── cc v1.0.68
[dev-dependencies]
└── png v0.16.8
    ├── bitflags v1.2.1
    ├── crc32fast v1.2.1
    │   └── cfg-if v1.0.0
    ├── deflate v0.8.6
    │   ├── adler32 v1.2.0
    │   └── byteorder v1.4.3
    └── miniz_oxide v0.3.7
        └── adler32 v1.2.0

from which I'd infer that the dependency on the crate xkb is a large culprit.

emoon commented 3 years ago

Yeah that looks to be the case. I think many of these extra dependencies were due to Wayland support.

Would be good to investigae what is actually needed in the xkb crate and see if perhaps it can be moved out or so

rspencer01 commented 3 years ago

I took a brief look yesterday at the x11 code. The only usage under that feature flag is to convert a key to a unicode representation here: https://github.com/emoon/rust_minifb/blob/1a12653fc216875f2b8044e80978061ed792f8de/src/os/posix/x11.rs#L1018 I didn't look carefully but I believe its a bit more involved with wayland.

emoon commented 3 years ago

Yeah. I think wayland is the biggest one here. I haven't really done any of the work on wayland so I'm not sure exactly what is required there.

emoon commented 3 years ago

Maybe @nifker has any idea about xkb

nyovaya commented 3 years ago

Im pretty sure you can use the xkb stuff from x11 but I dont its a good idea to rely on x11 stuff for wayland

emoon commented 3 years ago

I investigated a bit more and it's a bit weird xkbcommon-sys v0.7.5 isn't pushed to github and it seem the bindgen dependency was added in that version (the current version on github is 0.7.4) and the author doesn't seem to respond :(

rspencer01 commented 3 years ago

Indeed - I think getting rid of bindgen in particular would reduce the load somewhat (I also often see intermediates being recompiled in my project which I think is due to bindgen rerunning).

For sure, wayland is going to be the bigger pain, but I took a look at x11 code and it seems that the call is simply to exactly the functionality removed by #184 in key_mapping.rs (i.e. key_mapping.rs contained a rust version of the function called by the c library xkb). A hacky solution for x11 is to reinstate that.

However, this is perhaps a loss of generality and doesn't help with wayland, which I think is more complicated.

emoon commented 3 years ago

I would be fine with some code duplication inside the crate to reduce the dependencies a bit.

Looking at the list above getting rid of xkb and replacing it with an alternative crate / dupe code would get rid of the larges chunk. The other dependencies looks quite reasonable except I'm not sure about tempfile and what that is being used for.

I also don't know about the wayland ones, but it seems pretty reasonable to me at least.

rspencer01 commented 2 years ago

I'm still thinking about this in the back of my head and it is on my long list of todo's. Here's a graphic to show what the current state of affairs looks like:

https://crates.live/minifb/0.19.3

emoon commented 2 years ago

Great! Yeah, it would be great to clean this up.

Cool tool. In that case it seems that the majority of dependencies comes from orbclient

vmedea commented 2 years ago

293 address some of these:

We discussed replacing our use of xkb with rust code but that turns out to a very deep rabbit hole.

emoon commented 2 years ago

The worst offender(s) are gone now so closing