-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into test-official-recommended-rust-version
- Loading branch information
Showing
6 changed files
with
38 additions
and
40 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
mod git_describe; | ||
pub mod post_build; | ||
mod wasm_imports; | ||
|
||
pub use git_describe::git_describe; | ||
pub use wasm_imports::extract_wasm_imports; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use anyhow::Result; | ||
use std::fs; | ||
use wasmparser::{Parser, Payload}; | ||
|
||
/// Parses the WebAssembly code and extracts all the import names. | ||
pub fn extract_wasm_imports(output_wasm_path: &str) -> Result<Vec<String>> { | ||
let wasm_data = fs::read(output_wasm_path)?; | ||
let mut import_names = Vec::new(); | ||
|
||
let parser = Parser::new(0); | ||
for payload in parser.parse_all(&wasm_data) { | ||
if let Payload::ImportSection(import_section) = payload? { | ||
for import in import_section { | ||
import_names.push(import?.name.to_string()); | ||
} | ||
} | ||
} | ||
|
||
Ok(import_names) | ||
} |