<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugzilla.yoctoproject.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.6"
          urlbase="https://bugzilla.yoctoproject.org/"
          
          maintainer="it-coreprojects-helpdesk@linuxfoundation.org"
>

    <bug>
          <bug_id>16094</bug_id>
          
          <creation_ts>2025-12-08 17:09:55 +0000</creation_ts>
          <short_desc>Generically improve cargo-based tests package reproducibility</short_desc>
          <delta_ts>2026-10-29 17:52:56 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>7</classification_id>
          <classification>Build System, Metadata &amp; Runtime</classification>
          <product>OE-Core</product>
          <component>devtools / tool chain</component>
          <version>unspecified</version>
          <rep_platform>x86</rep_platform>
          <op_sys>Multiple</op_sys>
          <bug_status>IN PROGRESS DESIGN</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>Medium</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>6.2</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Yoann Congal">yoann.congal</reporter>
          <assigned_to name="Unassigned">unassigned</assigned_to>
          <cc>ccasciato</cc>
    
    <cc>elmehdi.younes</cc>
    
    <cc>meta.mr.watcher</cc>
    
    <cc>meta.watcher</cc>
    
    <cc>randy.macleod</cc>
    
    <cc>sundeep.kokkonda</cc>
    
    <cc>SunilKumar.Dora</cc>
    
    <cc>yoann.congal</cc>
          
          
          <cf_os>---</cf_os>
          <cf_regression_type>---</cf_regression_type>
          
          <cf_docchange>No (bug/feature does not impact docs)</cf_docchange>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>103509</commentid>
    <comment_count>0</comment_count>
    <who name="Yoann Congal">yoann.congal</who>
    <bug_when>2025-12-08 17:09:55 +0000</bug_when>
    <thetext>When compiling tests, cargo set environment variables to allow test binaries to find tests binaries, vectors, ...

For example:
CARGO_BIN_EXE_&lt;name&gt; — Absolute path to a binary target’s executable.
CARGO_MANIFEST_PATH  — The path to the manifest of your package.
OUT_DIR — [...] set to the folder where the build script should place its output

If tests binaries use this through the env!() macro (ie putting the var value into the source code), they are not reproducible.

Current cargo does not allow to override these variables.

