{"id":30078613,"url":"https://github.com/golemcloud/moonbit-component-generator","last_synced_at":"2025-08-08T17:29:56.357Z","repository":{"id":305126186,"uuid":"1014968814","full_name":"golemcloud/moonbit-component-generator","owner":"golemcloud","description":"Rust library embedding the MoonBit compiler and WASM Component Model tooling","archived":false,"fork":false,"pushed_at":"2025-07-28T14:43:33.000Z","size":4414,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-28T14:53:05.182Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"MoonBit","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,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-06T18:54:43.000Z","updated_at":"2025-07-28T14:40:42.000Z","dependencies_parsed_at":"2025-07-18T13:52:11.081Z","dependency_job_id":null,"html_url":"https://github.com/golemcloud/moonbit-component-generator","commit_stats":null,"previous_names":["golemcloud/moonbit-component-generator"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/golemcloud/moonbit-component-generator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemcloud%2Fmoonbit-component-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemcloud%2Fmoonbit-component-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemcloud%2Fmoonbit-component-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemcloud%2Fmoonbit-component-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/golemcloud","download_url":"https://codeload.github.com/golemcloud/moonbit-component-generator/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/golemcloud%2Fmoonbit-component-generator/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":269459246,"owners_count":24420557,"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","status":"online","status_checked_at":"2025-08-08T02:00:09.200Z","response_time":72,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2025-08-08T17:29:52.793Z","updated_at":"2025-08-08T17:29:56.340Z","avatar_url":"https://github.com/golemcloud.png","language":"MoonBit","funding_links":[],"categories":[],"sub_categories":[],"readme":"# moonbit-component-generator\n\nRust library embedding the MoonBit compiler (compiled to WASM, executed on V8) and the MoonBit core library and various\ntools from the WASM ecosystem to programmatically generate MoonBit source code and compile it to WebAssembly Components.\n\nThe crate is fully self-contained, does not require any external dependencies.\nSome example use cases are exposed by crate features:\n\n- `get-script`: generates a WASM component with a single exported function `get-script` that returns an arbitrary string\n  embedded in the component. An example use case for this can be to compose JavaScript scripts with a precompiled WASM\n  JS engine.\n- `typed-config`: takes a simple WIT interface with functions getting \"typed configuration\", and generates a WASM\n  component that implements this interface using either the WASI environment or the WASI config APIs.\n\n## Use cases\nThe crate implements the general machinery for generating WASM components from MoonBit source, and it also exports a few example use cases:\n\n### \"Get Script\" component\nThe simplest example generates a WASM component that exports a single function `get-script` which returns a string.\nThis can be used to attach dynamic content to a statically compiled WASM component via composition,\nfor example providing user-defined JavaScript code to a precompiled WASM JavaScript engine.\n\nTo use this generator, just provide the script contents and the target WASM path:\n\n```rust\nuse moonbit_component_generator::get_script::generate_get_script_component;\n\nfn main() {\n    let script = \"console.log('Hello, world!');\";\n    let wasm_path = \"output/get_script.wasm\";\n    generate_get_script_component(script, wasm_path).expect(\"Failed to generate get-script component\");\n}\n```\n\n### \"Typed Config\" component\nThe \"Typed Config\" component generator inspects a given WIT package and generates a WASM component that implements it\nusing either the WASI environment API or the WASI config APIs. This can be used to have a statically typed configuration\nAPI provided for WASM components of any language.\n\nThe current implementation only supports string configuration values, but it can be extended to support more types including\nrecords and variants, as the code generator has access to the resolved WIT interface.\n\nTo use this generator, provide the WIT package path and the target WASM path:\n\n```rust\nuse moonbit_component_generator::typed_config::generate_typed_config_component;\n\nfn main() {\n  let wit = r#\"\n                package example:typed-config;\n\n                interface config {\n                    username: func() -\u003e string;\n                    password: func() -\u003e string;\n                    server: func() -\u003e string;\n                }\n\n                world example-config {\n                    export config;\n                }\n            \"#;\n  let wasm_path = \"output/typed_config.wasm\";\n  generate_typed_config_component(wit, wasm_path).expect(\"Failed to generate typed config component\");\n}\n\n```\n\n## Development\n\n- `moonc_wasm` is a cloned and patched version of https://github.com/moonbitlang/moonc_wasm to make it library crate.\n- `core` is a git submodule containing the MoonBit core library (https://github.com/moonbitlang/core)\n- `bundled-core` is the MoonBit core library (source and compiled for wasm), included in this repository to avoid users of the crate from having to build `core` themselves.\n\nTo update and build the MoonBit core library:\n\n**NOTE**: requires the 0.6.19 version of MoonBit currently\n\n```\ncurl -fsSL https://cli.moonbitlang.com/install/unix.sh | bash -s -- 0.6.19\ngit submodule update --recursive\n./update-bundle.sh\n```\n\nThe bundled core library is included in the compiled crate using the `include_dir!` macro.\nIt is also pushed into the repository (`bundled-core` directory) to avoid users of the crate from having to build the MoonBit core themselves as part\nof the Rust build process.\n\nRunning the tests require `wasmtime-cli` to be installed with the following features enabled:\n- `component-model`\n- `wasi-config`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgolemcloud%2Fmoonbit-component-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgolemcloud%2Fmoonbit-component-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgolemcloud%2Fmoonbit-component-generator/lists"}