Improve dependency gating on objdiff-core (#126)

* Reduce dependencies for no features

* Add missing deps to every feature

* Add missing `dep:`s

* Gate even more deps behind features

Removes dependency on tsify-next / wasm-bindgen unless
compiling with the wasm feature by using `#[cfg_attr]`

* Fix wasm

---------

Co-authored-by: Luke Street <luke@street.dev>
This commit is contained in:
Anghelo Carvajal 2024-10-20 23:04:29 -03:00 committed by GitHub
parent 6ff8d002f7
commit 5ef3416457
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 39 additions and 31 deletions

View File

@ -17,15 +17,15 @@ crate-type = ["cdylib", "rlib"]
[features] [features]
all = ["config", "dwarf", "mips", "ppc", "x86", "arm", "bindings"] all = ["config", "dwarf", "mips", "ppc", "x86", "arm", "bindings"]
any-arch = ["bimap"] # Implicit, used to check if any arch is enabled any-arch = ["config", "dep:bimap", "dep:strum", "dep:similar", "dep:flagset", "dep:log", "dep:memmap2", "dep:byteorder", "dep:num-traits"] # Implicit, used to check if any arch is enabled
config = ["bimap", "globset", "semver", "serde_json", "serde_yaml"] config = ["dep:bimap", "dep:globset", "dep:semver", "dep:serde_json", "dep:serde_yaml", "dep:serde", "dep:filetime"]
dwarf = ["gimli"] dwarf = ["dep:gimli"]
mips = ["any-arch", "rabbitizer"] mips = ["any-arch", "dep:rabbitizer"]
ppc = ["any-arch", "cwdemangle", "cwextab", "ppc750cl"] ppc = ["any-arch", "dep:cwdemangle", "dep:cwextab", "dep:ppc750cl"]
x86 = ["any-arch", "cpp_demangle", "iced-x86", "msvc-demangler"] x86 = ["any-arch", "dep:cpp_demangle", "dep:iced-x86", "dep:msvc-demangler"]
arm = ["any-arch", "cpp_demangle", "unarm", "arm-attr"] arm = ["any-arch", "dep:cpp_demangle", "dep:unarm", "dep:arm-attr"]
bindings = ["serde_json", "prost", "pbjson"] bindings = ["dep:serde_json", "dep:prost", "dep:pbjson", "dep:serde", "dep:prost-build", "dep:pbjson-build"]
wasm = ["bindings", "console_error_panic_hook", "console_log"] wasm = ["bindings", "any-arch", "dep:console_error_panic_hook", "dep:console_log", "dep:wasm-bindgen", "dep:tsify-next", "dep:log"]
[package.metadata.docs.rs] [package.metadata.docs.rs]
features = ["all"] features = ["all"]
@ -33,20 +33,20 @@ features = ["all"]
[dependencies] [dependencies]
anyhow = "1.0" anyhow = "1.0"
bimap = { version = "0.6", features = ["serde"], optional = true } bimap = { version = "0.6", features = ["serde"], optional = true }
byteorder = "1.5" byteorder = { version = "1.5", optional = true }
filetime = "0.2" filetime = { version = "0.2", optional = true }
flagset = "0.4" flagset = { version = "0.4", optional = true }
log = "0.4" log = { version = "0.4", optional = true }
memmap2 = "0.9" memmap2 = { version = "0.9", optional = true }
num-traits = "0.2" num-traits = { version = "0.2", optional = true }
object = { version = "0.36", features = ["read_core", "std", "elf", "pe"], default-features = false } object = { version = "0.36", features = ["read_core", "std", "elf", "pe"], default-features = false }
pbjson = { version = "0.7", optional = true } pbjson = { version = "0.7", optional = true }
prost = { version = "0.13", optional = true } prost = { version = "0.13", optional = true }
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"], optional = true }
similar = { version = "2.6", default-features = false } similar = { version = "2.6", default-features = false, optional = true }
strum = { version = "0.26", features = ["derive"] } strum = { version = "0.26", features = ["derive"], optional = true }
wasm-bindgen = "0.2" wasm-bindgen = { version = "0.2", optional = true }
tsify-next = { version = "0.5", default-features = false, features = ["js"] } tsify-next = { version = "0.5", default-features = false, features = ["js"], optional = true }
console_log = { version = "1.0", optional = true } console_log = { version = "1.0", optional = true }
console_error_panic_hook = { version = "0.1", optional = true } console_error_panic_hook = { version = "0.1", optional = true }
@ -77,5 +77,5 @@ unarm = { version = "1.6", optional = true }
arm-attr = { version = "0.1", optional = true } arm-attr = { version = "0.1", optional = true }
[build-dependencies] [build-dependencies]
prost-build = "0.13" prost-build = { version = "0.13", optional = true }
pbjson-build = "0.7" pbjson-build = { version = "0.7", optional = true }

View File

@ -1,6 +1,11 @@
use std::path::{Path, PathBuf};
fn main() { fn main() {
#[cfg(feature = "bindings")]
compile_protos();
}
#[cfg(feature = "bindings")]
fn compile_protos() {
use std::path::{Path, PathBuf};
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("protos"); let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("protos");
let descriptor_path = root.join("proto_descriptor.bin"); let descriptor_path = root.join("proto_descriptor.bin");
println!("cargo:rerun-if-changed={}", descriptor_path.display()); println!("cargo:rerun-if-changed={}", descriptor_path.display());

View File

@ -29,8 +29,8 @@ pub mod display;
serde::Serialize, serde::Serialize,
strum::VariantArray, strum::VariantArray,
strum::EnumMessage, strum::EnumMessage,
tsify_next::Tsify,
)] )]
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
pub enum X86Formatter { pub enum X86Formatter {
#[default] #[default]
#[strum(message = "Intel (default)")] #[strum(message = "Intel (default)")]
@ -54,8 +54,8 @@ pub enum X86Formatter {
serde::Serialize, serde::Serialize,
strum::VariantArray, strum::VariantArray,
strum::EnumMessage, strum::EnumMessage,
tsify_next::Tsify,
)] )]
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
pub enum MipsAbi { pub enum MipsAbi {
#[default] #[default]
#[strum(message = "Auto (default)")] #[strum(message = "Auto (default)")]
@ -79,8 +79,8 @@ pub enum MipsAbi {
serde::Serialize, serde::Serialize,
strum::VariantArray, strum::VariantArray,
strum::EnumMessage, strum::EnumMessage,
tsify_next::Tsify,
)] )]
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
pub enum MipsInstrCategory { pub enum MipsInstrCategory {
#[default] #[default]
#[strum(message = "Auto (default)")] #[strum(message = "Auto (default)")]
@ -108,8 +108,8 @@ pub enum MipsInstrCategory {
serde::Serialize, serde::Serialize,
strum::VariantArray, strum::VariantArray,
strum::EnumMessage, strum::EnumMessage,
tsify_next::Tsify,
)] )]
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
pub enum ArmArchVersion { pub enum ArmArchVersion {
#[default] #[default]
#[strum(message = "Auto (default)")] #[strum(message = "Auto (default)")]
@ -133,8 +133,8 @@ pub enum ArmArchVersion {
serde::Serialize, serde::Serialize,
strum::VariantArray, strum::VariantArray,
strum::EnumMessage, strum::EnumMessage,
tsify_next::Tsify,
)] )]
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
pub enum ArmR9Usage { pub enum ArmR9Usage {
#[default] #[default]
#[strum( #[strum(
@ -154,8 +154,9 @@ pub enum ArmR9Usage {
#[inline] #[inline]
const fn default_true() -> bool { true } const fn default_true() -> bool { true }
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, tsify_next::Tsify)] #[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
#[tsify(from_wasm_abi)] #[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
#[cfg_attr(feature = "wasm", tsify(from_wasm_abi))]
#[serde(default)] #[serde(default)]
pub struct DiffObjConfig { pub struct DiffObjConfig {
pub relax_reloc_diffs: bool, pub relax_reloc_diffs: bool,

View File

@ -8,4 +8,5 @@ pub mod config;
pub mod diff; pub mod diff;
#[cfg(feature = "any-arch")] #[cfg(feature = "any-arch")]
pub mod obj; pub mod obj;
#[cfg(feature = "any-arch")]
pub mod util; pub mod util;

View File

@ -64,6 +64,7 @@ fn to_obj_symbol(
if obj_file.format() == BinaryFormat::Elf && symbol.scope() == SymbolScope::Linkage { if obj_file.format() == BinaryFormat::Elf && symbol.scope() == SymbolScope::Linkage {
flags = ObjSymbolFlagSet(flags.0 | ObjSymbolFlags::Hidden); flags = ObjSymbolFlagSet(flags.0 | ObjSymbolFlags::Hidden);
} }
#[cfg(feature = "ppc")]
if arch if arch
.ppc() .ppc()
.and_then(|a| a.extab.as_ref()) .and_then(|a| a.extab.as_ref())