A solution is to patch upstream packages to override cargo-defined variables (like https://github.com/rpm-software-management/rpm-sequoia/pull/86) but it is not generic and will have to be repeated on every Rust package that has integration tests.

The proper idea is to work with the cargo community to find a generic solution. Something like path remapping but for these variables?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>103532</commentid>
    <comment_count>1</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2025-12-11 16:01:43 +0000</bug_when>
    <thetext>CC Sundeep as FYI. 
Yoann will work on this bug.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>104872</commentid>
    <comment_count>2</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2026-03-31 14:37:56 +0000</bug_when>
    <thetext>Yoann, Do you still plan to work on this bug ?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>104875</commentid>
    <comment_count>3</comment_count>
    <who name="Yoann Congal">yoann.congal</who>
    <bug_when>2026-03-31 14:43:18 +0000</bug_when>
    <thetext>(In reply to Randy MacLeod from comment #2)
&gt; Yoann, Do you still plan to work on this bug ?

Not myself but someone on my team (Mehdi) is working on it right now. He has a working PoC, I&apos;ll start reviewing code soon.
That will most likely NOT be done for 6.0 though (as it needs an upstream cargo approval)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>104887</commentid>
    <comment_count>4</comment_count>
    <who name="Randy MacLeod">randy.macleod</who>
    <bug_when>2026-03-31 21:52:21 +0000</bug_when>
    <thetext>Yoann, Thanks, if Medhi has a YP account they could take ownership of this issue.

Let us know if you want help for upstream or patch review, etc.

Bumping to 6.1.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>104892</commentid>
    <comment_count>5</comment_count>
    <who name="Yoann Congal">yoann.congal</who>
    <bug_when>2026-04-01 09:56:31 +0000</bug_when>
    <thetext>First piece of the puzzle:
Elyou/cargo ptest by elyouG · Pull Request #16816 · rust-lang/cargo
https://github.com/rust-lang/cargo/pull/16816</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>104948</commentid>
    <comment_count>6</comment_count>
    <who name="El Mehdi Younes">elmehdi.younes</who>
    <bug_when>2026-04-03 07:19:00 +0000</bug_when>
    <thetext>Hi All, 
About the problem of OUT_DIR, I only saw it at rpm-sequoia for now. Cargo maintainers confirm that it is a Cargo variable which has been used by projects in ways that were not originally intended. Rpm-sequoia for example uses it to find the out_dir and then they keep going back until they find the lib, which is not too clean, while Cargo is instead trying to move towards a new solution with a new layout that separates build-dir and target-dir. 

CARGO_BIN_EXE_&lt;name&gt;, Cargo is now providing it at runtime, so maybe we can try to convince the others to use an std::env::var_os(&quot;CARGO_BIN_EXE_*&quot;) instead of the env!, so that we can specify this at runtime. 

For CARGO_MANIFEST_PATH, in my solution, I tried to override this variable when we are in test cases, which works with yocto-ptest, since for each test we have just one manifest-dir. The cargo maintainer is concerned about having this in officially in Cargo, since it may break some use cases of Manifest-dir that we don&apos;t specially know. We have an ongoing discussion about possible solutions. 

See: https://github.com/rust-lang/cargo/issues/16817
https://blog.rust-lang.org/2026/03/13/call-for-testing-build-dir-layout-v2/</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105357</commentid>
    <comment_count>7</comment_count>
    <who name="El Mehdi Younes">elmehdi.younes</who>
    <bug_when>2026-05-05 13:10:19 +0000</bug_when>
    <thetext>I am stepping down from this task due to time constraints, but I have done
some work: since Cargo 1.94, CARGO_BIN_EXE_&lt;name&gt; variables are 
provided at runtime. We must pivot to this approach instead of using 
compile-time hardcoded paths. 

To maintain compatibility with Cargo&apos;s recommendation of using a fallback 
while satisfying our Yocto reproducibility requirements, I propose 
implementing a &quot;strict-paths&quot; (feel free to change the name) feature 
in upstream projects. 

The implementation would look like this (ripgrep):

    #[cfg(feature = &quot;strict-paths&quot;)]
    let rg = std::env::var_os(&quot;CARGO_BIN_EXE_rg&quot;)
        .map(PathBuf::from)
        .expect(&quot;CARGO_BIN_EXE_rg must be set at runtime&quot;);

    #[cfg(not(feature = &quot;strict-paths&quot;))]
    let rg = std::env::var_os(&quot;CARGO_BIN_EXE_rg&quot;)
        .map(PathBuf::from)
        .unwrap_or_else(|| PathBuf::from(env!(&quot;CARGO_BIN_EXE_rg&quot;)));

This allows projects to keep the Cargo-recommended `env!` fallback for 
standard usage, while we can enforce clean, runtime-only path resolution in 
our Yocto recipes by simply adding:

    CARGO_BUILD_FLAGS:append:task-compile-ptest-cargo = &quot; --features strict-paths&quot;

This approach prevents any hardcoded paths from being written into the 
resulting binaries during our build process.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>105358</commentid>
    <comment_count>8</comment_count>
    <who name="El Mehdi Younes">elmehdi.younes</who>
    <bug_when>2026-05-05 13:10:47 +0000</bug_when>
    <thetext>Regarding project resources, libraries, or test data, many projects rely on
`OUT_DIR` or `CARGO_MANIFEST_DIR` via `env!` macros to derive paths. 

My proposal is to shift entirely to runtime-provided paths, where the project
itself defines the environment variable needed, rather than relying on
cargo-injected variables.

To facilitate upstream adoption, I suggest using the same &quot;strict-paths&quot;
feature pattern. This allows us to present the change not as a radical
replacement, but as a robust compatibility layer:

    #[cfg(feature = &quot;strict-paths&quot;)]
    let data_path = std::env::var_os(&quot;MY_PROJECT_DATA_DIR&quot;)
        .map(PathBuf::from)
        .expect(&quot;Path must be provided at runtime&quot;);

    #[cfg(not(feature = &quot;strict-paths&quot;))]
    let data_path = std::env::var_os(&quot;MY_PROJECT_DATA_DIR&quot;)
        .map(PathBuf::from)
        .unwrap_or_else(|| PathBuf::from(env!(&quot;OUT_DIR&quot;)).join(&quot;data&quot;));

I am still awaiting a clear recommendation from the Cargo community to
validate this design before discussing it with other upstream projects. 
see https://github.com/rust-lang/cargo/issues/16817</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>