Skip to content

Commit 5ef3416

Browse files
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 <[email protected]>
1 parent 6ff8d00 commit 5ef3416

File tree

5 files changed

+39
-31
lines changed

5 files changed

+39
-31
lines changed

objdiff-core/Cargo.toml

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -17,36 +17,36 @@ crate-type = ["cdylib", "rlib"]
1717

1818
[features]
1919
all = ["config", "dwarf", "mips", "ppc", "x86", "arm", "bindings"]
20-
any-arch = ["bimap"] # Implicit, used to check if any arch is enabled
21-
config = ["bimap", "globset", "semver", "serde_json", "serde_yaml"]
22-
dwarf = ["gimli"]
23-
mips = ["any-arch", "rabbitizer"]
24-
ppc = ["any-arch", "cwdemangle", "cwextab", "ppc750cl"]
25-
x86 = ["any-arch", "cpp_demangle", "iced-x86", "msvc-demangler"]
26-
arm = ["any-arch", "cpp_demangle", "unarm", "arm-attr"]
27-
bindings = ["serde_json", "prost", "pbjson"]
28-
wasm = ["bindings", "console_error_panic_hook", "console_log"]
20+
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
21+
config = ["dep:bimap", "dep:globset", "dep:semver", "dep:serde_json", "dep:serde_yaml", "dep:serde", "dep:filetime"]
22+
dwarf = ["dep:gimli"]
23+
mips = ["any-arch", "dep:rabbitizer"]
24+
ppc = ["any-arch", "dep:cwdemangle", "dep:cwextab", "dep:ppc750cl"]
25+
x86 = ["any-arch", "dep:cpp_demangle", "dep:iced-x86", "dep:msvc-demangler"]
26+
arm = ["any-arch", "dep:cpp_demangle", "dep:unarm", "dep:arm-attr"]
27+
bindings = ["dep:serde_json", "dep:prost", "dep:pbjson", "dep:serde", "dep:prost-build", "dep:pbjson-build"]
28+
wasm = ["bindings", "any-arch", "dep:console_error_panic_hook", "dep:console_log", "dep:wasm-bindgen", "dep:tsify-next", "dep:log"]
2929

3030
[package.metadata.docs.rs]
3131
features = ["all"]
3232

3333
[dependencies]
3434
anyhow = "1.0"
3535
bimap = { version = "0.6", features = ["serde"], optional = true }
36-
byteorder = "1.5"
37-
filetime = "0.2"
38-
flagset = "0.4"
39-
log = "0.4"
40-
memmap2 = "0.9"
41-
num-traits = "0.2"
36+
byteorder = { version = "1.5", optional = true }
37+
filetime = { version = "0.2", optional = true }
38+
flagset = { version = "0.4", optional = true }
39+
log = { version = "0.4", optional = true }
40+
memmap2 = { version = "0.9", optional = true }
41+
num-traits = { version = "0.2", optional = true }
4242
object = { version = "0.36", features = ["read_core", "std", "elf", "pe"], default-features = false }
4343
pbjson = { version = "0.7", optional = true }
4444
prost = { version = "0.13", optional = true }
45-
serde = { version = "1.0", features = ["derive"] }
46-
similar = { version = "2.6", default-features = false }
47-
strum = { version = "0.26", features = ["derive"] }
48-
wasm-bindgen = "0.2"
49-
tsify-next = { version = "0.5", default-features = false, features = ["js"] }
45+
serde = { version = "1.0", features = ["derive"], optional = true }
46+
similar = { version = "2.6", default-features = false, optional = true }
47+
strum = { version = "0.26", features = ["derive"], optional = true }
48+
wasm-bindgen = { version = "0.2", optional = true }
49+
tsify-next = { version = "0.5", default-features = false, features = ["js"], optional = true }
5050
console_log = { version = "1.0", optional = true }
5151
console_error_panic_hook = { version = "0.1", optional = true }
5252

