8000 Gate the C symbols behind the feature capi by rlaisqls · Pull Request #5 · RustPython/mpdecimal · GitHub
[go: up one dir, main page]

Skip to content
8000

Gate the C symbols behind the feature capi - #5

Open
rlaisqls wants to merge 3 commits into
RustPython:mainfrom
rlaisqls:capi-feature
Open

rlaisqls wants to merge 3 commits into
RustPython:mainfrom
rlaisqls:capi-feature

Conversation

@rlaisqls
Copy link
Copy Markdown
Contributor

Description

Refs #2. Prepares for #3.

The root crate exported the C symbols of libmpdec unconditionally (480 #[no_mangle] items, including internal functions) and was always built as a staticlib. With this PR, the crate exports no C symbols by default. The upstream C tests
enable the new feature capi.

This also makes the differential fuzz tests of #3 simpler: the crate can be linked into the same binary as C libmpdec without renaming either side's symbols.

Commits

  1. Rename the root crate to mpdecimal-core. The name mpdecimal is left for a Rust-friendly API crate on top of it, as suggested in On splitting into core and sys crates by purpose #2.
  2. Build the staticlib for the C tests with cargo rustc. Removes crate-type = ["staticlib", "rlib"]. c2rust/test-short.sh and c2rust/test-long.sh build the root crate with cargo rustc --lib --crate-type staticlib. crate-type
    cannot depend on a feature, and this way no separate crate is needed for the staticlib.
  3. Gate the C symbols behind the feature capi. Every #[no_mangle] in src/ becomes #[cfg_attr(feature = "capi", no_mangle)]. test-hooks implies capi.

extern "C" and #[repr(C)] are kept, since the crate is a 1:1 port of the C code and the C tests rely on its layouts. Only the C names exposed to the linker are behind capi.

src/ is now edited by hand, so c2rust/install.py refuses to overwrite it (its existing check against c2rust/out/installed.sha256). The per-target translations in c2rust/out are unchanged.

Verification (macOS aarch64, uint128)

  • mpd_* symbols in the staticlib: 0 without capi, 360 with capi.
  • Short tests (runshort.sh, runshort_alloc.sh) pass with CRATE=root, with and without FEATURES=test-hooks.
  • Long tests that use internal symbols (test_transpose, ppro_mulmod) pass.

@coderabbitai
coderabbitai Bot commented Oct 27, 2026
Copy link
Copy Markdown

Important

  • 🔍 Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: defaults
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 033680ef-7fbe-4379-87dc-46e022b84e63
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

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.

1 participant

0