Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

- Cross-platform `install.sh` and `install.ps1` installers for the standalone
Cloudsmith CLI.
- Automatic platform detection and support for selecting a specific CLI
version or target.
- Automatic platform detection, including native Arm64 selection under
Rosetta 2, and support for selecting a specific CLI version or target.
- SHA-256 verification, archive safety checks, atomic installation, and
concurrent-install locking.
- Stable machine-readable output for CI/CD consumers.
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ executable=/home/runner/.local/share/cloudsmith-cli/1.19.0/linux-x86_64-gnu/clou
| Linux | x86-64 | `linux-x86_64-musl` | Alpine and other musl distributions |
| Linux | Arm64 | `linux-aarch64-musl` | Alpine and other musl distributions |
| macOS | x86-64 | `macos-x86_64` | Intel |
| macOS | Arm64 | `macos-arm64` | Apple silicon |
| macOS | Arm64 | `macos-arm64` | Apple silicon, including shells running under Rosetta 2 |
| Windows | x86-64 | `windows-x86_64` | Also used on Windows Arm64 through x86-64 emulation |

## Security
Expand Down
10 changes: 9 additions & 1 deletion install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,15 @@ detect_target() {
Darwin)
case "$machine" in
arm64|aarch64) printf '%s\n' macos-arm64 ;;
x86_64|amd64) printf '%s\n' macos-x86_64 ;;
x86_64|amd64)
# A translated shell reports x86_64 even when the host is Apple
# silicon. Prefer the native CLI binary when Rosetta 2 is detected.
if [ "$(sysctl -n sysctl.proc_translated 2>/dev/null || true)" = 1 ]; then
printf '%s\n' macos-arm64
else
printf '%s\n' macos-x86_64
fi
;;
*) die "unsupported macOS architecture: $machine" ;;
esac
;;
Expand Down
41 changes: 41 additions & 0 deletions tests/detect_target.bats
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,22 @@ EOF
chmod +x "$STUB_BIN/uname"
}

# write_sysctl_stub <native|translated|unavailable>: fakes Apple's Rosetta probe.
write_sysctl_stub() {
local mode="$1"
cat > "$STUB_BIN/sysctl" <<EOF
#!/usr/bin/env bash
[ "\${1-}" = "-n" ] || exit 2
[ "\${2-}" = "sysctl.proc_translated" ] || exit 2
case "$mode" in
native) printf '%s\n' 0 ;;
translated) printf '%s\n' 1 ;;
unavailable) exit 1 ;;
esac
EOF
chmod +x "$STUB_BIN/sysctl"
}

# write_getconf_stub <gnu|fail>: "gnu" simulates glibc; "fail" forces the ldd fallback.
write_getconf_stub() {
local mode="$1"
Expand Down Expand Up @@ -72,6 +88,31 @@ write_ldd_stub() {

@test "darwin/x86_64 is detected as macos-x86_64" {
write_uname_stub Darwin x86_64
write_sysctl_stub native

run --separate-stderr "$INSTALL_SH" \
--install-root "$INSTALL_ROOT" \
--manifest-url "$UNREACHABLE_MANIFEST_URL"

[ "$status" -ne 0 ]
[[ "$stderr" == *"detected target macos-x86_64"* ]]
}

@test "darwin/x86_64 under Rosetta is detected as macos-arm64" {
write_uname_stub Darwin x86_64
write_sysctl_stub translated

run --separate-stderr "$INSTALL_SH" \
--install-root "$INSTALL_ROOT" \
--manifest-url "$UNREACHABLE_MANIFEST_URL"

[ "$status" -ne 0 ]
[[ "$stderr" == *"detected target macos-arm64"* ]]
}

@test "darwin/x86_64 stays macos-x86_64 when the Rosetta probe is unavailable" {
write_uname_stub Darwin x86_64
write_sysctl_stub unavailable

run --separate-stderr "$INSTALL_SH" \
--install-root "$INSTALL_ROOT" \
Expand Down
Loading