Skip to content

Commit

Permalink
fix patchelf order of operations in setup_native
Browse files Browse the repository at this point in the history
  • Loading branch information
nkraetzschmar committed Dec 8, 2023
1 parent ffcb84e commit 5541d37
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 21 deletions.
29 changes: 14 additions & 15 deletions .github/workflows/build_container.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
on:
push:
workflow_dispatch:
inputs:
version:
Expand All @@ -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
Expand All @@ -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-arm64/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-arm64/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 }}
12 changes: 6 additions & 6 deletions container/setup_native
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5541d37

Please sign in to comment.