From 09dd859b56aeb267d70de4914f6a6b35c4af8055 Mon Sep 17 00:00:00 2001 From: Frederic Branczyk Date: Mon, 17 Jul 2023 13:59:13 +0200 Subject: [PATCH] Add ability to retain debuginfo before stripping binaries --- .github/.cspell/project-dictionary.txt | 3 +++ action.yml | 5 +++++ main.sh | 12 ++++++++++++ 3 files changed, 20 insertions(+) diff --git a/.github/.cspell/project-dictionary.txt b/.github/.cspell/project-dictionary.txt index 2a4bf446..61d9e33a 100644 --- a/.github/.cspell/project-dictionary.txt +++ b/.github/.cspell/project-dictionary.txt @@ -3,3 +3,6 @@ gtar lipo mktemp tmpdir +debuginfo +debuginfos +objcopy diff --git a/action.yml b/action.yml index 6f5e0ed0..195abf2a 100644 --- a/action.yml +++ b/action.yml @@ -68,6 +68,10 @@ inputs: description: The cargo profile to build. This defaults to the release profile. required: false default: 'release' + split_debuginfo: + description: Split debuginfos off of the production binary using objcopy before stripping. + required: false + default: 'false' # TODO: allow kebab-case input option names? # Note: @@ -95,3 +99,4 @@ runs: INPUT_TOKEN: ${{ inputs.token }} INPUT_REF: ${{ inputs.ref }} INPUT_PROFILE: ${{ inputs.profile }} + INPUT_SPLIT_DEBUGINFO: ${{ inputs.split_debuginfo }} diff --git a/main.sh b/main.sh index 6da59088..11ae4020 100755 --- a/main.sh +++ b/main.sh @@ -47,6 +47,13 @@ elif [[ ! "${INPUT_ZIP}" =~ ^(all|unix|windows|none)$ ]]; then bail "invalid input 'zip': ${INPUT_ZIP}" fi +split_debuginfo="${INPUT_SPLIT_DEBUGINFO:-}" +case "${split_debuginfo}" in + true) split_debuginfo="1" ;; + false) split_debuginfo="" ;; + *) bail "'split_debuginfo' input option must be 'true' or 'false': '${split_debuginfo}'" ;; +esac + leading_dir="${INPUT_LEADING_DIR:-}" case "${leading_dir}" in true) leading_dir="1" ;; @@ -245,6 +252,11 @@ build() { do_strip() { target_dir="$1" if [[ -n "${strip:-}" ]]; then + if [[ -n "${split_debuginfo}" ]]; then + for bin_exe in "${bins[@]}"; do + x objcopy --only-keep-debug "${target_dir}/${bin_exe}" "${target_dir}/${bin_exe}.debug" + done + fi for bin_exe in "${bins[@]}"; do x "${strip}" "${target_dir}/${bin_exe}" done