Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Is it possible to compile linux arm64 architecture? #902

Closed
1111mp opened this issue Sep 5, 2024 · 1 comment
Closed

Is it possible to compile linux arm64 architecture? #902

1111mp opened this issue Sep 5, 2024 · 1 comment
Labels
type: question Further information is requested

Comments

@1111mp
Copy link

1111mp commented Sep 5, 2024

Currently I have it implemented via docker based on docker/setup-qemu-action and setup-buildx-action, but the compilation speed is too slow (it took a total of 1 hour and 35 minutes)

release.yml:

release-for-linux-arm64:
    strategy:
      fail-fast: false
      matrix:
        include:
          - os: ubuntu-latest
            target: aarch64-unknown-linux-gnu
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout Repository
        uses: actions/checkout@v4

      - name: Set up QEMU
        uses: docker/setup-qemu-action@v2
        with:
          platforms: arm64

      - name: Set up Docker Buildx
        uses: docker/setup-buildx-action@v2

      - name: Build for Linux
        uses: ./.github/build-for-linux-arm64
        env:
          NODE_OPTIONS: '--max_old_space_size=4096'
          TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY }}
          TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_SIGNING_PRIVATE_KEY_PASSWORD }}
        with:
          target: ${{ matrix.target }}

      - name: Get Version
        run: |
          sudo apt-get update
          sudo apt-get install jq
          echo "VERSION=$(cat package.json | jq '.version' | tr -d '"')" >> $GITHUB_ENV

      - name: Upload Release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: v${{env.VERSION}}
          name: 'NVM Desktop v${{env.VERSION}}'
          body: 'More new features are now supported.'
          token: ${{ secrets.GITHUB_TOKEN }}
          files: |
            src-tauri/target/${{ matrix.target }}/release/bundle/deb/*.deb
            src-tauri/target/${{ matrix.target }}/release/bundle/rpm/*.rpm

action.yml file in the ./.github/build-for-linux-arm64 directory:

name: "Build for Linux"
branding:
  icon: user-check
  color: gray-dark
inputs:
  target:
    required: true
    description: "Rust Target"

runs:
  using: "docker"
  image: "Dockerfile"
  args:
    - ${{ inputs.target }}

Dockerfile:

FROM --platform=linux/arm64 ubuntu:22.04

# 安装必要的依赖
RUN apt-get update && \
    apt-get install -y curl build-essential wget

# 安装最新的 Rust 稳定版本
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y --default-toolchain stable
ENV PATH="/root/.cargo/bin:${PATH}"

COPY entrypoint.sh /entrypoint.sh
RUN chmod a+x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"] 

entrypoint.sh:

#!/bin/bash

# 设置 Rust 默认工具链为稳定版本
rustup default stable
rustup --version

wget https://nodejs.org/dist/v20.17.0/node-v20.17.0-linux-arm64.tar.xz
tar -Jxvf ./node-v20.17.0-linux-arm64.tar.xz
export PATH=$(pwd)/node-v20.17.0-linux-arm64/bin:$PATH
npm install pnpm -g

rustup target add "$INPUT_TARGET"

if [ "$INPUT_TARGET" = "aarch64-unknown-linux-gnu" ]; then
    apt-get update
    apt-get install -y libwebkit2gtk-4.1-dev libappindicator3-dev librsvg2-dev patchelf
else
    echo "Unknown target: $INPUT_TARGET" && exit 1
fi

bash .github/build-for-linux-arm64/build.sh

build.sh:

pnpm install
pnpm check $INPUT_TARGET
sed -i "s/#openssl/openssl={version=\"0.10\",features=[\"vendored\"]}/g" src-tauri/Cargo.toml

pnpm build --target $INPUT_TARGET

The complete code can be viewed at: https://github.com/1111mp/nvm-desktop-test

Is there any better way?
Thanks in advance 🙏

@FabianLars
Copy link
Member

This question is actually not really related to this action. tauri-action doesn't do anything fancy, it just executes tauri build on the currently used github runner.

If you do not need the .AppImage bundle you can cross-compile your app on the normal runners by basically doing this: https://tauri.app/v1/guides/building/linux#manual-compilation (changing webkitgtk 4.0 to 4.1 for v2).

If you do need the .AppImage then what you did (which is pretty similar to our docs https://v2.tauri.app/distribute/pipelines/github/#arm-runner-compilation) is required if you do not want to pay for GitHub's native arm runners.

For reference, this is the main upstream issue for cross compiling appimages linuxdeploy/linuxdeploy#258 (though iirc other appimage tooling has the same problem, not sure anymore)

@FabianLars FabianLars closed this as not planned Won't fix, can't repro, duplicate, stale Sep 5, 2024
@FabianLars FabianLars added the type: question Further information is requested label Sep 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants