◐ Shell
reader mode source ↗
Skip to content

Update libc to 0.2.182#7247

Merged
youknowone merged 2 commits into
RustPython:mainfrom
ShaharNaveh:update-libc-0-2-182
Mar 4, 2026
Merged

Update libc to 0.2.182#7247
youknowone merged 2 commits into
RustPython:mainfrom
ShaharNaveh:update-libc-0-2-182

Conversation

@ShaharNaveh

@ShaharNaveh ShaharNaveh commented Feb 27, 2026

Copy link
Copy Markdown
Contributor

Summary by CodeRabbit

  • Chores
    • Bumped libc dependency to 0.2.182.
    • Expanded platform-specific POSIX constant coverage across many OS targets.
  • New Features
    • Replaced ad-hoc constant extraction with a data-driven generation pipeline that derives libc version at runtime, fetches upstream sources, and formats output.
  • Stability
    • Improved error reporting and output formatting for the platform-constant generation process.

@coderabbitai

coderabbitai Bot commented Feb 27, 2026

Copy link
Copy Markdown
Contributor
📝 Walkthrough

Walkthrough

Bumps the libc dependency, reorganizes and expands per-target libc symbol imports and cfg gating in the POSIX module, and replaces the hardcoded const-generation script with a TOML-driven, multi-target extraction pipeline that fetches upstream docs and formats generated Rust.

Changes

Cohort / File(s) Summary
Dependency Update
Cargo.toml
Bumped libc from 0.2.1800.2.182.
POSIX libc imports & cfgs
crates/vm/src/stdlib/posix.rs
Reorganized and split libc symbol imports into finer-grained #[cfg(...)] blocks, added/relocated many OS-specific constants (scheduling, file flags, spawn items), introduced FreeBSD SF_* exposures. No public API signatures changed.
Const-generation script
scripts/libc_posix.py
Replaced ad-hoc extraction with a data-driven pipeline: reads Cargo.toml for libc version, fetches upstream docs per-target, extracts constants, groups by cfgs, integrates extras, formats output with rustfmt. Added dataclasses Cfg, Target, helper functions (rustfmt, extract_consts, consts_from_url) and TARGETS configuration.

Sequence Diagram(s)

sequenceDiagram
    participant Dev as Developer / CI
    participant Script as scripts/libc_posix.py
    participant Cargo as Cargo.toml
    participant Remote as Upstream Docs
    participant Rustfmt as rustfmt
    participant Out as Generated Rust (posix.rs)

    Dev->>Script: invoke generation
    Script->>Cargo: read libc version from Cargo.toml
    Script->>Remote: fetch source pages for each TARGET
    Remote-->>Script: return HTML/text
    Script->>Script: extract constants, group by Cfg/Target, attach extras
    Script->>Rustfmt: format generated Rust code
    Rustfmt-->>Script: return formatted code
    Script->>Out: write cfg-tagged Rust blocks into posix.rs
    Script-->>Dev: exit (success or error)
Loading

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • youknowone

Poem

🐇 I nibble TOML, hop to fetch,
constants gathered, matched to each fetch.
Rustfmt tidies every cfg line,
flags aligned, platforms fine.
A joyful hop — generation's fresh! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Update libc to 0.2.182' directly aligns with the main change—a dependency version bump of libc from 0.2.180 to 0.2.182. While the PR includes substantial refactoring of the posix.rs file and the libc_posix.py script, the title focuses on the primary motivating change (the version update), which is appropriate for a concise PR title.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

@github-actions

Copy link
Copy Markdown
Contributor

Code has been automatically formatted

The code in this PR has been formatted using:

  • ruff format
    Please pull the latest changes before pushing again:
git pull origin update-libc-0-2-182

@ShaharNaveh ShaharNaveh marked this pull request as ready for review February 28, 2026 14:34

@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.

