|
| 1 | +name: "Native solver" |
| 2 | + |
| 3 | +# This workflow checks the Rust crate loop_interpolation_core. |
| 4 | +# It runs only when the crate, the Python adapter or this file changes. |
| 5 | + |
| 6 | +on: |
| 7 | + push: |
| 8 | + branches: |
| 9 | + - master |
| 10 | + paths: |
| 11 | + - 'packages/loop_interpolation_core/**' |
| 12 | + - 'packages/loop_interpolation/src/loop_interpolation/_native.py' |
| 13 | + - '.github/workflows/native.yml' |
| 14 | + pull_request: |
| 15 | + branches: |
| 16 | + - master |
| 17 | + paths: |
| 18 | + - 'packages/loop_interpolation_core/**' |
| 19 | + - 'packages/loop_interpolation/src/loop_interpolation/_native.py' |
| 20 | + - '.github/workflows/native.yml' |
| 21 | + workflow_dispatch: |
| 22 | + |
| 23 | +permissions: |
| 24 | + contents: read |
| 25 | + |
| 26 | +env: |
| 27 | + CARGO_TERM_COLOR: always |
| 28 | + MANIFEST: packages/loop_interpolation_core/Cargo.toml |
| 29 | + |
| 30 | +jobs: |
| 31 | + # Format, lint and test the crate with all feature sets. |
| 32 | + rust: |
| 33 | + name: Rust checks |
| 34 | + runs-on: ubuntu-latest |
| 35 | + steps: |
| 36 | + - uses: actions/checkout@v4 |
| 37 | + - name: Install the Rust toolchain |
| 38 | + run: | |
| 39 | + rustup toolchain install stable --profile minimal --component rustfmt --component clippy --target wasm32-unknown-unknown |
| 40 | + rustup default stable |
| 41 | + - uses: actions/cache@v4 |
| 42 | + with: |
| 43 | + path: | |
| 44 | + ~/.cargo/registry |
| 45 | + ~/.cargo/git |
| 46 | + packages/loop_interpolation_core/target |
| 47 | + key: rust-${{ runner.os }}-${{ hashFiles('packages/loop_interpolation_core/Cargo.lock') }} |
| 48 | + restore-keys: rust-${{ runner.os }}- |
| 49 | + - name: Format |
| 50 | + run: cargo fmt --manifest-path "$MANIFEST" --check |
| 51 | + - name: Clippy, no features |
| 52 | + run: cargo clippy --manifest-path "$MANIFEST" --all-targets -- -D warnings |
| 53 | + - name: Clippy, parallel |
| 54 | + run: cargo clippy --manifest-path "$MANIFEST" --all-targets --features parallel -- -D warnings |
| 55 | + - name: Clippy, python |
| 56 | + run: cargo clippy --manifest-path "$MANIFEST" --all-targets --features python -- -D warnings |
| 57 | + - name: Clippy, wasm |
| 58 | + run: cargo clippy --manifest-path "$MANIFEST" --all-targets --features wasm --target wasm32-unknown-unknown -- -D warnings |
| 59 | + # Use --release. Debug test runs take many minutes. |
| 60 | + - name: Test, no features |
| 61 | + run: cargo test --manifest-path "$MANIFEST" --release |
| 62 | + - name: Test, parallel |
| 63 | + run: cargo test --manifest-path "$MANIFEST" --release --features parallel |
| 64 | + |
| 65 | + # Build the Python wheel and run the Python tests with the native core installed. |
| 66 | + wheel: |
| 67 | + name: Wheel ${{ matrix.os }} |
| 68 | + runs-on: ${{ matrix.os }} |
| 69 | + strategy: |
| 70 | + fail-fast: false |
| 71 | + matrix: |
| 72 | + os: [ubuntu-latest, windows-latest, macos-latest] |
| 73 | + steps: |
| 74 | + - uses: actions/checkout@v4 |
| 75 | + - uses: actions/setup-python@v5 |
| 76 | + with: |
| 77 | + python-version: '3.12' |
| 78 | + - uses: actions/cache@v4 |
| 79 | + with: |
| 80 | + path: | |
| 81 | + ~/.cargo/registry |
| 82 | + ~/.cargo/git |
| 83 | + packages/loop_interpolation_core/target |
| 84 | + key: wheel-${{ runner.os }}-${{ hashFiles('packages/loop_interpolation_core/Cargo.lock') }} |
| 85 | + restore-keys: wheel-${{ runner.os }}- |
| 86 | + # maturin develop needs a virtual environment. |
| 87 | + # The Linux and macOS folder is bin. The Windows folder is Scripts. |
| 88 | + - name: Install, build and test |
| 89 | + shell: bash |
| 90 | + run: | |
| 91 | + python -m venv .venv |
| 92 | + if [ -f .venv/Scripts/activate ]; then source .venv/Scripts/activate; else source .venv/bin/activate; fi |
| 93 | + python -m pip install --upgrade pip |
| 94 | + python -m pip install maturin numpy scipy pytest |
| 95 | + python -m pip install -e packages/loop_common -e packages/loop_interpolation |
| 96 | + maturin develop --release -m packages/loop_interpolation_core/Cargo.toml |
| 97 | + python -m pytest packages/loop_interpolation/tests -q |
| 98 | +
|
| 99 | + # Build the WebAssembly package, check its size and run the browser tests. |
| 100 | + wasm: |
| 101 | + name: WebAssembly |
| 102 | + runs-on: ubuntu-latest |
| 103 | + steps: |
| 104 | + - uses: actions/checkout@v4 |
| 105 | + - uses: actions/setup-python@v5 |
| 106 | + with: |
| 107 | + python-version: '3.12' |
| 108 | + - uses: actions/setup-node@v4 |
| 109 | + with: |
| 110 | + node-version: '20' |
| 111 | + - name: Install the Rust toolchain |
| 112 | + run: | |
| 113 | + rustup toolchain install stable --profile minimal --target wasm32-unknown-unknown |
| 114 | + rustup default stable |
| 115 | + - uses: actions/cache@v4 |
| 116 | + with: |
| 117 | + path: | |
| 118 | + ~/.cargo/registry |
| 119 | + ~/.cargo/git |
| 120 | + packages/loop_interpolation_core/target |
| 121 | + key: wasm-${{ runner.os }}-${{ hashFiles('packages/loop_interpolation_core/Cargo.lock') }} |
| 122 | + restore-keys: wasm-${{ runner.os }}- |
| 123 | + # The wasm-bindgen CLI version must equal the wasm-bindgen version in Cargo.lock. |
| 124 | + - name: Read the wasm-bindgen version |
| 125 | + run: | |
| 126 | + V=$(grep -A1 '^name = "wasm-bindgen"$' packages/loop_interpolation_core/Cargo.lock | sed -n 's/^version = "\(.*\)"$/\1/p') |
| 127 | + echo "Version: $V" |
| 128 | + test -n "$V" |
| 129 | + echo "WASM_BINDGEN_VERSION=$V" >> "$GITHUB_ENV" |
| 130 | + - name: Cache the wasm-bindgen CLI |
| 131 | + id: bindgen-cache |
| 132 | + uses: actions/cache@v4 |
| 133 | + with: |
| 134 | + path: ~/.cargo/bin/wasm-bindgen |
| 135 | + key: wasm-bindgen-cli-${{ runner.os }}-${{ env.WASM_BINDGEN_VERSION }} |
| 136 | + - name: Install the wasm-bindgen CLI |
| 137 | + if: steps.bindgen-cache.outputs.cache-hit != 'true' |
| 138 | + run: cargo install wasm-bindgen-cli --version "$WASM_BINDGEN_VERSION" --locked |
| 139 | + - name: Build the WebAssembly package |
| 140 | + run: bash packages/loop_interpolation_core/scripts/build_wasm.sh |
| 141 | + - name: Check the size |
| 142 | + run: python -I packages/loop_interpolation_core/scripts/check_wasm_size.py |
| 143 | + - name: Install the browser test packages |
| 144 | + working-directory: packages/loop_interpolation_core/tests_web |
| 145 | + run: | |
| 146 | + npm ci |
| 147 | + npx playwright install --with-deps chromium |
| 148 | + - name: Browser tests |
| 149 | + working-directory: packages/loop_interpolation_core/tests_web |
| 150 | + run: npm test |
| 151 | + |
| 152 | + # Slow reference runs. Start these by hand only. |
| 153 | + reference: |
| 154 | + name: Reference problems |
| 155 | + if: github.event_name == 'workflow_dispatch' |
| 156 | + runs-on: ubuntu-latest |
| 157 | + steps: |
| 158 | + - uses: actions/checkout@v4 |
| 159 | + - uses: actions/setup-node@v4 |
| 160 | + with: |
| 161 | + node-version: '20' |
| 162 | + - name: Install the Rust toolchain |
| 163 | + run: | |
| 164 | + rustup toolchain install stable --profile minimal --target wasm32-unknown-unknown |
| 165 | + rustup default stable |
| 166 | + - uses: actions/cache@v4 |
| 167 | + with: |
| 168 | + path: | |
| 169 | + ~/.cargo/registry |
| 170 | + ~/.cargo/git |
| 171 | + packages/loop_interpolation_core/target |
| 172 | + key: reference-${{ runner.os }}-${{ hashFiles('packages/loop_interpolation_core/Cargo.lock') }} |
| 173 | + restore-keys: reference-${{ runner.os }}- |
| 174 | + - name: Read the wasm-bindgen version |
| 175 | + run: | |
| 176 | + V=$(grep -A1 '^name = "wasm-bindgen"$' packages/loop_interpolation_core/Cargo.lock | sed -n 's/^version = "\(.*\)"$/\1/p') |
| 177 | + test -n "$V" |
| 178 | + echo "WASM_BINDGEN_VERSION=$V" >> "$GITHUB_ENV" |
| 179 | + - name: Cache the wasm-bindgen CLI |
| 180 | + id: bindgen-cache |
| 181 | + uses: actions/cache@v4 |
| 182 | + with: |
| 183 | + path: ~/.cargo/bin/wasm-bindgen |
| 184 | + key: wasm-bindgen-cli-${{ runner.os }}-${{ env.WASM_BINDGEN_VERSION }} |
| 185 | + - name: Install the wasm-bindgen CLI |
| 186 | + if: steps.bindgen-cache.outputs.cache-hit != 'true' |
| 187 | + run: cargo install wasm-bindgen-cli --version "$WASM_BINDGEN_VERSION" --locked |
| 188 | + # The test f32_250_cubed_within_budget is too slow for CI. Skip it. |
| 189 | + - name: Ignored Rust tests |
| 190 | + run: | |
| 191 | + set -o pipefail |
| 192 | + cargo test --manifest-path "$MANIFEST" --release --test reference_problems -- --ignored --nocapture --test-threads=1 --skip f32_250_cubed_within_budget 2>&1 | tee rust_reference.log |
| 193 | + - name: Write the reference field |
| 194 | + run: cargo test --manifest-path "$MANIFEST" --release --test reference_problems r1_write_field -- --ignored |
| 195 | + - name: Build the WebAssembly package |
| 196 | + run: bash packages/loop_interpolation_core/scripts/build_wasm.sh |
| 197 | + - name: Browser reference spec |
| 198 | + working-directory: packages/loop_interpolation_core/tests_web |
| 199 | + env: |
| 200 | + RUN_REFERENCE: '1' |
| 201 | + run: | |
| 202 | + set -o pipefail |
| 203 | + npm ci |
| 204 | + npx playwright install --with-deps chromium |
| 205 | + npm test -- reference 2>&1 | tee "$GITHUB_WORKSPACE/browser_reference.log" |
| 206 | + - name: Write the job summary |
| 207 | + if: always() |
| 208 | + run: | |
| 209 | + { |
| 210 | + echo "## Rust reference problems" |
| 211 | + echo '```' |
| 212 | + cat rust_reference.log 2>/dev/null || echo "No output." |
| 213 | + echo '```' |
| 214 | + echo "## Browser reference spec" |
| 215 | + echo '```' |
| 216 | + cat browser_reference.log 2>/dev/null || echo "No output." |
| 217 | + echo '```' |
| 218 | + } >> "$GITHUB_STEP_SUMMARY" |
0 commit comments