Skip to content

Commit

Permalink
package cargo.toml (#2124)
Browse files Browse the repository at this point in the history
Co-authored-by: Alexandre Lissy <[email protected]>
  • Loading branch information
lissyx and Alexandre Lissy authored Mar 13, 2024
1 parent ad2484d commit 25480ef
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions src/compiler/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,64 @@ fn test_can_trim_this() {
assert!(!can_trim_this(&rlib_file));
}

#[cfg(feature = "dist-client")]
fn maybe_add_cargo_toml(input_path: &Path, verify: bool) -> Option<PathBuf> {
let lib_rs = PathBuf::new().join("src").join("lib.rs");
if input_path.ends_with(lib_rs) {
let cargo_toml_path = input_path
.parent()
.expect("No parent")
.parent()
.expect("No parent")
.join("Cargo.toml");
// We want to:
// - either make sure the file exists (verify=true)
// - just return the path (verify=false)
if cargo_toml_path.is_file() || !verify {
Some(cargo_toml_path)
} else {
None
}
} else {
None
}
}

#[test]
#[cfg(feature = "dist-client")]
fn test_maybe_add_cargo_toml() {
let (root, result_cargo_toml_path) = if cfg!(windows) {
(
r"C:\mozilla-source\mozilla-unified\third_party\rust",
r"C:\mozilla-source\mozilla-unified\third_party\rust\wgpu-core\Cargo.toml",
)
} else {
(
"/home/user/mozilla-source/mozilla-unified/third_party/rust",
"/home/user/mozilla-source/mozilla-unified/third_party/rust/wgpu-core/Cargo.toml",
)
};

let wgpu_core = PathBuf::from(&root)
.join("wgpu-core")
.join("src")
.join("core.rs");
let wgpu_lib = PathBuf::from(&root)
.join("wgpu-core")
.join("src")
.join("lib.rs");
assert!(maybe_add_cargo_toml(&wgpu_core, false).is_none());
assert!(maybe_add_cargo_toml(&wgpu_core, true).is_none());
assert!(
maybe_add_cargo_toml(&wgpu_lib, false)
== Some(PathBuf::from(&root).join("wgpu-core").join("Cargo.toml"))
);
assert!(
maybe_add_cargo_toml(&wgpu_lib, false).unwrap().to_str() == Some(result_cargo_toml_path)
);
assert!(maybe_add_cargo_toml(&wgpu_lib, true).is_none());
}

#[cfg(feature = "dist-client")]
impl pkg::InputsPackager for RustInputsPackager {
#[allow(clippy::cognitive_complexity)] // TODO simplify this method.
Expand Down Expand Up @@ -1893,9 +1951,23 @@ impl pkg::InputsPackager for RustInputsPackager {
}
}
}

if let Some(cargo_toml_path) = maybe_add_cargo_toml(&input_path, true) {
let dist_cargo_toml_path = path_transformer
.as_dist(&cargo_toml_path)
.with_context(|| {
format!(
"unable to transform input path {}",
cargo_toml_path.display()
)
})?;
tar_inputs.push((cargo_toml_path, dist_cargo_toml_path));
}

let dist_input_path = path_transformer.as_dist(&input_path).with_context(|| {
format!("unable to transform input path {}", input_path.display())
})?;

tar_inputs.push((input_path, dist_input_path))
}

Expand Down

0 comments on commit 25480ef

Please sign in to comment.