Skip to content

Expose mknodat/mkfifoat on Apple targets - #1625

Open
mattsu2020 wants to merge 1 commit into
bytecodealliance:mainfrom
mattsu2020:mknodat_macos
Open

mattsu2020 wants to merge 1 commit into
bytecodealliance:mainfrom
mattsu2020:mknodat_macos

Conversation

@mattsu2020

@mattsu2020 mattsu2020 commented May 16, 2026

Copy link
Copy Markdown

Summary

  • Expose rustix::fs::{mknodat, mkfifoat} on Apple targets, with support starting in macOS 13.0, iOS 16.0, tvOS 16.0, and watchOS 9.0.
  • Weak-link mknodat on Apple and return NOSYS when unavailable on older systems. mkfifoat delegates to the same implementation. Other targets retain direct libc calls.
  • Document the supported Apple OS versions and behavior on older systems for both public APIs.

Validation

  • cargo doc --no-deps --features all-apis
  • git diff --check

The documentation build succeeded on macOS with 10 unresolved-link warnings in unchanged documentation; none were in the updated API documentation.

@xtqqczze

xtqqczze commented May 17, 2026

Copy link
Copy Markdown
Contributor

I think a fallback is needed for macOS ≤ 13 since Apple macOS targets are supported as far back as macOS 10.12, and there are also additional Apple platforms to consider such as tvOS and watchOS.

It would also be good to add references for the newly exposed functions on Apple targets. For example, https://github.com/apple-oss-distributions/xnu/blob/main/bsd/man/man2/mkfifoat.2

@oech3

oech3 commented May 17, 2026

Copy link
Copy Markdown

Or add non-*at too for macOS?

@xtqqczze

Copy link
Copy Markdown
Contributor

Right, the POSIX mknod and mkfifo are currently absent from all platforms.

@mattsu2020

Copy link
Copy Markdown
Author

I'll revise this PR to restore weak-linking/runtime detection. When the symbol is unavailable, I'll only fall back to mknod/mkfifo for the AT_FDCWD case, and otherwise return an unsupported/error result. I'll also add Apple man page references for these functions.

@xtqqczze

Copy link
Copy Markdown
Contributor

On second thoughts, we probably don't need to implement a fallback for the libc backend. We can just return the appropriate Err and let callers handle it.

Comment thread src/backend/libc/fs/syscalls.rs Outdated
@mattsu2020
mattsu2020 requested a review from xtqqczze June 30, 2026 09:27
Comment thread src/backend/libc/fs/syscalls.rs Outdated
@xtqqczze

This comment was marked as outdated.

@oech3

This comment was marked as duplicate.

Comment thread src/backend/libc/fs/syscalls.rs
@badeend

badeend commented Aug 25, 2026

Copy link
Copy Markdown
Member

@mattsu2020 The fix for the CI failure #1620 has been merged. Could you update this PR?

@mattsu2020

Copy link
Copy Markdown
Author

@mattsu2020 The fix for the CI failure #1620 has been merged. Could you update this PR?

I’ve updated it.

@badeend

badeend commented Aug 28, 2026

Copy link
Copy Markdown
Member

@sunfishcode Could you take a look at this? The code change seems relatively straightforward, and it passes CI.

@oech3

oech3 commented Sep 18, 2026

Copy link
Copy Markdown

Resolve conflicts

@mattsu2020

Copy link
Copy Markdown
Author

Resolve conflicts

fix it

@xtqqczze

Copy link
Copy Markdown
Contributor

@mattsu2020 please squash your commits and write a new commit description in your own words

mattsu2020 added a commit to mattsu2020/rustix that referenced this pull request Sep 19, 2026
macOS 13 and corresponding Apple platforms added mknodat/mkfifoat.
These APIs were previously excluded with cfg(not(apple)).

On Apple, resolve mknodat at runtime with the same weak-linking
pattern used for linkat/unlinkat/renameat. If the symbol is absent
(macOS < 13 and older Apple OS variants), return NOSYS so a binary
built against a newer SDK can still run on older systems. Other
targets keep calling libc mknodat directly. mkfifoat goes through
the same path.

Also import Dev and FileType on Apple so the public wrappers
compile, add XNU man-page references, and shrink the unsafe block
around the syscall.
@mattsu2020

Copy link
Copy Markdown
Author

@mattsu2020 please squash your commits and write a new commit description in your own words

I performed a squash merge and added a comment.
Do you think we can merge it?

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

Can we clarify the platform support for mknodat and mkfifoat in src/fs/at.rs?

The macro-expanded declaration in sys/stat.h shows that it was introduced in macOS 13.0, iOS 16.0, tvOS 16.0, and watchOS 9.0.

Macro-expanded declaration
int mkfifoat(int, const char *, mode_t)
__attribute__((availability(macos,introduced=13.0)))
__attribute__((availability(ios,introduced=16.0)))
__attribute__((availability(tvos,introduced=16.0)))
__attribute__((availability(watchos,introduced=9.0)));

Also, please amend the commit message to summarize the changes rather than describing every implementation detail. For example:

Expose mknodat and mkfifoat on Apple targets.

Weak-link mknodat on Apple and return NOSYS when unavailable on older systems. Keep direct libc calls on other targets.

This will make the PR easier to review when the maintainer gets to it.

mattsu2020 added a commit to mattsu2020/rustix that referenced this pull request Sep 19, 2026
Weak-link mknodat on Apple and return NOSYS when unavailable on older
systems. Keep direct libc calls on other targets.

Document availability starting in macOS 13.0, iOS 16.0, tvOS 16.0,
and watchOS 9.0 for both APIs.
@mattsu2020

Copy link
Copy Markdown
Author

Thank you for your feedback. I have incorporated your comments accordingly.

@xtqqczze

xtqqczze commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

@mattsu2020 Please don't include PR number in commit.

Also, please update the PR description to remove unnecessary details, was that generated by an LLM?

I opened an issue for the rustdoc warnings: #1685

Weak-link mknodat on Apple and return NOSYS when unavailable on older
systems. Keep direct libc calls on other targets.
@mattsu2020

Copy link
Copy Markdown
Author

I added it because I thought it was necessary, but I'll remove it.

@mattsu2020

Copy link
Copy Markdown
Author

Should the rustdoc warnings be addressed in this PR?

I'm also fine with handling them in a separate PR.

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.

4 participants