2

我的 build.rs 脚本在我的 CI 管道 (Azure Pipelines) 中失败,但在本地运行它工作正常。我特别知道我无法生成我的 cbindgen 标头,但错误消息只是列出了它解析的文件,并没有真正说明它失败的原因。

构建.rs:


extern crate cbindgen;

use cbindgen::Config;
use std::env;
use std::path::PathBuf;

fn main() {
    let crate_dir = env::var("CARGO_MANIFEST_DIR").unwrap();
    let build_ffi = env::var("CARGO_GENERATE_FFI").unwrap();

    if build_ffi == "True" {
        let output_file = target_dir().join("smartscreen.h").display().to_string();

        let config = Config::from_file("cbindgen.toml").unwrap();

        cbindgen::generate_with_config(&crate_dir, config)
            .unwrap()
            .write_to_file(&output_file);
    }
}

/// Find the location of the `target/` directory. Note that this may be
/// overridden by `cmake`, so we also need to check the `CARGO_TARGET_DIR`
/// variable.
fn target_dir() -> PathBuf {
    if let Ok(target) = env::var("CARGO_TARGET_DIR") {
        PathBuf::from(target)
    } else {
        PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap()).join("target")
    }
}

cbindgen.toml:

language = "C"

[parse]
parse_deps = false
include = ["src/lib.rs"]
exclude = ["src/urlrep.rs", "src/core.rs", "src/service.rs", "src/smartscreen.rs"]
clean = true
extra_bindings = []

[parse.expand]
crates = ["rustscreen"]
all_features = false
default_features = true
features = []

我在 generate_with_config().unwrap() 上失败了,错误消息是我正在尝试编译的 crate 列表,然后是一个典型的 unwrap() 堆栈,开头为:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: 
CargoExpand("rustscreen", Compile("   Compiling libc v0.2.67
Compiling proc-macro2 v1.0.8Compiling unicode-xid v0.2.0Compiling syn v1.0.14
  Running `rustc --crate-name build_script_build /Users/runner/.cargo/registry/src/github.com-1ecc6299db9ec823/libc-0.2.67/build.rs --error-format=json --json=diagnostic-rendered-ansi --crate-type bin --emit=dep-info,link -C debuginfo=2 --cfg \'feature=\"default\"\' --cfg \'feature=\"std\"\' -C metadata=7d7a4e8d940c7a40 -C extra-filename=-7d7a4e8d940c7a40 --out-dir /var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/cbindgen-expandleR23k/debug/build/libc-7d7a4e8d940c7a40 -L dependency=/var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T/cbindgen-expandleR23k/debug/deps --cap-lints allow`

... SNIP

对于每个依赖项都像这样继续,没有错误消息

4

0 回答 0