Skip to content

Add cargo features for arch support #180

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
May 24, 2025
Merged

Add cargo features for arch support #180

merged 7 commits into from
May 24, 2025

Conversation

jiegec
Copy link
Contributor

@jiegec jiegec commented May 24, 2025

This pr implements the first and second approach for issue #61, which conditionally compiles capstone arch support based on cargo feature flags and enables arch modules on Rust side.

It reduces file size greatly:

  • cargo build: cstool is 31MB in size
  • cargo build --no-default-features --features full,arch_x86: cstool is 19MB in size

It disable Rust arch modules if feature flag is not provided. Creating capstone instance with disabled archs will fail with errors.

jiegec added 2 commits May 24, 2025 10:29
All archs enabled: 43MB.
No archs enabled: 18MB.
Only x86 arch enabled: 25MB.
@jiegec jiegec requested a review from Copilot May 24, 2025 02:47
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds cargo feature flags for selective architecture support in Capstone, reducing binary size when non-essential architectures are disabled. Key changes include updating Cargo.toml files to include new arch-specific feature flags, modifying build.rs to conditionally define arch macros, and updating test configuration to gate tests based on specific arch features.

Reviewed Changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
cstool/Cargo.toml Updated capstone dependency to disable default features and added arch flags.
capstone-sys/build.rs Introduced a macro to conditionally define architecture flags based on features.
capstone-sys/Cargo.toml Added default inclusion of support_all_archs and arch-specific features.
capstone-rs/src/test.rs Adjusted test configuration to require explicit arch flags for certain tests.
capstone-rs/src/arch/m68k.rs Modified test configuration for m68k to also require the arch_m68k flag.
capstone-rs/Cargo.toml Extended default features to include support_all_archs and mapped arch flags.
.github/workflows/main.yml Added a workflow to run tests with only a limited set of arch features enabled.

@jiegec jiegec linked an issue May 24, 2025 that may be closed by this pull request
@jiegec jiegec merged commit be13cf4 into master May 24, 2025
29 checks passed
@jiegec jiegec deleted the arch-features branch May 24, 2025 03:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

add cargo features for architecture-specific support
1 participant