MCPcopy Create free account
hub / github.com/bytecodealliance/wit-bindgen / verify

Function verify

ci/publish.rs:363–452  ·  view source on GitHub ↗

Verify the current tree is publish-able to crates.io. The intention here is that we'll run `cargo package` on everything which verifies the build as-if it were published to crates.io. This requires using an incrementally-built directory registry generated from `cargo vendor` because the versions referenced from `Cargo.toml` may not exist on crates.io.

(crates: &[Crate])

Source from the content-addressed store, hash-verified

361// directory registry generated from `cargo vendor` because the versions
362// referenced from `Cargo.toml` may not exist on crates.io.
363fn verify(crates: &[Crate]) {
364 drop(fs::remove_dir_all(".cargo"));
365 drop(fs::remove_dir_all("vendor"));
366 let vendor = Command::new("cargo")
367 .arg("vendor")
368 .stderr(Stdio::inherit())
369 .output()
370 .unwrap();
371 assert!(vendor.status.success());
372
373 fs::create_dir_all(".cargo").unwrap();
374 fs::write(".cargo/config.toml", vendor.stdout).unwrap();
375
376 for krate in crates {
377 if !krate.publish {
378 continue;
379 }
380 verify_crates_io(krate);
381 verify_and_vendor(&krate);
382 }
383
384 fn verify_and_vendor(krate: &Crate) {
385 let mut cmd = Command::new("cargo");
386 cmd.arg("package")
387 .arg("--allow-dirty")
388 .arg("--manifest-path")
389 .arg(&krate.manifest)
390 .env("CARGO_TARGET_DIR", "./target");
391 let status = cmd.status().unwrap();
392 assert!(status.success(), "failed to verify {:?}", &krate.manifest);
393 let tar = Command::new("tar")
394 .arg("xf")
395 .arg(format!(
396 "../target/package/{}-{}.crate",
397 krate.name, krate.version
398 ))
399 .current_dir("./vendor")
400 .status()
401 .unwrap();
402 assert!(tar.success());
403 fs::write(
404 format!(
405 "./vendor/{}-{}/.cargo-checksum.json",
406 krate.name, krate.version
407 ),
408 "{\"files\":{}}",
409 )
410 .unwrap();
411 }
412
413 fn verify_crates_io(krate: &Crate) {
414 let name = &krate.name;
415 let Some(owners) = curl(&format!("https://crates.io/api/v1/crates/{name}/owners")) else {
416 panic!(
417 "
418failed to get owners for {name}
419
420If this crate does not exist on crates.io yet please ping wasm-tools maintainers

Callers 1

mainFunction · 0.70

Calls 4

dropFunction · 0.85
newFunction · 0.85
verify_crates_ioFunction · 0.85
verify_and_vendorFunction · 0.85

Tested by

no test coverage detected