{"id":21130612,"url":"https://github.com/golemcloud/golem-wasm-ast","last_synced_at":"2025-07-09T01:33:34.170Z","repository":{"id":206569592,"uuid":"715663593","full_name":"golemcloud/golem-wasm-ast","owner":"golemcloud","description":"Higher level WASM library for Rust","archived":false,"fork":false,"pushed_at":"2024-02-27T17:08:37.000Z","size":2106,"stargazers_count":5,"open_issues_count":0,"forks_count":4,"subscribers_count":6,"default_branch":"main","last_synced_at":"2024-02-27T18:29:42.844Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/golemcloud.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2023-11-07T15:33:00.000Z","updated_at":"2024-02-27T18:29:44.381Z","dependencies_parsed_at":"2023-12-18T11:28:50.041Z","dependency_job_id":"d1162500-3e26-44ea-afb2-3b8b83590490","html_url":"https://github.com/golemcloud/golem-wasm-ast","commit_stats":null,"previous_names":["golemcloud/wasm-ast"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/golemcloud/golem-wasm-ast","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemcloud%2Fgolem-wasm-ast","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemcloud%2Fgolem-wasm-ast/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemcloud%2Fgolem-wasm-ast/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemcloud%2Fgolem-wasm-ast/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/golemcloud","download_url":"https://codeload.github.com/golemcloud/golem-wasm-ast/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemcloud%2Fgolem-wasm-ast/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264375582,"owners_count":23598407,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-20T05:35:40.123Z","updated_at":"2025-07-09T01:33:34.154Z","avatar_url":"https://github.com/golemcloud.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"**MERGED TO THE https://github.com/golemcloud/golem/ REPOSITORY**\n\n# golem-wasm-ast\n\n\u003cp\u003e\n    \u003ca href=\"https://crates.io/crates/golem-wasm-ast\"\u003e\n        \u003cimg src=\"https://img.shields.io/crates/v/golem-wasm-ast.svg\" alt=\"Crate\"/\u003e\n    \u003c/a\u003e\n    \u003ca href=\"https://docs.rs/golem-wasm-ast/latest/\"\u003e\n        \u003cimg src=\"https://docs.rs/golem-wasm-ast/badge.svg\" alt=\"Docs\"/\u003e\n    \u003c/a\u003e\n\u003c/p\u003e\n\nHigher level WASM library for Rust\n\nThis library defines an in-memory, mutable representation of WebAssembly modules and [components](https://github.com/WebAssembly/component-model). It uses  \nthe [wasmparser](https://crates.io/crates/wasmparser) and [wasm-encoder](https://crates.io/crates/wasm-encoder) crates for building up and serializing this model.\n\nBuilding up the full AST in memory makes it easier to perform analysis and mutation on a whole WASM component. \nThe `analysis` module defines such higher level operations.\n\n## Usage\nAdd wasm-ast to your Cargo.toml\n\n```shell\n$ cargo add golem-wasm-ast\n```\n\nThen parse a WASM module or component from an array of bytes:\n\n```rust\nuse std::fmt::Debug;\nuse golem_wasm_ast::DefaultAst;\nuse golem_wasm_ast::analysis::AnalysisContext;\nuse golem_wasm_ast::core::{Expr, Module};\nuse golem_wasm_ast::component::Component;\n\nfn main() {\n    let module_bytes: Vec\u003cu8\u003e = ...;\n    let module: Module\u003cDefaultAst\u003e = Component::from_bytes(\u0026component_bytes).unwrap();\n    \n    let component_bytes: Vec\u003cu8\u003e = ...;\n    let component: Component\u003cDefaultAst\u003e = Component::from_bytes(\u0026component_bytes).unwrap();\n\n    println!(\"component metadata {:?}\", component.get_metadata());\n\n    let state = AnalysisContext::new(component);\n    let analysed_exports = state.get_top_level_exports().unwrap();\n    println!(\"analysed exports: {:?}\", analysed_exports);\n\n}\n```\n\nUse the top level `Module` or `Component` structs to query and manipulate parts of the model. \nIt is possible to use a different type than `Expr`, `Data` and `Custom` to represent the code blocks, data and custom sections in the parsed AST to reduce the memory footprint in case the actual code is not required for the analysis. Note that if this custom representation cannot be serialized back to a stream of WASM instructions, the AST will no longer be serializable.\n\nThe following example just ignores all the code blocks, but keeps the data and custom sections:\n\n```rust\n#[derive(Debug, Clone, PartialEq)]\nstruct IgnoredExpr {}\n\nimpl TryFromExprSource for IgnoredExpr {\n    fn try_from\u003cS: ExprSource\u003e(_value: S) -\u003e Result\u003cSelf, String\u003e\n    where\n        Self: Sized,\n    {\n        Ok(IgnoredExpr {})\n    }\n}\n\n#[derive(Debug, Clone, PartialEq)]\npub struct CustomAst;\n\nimpl AstCustomization for CustomAst {\n    type Expr = IgnoredExpr;\n    type Data = Data\u003cIgnoredExpr\u003e;\n    type Custom = Custom;\n}\n\nfn main() {\n    let module_bytes: Vec\u003cu8\u003e = ...;\n    let module: Module\u003cCustomAst\u003e = Component::from_bytes(\u0026component_bytes).unwrap();\n}\n```\n\nIt is possible to do some parse-time analysis of the code blocks in the `TryFromExprSource` implementation and store the analysation result in place of the `Expr` nodes.\n\n## Features\n- `component` enables support for the WASM Component Model \n- `parser` enables parsing of WASM modules and components\n- `writer` enables the serialization of WASM modules and components\n- `metadata` enables the parsing of WASM metadata sections using the [wasm-metadata](https://crates.io/crates/wasm-metadata) crate\n- `analysis` enables higher level analysis and mutation of WASM modules and components\n\nThe `default` feature enables all the above.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgolemcloud%2Fgolem-wasm-ast","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgolemcloud%2Fgolem-wasm-ast","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgolemcloud%2Fgolem-wasm-ast/lists"}