From 0cebfe9474b06f8ef4f92aeff82ab3fe4e181fb2 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 14 May 2026 00:39:53 +0900 Subject: [PATCH] Use setup/ubuntu action for cross-compiling --- .github/actions/setup/ubuntu/action.yml | 28 +++++++++++++++++++------ .github/workflows/crosscompile.yml | 17 +++++---------- 2 files changed, 27 insertions(+), 18 deletions(-) diff --git a/.github/actions/setup/ubuntu/action.yml b/.github/actions/setup/ubuntu/action.yml index b4454d49c7..7a5e1991e5 100644 --- a/.github/actions/setup/ubuntu/action.yml +++ b/.github/actions/setup/ubuntu/action.yml @@ -24,18 +24,35 @@ runs: using: composite steps: + - id: uname + name: uname + shell: bash + env: + arch: ${{ inputs.arch }} + run: | + setarch="${arch:+setarch $arch --}" + # normalize `uname` + if uname=$(${setarch} uname -m 2> /dev/null); then + echo "setarch=${setarch}" >> "$GITHUB_OUTPUT" + else + # if `setarch` failed, take the given `arch` as-is. + uname="${arch}" + setarch="" + fi + echo "uname=$uname" >> "$GITHUB_OUTPUT" + echo "dpkg=${uname/686/386}" >> "$GITHUB_OUTPUT" + - name: set SETARCH shell: bash run: echo "SETARCH=${setarch}" >> "$GITHUB_ENV" # zizmor: ignore[github-env] env: - setarch: ${{ inputs.arch && format('setarch {0} --', inputs.arch) }} + setarch: ${{ steps.uname.outputs.setarch }} - - id: uname - name: uname + - name: dpkg setup shell: bash run: | - echo uname=`${SETARCH} uname -m` >> "$GITHUB_OUTPUT" - echo dpkg=`${SETARCH} uname -m | sed s/686/386/` >> "$GITHUB_OUTPUT" + sudo dpkg --add-architecture ${{ steps.uname.outputs.dpkg }} + if: ${{ inputs.arch }} - name: apt-get shell: bash @@ -43,7 +60,6 @@ runs: arch: ${{ inputs.arch && format(':{0}', steps.uname.outputs.dpkg) || '' }} run: | set -x - ${arch:+sudo dpkg --add-architecture ${arch#:}} sudo apt-get update -qq || : sudo apt-get install --no-install-recommends -qq -y -o=Dpkg::Use-Pty=0 \ ${arch:+cross}build-essential${arch/:/-} \ diff --git a/.github/workflows/crosscompile.yml b/.github/workflows/crosscompile.yml index 8c0d23898a..4c28516e25 100644 --- a/.github/workflows/crosscompile.yml +++ b/.github/workflows/crosscompile.yml @@ -64,9 +64,8 @@ jobs: builddir: build makeup: true - - name: Install cross-compilation toolchain + - name: Setup cross-compilation toolchain sources run: | - sudo dpkg --add-architecture ${{ matrix.arch }} native_arch=$(dpkg --print-architecture) # Restrict existing sources to native arch sudo sed -i '/^Architectures:/d' /etc/apt/sources.list.d/ubuntu.sources @@ -84,16 +83,10 @@ jobs: "Components: main universe" \ "Architectures: ${{ matrix.arch }}" \ | sudo tee /etc/apt/sources.list.d/cross-${{ matrix.arch }}.sources - sudo apt-get update -qq - sudo apt-get install --no-install-recommends -qq -y \ - crossbuild-essential-${{ matrix.arch }} \ - libssl-dev:${{ matrix.arch }} \ - libyaml-dev:${{ matrix.arch }} \ - zlib1g-dev:${{ matrix.arch }} \ - libffi-dev:${{ matrix.arch }} \ - libreadline-dev:${{ matrix.arch }} \ - libncurses-dev:${{ matrix.arch }} \ - autoconf ruby + + - uses: ./.github/actions/setup/ubuntu + with: + arch: ${{ matrix.arch }} - uses: ./.github/actions/setup/baseruby id: baseruby