Skip to content

Commit

Permalink
Align default strip behavior to Cargo 1.77+'s default
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e committed Mar 5, 2024
1 parent 380af0a commit 1d32255
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ Note: In this file, do not use the hard wrap in the middle of a sentence for com

## [Unreleased]

- Align default strip behavior to [Cargo 1.77+'s default (strip=debuginfo)](https://github.com/rust-lang/cargo/pull/13257). See [#66](https://github.com/taiki-e/upload-rust-binary-action/pull/66) for details.

## [1.18.0] - 2023-12-03

- Support signing with `codesign` on macOS. ([#61](https://github.com/taiki-e/upload-rust-binary-action/pull/61), thanks @doinkythederp)
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,8 @@ The followings are examples to specify profile options:
strip = true
```

[Default is `strip = debuginfo`.](https://github.com/rust-lang/cargo/pull/13257)

**Note:** Some of these options may increase the build time.

## Supported events
Expand Down
34 changes: 5 additions & 29 deletions main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -250,25 +250,13 @@ else
target_dir=$(jq <<<"${metadata}" -r '.target_directory')
fi

strip=""
workspace_root=$(jq <<<"${metadata}" -r '.workspace_root')
# TODO: This is a somewhat rough check as it does not look at the type of profile.
if ! grep -Eq '^strip\s*=' "${workspace_root}/Cargo.toml"; then
case "${target}" in
*-pc-windows-msvc) ;;
x86_64* | i?86-*) strip="strip" ;;
arm*-linux-*eabi) strip="arm-linux-gnueabi-strip" ;;
arm*-linux-*eabihf | thumb*-linux-*eabihf) strip="arm-linux-gnueabihf-strip" ;;
arm*-none-eabi* | thumb*-none-eabi*) strip="arm-none-eabi-strip" ;;
aarch64*-linux-*) strip="aarch64-linux-gnu-strip" ;;
powerpc64le-*-linux-*) strip="powerpc64le-linux-gnu-strip" ;;
s390x-*-linux-*) strip="s390x-linux-gnu-strip" ;;
esac
if [[ -n "${strip:-}" ]]; then
if ! type -P "${strip}" &>/dev/null; then
warn "${strip} not found, skip stripping"
strip=""
fi
if ! grep -Eq '^strip\s*=' "${workspace_root}/Cargo.toml" && [[ -z "${CARGO_PROFILE_RELEASE_STRIP:-}" ]]; then
# On pre-1.77, align to Cargo 1.77+'s default: https://github.com/rust-lang/cargo/pull/13257
# strip option builds requires Cargo 1.59
if [[ "${rustc_minor_version}" -lt 77 ]] && [[ "${rustc_minor_version}" -ge 59 ]]; then
export CARGO_PROFILE_RELEASE_STRIP=debuginfo
fi
fi

Expand All @@ -295,14 +283,6 @@ build() {
*) bail "unrecognized build tool '${build_tool}'" ;;
esac
}
do_strip() {
target_dir="$1"
if [[ -n "${strip:-}" ]]; then
for bin_exe in "${bins[@]}"; do
x "${strip}" "${target_dir}/${bin_exe}"
done
fi
}
do_codesign() {
target_dir="$1"
if [[ -n "${INPUT_CODESIGN:-}" ]]; then
Expand All @@ -316,7 +296,6 @@ case "${INPUT_TARGET:-}" in
'')
build
target_dir="${target_dir}/${profile_directory}"
do_strip "${target_dir}"
;;
universal-apple-darwin)
# Refs: https://developer.apple.com/documentation/apple-silicon/building-a-universal-macos-binary
Expand All @@ -331,16 +310,13 @@ case "${INPUT_TARGET:-}" in
x86_64_target_dir="${target_dir}/x86_64-apple-darwin/${profile_directory}"
target_dir="${target_dir}/${target}/${profile_directory}"
mkdir -p "${target_dir}"
do_strip "${aarch64_target_dir}"
do_strip "${x86_64_target_dir}"
for bin_exe in "${bins[@]}"; do
x lipo -create -output "${target_dir}/${bin_exe}" "${aarch64_target_dir}/${bin_exe}" "${x86_64_target_dir}/${bin_exe}"
done
;;
*)
build --target "${zigbuild_target:-"${target}"}"
target_dir="${target_dir}/${target}/${profile_directory}"
do_strip "${target_dir}"
;;
esac

Expand Down

0 comments on commit 1d32255

Please sign in to comment.