From 953153ea1a375f0c202a7ceee86bd4c87f35ff4e Mon Sep 17 00:00:00 2001 From: The1111mp <31227919+1111mp@users.noreply.github.com> Date: Thu, 31 Oct 2024 17:20:16 +0800 Subject: [PATCH] chore: added support for compiling linux arm architecture (#1945) * chore: added support for compiling linux arm architecture Signed-off-by: The1111mp * chore: remove debug code Signed-off-by: The1111mp --------- Signed-off-by: The1111mp --- .cargo/config.toml | 5 ++ .github/build-for-linux/Dockerfile | 4 - .github/build-for-linux/action.yml | 14 ---- .github/build-for-linux/build.sh | 5 -- .github/build-for-linux/entrypoint.sh | 17 ---- .github/workflows/alpha.yml | 107 +++++++++++++++++++++++-- .github/workflows/release.yml | 111 +++++++++++++++++++++++--- 7 files changed, 204 insertions(+), 59 deletions(-) create mode 100644 .cargo/config.toml delete mode 100644 .github/build-for-linux/Dockerfile delete mode 100644 .github/build-for-linux/action.yml delete mode 100644 .github/build-for-linux/build.sh delete mode 100644 .github/build-for-linux/entrypoint.sh diff --git a/.cargo/config.toml b/.cargo/config.toml new file mode 100644 index 0000000..beb596d --- /dev/null +++ b/.cargo/config.toml @@ -0,0 +1,5 @@ +[target.aarch64-unknown-linux-gnu] +linker = "aarch64-linux-gnu-gcc" + +[target.armv7-unknown-linux-gnueabihf] +linker = "arm-linux-gnueabihf-gcc" diff --git a/.github/build-for-linux/Dockerfile b/.github/build-for-linux/Dockerfile deleted file mode 100644 index 729644b..0000000 --- a/.github/build-for-linux/Dockerfile +++ /dev/null @@ -1,4 +0,0 @@ -FROM rust:bookworm -COPY entrypoint.sh /entrypoint.sh -RUN chmod a+x /entrypoint.sh -ENTRYPOINT ["/entrypoint.sh"] diff --git a/.github/build-for-linux/action.yml b/.github/build-for-linux/action.yml deleted file mode 100644 index 17c171a..0000000 --- a/.github/build-for-linux/action.yml +++ /dev/null @@ -1,14 +0,0 @@ -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 }} diff --git a/.github/build-for-linux/build.sh b/.github/build-for-linux/build.sh deleted file mode 100644 index fbc18cc..0000000 --- a/.github/build-for-linux/build.sh +++ /dev/null @@ -1,5 +0,0 @@ -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 diff --git a/.github/build-for-linux/entrypoint.sh b/.github/build-for-linux/entrypoint.sh deleted file mode 100644 index f02b7d8..0000000 --- a/.github/build-for-linux/entrypoint.sh +++ /dev/null @@ -1,17 +0,0 @@ -#!/bin/bash - -wget https://nodejs.org/dist/v20.10.0/node-v20.10.0-linux-x64.tar.xz -tar -Jxvf ./node-v20.10.0-linux-x64.tar.xz -export PATH=$(pwd)/node-v20.10.0-linux-x64/bin:$PATH -npm install pnpm -g - -rustup target add "$INPUT_TARGET" -echo "rustc version: $(rustc --version)" - -if [ "$INPUT_TARGET" = "x86_64-unknown-linux-gnu" ]; then - apt-get update - apt-get install -y libxdo-dev libssl-dev libayatana-appindicator3-dev librsvg2-dev libglib2.0-dev libgtk-3-dev libwebkit2gtk-4.1-dev libsoup-3.0-dev libjavascriptcoregtk-4.1-dev - export PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig -fi - -bash .github/build-for-linux/build.sh diff --git a/.github/workflows/alpha.yml b/.github/workflows/alpha.yml index 9fd3706..8d53275 100644 --- a/.github/workflows/alpha.yml +++ b/.github/workflows/alpha.yml @@ -28,6 +28,8 @@ jobs: target: aarch64-apple-darwin - os: macos-latest target: x86_64-apple-darwin + - os: ubuntu-22.04 + target: x86_64-unknown-linux-gnu runs-on: ${{ matrix.os }} steps: @@ -46,6 +48,12 @@ jobs: workspaces: src-tauri cache-all-crates: true cache-on-failure: true + + - name: Install dependencies (ubuntu only) + if: matrix.os == 'ubuntu-22.04' + run: | + sudo apt-get update + sudo apt-get install -y libwebkit2gtk-4.1-dev libayatana-appindicator3-dev librsvg2-dev patchelf - name: Install Node uses: actions/setup-node@v4 @@ -90,26 +98,107 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - alpha-for-linux: + alpha-for-linux-arm: strategy: fail-fast: false matrix: include: - - os: ubuntu-latest - target: x86_64-unknown-linux-gnu + - os: ubuntu-22.04 + target: aarch64-unknown-linux-gnu + arch: arm64 + - os: ubuntu-22.04 + target: armv7-unknown-linux-gnueabihf + arch: armhf runs-on: ${{ matrix.os }} steps: - name: Checkout Repository uses: actions/checkout@v4 + - name: Install Rust Stable + uses: dtolnay/rust-toolchain@stable + + - name: Add Rust Target + run: rustup target add ${{ matrix.target }} + + - name: Rust Cache + uses: Swatinem/rust-cache@v2 + with: + workspaces: src-tauri + cache-all-crates: true + + - name: Install Node + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install pnpm + uses: pnpm/action-setup@v4 + with: + run_install: false + + - name: Pnpm install and check + run: | + pnpm i + pnpm check ${{ matrix.target }} + + - name: 'Setup for linux' + run: |- + sudo ls -lR /etc/apt/ + + cat > /tmp/sources.list << EOF + deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu jammy main multiverse universe restricted + deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu jammy-security main multiverse universe restricted + deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu jammy-updates main multiverse universe restricted + deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu jammy-backports main multiverse universe restricted + + deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy main multiverse universe restricted + deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security main multiverse universe restricted + deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates main multiverse universe restricted + deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-backports main multiverse universe restricted + EOF + + sudo mv /etc/apt/sources.list /etc/apt/sources.list.default + sudo mv /tmp/sources.list /etc/apt/sources.list + + sudo dpkg --add-architecture ${{ matrix.arch }} + sudo apt update + + sudo apt install -y \ + libwebkit2gtk-4.1-dev:${{ matrix.arch }} \ + libayatana-appindicator3-dev:${{ matrix.arch }} \ + libssl-dev:${{ matrix.arch }} \ + patchelf:${{ matrix.arch }} \ + librsvg2-dev:${{ matrix.arch }} + + - name: 'Install aarch64 tools' + if: matrix.target == 'aarch64-unknown-linux-gnu' + run: | + sudo apt install -y \ + gcc-aarch64-linux-gnu \ + g++-aarch64-linux-gnu + + - name: 'Install armv7 tools' + if: matrix.target == 'armv7-unknown-linux-gnueabihf' + run: | + sudo apt install -y \ + gcc-arm-linux-gnueabihf \ + g++-arm-linux-gnueabihf + - name: Build for Linux - uses: ./.github/build-for-linux + run: | + export PKG_CONFIG_ALLOW_CROSS=1 + if [ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]; then + export PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig/:$PKG_CONFIG_PATH + export PKG_CONFIG_SYSROOT_DIR=/usr/aarch64-linux-gnu/ + elif [ "${{ matrix.target }}" == "armv7-unknown-linux-gnueabihf" ]; then + export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig/:$PKG_CONFIG_PATH + export PKG_CONFIG_SYSROOT_DIR=/usr/arm-linux-gnueabihf/ + fi + pnpm build --target ${{ matrix.target }} env: - NODE_OPTIONS: "--max_old_space_size=4096" + NODE_OPTIONS: '--max_old_space_size=4096' TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }} TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }} - with: - target: ${{ matrix.target }} - name: Get Version run: | @@ -214,7 +303,7 @@ jobs: update_tag: name: Update tag runs-on: ubuntu-latest - needs: [alpha, alpha-for-linux, alpha-for-fixed-webview2] + needs: [alpha, alpha-for-linux-arm, alpha-for-fixed-webview2] steps: - name: Checkout repository uses: actions/checkout@v4 @@ -241,6 +330,8 @@ jobs: ### Linux - Linux 64位: amd64.deb/amd64.rpm + - Linux arm64 architecture: arm64.deb/aarch64.rpm + - Linux armv7架构: armhf.deb/armhfp.rpm ### Windows (Win7 用户请查看下面FAQ中的解决方案) #### 正常版本(推荐) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index d753d6a..0a0c959 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,6 +21,8 @@ jobs: target: aarch64-apple-darwin - os: macos-latest target: x86_64-apple-darwin + - os: ubuntu-22.04 + target: x86_64-unknown-linux-gnu runs-on: ${{ matrix.os }} steps: @@ -39,6 +41,12 @@ jobs: workspaces: src-tauri cache-all-crates: true + - name: Install dependencies (ubuntu only) + if: matrix.os == 'ubuntu-22.04' + run: | + sudo apt-get update + sudo apt-get install -y libwebkit2gtk-4.1-dev libayatana-appindicator3-dev librsvg2-dev patchelf + - name: Install Node uses: actions/setup-node@v4 with: @@ -80,26 +88,107 @@ jobs: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - release-for-linux: + release-for-linux-arm: strategy: fail-fast: false matrix: include: - - os: ubuntu-latest - target: x86_64-unknown-linux-gnu + - os: ubuntu-22.04 + target: aarch64-unknown-linux-gnu + arch: arm64 + - os: ubuntu-22.04 + target: armv7-unknown-linux-gnueabihf + arch: armhf runs-on: ${{ matrix.os }} steps: - name: Checkout Repository uses: actions/checkout@v4 - - name: Build for Linux - uses: ./.github/build-for-linux - env: - NODE_OPTIONS: "--max_old_space_size=4096" - TAURI_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }} - TAURI_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }} + - name: Install Rust Stable + uses: dtolnay/rust-toolchain@stable + + - name: Add Rust Target + run: rustup target add ${{ matrix.target }} + + - name: Rust Cache + uses: Swatinem/rust-cache@v2 with: - target: ${{ matrix.target }} + workspaces: src-tauri + cache-all-crates: true + + - name: Install Node + uses: actions/setup-node@v4 + with: + node-version: '20' + + - name: Install pnpm + uses: pnpm/action-setup@v4 + with: + run_install: false + + - name: Pnpm install and check + run: | + pnpm i + pnpm check ${{ matrix.target }} + + - name: 'Setup for linux' + run: |- + sudo ls -lR /etc/apt/ + + cat > /tmp/sources.list << EOF + deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu jammy main multiverse universe restricted + deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu jammy-security main multiverse universe restricted + deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu jammy-updates main multiverse universe restricted + deb [arch=amd64,i386] http://archive.ubuntu.com/ubuntu jammy-backports main multiverse universe restricted + + deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy main multiverse universe restricted + deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-security main multiverse universe restricted + deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-updates main multiverse universe restricted + deb [arch=armhf,arm64] http://ports.ubuntu.com/ubuntu-ports jammy-backports main multiverse universe restricted + EOF + + sudo mv /etc/apt/sources.list /etc/apt/sources.list.default + sudo mv /tmp/sources.list /etc/apt/sources.list + + sudo dpkg --add-architecture ${{ matrix.arch }} + sudo apt update + + sudo apt install -y \ + libwebkit2gtk-4.1-dev:${{ matrix.arch }} \ + libayatana-appindicator3-dev:${{ matrix.arch }} \ + libssl-dev:${{ matrix.arch }} \ + patchelf:${{ matrix.arch }} \ + librsvg2-dev:${{ matrix.arch }} + + - name: 'Install aarch64 tools' + if: matrix.target == 'aarch64-unknown-linux-gnu' + run: | + sudo apt install -y \ + gcc-aarch64-linux-gnu \ + g++-aarch64-linux-gnu + + - name: 'Install armv7 tools' + if: matrix.target == 'armv7-unknown-linux-gnueabihf' + run: | + sudo apt install -y \ + gcc-arm-linux-gnueabihf \ + g++-arm-linux-gnueabihf + + - name: Build for Linux + run: | + export PKG_CONFIG_ALLOW_CROSS=1 + if [ "${{ matrix.target }}" == "aarch64-unknown-linux-gnu" ]; then + export PKG_CONFIG_PATH=/usr/lib/aarch64-linux-gnu/pkgconfig/:$PKG_CONFIG_PATH + export PKG_CONFIG_SYSROOT_DIR=/usr/aarch64-linux-gnu/ + elif [ "${{ matrix.target }}" == "armv7-unknown-linux-gnueabihf" ]; then + export PKG_CONFIG_PATH=/usr/lib/arm-linux-gnueabihf/pkgconfig/:$PKG_CONFIG_PATH + export PKG_CONFIG_SYSROOT_DIR=/usr/arm-linux-gnueabihf/ + fi + pnpm build --target ${{ matrix.target }} + env: + NODE_OPTIONS: '--max_old_space_size=4096' + TAURI_SIGNING_PRIVATE_KEY: ${{ secrets.TAURI_PRIVATE_KEY }} + TAURI_SIGNING_PRIVATE_KEY_PASSWORD: ${{ secrets.TAURI_KEY_PASSWORD }} - name: Get Version run: | @@ -201,7 +290,7 @@ jobs: release-update: runs-on: ubuntu-latest - needs: [release, release-for-linux] + needs: [release, release-for-linux-arm] steps: - name: Checkout repository uses: actions/checkout@v4