@@ -70,7 +70,6 @@ pub fn get_wasmtime_version() -> &'static str {
7070#[ cfg( test) ]
7171mod tests {
7272 use std:: env;
73- use std:: path:: Path ;
7473
7574 // Test that the build info is correct
7675 #[ test]
@@ -90,16 +89,46 @@ mod tests {
9089 fn test_wasmtime_version ( ) {
9190 let wasmtime_version = super :: get_wasmtime_version ( ) ;
9291 // get the wasmtime version from the wasm_runtime binary's Cargo.toml
93- let cargo_toml_path = Path :: new ( env ! ( "OUT_DIR" ) )
94- . join ( "vendor" )
95- . join ( "wasm_runtime" )
96- . join ( "Cargo.toml" ) ;
92+
93+ let manifest_path = env ! ( "CARGO_MANIFEST_PATH" ) ;
94+ let output = std:: process:: Command :: new ( "cargo" )
95+ . arg ( "metadata" )
96+ . arg ( "--manifest-path" )
97+ . arg ( manifest_path)
98+ . arg ( "--format-version=1" )
99+ . output ( )
100+ . expect ( "Failed to get cargo metadata" ) ;
101+
102+ #[ derive( serde:: Deserialize ) ]
103+ struct CargoMetadata {
104+ packages : Vec < CargoPackage > ,
105+ }
106+
107+ #[ derive( serde:: Deserialize ) ]
108+ struct CargoPackage {
109+ name : String ,
110+ manifest_path : std:: path:: PathBuf ,
111+ }
112+
113+ let metadata: CargoMetadata =
114+ serde_json:: from_slice ( & output. stdout ) . expect ( "Failed to parse cargo metadata" ) ;
115+
116+ // find the package entry for wasm-runtime and get its manifest_path
117+ let wasm_runtime = metadata
118+ . packages
119+ . into_iter ( )
120+ . find ( |pkg| pkg. name == "wasm-runtime" )
121+ . expect ( "wasm-runtime crate not found in cargo metadata" ) ;
122+
123+ let cargo_toml_path = wasm_runtime. manifest_path ;
97124 let cargo_toml_content =
98125 std:: fs:: read_to_string ( cargo_toml_path) . expect ( "Failed to read Cargo.toml" ) ;
99126 let cargo_toml: toml:: Value =
100127 toml:: from_str ( & cargo_toml_content) . expect ( "Failed to parse Cargo.toml" ) ;
101128 let wasmtime_version_from_toml = cargo_toml
102- . get ( "dependencies" )
129+ . get ( "target" )
130+ . and_then ( |deps| deps. get ( "cfg(hyperlight)" ) )
131+ . and_then ( |cfg| cfg. get ( "dependencies" ) )
103132 . and_then ( |deps| deps. get ( "wasmtime" ) )
104133 . and_then ( |wasmtime| wasmtime. get ( "version" ) )
105134 . and_then ( |version| version. as_str ( ) )
0 commit comments