Skip to content

Build all Rust apps #67

Build all Rust apps

Build all Rust apps #67

name: Build all Rust apps
on:
workflow_call:
inputs:
c_sdk_branch:
required: false
default: ''
type: string
rust_sdk_branch:
required: false
default: 'master'
type: string
workflow_dispatch:
inputs:
c_sdk_branch:
required: false
default: ''
type: string
rust_sdk_branch:
required: false
default: 'master'
type: string
env:
C_SDK_URL: 'https://github.com/LedgerHQ/ledger-secure-sdk.git'
jobs:
retrieve-rust-apps:
name: Retrieve Rust Apps
runs-on: ubuntu-latest
outputs:
rust_apps: ${{ steps.get_rust_apps.outputs.rust_apps }}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
repository: LedgerHQ/ledger-device-rust-sdk
ref: ${{ inputs.rust_sdk_branch }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.x'
- name: Install ledgered
run: pip install ledgered
- name: Get all rust apps
id: get_rust_apps
run: |
python .github/workflows/get_rust_apps.py ${{ secrets.GITHUB_TOKEN }}
echo "rust_apps=$(cat rust_apps.json)" >> $GITHUB_OUTPUT
display-rust-apps:
name: Display Rust Apps
runs-on: ubuntu-latest
needs: retrieve-rust-apps
steps:
- name: Display Rust Apps
run: |
echo "Rust apps: ${{ needs.retrieve-rust-apps.outputs.rust_apps }}"
test-build:
name: Build for all targets
needs: [retrieve-rust-apps]
strategy:
fail-fast: false
matrix:
app-name: ["app-boilerplate-rust"]
device: ["nanos+", "nanox", "stax", "flex"]
include: ${{ fromJSON(needs.retrieve-rust-apps.outputs.rust_apps) }}
runs-on: ubuntu-latest
container:
image: ghcr.io/ledgerhq/ledger-app-builder/ledger-app-builder:latest
steps:
- name: Install ledgered
run: pip install ledgered --break-system-packages
- name: Clone SDK
uses: actions/checkout@v4
with:
path: sdk
repository: LedgerHQ/ledger-device-rust-sdk
ref: ${{ inputs.rust_sdk_branch }}
- name: Clone App
uses: actions/checkout@v4
with:
repository: LedgerHQ/${{ matrix.app-name }}
submodules: true
path: ${{ matrix.app-name }}
- name: Patch Cargo.toml
continue-on-error: false
run: |
cd ${{ matrix.app-name }}
build_directory=$(ledger-manifest --output-build-directory ledger_app.toml)
cd $build_directory
workspace_root=$(cargo metadata --no-deps --format-version 1 | jq -r '.workspace_root')
cargo_toml_path="$workspace_root/Cargo.toml"
# Patch ledger_device_sdk
echo "" >> $cargo_toml_path
echo "[patch.crates-io.ledger_device_sdk]" >> $cargo_toml_path
path=\"$GITHUB_WORKSPACE/sdk/ledger_device_sdk\"
echo "path=$path" >> $cargo_toml_path
echo "Patch added to Cargo.toml"
# Patch ledger_secure_sdk_sys
echo "" >> $cargo_toml_path
echo "[patch.crates-io.ledger_secure_sdk_sys]" >> $cargo_toml_path
path=\"$GITHUB_WORKSPACE/sdk/ledger_secure_sdk_sys\"
echo "path=$path" >> $cargo_toml_path
echo "Patch added to Cargo.toml"
# Patch include_gif
echo "" >> $cargo_toml_path
echo "[patch.crates-io.include_gif]" >> $cargo_toml_path
path=\"$GITHUB_WORKSPACE/sdk/include_gif\"
echo "path=$path" >> $cargo_toml_path
echo "Patch added to Cargo.toml"
# Print Cargo.toml
echo "Cargo.toml:"
cat $cargo_toml_path
- name: Build
run: |
# Clone C SDK if provided
if [ -n "${{ inputs.c_sdk_branch }}" ]; then
git clone $C_SDK_URL --branch ${{ inputs.c_sdk_branch }} --single-branch c_sdk
echo "setting LEDGER_SDK_PATH to $(realpath c_sdk)"
export LEDGER_SDK_PATH=$(realpath c_sdk)
else
echo "using C SDK from ledger-app-builder"
fi
cd ${{ matrix.app-name }}
build_directory=$(ledger-manifest --output-build-directory ledger_app.toml)
cd $build_directory
# Required as patch has a different version from what is locked in Cargo.lock
cargo update include_gif
cargo update ledger_secure_sdk_sys
cargo update ledger_device_sdk
device=$(echo ${{ matrix.device }} | sed 's/+/plus/')
echo "Build for "$device
cargo ledger build $device