Skip to content

Commit

Permalink
Improve host/target handling
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Apr 18, 2024
1 parent 116e644 commit 67cb713
Showing 1 changed file with 46 additions and 32 deletions.
78 changes: 46 additions & 32 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -167,40 +167,16 @@ fi
target_lower="${target//-/_}"
target_lower="${target_lower//./_}"
target_upper=$(tr '[:lower:]' '[:upper:]' <<<"${target_lower}")
if [[ -z "${build_tool}" ]]; then
build_tool="cargo"
if [[ "${host}" != "${target}" ]]; then
case "${target}" in
# https://github.com/cross-rs/cross#supported-targets
*-windows* | *-darwin* | *-fuchsia* | *-redox*) ;;
*)
# If any of these are set, it is obvious that the user has set up a cross-compilation environment on the host.
if [[ -z "$(eval "echo \${CARGO_TARGET_${target_upper}_LINKER:-}")" ]] && [[ -z "$(eval "echo \${CARGO_TARGET_${target_upper}_RUNNER:-}")" ]]; then
build_tool="cross"
fi
;;
esac
fi
fi

if [[ "${build_tool}" == "cargo" ]]; then
case "${target}" in
universal-apple-darwin) x rustup target add aarch64-apple-darwin x86_64-apple-darwin ;;
*) x rustup target add "${target}" ;;
esac
fi

archive="${archive/\$bin/${bin_names[0]}}"
archive="${archive/\$target/${target}}"
archive="${archive/\$tag/${tag}}"

tar="tar"
case "$(uname -s)" in
Linux)
platform="unix"
platform=unix
host_os=linux
;;
Darwin)
platform="unix"
platform=unix
host_os=macos
# Work around https://github.com/actions/cache/issues/403 by using GNU tar
# instead of BSD tar.
tar="gtar"
Expand All @@ -212,12 +188,50 @@ case "$(uname -s)" in
fi
;;
MINGW* | MSYS* | CYGWIN* | Windows_NT)
platform="windows"
platform=windows
host_os=windows
exe=".exe"
;;
*) bail "unrecognized OS type '$(uname -s)'" ;;
esac

if [[ -z "${build_tool}" ]]; then
build_tool="cargo"
if [[ "${host}" != "${target}" ]]; then
# If any of these are set, it is obvious that the user has set up a cross-compilation environment on the host.
if [[ -z "$(eval "echo \${CARGO_TARGET_${target_upper}_LINKER:-}")" ]] && [[ -z "$(eval "echo \${CARGO_TARGET_${target_upper}_RUNNER:-}")" ]]; then
case "${target}" in
# https://github.com/cross-rs/cross#supported-targets
*-windows*)
case "${host_os}" in
windows) ;;
*) build_tool="cross" ;;
esac
;;
*-apple-*)
case "${host_os}" in
macos) ;;
*) build_tool="cross" ;;
esac
;;
*-fuchsia* | *-redox*) ;;
*) build_tool="cross" ;;
esac
fi
fi
fi

if [[ "${build_tool}" == "cargo" ]]; then
case "${target}" in
universal-apple-darwin) x rustup target add aarch64-apple-darwin x86_64-apple-darwin ;;
*) x rustup target add "${target}" ;;
esac
fi

archive="${archive/\$bin/${bin_names[0]}}"
archive="${archive/\$target/${target}}"
archive="${archive/\$tag/${tag}}"

input_profile=${INPUT_PROFILE:-release}
case "${input_profile}" in
release) build_options=("--release") ;;
Expand Down Expand Up @@ -264,7 +278,7 @@ if ! grep -Eq '^\s*strip\s*=' "${workspace_root}/Cargo.toml" && [[ -z "${CARGO_P
case "${target}" in
# Do not strip debuginfo on MSVC https://github.com/rust-lang/cargo/pull/13630
# This is the same behavior as pre-1.19.0 upload-rust-binary-action.
*-pc-windows-msvc) strip_default=none ;;
*-windows-msvc) strip_default=none ;;
*) strip_default=debuginfo ;;
esac
if [[ "${rustc_minor_version}" -lt 79 ]] && [[ "${rustc_minor_version}" -ge 59 ]]; then
Expand Down Expand Up @@ -332,8 +346,8 @@ case "${INPUT_TARGET:-}" in
;;
esac

case "$(uname -s)" in
Darwin)
case "${host_os}" in
macos)
if type -P codesign &>/dev/null; then
do_codesign "${target_dir}"
fi
Expand Down

0 comments on commit 67cb713

Please sign in to comment.