|
4 | 4 | - master |
5 | 5 | pull_request: |
6 | 6 | jobs: |
7 | | - build_and_upload: |
8 | | - name: Build and archive artifacts |
9 | | - runs-on: ${{ matrix.os }} |
| 7 | + build: |
| 8 | + name: Build ddns-updater |
| 9 | + runs-on: ${{ matrix.artifact.os }} |
10 | 10 | env: |
11 | 11 | CARGO_TERM_COLOR: always |
| 12 | + # https://github.com/rust-lang/rust/issues/78210 |
| 13 | + RUSTFLAGS: -C strip=symbols -C target-feature=+crt-static |
| 14 | + TARGETS: ${{ join(matrix.artifact.targets, ' ') || matrix.artifact.name }} |
| 15 | + ANDROID_API: ${{ matrix.artifact.android_api }} |
12 | 16 | strategy: |
13 | 17 | fail-fast: false |
14 | 18 | matrix: |
15 | | - os: |
16 | | - - ubuntu-latest |
17 | | - - windows-latest |
18 | | - - macos-latest |
| 19 | + artifact: |
| 20 | + - os: ubuntu-latest |
| 21 | + name: x86_64-unknown-linux-gnu |
| 22 | + - os: windows-latest |
| 23 | + name: x86_64-pc-windows-gnu |
| 24 | + - os: macos-latest |
| 25 | + name: universal-apple-darwin |
| 26 | + targets: |
| 27 | + - aarch64-apple-darwin |
| 28 | + - x86_64-apple-darwin |
| 29 | + combine: lipo |
| 30 | + - os: ubuntu-latest |
| 31 | + name: aarch64-linux-android31 |
| 32 | + targets: |
| 33 | + - aarch64-linux-android |
| 34 | + android_api: '31' |
19 | 35 | steps: |
20 | 36 | - name: Check out repository |
21 | 37 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
22 | 38 | with: |
23 | | - fetch-depth: 1 |
| 39 | + # For git describe |
| 40 | + fetch-depth: 0 |
24 | 41 |
|
25 | | - - name: Get Rust target triple |
26 | | - id: get_target |
| 42 | + - name: Update Rust |
| 43 | + run: rustup update stable |
| 44 | + |
| 45 | + - name: Install cargo-android |
| 46 | + shell: bash |
| 47 | + run: | |
| 48 | + cargo install \ |
| 49 | + --git https://github.com/chenxiaolong/cargo-android \ |
| 50 | + --tag v0.1.3 |
| 51 | +
|
| 52 | + - name: Get version |
| 53 | + id: get_version |
| 54 | + shell: bash |
| 55 | + run: | |
| 56 | + echo -n 'version=' >> "${GITHUB_OUTPUT}" |
| 57 | + git describe --always \ |
| 58 | + | sed -E "s/^v//g;s/([^-]*-g)/r\1/;s/-/./g" \ |
| 59 | + >> "${GITHUB_OUTPUT}" |
| 60 | +
|
| 61 | + - name: Install toolchains |
| 62 | + shell: bash |
| 63 | + run: | |
| 64 | + for target in ${TARGETS}; do |
| 65 | + rustup target add "${target}" |
| 66 | + done |
| 67 | +
|
| 68 | + - name: Cache Rust dependencies |
| 69 | + uses: Swatinem/rust-cache@9d47c6ad4b02e050fd481d890b2ea34778fd09d6 # v2.7.8 |
| 70 | + |
| 71 | + - name: Clippy |
| 72 | + shell: bash |
| 73 | + run: | |
| 74 | + for target in ${TARGETS}; do |
| 75 | + cargo android \ |
| 76 | + clippy --release --features static \ |
| 77 | + --target "${target}" |
| 78 | + done |
| 79 | +
|
| 80 | + - name: Formatting |
| 81 | + run: cargo fmt -- --check |
| 82 | + |
| 83 | + - name: Build |
27 | 84 | shell: bash |
28 | 85 | run: | |
29 | | - echo -n 'name=' >> "${GITHUB_OUTPUT}" |
30 | | - rustc -vV | sed -n 's|host: ||p' >> "${GITHUB_OUTPUT}" |
| 86 | + for target in ${TARGETS}; do |
| 87 | + cargo android \ |
| 88 | + build --release --features static \ |
| 89 | + --target "${target}" |
| 90 | + done |
31 | 91 |
|
32 | | - - name: Run tests in debug mode |
33 | | - env: |
34 | | - RUST_BACKTRACE: 1 |
35 | | - TERM: xterm |
| 92 | + - name: Create output directory |
| 93 | + shell: bash |
36 | 94 | run: | |
37 | | - cargo clippy --workspace -- -D warnings |
38 | | - cargo test --workspace |
| 95 | + rm -rf target/output |
39 | 96 |
|
40 | | - - name: Build in debug mode |
41 | | - run: cargo build --verbose |
| 97 | + case "${{ matrix.artifact.combine }}" in |
| 98 | + lipo) |
| 99 | + mkdir target/output |
| 100 | + cmd=(lipo -output target/output/ddns-updater -create) |
| 101 | + for target in ${TARGETS}; do |
| 102 | + cmd+=("target/${target}/release/ddns-updater") |
| 103 | + done |
| 104 | + "${cmd[@]}" |
| 105 | + ;; |
| 106 | + '') |
| 107 | + ln -s "${TARGETS}/release" target/output |
| 108 | + ;; |
| 109 | + *) |
| 110 | + echo >&2 "Unsupported combine argument" |
| 111 | + exit 1 |
| 112 | + ;; |
| 113 | + esac |
42 | 114 |
|
43 | 115 | - name: Archive artifacts |
44 | 116 | uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 |
45 | 117 | with: |
46 | | - name: ddns-updater-${{ steps.get_target.outputs.name }} |
| 118 | + name: ddns-updater-${{ steps.get_version.outputs.version }}-${{ matrix.artifact.name }} |
47 | 119 | path: | |
48 | 120 | target/debug/ddns-updater |
49 | 121 | target/debug/ddns-updater.exe |
50 | | - target/debug/ddns_updater.pdb |
|
0 commit comments