Reduce uname usage

This commit is contained in:
Taiki Endo
2026-05-05 03:17:38 +09:00
parent ca67a3acf1
commit c4a18d6cc6
2 changed files with 36 additions and 23 deletions

View File

@@ -54,6 +54,8 @@ runs:
INPUT_FALLBACK: ${{ inputs.fallback }} INPUT_FALLBACK: ${{ inputs.fallback }}
DEFAULT_GITHUB_TOKEN: ${{ inputs.fallback == 'cargo-binstall' && github.token || '' }} DEFAULT_GITHUB_TOKEN: ${{ inputs.fallback == 'cargo-binstall' && github.token || '' }}
ACTION_USER_AGENT: ${{ github.action_repository }} (${{ github.action_ref }}) ACTION_USER_AGENT: ${{ github.action_repository }} (${{ github.action_ref }})
RUNNER_OS: ${{ runner.os }}
RUNNER_ARCH: ${{ runner.arch }}
if: runner.os != 'Windows' if: runner.os != 'Windows'
# Use pwsh and retry on bash startup failure to work around windows-11-arm runner bug: # Use pwsh and retry on bash startup failure to work around windows-11-arm runner bug:
# https://github.com/actions/partner-runner-images/issues/169 # https://github.com/actions/partner-runner-images/issues/169
@@ -88,4 +90,6 @@ runs:
INPUT_FALLBACK: ${{ inputs.fallback }} INPUT_FALLBACK: ${{ inputs.fallback }}
DEFAULT_GITHUB_TOKEN: ${{ inputs.fallback == 'cargo-binstall' && github.token || '' }} DEFAULT_GITHUB_TOKEN: ${{ inputs.fallback == 'cargo-binstall' && github.token || '' }}
ACTION_USER_AGENT: ${{ github.action_repository }} (${{ github.action_ref }}) ACTION_USER_AGENT: ${{ github.action_repository }} (${{ github.action_ref }})
RUNNER_OS: ${{ runner.os }}
RUNNER_ARCH: ${{ runner.arch }}
if: runner.os == 'Windows' if: runner.os == 'Windows'

55
main.sh
View File

