feat(core): support building for iOS targets - #1246
Conversation
brush-core currently fails to compile for aarch64-apple-ios / aarch64-apple-ios-sim, even though the crate's instance-scoped design (per-Shell working dir/env, fd-table-based I/O) otherwise works well inside an iOS app. Three small platform issues block the build: - uzers does not compile for iOS, and there is no user database inside the iOS app sandbox anyway. Gate the dependency to non-iOS unix and add a users_ios module that answers identity queries from uid/gid syscalls and the process environment. - nix does not expose waitid() on iOS; take the same waitpid() fallback already used for NetBSD/OpenBSD. - the ioctl(TIOCSCTTY) request argument is c_ulong on iOS just like macOS; widen the cfg from target_os = "macos" to target_vendor = "apple". No behavior change on any currently supported platform: all edits are cfg-gated to iOS except the ioctl cfg widening, which is identical on macOS. cargo check/clippy pass for aarch64-apple-ios, aarch64-apple-ios-sim, and the host. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_011tLwxQ47SiGLGDDPXd8tzz
|
Thanks for the contribution, @Jackkakaya! It's great to hear that you were able to make use of I'll need to look a bit more closely at |
Lets embedders distinguish a redirected/piped fd from an inherited one (e.g. tell a piped stdin from an interactive terminal). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Public API changes for crate: brush-coreAdded itemsPerformance Benchmark Report
Code Coverage Report: Only Changed Files listed
Minimum allowed coverage is Test Summary: bash-completion test suite
|
reubeno
left a comment
There was a problem hiding this comment.
Changes generally looking good -- just a few requests/questions.
| #[expect(clippy::unnecessary_wraps)] | ||
| pub(crate) fn get_user_group_ids() -> Result<Vec<u32>, error::Error> { | ||
| // SAFETY: getgid is always successful and has no preconditions. | ||
| Ok(vec![unsafe { libc::getgid() }]) |
There was a problem hiding this comment.
While these are straightforward, we prefer using the nix crate instead of direct unsafe libc calls. Could you please update the libc calls in this file to go through it instead?
|
|
||
| #[expect(clippy::unnecessary_wraps)] | ||
| pub(crate) fn get_all_groups() -> Result<Vec<String>, error::Error> { | ||
| Ok(vec!["mobile".to_owned()]) |
There was a problem hiding this comment.
Did you find a case where it's important to return at least one group instead of just returning an empty vector?
|
|
||
| #[expect(clippy::unnecessary_wraps)] | ||
| pub(crate) fn get_current_username() -> Result<String, error::Error> { | ||
| Ok(std::env::var("USER").unwrap_or_else(|_| "mobile".to_owned())) |
There was a problem hiding this comment.
Is USER typically set in the iOS targets you've tested with? If so, I'm tempted to avoid a hard-coded fake fallback.
What
Makes
brush-corecompile (and run) for iOS targets (aarch64-apple-ios,aarch64-apple-ios-sim). Three small, cfg-gated changes:uzers→ non-iOS unix only, newusers_iosmodule.uzersfails to compile for iOS, and the iOS app sandbox has no user database to query anyway. The new module answers identity queries fromgetuid()/getgid()-family syscalls and the process environment ($HOME,$USER).waitid→waitpidfallback on iOS.nixdoes not exposewaitid()on iOS; this reuses the exact fallback path already in place for NetBSD/OpenBSD.ioctl(TIOCSCTTY)cfg widened fromtarget_os = "macos"totarget_vendor = "apple". The request argument isc_ulongon iOS just like macOS.Why
brush-core turns out to be a remarkably good fit for embedding a shell inside an iOS app, where
fork/execis forbidden: working dir and env are per-Shell-instance state rather than process globals, builtins do I/O through the shell's fd table (real pipes) rather than process stdio, and any command name can be routed to an in-process builtin. With just this patch, brush-core powers a working iOS terminal app.Testing
cargo check+cargo clippyclean foraarch64-apple-ios,aarch64-apple-ios-sim, and the host (macOS).Happy to also add an iOS check target to CI in a follow-up if that's welcome.
🤖 Generated with Claude Code
https://claude.ai/code/session_011tLwxQ47SiGLGDDPXd8tzz