|
| 1 | +name: Build all Rust apps |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_call: |
| 5 | + inputs: |
| 6 | + c_sdk_branch: |
| 7 | + required: false |
| 8 | + default: '' |
| 9 | + type: string |
| 10 | + workflow_dispatch: |
| 11 | + pull_request: |
| 12 | + |
| 13 | +env: |
| 14 | + C_SDK_URL: 'https://github.com/LedgerHQ/ledger-secure-sdk.git' |
| 15 | + |
| 16 | +jobs: |
| 17 | + how-workflow-is-called: |
| 18 | + name: Determine how the workflow is called |
| 19 | + runs-on: ubuntu-latest |
| 20 | + outputs: |
| 21 | + repository: ${{ steps.get_repo_and_branch.outputs.repo }} |
| 22 | + branch: ${{ steps.get_repo_and_branch.outputs.branch }} |
| 23 | + steps: |
| 24 | + - name: Get repository and branch |
| 25 | + id: get_repo_and_branch |
| 26 | + run: | |
| 27 | + if [ -n "${{ inputs.c_sdk_branch }}" ]; then |
| 28 | + echo "repo=LedgerHQ/ledger-device-rust-sdk" >> $GITHUB_OUTPUT |
| 29 | + echo "branch=master" >> $GITHUB_OUTPUT |
| 30 | + else |
| 31 | + echo "repo=${{ github.repository}}" >> $GITHUB_OUTPUT |
| 32 | + echo "branch=${{ github.ref }}" >> $GITHUB_OUTPUT |
| 33 | + fi |
| 34 | + retrieve-rust-apps: |
| 35 | + name: Retrieve Rust Apps |
| 36 | + runs-on: ubuntu-latest |
| 37 | + needs: how-workflow-is-called |
| 38 | + outputs: |
| 39 | + rust_apps: ${{ steps.get_rust_apps.outputs.rust_apps }} |
| 40 | + steps: |
| 41 | + - name: Checkout repository |
| 42 | + uses: actions/checkout@v4 |
| 43 | + with: |
| 44 | + repository: ${{ needs.how-workflow-is-called.outputs.repository }} |
| 45 | + ref: ${{ needs.how-workflow-is-called.outputs.branch }} |
| 46 | + - name: Set up Python |
| 47 | + uses: actions/setup-python@v4 |
| 48 | + with: |
| 49 | + python-version: '3.x' |
| 50 | + - name: Install ledgered |
| 51 | + run: pip install ledgered |
| 52 | + - name: Get all rust apps |
| 53 | + id: get_rust_apps |
| 54 | + run: | |
| 55 | + python .github/workflows/get_rust_apps.py ${{ secrets.GITHUB_TOKEN }} |
| 56 | + echo "rust_apps=$(cat rust_apps.json)" >> $GITHUB_OUTPUT |
| 57 | +
|
| 58 | + display-rust-apps: |
| 59 | + name: Display Rust Apps |
| 60 | + runs-on: ubuntu-latest |
| 61 | + needs: retrieve-rust-apps |
| 62 | + steps: |
| 63 | + - name: Display Rust Apps |
| 64 | + run: | |
| 65 | + echo "Rust apps: ${{ needs.retrieve-rust-apps.outputs.rust_apps }}" |
| 66 | +
|
| 67 | + test-build: |
| 68 | + name: Build for all targets |
| 69 | + needs: [retrieve-rust-apps, how-workflow-is-called] |
| 70 | + strategy: |
| 71 | + fail-fast: false |
| 72 | + matrix: |
| 73 | + app-name: ["app-boilerplate-rust"] |
| 74 | + device: ["nanos+", "nanox", "stax", "flex"] |
| 75 | + include: ${{ fromJSON(needs.retrieve-rust-apps.outputs.rust_apps) }} |
| 76 | + runs-on: ubuntu-latest |
| 77 | + container: |
| 78 | + image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest |
| 79 | + steps: |
| 80 | + - name: Install ledgered |
| 81 | + run: pip install ledgered |
| 82 | + - name: Clone SDK |
| 83 | + uses: actions/checkout@v4 |
| 84 | + with: |
| 85 | + path: sdk |
| 86 | + repository: ${{ needs.how-workflow-is-called.outputs.repository }} |
| 87 | + ref: ${{ needs.how-workflow-is-called.outputs.branch }} |
| 88 | + - name: Clone App |
| 89 | + uses: actions/checkout@v4 |
| 90 | + with: |
| 91 | + repository: LedgerHQ/${{ matrix.app-name }} |
| 92 | + submodules: true |
| 93 | + path: ${{ matrix.app-name }} |
| 94 | + - name: Patch Cargo.toml |
| 95 | + continue-on-error: false |
| 96 | + run: | |
| 97 | + cd ${{ matrix.app-name }} |
| 98 | + build_directory=$(ledger-manifest --output-build-directory ledger_app.toml) |
| 99 | + cd $build_directory |
| 100 | + workspace_root=$(cargo metadata --no-deps --format-version 1 | jq -r '.workspace_root') |
| 101 | + cargo_toml_path="$workspace_root/Cargo.toml" |
| 102 | + |
| 103 | + # Patch ledger_device_sdk |
| 104 | + echo "" >> $cargo_toml_path |
| 105 | + echo "[patch.crates-io.ledger_device_sdk]" >> $cargo_toml_path |
| 106 | + path=\"$GITHUB_WORKSPACE/sdk/ledger_device_sdk\" |
| 107 | + echo "path=$path" >> $cargo_toml_path |
| 108 | + echo "Patch added to Cargo.toml" |
| 109 | + |
| 110 | + # Patch ledger_secure_sdk_sys |
| 111 | + echo "" >> $cargo_toml_path |
| 112 | + echo "[patch.crates-io.ledger_secure_sdk_sys]" >> $cargo_toml_path |
| 113 | + path=\"$GITHUB_WORKSPACE/sdk/ledger_secure_sdk_sys\" |
| 114 | + echo "path=$path" >> $cargo_toml_path |
| 115 | + echo "Patch added to Cargo.toml" |
| 116 | + |
| 117 | + # Patch include_gif |
| 118 | + echo "" >> $cargo_toml_path |
| 119 | + echo "[patch.crates-io.include_gif]" >> $cargo_toml_path |
| 120 | + path=\"$GITHUB_WORKSPACE/sdk/include_gif\" |
| 121 | + echo "path=$path" >> $cargo_toml_path |
| 122 | + echo "Patch added to Cargo.toml" |
| 123 | +
|
| 124 | + # Print Cargo.toml |
| 125 | + echo "Cargo.toml:" |
| 126 | + cat $cargo_toml_path |
| 127 | +
|
| 128 | + - name: Build |
| 129 | + run: | |
| 130 | + # Clone C SDK if provided |
| 131 | + if [ -n "${{ inputs.c_sdk_branch }}" ]; then |
| 132 | + git clone $C_SDK_URL --branch ${{ inputs.c_sdk_branch }} --single-branch c_sdk |
| 133 | + echo "setting LEDGER_SDK_PATH to $(realpath c_sdk)" |
| 134 | + LEDGER_SDK_PATH=$(realpath c_sdk) |
| 135 | + else |
| 136 | + echo "using C SDK from ledger-app-builder" |
| 137 | + fi |
| 138 | + cd ${{ matrix.app-name }} |
| 139 | + build_directory=$(ledger-manifest --output-build-directory ledger_app.toml) |
| 140 | + cd $build_directory |
| 141 | + # Required as patch has a different version from what is locked in Cargo.lock |
| 142 | + cargo +$RUST_NIGHTLY update include_gif |
| 143 | + cargo +$RUST_NIGHTLY update ledger_secure_sdk_sys |
| 144 | + cargo +$RUST_NIGHTLY update ledger_device_sdk |
| 145 | + device=$(echo ${{ matrix.device }} | sed 's/+/plus/') |
| 146 | + echo "Build for "$device |
| 147 | + cargo ledger build $device |
0 commit comments