@@ -515,10 +515,13 @@ token="${GITHUB_TOKEN:-"${GH_TOKEN:-"${DEFAULT_GITHUB_TOKEN:-}"}"}"
# via `ps -Eww` on macOS. It only reduces the risk of leaks. # via `ps -Eww` on macOS. It only reduces the risk of leaks.
unset GITHUB_TOKEN GH_TOKEN DEFAULT_GITHUB_TOKEN unset GITHUB_TOKEN GH_TOKEN DEFAULT_GITHUB_TOKEN
# Refs: https://github.com/rust-lang/rustup/blob/HEAD/rustup-init.sh # Refs:
# - https://github.com/rust-lang/rustup/blob/HEAD/rustup-init.sh
# - https://docs.github.com/en/actions/reference/workflows-and-actions/contexts#runner-context
# NB: Sync with tools/ci/tool-list.sh.
base_distro='' base_distro=''
exe='' exe=''
case "$(uname -s)" in case "${RUNNER_OS}" in
Linux) Linux)
host_os=linux host_os=linux
ldd_version=$(ldd --version 2>&1 || true) ldd_version=$(ldd --version 2>&1 || true)
@@ -568,16 +571,15 @@ case "$(uname -s)" in
;; ;;
esac esac
;; ;;
Darwin) host_os=macos ;; macOS) host_os=macos ;;
MINGW* | MSYS* | CYGWIN* | Windows_NT) Windows)
host_os=windows host_os=windows
exe=.exe exe=.exe
;; ;;
*) bail "unrecognized OS type '$(uname -s)'" ;; *) bail "unrecognized runner.os '${RUNNER_OS}'" ;;
esac esac
# NB: Sync with tools/ci/tool-list.sh. case "${RUNNER_ARCH}" in
case "$(uname -m)" in X64) host_arch=x86_64 ;;
aarch64 | arm64) host_arch=aarch64 ;;
# Ignore 32-bit Arm for now, as we need to consider the version and whether hard-float is supported. # Ignore 32-bit Arm for now, as we need to consider the version and whether hard-float is supported.
# https://github.com/rust-lang/rustup/pull/593 # https://github.com/rust-lang/rustup/pull/593
# https://github.com/cross-rs/cross/pull/1018 # https://github.com/cross-rs/cross/pull/1018
@@ -586,21 +588,28 @@ case "$(uname -m)" in
# Does it seem only armv7l+ is supported? # Does it seem only armv7l+ is supported?
# https://github.com/actions/runner/blob/v2.321.0/src/Misc/externals.sh#L178 # https://github.com/actions/runner/blob/v2.321.0/src/Misc/externals.sh#L178
# https://github.com/actions/runner/issues/688 # https://github.com/actions/runner/issues/688
xscale | arm | armv*l) bail "32-bit Arm runner is not supported yet by this action; if you need support for this platform, please submit an issue at <https://github.com/taiki-e/install-action>" ;; ARM) bail "32-bit Arm runner is not supported yet by this action; if you need support for this platform, please submit an issue at <https://github.com/taiki-e/install-action>" ;;
ppc64le) host_arch=powerpc64le ;; ARM64) host_arch=aarch64 ;;
riscv64) host_arch=riscv64 ;; *)
s390x) host_arch=s390x ;; info "unrecognized runner.arch '${RUNNER_ARCH}'; fallback to uname -m"
# Very few tools provide prebuilt binaries for these. case "$(uname -m)" in
# TODO: fallback to `cargo install`? (binstall fallback is not good idea here as cargo-binstall doesn't provide prebuilt binaries for these.) aarch64 | arm64) host_arch=aarch64 ;;
loongarch64 | mips | mips64 | ppc | ppc64 | sun4v) bail "$(uname -m) runner is not supported yet by this action; if you need support for this platform, please submit an issue at <https://github.com/taiki-e/install-action>" ;; xscale | arm | armv*l) bail "32-bit Arm runner is not supported yet by this action; if you need support for this platform, please submit an issue at <https://github.com/taiki-e/install-action>" ;;
# GitHub Actions Runner supports x86_64/AArch64/Arm Linux and x86_64/AArch64 Windows/macOS. ppc64le) host_arch=powerpc64le ;;
# https://github.com/actions/runner/blob/v2.332.0/.github/workflows/build.yml#L24 riscv64) host_arch=riscv64 ;;
# https://docs.github.com/en/actions/reference/runners/self-hosted-runners#supported-processor-architectures s390x) host_arch=s390x ;;
# And IBM provides runners for powerpc64le/s390x Linux. # Very few tools provide prebuilt binaries for these.
# https://github.com/IBM/actionspz # TODO: fallback to `cargo install`? (binstall fallback is not good idea here as cargo-binstall doesn't provide prebuilt binaries for these.)
# So we can assume x86_64 unless it has a known non-x86_64 uname -m result. loongarch64 | mips | mips64 | ppc | ppc64 | sun4v) bail "$(uname -m) runner is not supported yet by this action; if you need support for this platform, please submit an issue at <https://github.com/taiki-e/install-action>" ;;
# TODO: uname -m on windows-11-arm returns "x86_64" # GitHub Actions Runner supports x86_64/AArch64/Arm Linux and x86_64/AArch64 Windows/macOS.
*) host_arch=x86_64 ;; # https://github.com/actions/runner/blob/v2.332.0/.github/workflows/build.yml#L24
# https://docs.github.com/en/actions/reference/runners/self-hosted-runners#supported-processor-architectures
# And IBM provides runners for powerpc64le/s390x Linux.
# https://github.com/IBM/actionspz
# So we can assume x86_64 unless it has a known non-x86_64 uname -m result.
*) host_arch=x86_64 ;;
esac
;;
esac esac
info "host platform: ${host_arch}_${host_os}" info "host platform: ${host_arch}_${host_os}"