Skip to content

Commit 9db233f

Browse files
authored
Merge pull request #4806 from namada-net/mergify/bp/maint-libs-0.251/pr-4799
safer wasm cache key (backport #4799)
2 parents 16ec222 + c612673 commit 9db233f

File tree

5 files changed

+27
-2
lines changed

5 files changed

+27
-2
lines changed
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
- Use more precise version for wasm cache key to avoid collisions of serialized
2+
artifacts ([\#4799](https://github.com/anoma/namada/pull/4799))

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/vm/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,6 @@ tempfile.workspace = true
6666
test-log.workspace = true
6767
wasmer-compiler.workspace = true
6868
wasmer-types.workspace = true
69+
70+
[build-dependencies]
71+
git2.workspace = true

crates/vm/build.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
use git2::{DescribeFormatOptions, DescribeOptions, Repository};
2+
3+
fn main() {
4+
// Discover the repository version, if it exists
5+
println!("cargo:rerun-if-changed=../../.git");
6+
let describe_opts = DescribeOptions::new();
7+
let mut describe_format = DescribeFormatOptions::new();
8+
describe_format.dirty_suffix("-dirty");
9+
let version = Repository::discover(".")
10+
.ok()
11+
.as_ref()
12+
.and_then(|repo| repo.describe(&describe_opts).ok())
13+
.and_then(|describe| describe.format(Some(&describe_format)).ok());
14+
if let Some(version) = version {
15+
println!("cargo:rustc-env=GIT_DESCRIBED={version}");
16+
}
17+
}

crates/vm/src/wasm/compilation_cache/common.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,11 @@ impl<N: CacheName, A: WasmCacheAccess> Cache<N, A> {
101101
wasmer::Target::default().hash(&mut hasher);
102102
hasher.finish()
103103
};
104+
let version_prefix =
105+
option_env!("GIT_DESCRIBED").unwrap_or(env!("CARGO_PKG_VERSION"));
104106
let version = format!(
105-
"{}_{:x}",
106-
concat!(env!("CARGO_PKG_VERSION"), "_", env!("RUSTUP_TOOLCHAIN")),
107+
"{version_prefix}{}{:x}",
108+
concat!("_", env!("RUSTUP_TOOLCHAIN"), "_"),
107109
target_hash,
108110
);
109111
let dir = dir.into().join(version);

0 commit comments

Comments
 (0)