Skip to content
This repository was archived by the owner on Nov 15, 2023. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
13 changes: 13 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions utils/wasm-builder/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ toml = "0.5.4"
walkdir = "2.3.2"
wasm-gc-api = "0.1.11"
sp-maybe-compressed-blob = { version = "4.1.0-dev", path = "../../primitives/maybe-compressed-blob" }
filetime = "0.2.16"
32 changes: 32 additions & 0 deletions utils/wasm-builder/src/wasm_project.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,41 @@ pub(crate) fn create_and_compile(
&bloaty,
);

if let Err(err) = adjust_mtime(&bloaty, final_wasm_binary.as_ref()) {
build_helper::warning!("Error while adjusting the mtime of the wasm binaries: {}", err)
}

(final_wasm_binary, bloaty)
}

/// Adjust the mtime of the bloaty and compressed/compact wasm files.
///
/// We add the bloaty and the compressed/compact wasm file to the `rerun-if-changed` files.
/// Cargo/Rustc determines based on the timestamp of the `invoked.timestamp` file that can be found
Copy link
Contributor

Choose a reason for hiding this comment

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

It's cargo that does it; rustc doesn't care. (:

/// in the `OUT_DIR/..`, if it needs to rerun a `build.rs` script. The problem is that this
/// `invoked.timestamp` is created when the `build.rs` is executed and the wasm binaries are created
/// later. This leads to them having a later mtime than the `invoked.timestamp` file and thus,
/// cargo/rustc always re-executes the `build.rs` script. To hack around this, we copy the mtime of
/// the `invoked.timestamp` to the wasm binaries.
fn adjust_mtime(
bloaty_wasm: &WasmBinaryBloaty,
compressed_or_compact_wasm: Option<&WasmBinary>,
) -> std::io::Result<()> {
let out_dir = build_helper::out_dir();
let invoked_timestamp = out_dir.join("../invoked.timestamp");

// Get the mtime of the `invoked.timestamp`
let metadata = fs::metadata(invoked_timestamp)?;
let mtime = filetime::FileTime::from_last_modification_time(&metadata);

filetime::set_file_mtime(bloaty_wasm.wasm_binary_bloaty_path(), mtime)?;
if let Some(binary) = compressed_or_compact_wasm.as_ref() {
filetime::set_file_mtime(binary.wasm_binary_path(), mtime)?;
}

Ok(())
}

/// Find the `Cargo.lock` relative to the `OUT_DIR` environment variable.
///
/// If the `Cargo.lock` cannot be found, we emit a warning and return `None`.
Expand Down