Skip to content

Add more build-info functions to c-api - #8216

Merged
youknowone merged 4 commits into
RustPython:mainfrom
bschoenmaeckers:c-api-buildinfo
Jul 9, 2026
Merged

Add more build-info functions to c-api#8216
youknowone merged 4 commits into
RustPython:mainfrom
bschoenmaeckers:c-api-buildinfo

Conversation

@bschoenmaeckers

@bschoenmaeckers bschoenmaeckers commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • New Features
    • Added runtime access to system metadata (build, compiler, copyright, platform) via standard C-ABI entry points.
    • Exposed additional sys metadata constants with consistent string handling.
  • Bug Fixes
    • Improved conversion of C strings into Python str to better represent system metadata reliably.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Note

Reviews paused

It looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Publicizes build metadata in sys, adds &CStr conversion support, and exports four C-ABI getters for those values.

Changes

Build metadata C API exposure

Layer / File(s) Summary
Publicize sys module metadata
crates/vm/src/stdlib/sys.rs
Re-exports build and version metadata at module scope, makes the inner sys constants public, changes COPYRIGHT and PLATFORM to &CStr, and updates sysconfigdata_name() to use to_string_lossy() on PLATFORM.
Add CStr string conversion
crates/vm/src/builtins/str.rs
Imports CStr and adds a ToPyObject implementation that converts &CStr values into Python strings with to_str().
Add extern C metadata getters
crates/capi/src/pylifecycle.rs
Imports rustpython_vm::stdlib::sys and adds Py_GetBuildInfo, Py_GetCompiler, Py_GetCopyright, and Py_GetPlatform as exported extern C functions that return the matching metadata pointers.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

Suggested reviewers: ShaharNaveh, youknowone

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: adding new build-info-related C-API functions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@crates/capi/src/pylifecycle.rs`:
- Around line 84-115: The four getter functions are duplicated and should be
refactored into a macro-based helper. Extract the shared CString/LazyLock/as_ptr
logic into a single reusable macro or helper and parameterize only the differing
sys constant, static identifier, and panic text for Py_GetBuildInfo,
Py_GetCompiler, Py_GetCopyright, and Py_GetPlatform. Keep the public extern "C"
function names unchanged and apply the same pattern consistently if
Py_GetVersion or similar getters in pylifecycle.rs use the same structure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

Run ID: d582c5db-c613-42ea-a2b7-5f7d60708967

📥 Commits

Reviewing files that changed from the base of the PR and between 3f9d80b and 44e1a4c.

📒 Files selected for processing (2)
  • crates/capi/src/pylifecycle.rs
  • crates/vm/src/stdlib/sys.rs

Comment thread crates/capi/src/pylifecycle.rs
Comment thread crates/vm/src/stdlib/sys.rs Outdated
@bschoenmaeckers
bschoenmaeckers force-pushed the c-api-buildinfo branch 2 times, most recently from 2670157 to 141d0f4 Compare July 7, 2026 09:05
Comment thread crates/vm/src/builtins/str.rs Outdated
Comment thread crates/vm/src/stdlib/sys.rs Outdated

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

👍 Thanks!

@youknowone
youknowone merged commit adb7d8a into RustPython:main Jul 9, 2026
26 checks passed
@bschoenmaeckers
bschoenmaeckers deleted the c-api-buildinfo branch July 9, 2026 06:35
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.

2 participants