Skip to content

fix(toolchain): avoid bash / scripting issues on MacOS#1870

Open
sakompella wants to merge 4 commits into
rivet-dev:mainfrom
sakompella:fix-macos-bash-compat
Open

fix(toolchain): avoid bash / scripting issues on MacOS#1870
sakompella wants to merge 4 commits into
rivet-dev:mainfrom
sakompella:fix-macos-bash-compat

Conversation

@sakompella

Copy link
Copy Markdown

This is a series of small script fixes.

  1. toolchain/scripts/patch-wasi-libc.sh uses #!/bin/bash shebang, as well as mapfile builtin. mapfile bash builtin is only available for bash 4.x
  • MacOS's /bin/bash is stuck on version 3.2.57 (on MacOS 26.5) and will not update. Does not have access to mapfile, leading to failure running make sysroot, with error mapfile: command not found
  • This PR replaces both call sites with an equivalent while read loop over the same process substitution
  1. Support using shasum if sha256sum is not installed.
  2. Support use of BSD patch along with GNU patch.
  3. Replaces #!/bin/bash with #!/usr/bin/env bash, which is more standard, and will use $PATH (ex, if user used brew's bash, which is more up-to-date, this would not have happened)

bash versions under 4 lack `mapfile`. In particular, this means any
macOS machines will break (especially as `#!` points to `/bin/bash`
rather than using `#!/usr/bin/env bash`).
Not every environment ships GNU coreutils' sha256sum. In particular,
macOS ships only `shasum -a 256` by default. Resolve the digest
command once into an array (needed so it still composes with the
xargs pipeline, since xargs execs external commands, not shell
functions), matching the same command -v fallback already used in
build-openssl-upstream.sh and build-ssh-upstream.sh.
…s GNU/BSD patch

Some non-GNU patch implementations auto-answer their interactive
"Ignore -R?" prompt's "[y]" default non-deterministically when stdin
isn't a tty. In particular, BSD/Apple patch -- as shipped by macOS --
does this, which can make a reverse dry-run falsely report "already
applied" on a genuinely unpatched tree, skipping the real patch
application and causing later compile errors (e.g. libunwind's
wasm-exception-support patch).

Reproduced directly: without -f, a reverse dry-run against an unpatched
tree reported false success; with -f, it correctly reports failure
(and still correctly reports success against an already-patched tree).
-f is a standard flag on both GNU and BSD patch, so this keeps the
forward/reverse detection deterministic regardless of which
implementation is on PATH.
Matches the env-relative shebang convention already used by most other
scripts in the repo, and lets anyone with a newer bash earlier on PATH
opt in without needing bash-3.2-compatible rewrites as a fallback.

Left scripts/ralph/ralph-docker.sh, ralph-docker-per-iter.sh (docker
orchestration wrappers whose target environment is fixed by the
container image), scripts/ralph/ralph.sh, and the vendored upstream
software/vim/share/vim/vim92/macros/less.sh untouched.
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.

1 participant