Skip to content

Commit

Permalink
feat!: resource update and refactor maa core binding (#126)
Browse files Browse the repository at this point in the history
**Features:**

- Introduce resource update functionality by fetch `MaaResource` repo. There are two backend of git: command `git` and library `libgit2`.

**Refactors:**

- Reorganize configs.
- Restructure mod `run`.
- Move some types into `maa-sys`.
- Replace the use of transport provided by `rustls` with `native_tls`.

**BREAKING CHANGES:**

- Resource-related configurations have been moved to a separate section, 'resource'.

**Build features:**

- **`cli_installer`:** Provides `maa self update` and can be disabled when compiled by a package manager.
- **`core_installer`:** Provides `maa install/update` and may be disabled when compiled as an AppImage.
- **`git2`:** Provides the resource update backend `libgit2`.
- **`vendored-openssl`:** Compiles and statically links OpenSSL for `git2` (all platforms) and `reqwest` (on Linux) if OpenSSL is not available in the system. This feature is not enabled by default.
  • Loading branch information
wangl-cc authored Dec 12, 2023
1 parent e276d77 commit 24c7a89
Show file tree
Hide file tree
Showing 36 changed files with 4,410 additions and 1,710 deletions.
4 changes: 2 additions & 2 deletions .github/actions/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ runs:
esac
echo "CARGO_BUILD_TARGET=$target" >> $GITHUB_ENV
- name: Install Target
if: inputs.arch == 'aarch64'
if: inputs.arch != 'x86_64'
shell: bash
run: rustup target add $CARGO_BUILD_TARGET
- name: Cross Compile Dependencies (Linux)
- name: Setup Cross Compiling Toolchain (Linux x86_64 to aarch64)
if: inputs.arch == 'aarch64' && startsWith(inputs.os, 'ubuntu')
shell: bash
run: |
Expand Down
69 changes: 0 additions & 69 deletions .github/workflows/ci-sys.yml

This file was deleted.

114 changes: 91 additions & 23 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,6 @@ jobs:
- ubuntu-latest
- macos-latest
- windows-latest
arch:
- x86_64
- aarch64
exclude:
# Failed to cross compile ring on Windows
- os: windows-latest
arch: aarch64
env:
MAA_EXTRA_SHARE_NAME: maa-test
steps:
Expand All @@ -53,23 +46,20 @@ jobs:
uses: ./.github/actions/setup
with:
os: ${{ matrix.os }}
arch: ${{ matrix.arch }}
arch: x86_64
coverage: true
- name: Setup Cache
uses: Swatinem/rust-cache@v2
- name: Build (maa-cli)
run: |
cargo build --package maa-cli --locked
- name: Lint (clippy)
if: matrix.arch == 'x86_64'
run: |
cargo clippy --all-targets --all-features -- -D warnings
cargo clippy -- -D warnings
- name: Lint (rustfmt)
if: matrix.arch == 'x86_64'
run: |
cargo fmt --all -- --check
- name: Install MaaCore
if: matrix.arch == 'x86_64'
env:
MAA_CONFIG_DIR: ${{ github.workspace }}/config_examples
run: |
Expand All @@ -87,21 +77,43 @@ jobs:
fi
echo "MAA_CORE_INSTALLED=true" >> "$GITHUB_ENV"
- name: Test
if: matrix.arch == 'x86_64'
run: |
cargo test
- name: Coverage
if: matrix.arch == 'x86_64'
run: |
cargo tarpaulin --all-features --workspace --timeout 120 --out xml ${{ github.run_attempt == 1 && '--skip-clean' || '' }}
cargo tarpaulin --packages maa-cli --timeout 120 --out xml \
${{ github.run_attempt == 1 && '--skip-clean' || '' }}
- name: Upload to codecov.io
if: matrix.arch == 'x86_64'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true

features:
build-aarch64:
name: Build (aarch64)
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust
uses: ./.github/actions/setup
with:
os: ${{ matrix.os }}
arch: aarch64
- name: Setup Cache
uses: Swatinem/rust-cache@v2
- name: Build
run: |
cargo build --package maa-cli --locked \
--features vendored-openssl
build-feature:
name: Build and Test (no default features)
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -111,10 +123,9 @@ jobs:
- ubuntu-latest
- macos-latest
- windows-latest
features:
- --features core_installer
- --features cli_installer
- ""
feature:
- core_installer # disabled cli_installer and git2, used by package manager
- git2 # disabled both cli_installer and core_installer, used by appimage
steps:
- name: Checkout repository
uses: actions/checkout@v4
Expand All @@ -126,10 +137,67 @@ jobs:
- name: Setup Cache
uses: Swatinem/rust-cache@v2
with:
key: feature-${{ matrix.features }}
key: ${{ matrix.feature }}
- name: Build
run: |
cargo build --package maa-cli --no-default-features ${{ matrix.features }} --locked
cargo build --package maa-cli --locked \
--no-default-features --features ${{ matrix.feature }}
- name: Test
run: |
cargo test
build-sys:
name: Build and test (maa-sys, static)
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
os:
- ubuntu-latest
- macos-latest
- windows-latest
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Setup Rust
uses: ./.github/actions/setup
with:
os: ${{ matrix.os }}
arch: x86_64
coverage: true
- name: Setup Cache
uses: Swatinem/rust-cache@v2
- name: Install MaaCore
env:
MAA_CONFIG_DIR: ${{ github.workspace }}/config_examples
run: |
cargo run -- install stable -t0
MAA_CORE_DIR="$(cargo run -- dir lib)"
MAA_RESOURCE_DIR="$(cargo run -- dir resource)"
ls -l "$MAA_CORE_DIR"
ls -l "$MAA_RESOURCE_DIR"
echo "MAA_CORE_DIR=$MAA_CORE_DIR" >> $GITHUB_ENV
echo "MAA_RESOURCE_DIR=$MAA_RESOURCE_DIR" >> $GITHUB_ENV
- name: Build
run: cargo build --package maa-sys --locked
- name: Lint (clippy)
run: cargo clippy --package maa-sys -- -D warnings
- name: Lint (fmt)
run: cargo fmt --package maa-sys -- --check
- name: Test
# It seems rust needs a static library to check the linking.
# Without this, we can not link maa-sys to MaaCore on Windows.
# https://stackoverflow.com/questions/63394094/rust-linker-seeks-a-lib-rather-than-a-dll
if: ${{ !startsWith(matrix.os, 'windows') }}
run: cargo test --package maa-sys
- name: Coverage
if: ${{ !startsWith(matrix.os, 'windows') }}
run: |
cargo tarpaulin --packages maa-sys --timeout 120 --out xml \
${{ github.run_attempt == 1 && '--skip-clean' || '' }}
- name: Upload to codecov.io
if: ${{ !startsWith(matrix.os, 'windows') }}
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
fail_ci_if_error: true
4 changes: 3 additions & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
- main
paths:
- ".github/workflows/release.yml"
- ".github/actions/setup/action.yml"
workflow_dispatch:
inputs:
channel:
Expand Down Expand Up @@ -136,7 +137,8 @@ jobs:
CARGO_PROFILE_RELEASE_LTO: true
CARGO_PROFILE_RELEASE_STRIP: true
run: |
cargo build --release --package maa-cli
cargo build --release --package maa-cli \
${{ matrix.arch != 'x86_64' && '--features git2/vendored-openssl,reqwest/native-tls-vendored' || '' }}
- name: Tar Artifact
run: |
tar -cvf "$CARGO_BUILD_TARGET.tar" -C "target/$CARGO_BUILD_TARGET/release" maa
Expand Down
Loading

0 comments on commit 24c7a89

Please sign in to comment.