Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,4 @@ examples/.cache
cranelift/isle/veri/veri_engine/test_output
crates/explorer/node_modules
tests/all/pulley_provenance_test.cwasm
artifacts
/artifacts
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't look right

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh this is actually intentional, although I forgot to mention it. We ./crates/test-programs/artifacts in the repo which was otherwise being ignored when new changes were being added to it and I was editing things around there so figured I'd fix it up here as well. This was added originally because our c-api documentation generated this folder in the root of the repo

49 changes: 38 additions & 11 deletions crates/test-programs/artifacts/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ fn build_and_generate_tests() {
&["--no-default-features", "--features=proxy"],
);

println!("cargo:rerun-if-changed=../src");

// Build the test programs:
let mut cmd = cargo();
cmd.arg("build")
Expand Down Expand Up @@ -62,6 +60,7 @@ fn build_and_generate_tests() {
.join("wasm32-wasip1")
.join("debug")
.join(format!("{target}.wasm"));
read_deps_of(&wasm);

generated_code += &format!("pub const {camel}: &'static str = {wasm:?};\n");

Expand Down Expand Up @@ -123,7 +122,6 @@ fn build_and_generate_tests() {

// Build the WASI Preview 1 adapter, and get the binary:
fn build_adapter(out_dir: &PathBuf, name: &str, features: &[&str]) -> Vec<u8> {
println!("cargo:rerun-if-changed=../../wasi-preview1-component-adapter");
let mut cmd = cargo();
cmd.arg("build")
.arg("--release")
Expand All @@ -139,15 +137,13 @@ fn build_adapter(out_dir: &PathBuf, name: &str, features: &[&str]) -> Vec<u8> {
let status = cmd.status().unwrap();
assert!(status.success());

let artifact = out_dir
.join("wasm32-unknown-unknown")
.join("release")
.join("wasi_snapshot_preview1.wasm");
let adapter = out_dir.join(format!("wasi_snapshot_preview1.{name}.wasm"));
std::fs::copy(
out_dir
.join("wasm32-unknown-unknown")
.join("release")
.join("wasi_snapshot_preview1.wasm"),
&adapter,
)
.unwrap();
std::fs::copy(&artifact, &adapter).unwrap();
read_deps_of(&artifact);
println!("wasi {name} adapter: {:?}", &adapter);
fs::read(&adapter).unwrap()
}
Expand Down Expand Up @@ -190,3 +186,34 @@ fn cargo() -> Command {
}
cargo
}

/// Helper function to read the `*.d` file that corresponds to `artifact`, an
/// artifact of a Cargo compilation.
///
/// This function will "parse" the makefile-based dep-info format to learn about
/// what files each binary depended on to ensure that this build script reruns
/// if any of these files change.
///
/// See
/// <https://doc.rust-lang.org/nightly/cargo/reference/build-cache.html#dep-info-files>
/// for more info.
fn read_deps_of(artifact: &Path) {
let deps_file = artifact.with_extension("d");
let contents = std::fs::read_to_string(&deps_file).expect("failed to read deps file");
for line in contents.lines() {
let Some(pos) = line.find(": ") else {
continue;
};
let line = &line[pos + 2..];
let mut parts = line.split_whitespace();
while let Some(part) = parts.next() {
let mut file = part.to_string();
while file.ends_with('\\') {
file.pop();
file.push(' ');
file.push_str(parts.next().unwrap());
}
println!("cargo:rerun-if-changed={file}");
}
}
}