Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cargo package source directory modified false positive #15011

Open
Jex-y opened this issue Jan 3, 2025 · 3 comments
Open

Cargo package source directory modified false positive #15011

Jex-y opened this issue Jan 3, 2025 · 3 comments
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.

Comments

@Jex-y
Copy link

Jex-y commented Jan 3, 2025

Problem

I am building rust bindings to a c library which is built using the cmake crate.
cargo build runs successfully, however on running cargo package, the following error is shown:

error: failed to verify package tarball

Caused by:
  Source directory was modified by build.rs during cargo publish. Build scripts should not modify anything outside of OUT_DIR.
  Added: /home/ejex/code/libhailort-sys/target/package/libhailort-sys-0.1.0/hailort/hailort/external
  	/home/ejex/code/libhailort-sys/target/package/libhailort-sys-0.1.0/hailort/hailort/external/cli11-src
  	/home/ejex/code/libhailort-sys/target/package/libhailort-sys-0.1.0/hailort/hailort/external/cli11-src/.all-contributorsrc
  	/home/ejex/code/libhailort-sys/target/package/libhailort-sys-0.1.0/hailort/hailort/external/cli11-src/.appveyor.yml
  	/home/ejex/code/libhailort-sys/target/package/libhailort-sys-0.1.0/hailort/hailort/external/cli11-src/.ci
  	/home/ejex/code/libhailort-sys/target/package/libhailort-sys-0.1.0/hailort/hailort/external/cli11-src/.ci/azure-build.yml
  	/home/ejex/code/libhailort-sys/target/package/libhailort-sys-0.1.0/hailort/hailort/external/cli11-src/.ci/azure-cmake.yml
  	/home/ejex/code/libhailort-sys/target/package/libhailort-sys-0.1.0/hailort/hailort/external/cli11-src/.ci/azure-test.yml
  	/home/ejex/code/libhailort-sys/target/package/libhailort-sys-0.1.0/hailort/hailort/external/cli11-src/.ci/build_doxygen.sh
  	/home/ejex/code/libhailort-sys/target/package/libhailort-sys-0.1.0/hailort/hailort/external/cli11-src/.ci/build_lcov.sh
  	/home/ejex/code/libhailort-sys/target/package/libhailort-sys-0.1.0/hailort/hailort/external/cli11-src/.ci/make_and_test.sh
...

My understanding is that <crate>/target and is not the source directory.

My build.rs file looks like this:

use cmake;
use std::env;
use std::path::PathBuf;

fn main() {
    let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());

    let dst = cmake::Config::new("hailort").build();

    let obj_path = dst.join("build/hailort/libhailort/src/libhailort.so");
    let lib_path = out_dir.clone().join("libhailort.a");

    let headers_path = dst.join("include/hailo/hailort.h");
    let headers_path_str = headers_path
        .to_str()
        .expect("Header path is not a valid string");

    // Link to the hailort library
    println!("cargo:rustc-link-search=native={}", dst.display());
    println!("cargo:rustc-link-lib=static=hailort");

    // Generate .a file
    let ar_output = std::process::Command::new("ar")
        .arg("rcs")
        .arg(lib_path)
        .arg(obj_path)
        .output()
        .expect("could not spawn ar");

    if !ar_output.status.success() {
        panic!("Failed to generate libhailort.a: {:?}", ar_output);
    }

    let bindings = bindgen::Builder::default()
        .header(headers_path_str)
        .parse_callbacks(Box::new(bindgen::CargoCallbacks::new()))
        .generate()
        .expect("Unable to generate bindings");

    bindings
        .write_to_file(out_dir.join("bindings.rs"))
        .expect("Couldn't write bindings!");
}

Steps

  1. git clone https://github.com/Jex-y/libhailort-sys.git
  2. cd libhailort-sys
  3. cargo package

Possible Solution(s)

No response

Notes

No response

Version

cargo 1.83.0 (5ffbef321 2024-10-29)
release: 1.83.0
commit-hash: 5ffbef3211a8c378857905775a15c5b32a174d3b
commit-date: 2024-10-29
host: x86_64-unknown-linux-gnu
libgit2: 1.8.1 (sys:0.19.0 vendored)
libcurl: 8.9.0-DEV (sys:0.4.74+curl-8.9.0 vendored ssl:OpenSSL/1.1.1w)
ssl: OpenSSL 1.1.1w  11 Sep 2023
os: Ubuntu 24.10.0 (oracular) [64-bit]
@Jex-y Jex-y added C-bug Category: bug S-triage Status: This issue is waiting on initial triage. labels Jan 3, 2025
@epage
Copy link
Contributor

epage commented Jan 3, 2025

The generated .crate was extracted to /home/ejex/code/libhailort-sys/target/package/libhailort-sys-0.1.0. A build is then performed inside of that with changes found to hailort/hailort/external/** which is part of the "source".

As far as I can tell, the error is reporting correctly.

Based on the output, it isn't directly hailort that is causing problems but an external dependency on cli11

I'm not too sure what is causing it, whether its cmake pulling in cli11 directly into that location (which should then have more files) or if cli11 is generating those (which I'm not seeing inside of their repo.

@Jex-y
Copy link
Author

Jex-y commented Jan 3, 2025

The generated .crate was extracted to /home/ejex/code/libhailort-sys/target/package/libhailort-sys-0.1.0. A build is then performed inside of that with changes found to hailort/hailort/external/** which is part of the "source".

As far as I can tell, the error is reporting correctly.

Based on the output, it isn't directly hailort that is causing problems but an external dependency on cli11

I'm not too sure what is causing it, whether its cmake pulling in cli11 directly into that location (which should then have more files) or if cli11 is generating those (which I'm not seeing inside of their repo.

I don't think it is just cli11, the error lists what I assume is all of the files in the hailort/external directory, I just cut it off as there were so many. For reference I have uploaded the full error message here: https://gist.githubusercontent.com/Jex-y/38c65cb665c95e001435087157723fcf/raw/780bbfbd506afcda8a9a344922b593858a526bbc/gistfile1.txt

That would make sense, I didn't realise that it copies the source to /target/package, the files are probably being modified by cmake as part of the build. Would this be a bug with the cmake crate then?

@epage
Copy link
Contributor

epage commented Jan 3, 2025

Would this be a bug with the cmake crate then?

I don't know enough about cmake to say whether this is a design problem with cmake, with hailorts cmakle logic, or with the cmake crate.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: bug S-triage Status: This issue is waiting on initial triage.
Projects
None yet
Development

No branches or pull requests

2 participants