capstone-rust / capstone-rs

high-level Capstone system bindings for Rust
217 stars 75 forks source link

add cargo features for architecture-specific support #61

Open froydnj opened 5 years ago

froydnj commented 5 years ago

It would be splendid if capstone exposed Cargo features such that you could only compile support in for specific architecture(s)--usually one, but maybe multiple architectures depending on circumstances. I realize this would probably complicate a few things (e.g. using pregenerated bindings could only be done under certain circumstances), but it'd be nice for building things that are guaranteed to only target architecture X and you don't care about disassembling things for not-X.

How complicated do you think this would be to add?

/cc @lars-t-hansen

tmfink commented 5 years ago

@froydnj Thanks for your bug report!

I've considered adding this feature, but, depending on the implementation, it's a lot of work. We could have a feature support_all_archs that depends on each arch's feature. By default, the support_all_archs could be enabled.

From there, there are two approaches

  1. Compile Capstone with only the archs specified.
    • Could use the pre-generated bindings.
    • We would have unused Rust code, but at least the Capstone C library would be much smaller, which would cut down on the final binary size.
  2. Same as 1, but also add #[cfg(...)] attributes capstone-rs to conditionally compile Rust code for each architecture.
    • This would additionally reduce Rust compile times
    • This is a lot more work, especially with macros that generate a lot of the architecture-specific code