Skip to content

Commit 2bf5e01

Browse files
Fixes to macos setup and CARGO_PROFILE_DEV_DEBUG (#22)
* ensure that homebrew is available on mac Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> * Repair Homebrew permissions and preserve dev debug information Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> * Remove unnecessary Homebrew ownership restriction Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> --------- Signed-off-by: Simon Davies <simongdavies@users.noreply.github.com> Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 4b7107a commit 2bf5e01

2 files changed

Lines changed: 49 additions & 4 deletions

File tree

‎README.md‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ Rustup reads the version, profile, components, and targets from each toolchain
3636
file. Put required extras such as `clippy`, `rustfmt`, `x86_64-unknown-none`,
3737
or cross-compilation targets in those files.
3838

39+
The action defaults `CARGO_PROFILE_DEV_DEBUG` to `2` before Rust setup so
40+
development builds retain full debug information. Explicit caller values,
41+
including `0` or `false`, are preserved.
42+
3943
## Overview
4044

4145
This action performs the following steps:
@@ -50,8 +54,11 @@ This action performs the following steps:
5054

5155
Runners need Bash 5 and rustup or curl. On macOS, the action discovers Homebrew
5256
on PATH or in its standard Apple Silicon and Intel locations, installing it
53-
noninteractively with the official installer when missing. Installing Homebrew
54-
requires the runner user to have the permissions required by that installer.
57+
noninteractively with the official installer when missing. If an existing
58+
installation is not writable, the action reruns the official installer to repair
59+
its permissions and checks them again before continuing. Installation and repair
60+
require the runner user to have the permissions required by that installer,
61+
including noninteractive sudo access when ownership changes are needed.
5562
The Rust setup action installs rustup when missing and Bash through Homebrew
5663
on macOS.
5764

‎action.yml‎

Lines changed: 40 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@ runs:
1919
if: ${{ runner.os == 'macOS' }}
2020
run: |
2121
find_brew() {
22-
command -v brew && return 0
22+
local candidate
23+
if candidate="$(command -v brew)" && [ -x "$candidate" ]; then
24+
echo "$candidate"
25+
return 0
26+
fi
2327
for candidate in /opt/homebrew/bin/brew /usr/local/bin/brew; do
2428
if [ -x "$candidate" ]; then
2529
echo "$candidate"
@@ -29,7 +33,29 @@ runs:
2933
return 1
3034
}
3135
32-
if ! brew="$(find_brew)"; then
36+
brew_is_writable() {
37+
prefix="$("$brew" --prefix)" || return 1
38+
repository="$("$brew" --repository)" || return 1
39+
for directory in "$prefix" "$repository" \
40+
"$prefix/Cellar" "$prefix/Frameworks" "$prefix/bin" \
41+
"$prefix/etc" "$prefix/etc/bash_completion.d" \
42+
"$prefix/include" "$prefix/lib" "$prefix/lib/pkgconfig" \
43+
"$prefix/opt" "$prefix/sbin" "$prefix/share" \
44+
"$prefix/share/doc" "$prefix/share/man" \
45+
"$prefix/share/man/man1" "$prefix/share/man/man3" \
46+
"$prefix/share/man/man5" "$prefix/share/man/man7" \
47+
"$prefix/share/zsh" "$prefix/share/zsh/site-functions" \
48+
"$prefix/var/homebrew" "$prefix/var/homebrew/linked" \
49+
"$prefix/var/homebrew/locks"; do
50+
if [ -e "$directory" ] && [ ! -w "$directory" ]; then
51+
echo "Homebrew directory is not writable: $directory" >&2
52+
return 1
53+
fi
54+
done
55+
}
56+
57+
if ! brew="$(find_brew)" || ! brew_is_writable; then
58+
echo "Installing or repairing Homebrew for $(id -un)."
3359
installer="$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
3460
NONINTERACTIVE=1 /bin/bash -c "$installer"
3561
if ! brew="$(find_brew)"; then
@@ -38,10 +64,22 @@ runs:
3864
fi
3965
fi
4066
67+
if ! brew_is_writable; then
68+
echo "::error::Homebrew is still not writable after running its installer. Check runner sudo permissions and Homebrew ownership."
69+
exit 1
70+
fi
71+
4172
prefix="$("$brew" --prefix)"
4273
printf '%s\n' "$prefix/bin" "$prefix/sbin" >> "$GITHUB_PATH"
4374
shell: bash
4475

76+
- name: Preserve development debug information
77+
run: |
78+
if [ -z "${CARGO_PROFILE_DEV_DEBUG+x}" ]; then
79+
echo "CARGO_PROFILE_DEV_DEBUG=2" >> "$GITHUB_ENV"
80+
fi
81+
shell: bash
82+
4583
- name: Install Rust toolchain
4684
uses: actions-rust-lang/setup-rust-toolchain@ecabd13d1c56bd1345c230e542e9144811ad706f # v2
4785
with:

0 commit comments

Comments
 (0)