【问题标题】:How to build the docs.rs documentation of an FFI crate when the native library is not present?当本地库不存在时,如何构建 FFI crate 的 docs.rs 文档?
【发布时间】:2022-04-22 03:51:40
【问题描述】:

我有一个静态链接到库的“sys”板条箱:

Cargo.toml:

[package]
links = "foo-1.0"

build.rs:

fn main() {
    println!("cargo:rustc-link-lib=dylib=foo-1.0");
}

当我发布包时,docs.rs 无法生成文档,因为没有安装 libfoo:

error: failed to run custom build command for `foo-sys v0.0.1`

Caused by:
  process didn't exit successfully: `/home/cratesfyi/cratesfyi/debug/build/foo-sys-f4bd3ee95677500b/build-script-build` (exit code: 1)
--- stderr
`"pkg-config" "--libs" "--cflags" "foo-1.0 >= 1.0"` did not exit successfully: exit code: 1
--- stderr

如何配置我的 crate 以便在不安装库的情况下生成文档?

【问题讨论】:

    标签: rust documentation rust-cargo


    【解决方案1】:

    about/build page of docs.rs 提供了更多相关信息。 docs.rs 将设置一个环境变量DOCS_RS。

    可以在build.rs中禁用链接:

    fn main() {
        if std::env::var("DOCS_RS").is_ok() {
            println!("cargo:rustc-link-lib=dylib=foo-1.0");
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2017-09-03
      • 2018-06-26
      • 2018-04-03
      • 2013-12-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多