Hide comment

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@crates/vm/src/stdlib/posix.rs`:
- Around line 64-66: The cfg currently gating SCHED_DEADLINE and SCHED_NORMAL is
too narrow (only Android); change the attribute on the use/import of
SCHED_DEADLINE and SCHED_NORMAL in posix.rs from #[cfg(target_os = "android")]
to #[cfg(any(target_os = "android", target_os = "linux"))] so these constants
are available on Linux as well (match the pattern used for
SCHED_BATCH/SCHED_IDLE/SCHED_RESET_ON_FORK); update the cfg on the import that
references SCHED_DEADLINE and SCHED_NORMAL accordingly.

ℹ️ Review info

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 123b629 and 5248d83.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (2)
  • Cargo.toml
  • crates/vm/src/stdlib/posix.rs
🚧 Files skipped from review as they are similar to previous changes (1)
  • Cargo.toml

@ShaharNaveh ShaharNaveh force-pushed the update-libc-0-2-182 branch from 8f895d3 to 2979d36 Compare March 3, 2026 15:38

@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.

Hide comment

Actionable comments posted: 1

🧹 Nitpick comments (1)
scripts/libc_posix.py (1)

20-20: Use explicit UTF-8 when reading Cargo.toml.

Line 20 currently relies on platform default encoding; specifying UTF-8 avoids locale-dependent failures.

Proposed fix
-CARGO_TOML = tomllib.loads(CARGO_TOML_FILE.read_text())
+CARGO_TOML = tomllib.loads(CARGO_TOML_FILE.read_text(encoding="utf-8"))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/libc_posix.py` at line 20, The code reads Cargo.toml using
CARGO_TOML_FILE.read_text() which uses the platform default encoding; change the
read to explicitly use UTF-8 so parsing is deterministic by calling read_text
with encoding="utf-8" (or open the file with encoding="utf-8" and pass the
content to tomllib.loads) and assign the result back to CARGO_TOML; update the
CARGO_TOML assignment that references CARGO_TOML_FILE to use the UTF-8-decoded
text.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/libc_posix.py`:
- Around line 163-165: The return type annotation of consts_from_url is
incorrect (currently "str") — update its annotation to match the actual returned
type from extract_consts, e.g. change the function signature to return
frozenset[str] (or typing.FrozenSet[str] if using typing imports) so it aligns
with CONSTS_PATTERN, EXCLUDE, and the extract_consts(...) return value used in
the implementation.

---

Nitpick comments:
In `@scripts/libc_posix.py`:
- Line 20: The code reads Cargo.toml using CARGO_TOML_FILE.read_text() which
uses the platform default encoding; change the read to explicitly use UTF-8 so
parsing is deterministic by calling read_text with encoding="utf-8" (or open the
file with encoding="utf-8" and pass the content to tomllib.loads) and assign the
result back to CARGO_TOML; update the CARGO_TOML assignment that references
CARGO_TOML_FILE to use the UTF-8-decoded text.

ℹ️ Review info

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 5248d83 and 2979d36.

⛔ Files ignored due to path filters (1)
  • Cargo.lock is excluded by !**/*.lock
📒 Files selected for processing (3)
  • Cargo.toml
  • crates/vm/src/stdlib/posix.rs
  • scripts/libc_posix.py

@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.

Hide comment

Actionable comments posted: 1

🧹 Nitpick comments (1)
scripts/libc_posix.py (1)

235-235: Make import rendering deterministic before formatting.

Line 235 joins a set directly. Sorting here avoids nondeterministic intermediate output and avoids relying on formatter behavior for stable ordering.

Proposed fix
-        imports = ",".join(consts)
+        imports = ",".join(sorted(consts))
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@scripts/libc_posix.py` at line 235, The current code constructs imports by
joining consts directly which can be nondeterministic if consts is a set; make
the output deterministic by sorting before joining — replace the join over
consts with a join over sorted(consts) so the variable imports is produced in
stable, alphabetical order (referencing the consts collection and the imports
variable).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@scripts/libc_posix.py`:
- Around line 179-184: The Python helper libc_posix.py calls
urllib.request.urlopen(url) without a timeout; since Python code should remain
unchanged, enforce a request timeout in the Rust caller that invokes this
script: locate the Rust code that spawns or invokes libc_posix.py (the
Command/process that passes the `url` to libc_posix.py) and wrap the child
process execution with a timeout (e.g., use std::process::Child + wait_timeout
crate or tokio::time::timeout for async) so the Python helper is killed if it
hangs, return a clear error to the caller; ensure the timeout value is
configurable or documented and that the child process is terminated (kill) on
timeout and proper errors are propagated to the calling code.

---

Nitpick comments:
In `@scripts/libc_posix.py`:
- Line 235: The current code constructs imports by joining consts directly which
can be nondeterministic if consts is a set; make the output deterministic by
sorting before joining — replace the join over consts with a join over
sorted(consts) so the variable imports is produced in stable, alphabetical order
(referencing the consts collection and the imports variable).

ℹ️ Review info

Configuration used: Path: .coderabbit.yml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2979d36 and 7fe87cf.

📒 Files selected for processing (1)
  • scripts/libc_posix.py

@ShaharNaveh ShaharNaveh requested a review from youknowone March 4, 2026 06:39
Hide details View details @youknowone youknowone merged commit 798f9e8 into RustPython:main Mar 4, 2026
43 of 46 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Mar 12, 2026
youknowone pushed a commit to youknowone/RustPython that referenced this pull request Mar 22, 2026
* Update to libc 0.2.182, refactor update script

* Fix typing
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