Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Support renames and extras
  • Loading branch information
ShaharNaveh committed Aug 31, 2025
commit ef0d9c286164fd523cadfc52ae9d9f9b22988569
12 changes: 10 additions & 2 deletions scripts/libc_posix.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@
}
)

EXTRAS = {
frozenset({"macos"}): {"COPYFILE_DATA"},
}
RENAMES = {"COPYFILE_DATA": "_COPYFILE_DATA"}


def build_url(fname: str) -> str:
return f"https://raw.githubusercontent.com/rust-lang/libc/refs/tags/{LIBC_VERSION}/libc-test/semver/{fname}.txt"
Expand Down Expand Up @@ -77,7 +82,10 @@ def format_groups(groups: dict) -> "Iterator[tuple[str, str]]":
cond = f"any({cond})"
cfg = f"#[cfg({cond})]"

imports = ", ".join(sorted(consts))
imports = ", ".join(
const if const not in RENAMES else f"{const} as {RENAMES[const]}"
for const in sorted(consts)
)
use = f"use libc::{{{imports}}};"
yield cfg, use

Expand All @@ -101,7 +109,7 @@ def main():
continue

group_consts[target_oses].add(const)
group_consts = dict(group_consts)
group_consts = {grp: v | EXTRAS.get(grp, set()) for grp, v in group_consts.items()}
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

EXTRAS may be silently dropped when their group doesn’t already exist

EXTRAS are only merged into already-existing groups. If a group like {"macos"} has no other members, its extras (e.g., COPYFILE_DATA) won’t be emitted. Ensure extras create their group.

Apply this diff:

-    group_consts = {grp: v | EXTRAS.get(grp, set()) for grp, v in group_consts.items()}
+    # Merge extras and ensure their groups exist even if empty
+    for grp, extras in EXTRAS.items():
+        group_consts.setdefault(grp, set()).update(extras)
🤖 Prompt for AI Agents
In scripts/libc_posix.py around line 112, EXTRAS are only merged into groups
that already exist so groups present only in EXTRAS will be dropped; modify the
merge to ensure every key in EXTRAS is present by taking the union of
group_consts.keys() and EXTRAS.keys() and then for each group produce the union
of existing values and EXTRAS[group] (or use group_consts.get(group, set()) |
EXTRAS.get(group, set())), so extras create their group instead of being
silently ignored.


code = "\n\n".join(
f"""
Expand Down