@@ -77,5 +77,5 @@ unarm = { version = "1.6", optional = true }
7777
arm-attr = { version = "0.1", optional = true }
7878

7979
[build-dependencies]
80-
prost-build = "0.13"
81-
pbjson-build = "0.7"
80+
prost-build = { version = "0.13", optional = true }
81+
pbjson-build = { version = "0.7", optional = true }

objdiff-core/build.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
use std::path::{Path, PathBuf};
2-
31
fn main() {
2+
#[cfg(feature = "bindings")]
3+
compile_protos();
4+
}
5+
6+
#[cfg(feature = "bindings")]
7+
fn compile_protos() {
8+
use std::path::{Path, PathBuf};
49
let root = PathBuf::from(env!("CARGO_MANIFEST_DIR")).join("protos");
510
let descriptor_path = root.join("proto_descriptor.bin");
611
println!("cargo:rerun-if-changed={}", descriptor_path.display());

objdiff-core/src/diff/mod.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@ pub mod display;
2929
serde::Serialize,
3030
strum::VariantArray,
3131
strum::EnumMessage,
32-
tsify_next::Tsify,
3332
)]
33+
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
3434
pub enum X86Formatter {
3535
#[default]
3636
#[strum(message = "Intel (default)")]
@@ -54,8 +54,8 @@ pub enum X86Formatter {
5454
serde::Serialize,
5555
strum::VariantArray,
5656
strum::EnumMessage,
57-
tsify_next::Tsify,
5857
)]
58+
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
5959
pub enum MipsAbi {
6060
#[default]
6161
#[strum(message = "Auto (default)")]
@@ -79,8 +79,8 @@ pub enum MipsAbi {
7979
serde::Serialize,
8080
strum::VariantArray,
8181
strum::EnumMessage,
82-
tsify_next::Tsify,
8382
)]
83+
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
8484
pub enum MipsInstrCategory {
8585
#[default]
8686
#[strum(message = "Auto (default)")]
@@ -108,8 +108,8 @@ pub enum MipsInstrCategory {
108108
serde::Serialize,
109109
strum::VariantArray,
110110
strum::EnumMessage,
111-
tsify_next::Tsify,
112111
)]
112+
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
113113
pub enum ArmArchVersion {
114114
#[default]
115115
#[strum(message = "Auto (default)")]
@@ -133,8 +133,8 @@ pub enum ArmArchVersion {
133133
serde::Serialize,
134134
strum::VariantArray,
135135
strum::EnumMessage,
136-
tsify_next::Tsify,
137136
)]
137+
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
138138
pub enum ArmR9Usage {
139139
#[default]
140140
#[strum(
@@ -154,8 +154,9 @@ pub enum ArmR9Usage {
154154
#[inline]
155155
const fn default_true() -> bool { true }
156156

157-
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize, tsify_next::Tsify)]
158-
#[tsify(from_wasm_abi)]
157+
#[derive(Debug, Clone, Eq, PartialEq, serde::Deserialize, serde::Serialize)]
158+
#[cfg_attr(feature = "wasm", derive(tsify_next::Tsify))]
159+
#[cfg_attr(feature = "wasm", tsify(from_wasm_abi))]
159160
#[serde(default)]
160161
pub struct DiffObjConfig {
161162
pub relax_reloc_diffs: bool,

objdiff-core/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,5 @@ pub mod config;
88
pub mod diff;
99
#[cfg(feature = "any-arch")]
1010
pub mod obj;
11+
#[cfg(feature = "any-arch")]
1112
pub mod util;

objdiff-core/src/obj/read.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ fn to_obj_symbol(
6464
if obj_file.format() == BinaryFormat::Elf && symbol.scope() == SymbolScope::Linkage {
6565
flags = ObjSymbolFlagSet(flags.0 | ObjSymbolFlags::Hidden);
6666
}
67+
#[cfg(feature = "ppc")]
6768
if arch
6869
.ppc()
6970
.and_then(|a| a.extab.as_ref())

0 commit comments

Comments
 (0)