简体   繁体   English

在 sys crate 上达到 crates.io 的上传限制

[英]Hitting upload limit on crates.io on a sys crate

I'm trying to publish a sys crate for libvmaf.我正在尝试为 libvmaf 发布一个 sys crate。 Unfortunately I can not simply dynamically link to libvmaf because it's not distributed anywhere and I need to build it from source and include it in my library.不幸的是,我不能简单地动态链接到 libvmaf,因为它没有分发到任何地方,我需要从源代码构建它并将其包含在我的库中。 Unfortunately libvmaf is absolutely huge and my.rlib file is ending up at 1.4 megabytes which is over the upload limit for crates.io.不幸的是,libvmaf 非常庞大,my.rlib 文件最终达到 1.4 兆字节,超过了 crates.io 的上传限制。 Am I boned here?我在这里骨吗?

Here's my build.rs file这是我的 build.rs 文件

use meson_next;
use std::env;
use std::fs::canonicalize;
use std::path::PathBuf;

fn main() {
    //env::set_var("RUST_BACKTRACE", "1");
    let build_dir = PathBuf::from(env::var("OUT_DIR").unwrap()).join("build");
    let lib_dir = build_dir.join("src");

    let build_dir_str = build_dir.to_str().unwrap();
    let lib_dir_str = lib_dir.to_str().unwrap();

    meson_next::build("vmaf/libvmaf", build_dir_str);

    println!("cargo:rustc-link-lib=static=vmaf");
    println!("cargo:rustc-link-search=native={lib_dir_str}");

    // Path to vendor header files
    let headers_dir = PathBuf::from("vmaf/libvmaf/include");
    let headers_dir_canonical = canonicalize(headers_dir).unwrap();
    let include_path = headers_dir_canonical.to_str().unwrap();

    // Generate bindings to libvmaf using rust-bindgen
    let bindings = bindgen::Builder::default()
        .header("vmaf/libvmaf/include/libvmaf/libvmaf.h")
        .clang_arg(format!("-I{include_path}"))
        .parse_callbacks(Box::new(bindgen::CargoCallbacks))
        .generate()
        .expect("Unable to generate bindings");

    // Write bindings to build directory
    let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
    bindings
        .write_to_file(out_path.join("bindings.rs"))
        .expect("Couldn't write bindings!");
}

In general you should not be including compiled libraries in your package. Include the source code, and have your build script perform the build.通常,您不应在 package 中包含已编译的库。包含源代码,并让您的构建脚本执行构建。

This will usually result in a smaller package, and also means that your package works on any target architecture (that is supported by the library).这通常会导致 package 变小,也意味着您的 package 可以在任何目标架构(库支持的架构)上运行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM