我有一个带有使用 pyo3 绑定的 rust 扩展模块的 Python 项目。 该项目在本地成功构建和编译,并在 readthedocs 上构建和编译。它使用
pip install .
方法,并在 Rust 之后构建本地轮子,并在本地架构上构建所有依赖项。
但是,它无法在 github 工作流程上构建。 github工作流程命令的相关部分是:
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install . -v
错误的主要原因是 Rust 编译器警告,在其他情况下似乎被忽略,但在这里报告为直接错误而不是警告。
例如第一个是:
error: unused import: `Axis`
--> src/dual/dual2.rs:12:38
|
12 | use ndarray::{Array, Array1, Array2, Axis};
| ^^^^
|
= note: `-D unused-imports` implied by `-D warnings`
= help: to override `-D warnings` add `#[allow(unused_imports)]`
最终这是无关紧要的。当然我可以删除它,但是一些报告为“错误”的“警告”实际上并不明智地进行更改。
它导致:
💥 maturin failed
Caused by: Failed to build a native library through cargo
Caused by: Cargo build finished with "exit status: 101": `env -u CARGO PYO3_ENVIRONMENT_SIGNATURE="cpython-3.11-64bit" PYO3_PYTHON="/opt/hostedtoolcache/Python/3.11.8/x64/bin/python" PYTHON_SYS_EXECUTABLE="/opt/hostedtoolcache/Python/3.11.8/x64/bin/python" "cargo" "rustc" "--message-format" "json-render-diagnostics" "--manifest-path" "/home/runner/work/rateslib/rateslib/Cargo.toml" "--release" "--lib" "--crate-type" "cdylib"`
Error: command ['maturin', 'pep517', 'build-wheel', '-i', '/opt/hostedtoolcache/Python/3.11.8/x64/bin/python', '--compatibility', 'off'] returned non-zero exit status 1
error: subprocess-exited-with-error
在 github actions 上正确构建此构建的解决方案是什么?
actions-rust-lang/setup-rust-toolchain@v1
所有
警告是有争议的,但有些警告(例如未使用的导入!)绝对应该存在。
所以,真正的解决方法是修复你的代码。不过,如果您想覆盖此设置,您可以这样做:此工作流程具有
rustflags
输入
,您可以将其设置为空以防止-D warnings
:
jobs:
build:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
python-version: ["3.11"]
steps:
- uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rust-lang/setup-rust-toolchain@v1
with:
rustflags: ''
- name: Set up Python ${{ matrix.python-version }}
uses: actions/setup-python@v3
with:
python-version: ${{ matrix.python-version }}
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install . -v