From 43e522624b32039c9c9e7dce04748d7f2b2fe7d6 Mon Sep 17 00:00:00 2001 From: nkraetzschmar <9020053+nkraetzschmar@users.noreply.github.com> Date: Fri, 8 Dec 2023 09:57:47 +0100 Subject: [PATCH] fix patchelf order of operations in setup_native --- .github/workflows/build_container.yml | 29 +++++++++++++-------------- container/setup_native | 12 +++++------ 2 files changed, 20 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build_container.yml b/.github/workflows/build_container.yml index a33b232..caf40ba 100644 --- a/.github/workflows/build_container.yml +++ b/.github/workflows/build_container.yml @@ -1,5 +1,4 @@ on: - push: workflow_dispatch: inputs: version: @@ -26,20 +25,20 @@ jobs: set -x cd container if [ ${{ matrix.host }} = ${{ matrix.target }} ]; then - podman build --build-arg arch=${{ matrix.host }} -f build.containerfile -t ghcr.io/${{ github.repository }}/host-${{ matrix.host }}/target-${{ matrix.target }}:${{ inputs.version || 'latest' || 'latest' }} . + podman build --build-arg arch=${{ matrix.host }} -f build.containerfile -t ghcr.io/${{ github.repository }}/host-${{ matrix.host }}/target-${{ matrix.target }}:${{ inputs.version }} . else case ${{ matrix.target }} in amd64) gnu_arch=x86-64 ;; arm64v8) gnu_arch=aarch64 ;; esac - podman build --build-arg native_arch=${{ matrix.host }} --build-arg target_arch=${{ matrix.target }} --build-arg gnu_arch=$gnu_arch -f crossbuild.containerfile -t ghcr.io/${{ github.repository }}/host-${{ matrix.host }}/target-${{ matrix.target }}:${{ inputs.version || 'latest' || 'latest' }} . + podman build --build-arg native_arch=${{ matrix.host }} --build-arg target_arch=${{ matrix.target }} --build-arg gnu_arch=$gnu_arch -f crossbuild.containerfile -t ghcr.io/${{ github.repository }}/host-${{ matrix.host }}/target-${{ matrix.target }}:${{ inputs.version }} . fi - name: publish if: ${{ inputs.publish }} run: | podman login -u token -p ${{ github.token }} ghcr.io - podman push ghcr.io/${{ github.repository }}/host-${{ matrix.host }}/target-${{ matrix.target }}:${{ inputs.version || 'latest' || 'latest' }} - podman inspect ghcr.io/${{ github.repository }}/host-${{ matrix.host }}/target-${{ matrix.target }}:${{ inputs.version || 'latest' || 'latest' }} + podman push ghcr.io/${{ github.repository }}/host-${{ matrix.host }}/target-${{ matrix.target }}:${{ inputs.version }} + podman inspect ghcr.io/${{ github.repository }}/host-${{ matrix.host }}/target-${{ matrix.target }}:${{ inputs.version }} publish: runs-on: ubuntu-latest needs: build @@ -48,13 +47,13 @@ jobs: - name: publish run: | podman login -u token -p ${{ github.token }} ghcr.io - podman manifest create ghcr.io/${{ github.repository }}/target-amd64:${{ inputs.version || 'latest' }} - podman manifest add --arch amd64 ghcr.io/${{ github.repository }}/target-amd64:${{ inputs.version || 'latest' }} ghcr.io/${{ github.repository }}/host-amd64/target-amd64:${{ inputs.version || 'latest' }} - podman manifest add --arch arm64 ghcr.io/${{ github.repository }}/target-amd64:${{ inputs.version || 'latest' }} ghcr.io/${{ github.repository }}/host-arm64/target-amd64:${{ inputs.version || 'latest' }} - podman push ghcr.io/${{ github.repository }}/target-amd64:${{ inputs.version || 'latest' }} - podman manifest inspect ghcr.io/${{ github.repository }}/target-amd64:${{ inputs.version || 'latest' }} - podman manifest create ghcr.io/${{ github.repository }}/target-arm64v8:${{ inputs.version || 'latest' }} - podman manifest add --arch amd64 ghcr.io/${{ github.repository }}/target-arm64v8:${{ inputs.version || 'latest' }} ghcr.io/${{ github.repository }}/host-amd64/target-arm64v8:${{ inputs.version || 'latest' }} - podman manifest add --arch arm64 ghcr.io/${{ github.repository }}/target-arm64v8:${{ inputs.version || 'latest' }} ghcr.io/${{ github.repository }}/host-arm64/target-arm64v8:${{ inputs.version || 'latest' }} - podman push ghcr.io/${{ github.repository }}/target-arm64v8:${{ inputs.version || 'latest' }} - podman manifest inspect ghcr.io/${{ github.repository }}/target-arm64v8:${{ inputs.version || 'latest' }} + podman manifest create ghcr.io/${{ github.repository }}/target-amd64:${{ inputs.version }} + podman manifest add --arch amd64 ghcr.io/${{ github.repository }}/target-amd64:${{ inputs.version }} ghcr.io/${{ github.repository }}/host-amd64/target-amd64:${{ inputs.version }} + podman manifest add --arch arm64 ghcr.io/${{ github.repository }}/target-amd64:${{ inputs.version }} ghcr.io/${{ github.repository }}/host-arm64v8/target-amd64:${{ inputs.version }} + podman push ghcr.io/${{ github.repository }}/target-amd64:${{ inputs.version }} + podman manifest inspect ghcr.io/${{ github.repository }}/target-amd64:${{ inputs.version }} + podman manifest create ghcr.io/${{ github.repository }}/target-arm64v8:${{ inputs.version }} + podman manifest add --arch amd64 ghcr.io/${{ github.repository }}/target-arm64v8:${{ inputs.version }} ghcr.io/${{ github.repository }}/host-amd64/target-arm64v8:${{ inputs.version }} + podman manifest add --arch arm64 ghcr.io/${{ github.repository }}/target-arm64v8:${{ inputs.version }} ghcr.io/${{ github.repository }}/host-arm64v8/target-arm64v8:${{ inputs.version }} + podman push ghcr.io/${{ github.repository }}/target-arm64v8:${{ inputs.version }} + podman manifest inspect ghcr.io/${{ github.repository }}/target-arm64v8:${{ inputs.version }} diff --git a/container/setup_native b/container/setup_native index 3641a15..b2c621f 100755 --- a/container/setup_native +++ b/container/setup_native @@ -42,18 +42,18 @@ function export_elf ( chmod +x "$new_file" fi patchelf --remove-rpath "$new_file" - if interpreter="$(patchelf --print-interpreter "$new_file" 2> /dev/null)"; then - new_interpreter="/native/$(basename "$interpreter")" - [ -e "$new_interpreter" ] || export_elf "$interpreter" - chmod 755 "$new_interpreter" - patchelf --set-interpreter "$new_interpreter" "$new_file" - fi patchelf --print-needed "$new_file" | while read lib; do lib_path="$(realpath "$(ldconfig -p | grep "^\s*$lib " | awk -F ' => ' '{ print $2 }' | head -n 1)")" new_lib="/native/$(basename "$lib_path")" [ -e "$new_lib" ] || export_elf "$lib_path" patchelf --replace-needed "$lib" "$new_lib" "$new_file" done + if interpreter="$(patchelf --print-interpreter "$new_file" 2> /dev/null)"; then + new_interpreter="/native/$(basename "$interpreter")" + [ -e "$new_interpreter" ] || export_elf "$interpreter" + chmod 755 "$new_interpreter" + patchelf --set-interpreter "$new_interpreter" "$new_file" + fi echo "exported $file -> $new_file" ldd "$new_file" 2> /dev/null || true