{"id":41991616,"url":"https://github.com/rafaelbeckel/test-c-rust-wasm","last_synced_at":"2026-01-26T00:41:21.240Z","repository":{"id":241556446,"uuid":"807028988","full_name":"rafaelbeckel/test-c-rust-wasm","owner":"rafaelbeckel","description":"Rust+C WASM compilation under the same binary for the `wasm32-unknown-unknown` target","archived":false,"fork":false,"pushed_at":"2025-10-08T01:17:23.000Z","size":150,"stargazers_count":52,"open_issues_count":3,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-10-08T03:19:08.801Z","etag":null,"topics":["c","cpp","llvm","rust","wasm","wasm-bindgen"],"latest_commit_sha":null,"homepage":"https://github.com/rafaelbeckel/test-c-rust-wasm","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/rafaelbeckel.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-05-28T10:55:40.000Z","updated_at":"2025-10-08T01:17:27.000Z","dependencies_parsed_at":"2024-05-29T02:39:21.899Z","dependency_job_id":"a25f7a53-f61d-417a-a3c7-2bc60e50e184","html_url":"https://github.com/rafaelbeckel/test-c-rust-wasm","commit_stats":null,"previous_names":["rafaelbeckel/test-c-rust-wasm"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/rafaelbeckel/test-c-rust-wasm","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelbeckel%2Ftest-c-rust-wasm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelbeckel%2Ftest-c-rust-wasm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelbeckel%2Ftest-c-rust-wasm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelbeckel%2Ftest-c-rust-wasm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/rafaelbeckel","download_url":"https://codeload.github.com/rafaelbeckel/test-c-rust-wasm/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/rafaelbeckel%2Ftest-c-rust-wasm/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28763017,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-26T00:37:26.264Z","status":"ssl_error","status_checked_at":"2026-01-26T00:37:25.959Z","response_time":113,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["c","cpp","llvm","rust","wasm","wasm-bindgen"],"created_at":"2026-01-26T00:41:20.565Z","updated_at":"2026-01-26T00:41:21.233Z","avatar_url":"https://github.com/rafaelbeckel.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Rust+C in the same WASM binary\n\nThis repository was originally created to test the state of Rust nightly for producing a compatible C ABI for the `wasm32-unknown-unknown` target with the flag `--Z wasm_c_abi=spec`.\n\nNow [Rust v1.89](https://blog.rust-lang.org/2025/08/07/Rust-1.89.0/#standards-compliant-c-abi-on-the-wasm32-unknown-unknown-target) officially uses the \"C\" ABI by default.\n\nFor context, this is the [relevant tracking issue](https://github.com/rustwasm/wasm-bindgen/issues/3454) in Wasm Bingen, and the [official Rust blog post](https://blog.rust-lang.org/2025/04/04/c-abi-changes-for-wasm32-unknown-unknown/) talking about this.\n\n## Description\n\nThe workspace contains a series of small examples of how to produce a single WASM binary with both C and Rust code that can call each other.\n\nTo see how to do it, check out the `build.sh` file in each of the crates in this workspace.\n\n## Build Strategies\n\nThe crates experiment with different build strategies, with increasing levels of complexity:\n\n1. [Linking Manually](crates/1_linking_manually)\n\n   - A simple calculator with primitive data types and manual build\n\n2. [With CC Crate](crates/2_with_cc)\n\n   - The same calculator built with the [CC crate](https://docs.rs/cc/1.0.101/cc/)\n\n3. [Libc and Heap](crates/3_libc_and_heap_allocation)\n\n   - We use [OpenBSD libc](https://github.com/trevyn/wasm32-unknown-unknown-openbsd-libc) to implement the Mem function in the calculator and store/free a value in the heap from C with `malloc` and `free`\n\n4. [Wasm Bindgen](crates/4_wasm_bindgen/)\n\n   - We create a Calculator struct with member functions and export it with [Wasm Bindgen](https://github.com/rustwasm/wasm-bindgen)\n\n5. [Rust Bindgen](crates/5_rust_bindgen/)\n\n   - This is the same as the previous project, but instead of writing the Calculator struct manually, we generate the Rust bindings from the C header with [Rust Bindgen](https://rust-lang.github.io/rust-bindgen/), which is the recommended way to interact with C code from Rust.\n\n6. [Extern Types](crates/6_extern_types/)\n\n   - This project experiments with the nightly feature `extern types`.\n\n## Running\n\nTo see the examples in action, use your favorite local server:\n\n```bash\nnpx serve\n```\n\nThen, visit `http://localhost:3000` and click the example you want to see.\n\n## Building\n\nEither visit the specific crate and run its `build.sh` script or use the `build_all.sh` script in the root of the workspace to build all crates at once.\n\n### Dependencies\n\n- [LLVM](https://llvm.org/)\n- [Clang](https://clang.llvm.org/)\n- [Rust](https://www.rust-lang.org/) (1.89 or later)\n- [Wasm Binary Toolkit](https://github.com/WebAssembly/wabt)\n\n## Future plans\n\n1. Uniffi\n\n   - I plan to add an example with Uniffi in the future.\n\n2. Wgpu\n\n   - I have used these strategies in my work to build a `wgpu` project that depends on C libraries. I plan to bring a minimal example of it here.\n\n3. Combine different crates in a build script\n\n   - C code coming from a crate and Rust code from another, link them by using linker flags in build.rs.\n\n4. External C libs\n\n   - Finally, let's bring an external C lib and combine all of the above.\n\n## Contributing\n\nIf you'd like to see any other scenario listed here, feel free to open an Issue or a PR.\n\nIf submitting a new example, create a numbered subfolder in the `crates` directory following the existing structure, and ensure your example builds correctly for both WASM and unit tests.\n\nFinally, run `cargo clippy` and stick with the default rules.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafaelbeckel%2Ftest-c-rust-wasm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frafaelbeckel%2Ftest-c-rust-wasm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frafaelbeckel%2Ftest-c-rust-wasm/lists"}