name: 'AFFiNE Rust build' description: 'Rust build setup, including cache configuration' inputs: target: description: 'Cargo target' required: true package: description: 'Package to build' required: true nx_token: description: 'Nx Cloud access token' required: false runs: using: 'composite' steps: - name: Print rustup toolchain version shell: bash id: rustup-version run: | export RUST_TOOLCHAIN_VERSION="$(grep 'channel' rust-toolchain.toml | head -1 | awk -F '"' '{print $2}')" echo "Rust toolchain version: $RUST_TOOLCHAIN_VERSION" echo "RUST_TOOLCHAIN_VERSION=$RUST_TOOLCHAIN_VERSION" >> "$GITHUB_OUTPUT" - name: Setup Rust uses: dtolnay/rust-toolchain@stable with: toolchain: '${{ steps.rustup-version.outputs.RUST_TOOLCHAIN_VERSION }}' targets: ${{ inputs.target }} env: CARGO_INCREMENTAL: '1' - name: Cache cargo uses: actions/cache@v3 with: path: | ~/.cargo/registry/index/ ~/.cargo/registry/cache/ ~/.cargo/git/db/ .cargo-cache target/${{ inputs.target }} key: stable-${{ inputs.target }}-cargo-cache - name: Build if: ${{ inputs.target != 'x86_64-unknown-linux-gnu' && inputs.target != 'aarch64-unknown-linux-gnu' }} shell: bash run: | yarn workspace ${{ inputs.package }} nx build ${{ inputs.package }} --target ${{ inputs.target }} env: NX_CLOUD_ACCESS_TOKEN: ${{ inputs.nx_token }} - name: Build if: ${{ inputs.target == 'x86_64-unknown-linux-gnu' }} uses: addnab/docker-run-action@v3 with: image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian options: --user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build -e NX_CLOUD_ACCESS_TOKEN=${{ inputs.nx_token }} run: | export CC=x86_64-unknown-linux-gnu-gcc export CC_x86_64_unknown_linux_gnu=x86_64-unknown-linux-gnu-gcc rm -rf /usr/local/rustup/downloads/* rustup target add x86_64-unknown-linux-gnu export RUSTFLAGS="-C debuginfo=1" yarn workspace ${{ inputs.package }} nx build ${{ inputs.package }} --target ${{ inputs.target }} if [ -d "node_modules/.cache" ]; then chmod -R 777 node_modules/.cache fi if [ -d "target" ]; then chmod -R 777 target; fi - name: Build if: ${{ inputs.target == 'aarch64-unknown-linux-gnu' }} uses: addnab/docker-run-action@v3 with: image: ghcr.io/napi-rs/napi-rs/nodejs-rust:lts-debian-aarch64 options: --user 0:0 -v ${{ github.workspace }}/.cargo-cache/git/db:/usr/local/cargo/git/db -v ${{ github.workspace }}/.cargo/registry/cache:/usr/local/cargo/registry/cache -v ${{ github.workspace }}/.cargo/registry/index:/usr/local/cargo/registry/index -v ${{ github.workspace }}:/build -w /build -e NX_CLOUD_ACCESS_TOKEN=${{ inputs.nx_token }} run: | export RUSTFLAGS="-C debuginfo=1" rm -rf /usr/local/rustup/downloads/* rustup target add aarch64-unknown-linux-gnu yarn workspace ${{ inputs.package }} nx build ${{ inputs.package }} --target ${{ inputs.target }} if [ -d "node_modules/.cache" ]; then chmod -R 777 node_modules/.cache fi if [ -d "target" ]; then chmod -R 777 target; fi