├── .changeset ├── README.md ├── clean-radios-cover.md ├── config.json ├── custom-changelog-format.mjs └── gorgeous-swans-agree.md ├── .editorconfig ├── .gitattributes ├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.yml │ └── config.yml ├── actions │ ├── setup-wabt │ │ └── action.yml │ └── setup │ │ └── action.yml └── workflows │ ├── ci.yml │ ├── docs.yml │ └── release.yml ├── .gitignore ├── .nvmrc ├── .release-it.json ├── .yarn └── releases │ └── yarn-4.5.3.cjs ├── .yarnrc.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── apps └── example │ ├── .gitignore │ ├── .watchmanconfig │ ├── android │ ├── build.gradle │ ├── gradle.properties │ ├── gradle │ │ └── wrapper │ │ │ ├── gradle-wrapper.jar │ │ │ └── gradle-wrapper.properties │ ├── gradlew │ ├── gradlew.bat │ └── settings.gradle │ ├── app.json │ ├── babel.config.js │ ├── index.js │ ├── ios │ ├── Podfile │ ├── Podfile.lock │ └── WasmExample.xcworkspace │ │ ├── contents.xcworkspacedata │ │ └── xcshareddata │ │ └── IDEWorkspaceChecks.plist │ ├── metro.config.js │ ├── package.json │ ├── polygen.config.mjs │ ├── react-native.config.js │ ├── src │ ├── App.tsx │ ├── example-wasm-buffer.ts │ ├── example.wasm │ ├── examples │ │ ├── ExternalModuleExample.tsx │ │ ├── FetchExample.tsx │ │ ├── ImportValidationExample.tsx │ │ ├── ModuleFromBufferExample.tsx │ │ └── TableExample.tsx │ └── table_test.wasm │ └── tsconfig.json ├── babel.config.js ├── biome.json ├── docs ├── .eslintrc.json ├── .gitignore ├── .yarn │ └── install-state.gz ├── README.md ├── app │ ├── (home) │ │ ├── layout.tsx │ │ └── page.tsx │ ├── api │ │ └── search │ │ │ └── route.ts │ ├── docs │ │ ├── [[...slug]] │ │ │ └── page.tsx │ │ └── layout.tsx │ ├── globals.css │ ├── layout.client.tsx │ ├── layout.config.tsx │ └── layout.tsx ├── components │ ├── DocTable.tsx │ ├── PageHeader.tsx │ ├── PrettyCard.tsx │ └── ProsConsOverview.tsx ├── content │ └── docs │ │ ├── config │ │ ├── index.mdx │ │ ├── meta.json │ │ ├── modules.mdx │ │ └── output.mdx │ │ ├── meta.json │ │ └── polygen │ │ ├── (guide) │ │ ├── comparison.mdx │ │ ├── install.mdx │ │ └── intro.mdx │ │ ├── (ref) │ │ └── config.mdx │ │ ├── adding-modules.mdx │ │ ├── index.mdx │ │ ├── integrations │ │ ├── meta.json │ │ └── metro.mdx │ │ ├── loading-modules.mdx │ │ ├── meta.json │ │ ├── recipes │ │ ├── assembly-script.mdx │ │ ├── meta.json │ │ └── rust.mdx │ │ └── wasi.mdx ├── lib │ ├── source.ts │ └── ts-documentation.ts ├── next.config.mjs ├── package.json ├── postcss.config.mjs ├── public │ ├── assembly-script.svg │ ├── discord-mark-blue.svg │ ├── github-mark.svg │ ├── mdn-icon.png │ ├── metro.svg │ ├── polygen-logo.png │ └── rust.svg ├── source.config.ts ├── tsconfig.json └── yarn.lock ├── lefthook.yml ├── package.json ├── packages ├── binary-utils │ ├── package.json │ ├── src │ │ ├── __tests__ │ │ │ ├── binary-reader.spec.ts │ │ │ └── binary.spec.ts │ │ ├── binary-reader.ts │ │ ├── binary-writer.ts │ │ ├── common.ts │ │ ├── helpers.ts │ │ └── index.ts │ ├── tsconfig.json │ └── vitest.config.ts ├── codegen │ ├── CHANGELOG.md │ ├── assets │ │ ├── Info.plist │ │ ├── wasm-rt-weak.h │ │ └── wasm-rt │ │ │ ├── wasm-rt-exceptions.c │ │ │ ├── wasm-rt-exceptions.h │ │ │ ├── wasm-rt-impl-tableops.inc │ │ │ ├── wasm-rt-impl.c │ │ │ ├── wasm-rt-impl.h │ │ │ ├── wasm-rt-mem-impl-helper.inc │ │ │ ├── wasm-rt-mem-impl.c │ │ │ └── wasm-rt.h │ ├── package.json │ ├── src │ │ ├── codegen-pipeline.ts │ │ ├── codegen.ts │ │ ├── codegen │ │ │ ├── context.ts │ │ │ ├── modules.ts │ │ │ ├── types.ts │ │ │ └── utils.ts │ │ ├── generators │ │ │ └── module-bridge.ts │ │ ├── helpers │ │ │ ├── checksum.ts │ │ │ └── output-generator.ts │ │ ├── index.ts │ │ ├── pipeline │ │ │ ├── dump-metadata.ts │ │ │ ├── react-native │ │ │ │ ├── cocoapods.ts │ │ │ │ ├── metro.ts │ │ │ │ └── turbomodule.ts │ │ │ └── wasm2c-runtime.ts │ │ ├── plugin.ts │ │ ├── source-builder │ │ │ ├── builder.block.ts │ │ │ ├── builder.decls.ts │ │ │ ├── builder.expr.ts │ │ │ ├── builder.file.ts │ │ │ ├── builder.types.ts │ │ │ ├── common.ts │ │ │ ├── index.ts │ │ │ └── source-writer.ts │ │ ├── templates │ │ │ ├── common.ts │ │ │ ├── host.ts │ │ │ └── library │ │ │ │ ├── imports-bridge.ts │ │ │ │ ├── index.ts │ │ │ │ ├── module-bridge.ts │ │ │ │ └── static-lib.ts │ │ └── wasm2c │ │ │ ├── mangle.ts │ │ │ └── wasm2c.ts │ └── tsconfig.json ├── metro-config │ ├── CHANGELOG.md │ ├── package.json │ ├── src │ │ ├── index.ts │ │ └── wasm-loader.d.ts │ └── tsconfig.json ├── polygen-cli │ ├── CHANGELOG.md │ ├── bin │ │ └── polygen.js │ ├── package.json │ ├── src │ │ ├── actions │ │ │ ├── clean.ts │ │ │ └── codegen.ts │ │ ├── commands │ │ │ ├── clean.ts │ │ │ ├── generate.ts │ │ │ ├── init.ts │ │ │ └── scan.ts │ │ ├── helpers │ │ │ ├── errors.ts │ │ │ └── with-project-options.ts │ │ ├── index.ts │ │ ├── plugin.ts │ │ ├── templates │ │ │ └── default-polygen-config.ts │ │ └── types.ts │ └── tsconfig.json ├── polygen-config │ ├── CHANGELOG.md │ ├── package.json │ ├── src │ │ ├── find-config.ts │ │ ├── helpers.ts │ │ ├── index.ts │ │ └── types │ │ │ ├── global-config.ts │ │ │ └── module-config.ts │ └── tsconfig.json ├── polygen-project │ ├── CHANGELOG.md │ ├── package.json │ ├── src │ │ ├── deps.ts │ │ ├── index.ts │ │ ├── project.modules.ts │ │ ├── project.paths.ts │ │ ├── project.ts │ │ └── types.ts │ └── tsconfig.json ├── polygen │ ├── CHANGELOG.md │ ├── ReactNativePolygen.podspec │ ├── android │ │ ├── CMakeLists.txt │ │ ├── build.gradle │ │ ├── cpp-adapter.cpp │ │ ├── gradle.properties │ │ └── src │ │ │ ├── main │ │ │ ├── AndroidManifest.xml │ │ │ ├── AndroidManifestNew.xml │ │ │ └── java │ │ │ │ └── com │ │ │ │ └── wasm │ │ │ │ ├── WasmModule.kt │ │ │ │ └── WasmPackage.kt │ │ │ ├── newarch │ │ │ └── WasmSpec.kt │ │ │ └── oldarch │ │ │ └── WasmSpec.kt │ ├── cli.mjs │ ├── cpp │ │ ├── ReactNativePolygen │ │ │ ├── CMakeLists.txt │ │ │ ├── Loader.cpp │ │ │ ├── Loader.h │ │ │ ├── ModuleBag.h │ │ │ ├── NativeStateHelper.h │ │ │ ├── ReactNativePolygen.cpp │ │ │ ├── ReactNativePolygen.h │ │ │ ├── SharedLibraryModule.h │ │ │ ├── StaticLibraryModule.h │ │ │ ├── WebAssembly.h │ │ │ ├── WebAssembly │ │ │ │ ├── ExternRefTable.h │ │ │ │ ├── FuncRefTable.h │ │ │ │ ├── Global.h │ │ │ │ ├── Memory.h │ │ │ │ ├── Module.h │ │ │ │ └── Table.h │ │ │ ├── bridge.cpp │ │ │ ├── bridge.h │ │ │ ├── gen-utils.h │ │ │ ├── utils │ │ │ │ ├── checksum.cpp │ │ │ │ ├── checksum.h │ │ │ │ └── hashpp.h │ │ │ ├── w2c.cpp │ │ │ └── w2c.h │ │ └── wasm-rt │ │ │ ├── CMakeLists.txt │ │ │ ├── wasm-rt-exceptions.c │ │ │ ├── wasm-rt-exceptions.h │ │ │ ├── wasm-rt-impl-tableops.inc │ │ │ ├── wasm-rt-impl.c │ │ │ ├── wasm-rt-impl.h │ │ │ ├── wasm-rt-mem-impl-helper.inc │ │ │ ├── wasm-rt-mem-impl.c │ │ │ └── wasm-rt.h │ ├── ios │ │ ├── Wasm.h │ │ └── Wasm.mm │ ├── package.json │ ├── polygen.rb │ ├── react-native.config.js │ ├── src │ │ ├── NativePolygen.ts │ │ ├── api │ │ │ ├── Global.ts │ │ │ ├── Instance.ts │ │ │ ├── Memory.ts │ │ │ ├── Module.ts │ │ │ ├── Table.ts │ │ │ ├── WebAssembly.ts │ │ │ └── errors.ts │ │ ├── index.ts │ │ ├── polyfill.ts │ │ └── types.ts │ ├── tsconfig.build.json │ ├── tsconfig.json │ └── types │ │ └── WebAssembly-global.d.ts ├── typescript-config │ ├── package.json │ └── tsconfig.json └── wasm-parser │ ├── package.json │ ├── src │ ├── index.ts │ ├── module.ts │ ├── reader │ │ ├── errors.ts │ │ ├── module-reader.ts │ │ ├── section-reader.ts │ │ ├── type-reader.ts │ │ ├── types.ts │ │ └── utils.ts │ └── types.ts │ └── tsconfig.json ├── turbo.json ├── vitest.workspace.ts └── yarn.lock /.changeset/README.md: -------------------------------------------------------------------------------- 1 | # Changesets 2 | 3 | Hello and welcome! This folder has been automatically generated by `@changesets/cli`, a build tool that works 4 | with multi-package repos, or single-package repos to help you version and publish your code. You can 5 | find the full documentation for it [in our repository](https://github.com/changesets/changesets) 6 | 7 | We have a quick list of common questions to get you started engaging with this project in 8 | [our documentation](https://github.com/changesets/changesets/blob/main/docs/common-questions.md) 9 | -------------------------------------------------------------------------------- /.changeset/clean-radios-cover.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@callstack/polygen-cli": patch 3 | --- 4 | 5 | Fix running 'init' command in a package with no dependencies 6 | -------------------------------------------------------------------------------- /.changeset/config.json: -------------------------------------------------------------------------------- 1 | { 2 | "$schema": "https://unpkg.com/@changesets/config@3.0.5/schema.json", 3 | "changelog": "./custom-changelog-format.mjs", 4 | "commit": false, 5 | "fixed": [], 6 | "linked": [["@callstack/polygen-*"]], 7 | "access": "public", 8 | "baseBranch": "master", 9 | "updateInternalDependencies": "patch", 10 | "ignore": [ 11 | "polygen-example" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /.changeset/custom-changelog-format.mjs: -------------------------------------------------------------------------------- 1 | /** 2 | * Gets a single release line for a changeset 3 | * 4 | * @param {import("@changesets/types").NewChangesetWithCommit} changeset 5 | * @param {import("@changesets/types").VersionType} _type 6 | * @returns {Promise} 7 | */ 8 | const getReleaseLine = async (changeset, _type) => { 9 | let lines = changeset.summary 10 | .split('\n') 11 | .map((l) => l.trim().replace(/^\-\s*/, '')) 12 | .map((l) => `- ${l}`); 13 | 14 | if (changeset.commit) { 15 | lines = lines.map((l) => `${l} [${changeset.commit.slice(0, 7)}]`); 16 | } 17 | 18 | return lines.join('\n'); 19 | }; 20 | 21 | /** 22 | * 23 | * @param {import("@changesets/types").NewChangesetWithCommit[]} changesets 24 | * @param {import("@changesets/types").ModCompWithPackage[]} dependenciesUpdated 25 | * @returns {Promise} 26 | */ 27 | const getDependencyReleaseLine = async (changesets, dependenciesUpdated) => { 28 | if (dependenciesUpdated.length === 0) { 29 | return ''; 30 | } 31 | 32 | const changesetLinks = changesets.map( 33 | (changeset) => 34 | `- Updated dependencies${ 35 | changeset.commit ? ` [${changeset.commit.slice(0, 7)}]` : '' 36 | }` 37 | ); 38 | 39 | const updatedDependenciesList = dependenciesUpdated.map( 40 | (dependency) => ` - ${dependency.name}@${dependency.newVersion}` 41 | ); 42 | 43 | return [...changesetLinks, ...updatedDependenciesList].join('\n'); 44 | }; 45 | 46 | /** 47 | * 48 | * @type {import("@changesets/types").ChangelogFunctions} 49 | */ 50 | const defaultChangelogFunctions = { 51 | getReleaseLine, 52 | getDependencyReleaseLine, 53 | }; 54 | 55 | export default defaultChangelogFunctions; 56 | -------------------------------------------------------------------------------- /.changeset/gorgeous-swans-agree.md: -------------------------------------------------------------------------------- 1 | --- 2 | "@callstack/polygen": patch 3 | --- 4 | 5 | Include missing polygen.rb in polygen package. 6 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # EditorConfig helps developers define and maintain consistent 2 | # coding styles between different editors and IDEs 3 | # editorconfig.org 4 | 5 | root = true 6 | 7 | [*] 8 | 9 | indent_style = space 10 | indent_size = 2 11 | 12 | end_of_line = lf 13 | charset = utf-8 14 | trim_trailing_whitespace = true 15 | insert_final_newline = true 16 | -------------------------------------------------------------------------------- /.gitattributes: -------------------------------------------------------------------------------- 1 | *.pbxproj -text 2 | # specific for windows script files 3 | *.bat text eol=crlf -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: true 2 | contact_links: 3 | - name: Feature Request 💡 4 | url: https://github.com/callstackincubator/polygen/discussions/new?category=ideas 5 | about: If you have a feature request, please create a new discussion on GitHub. 6 | - name: Discussions on GitHub 💬 7 | url: https://github.com/callstackincubator/polygen/discussions 8 | about: If this library works as promised but you need help, please ask questions there. 9 | -------------------------------------------------------------------------------- /.github/actions/setup-wabt/action.yml: -------------------------------------------------------------------------------- 1 | name: Setup WebAssembly Toolkit 2 | description: Runs the setup for the WebAssembly Toolkit 3 | 4 | runs: 5 | using: composite 6 | steps: 7 | - name: Cache binary 8 | id: cache-binary 9 | uses: actions/cache@v4 10 | with: 11 | path: /tmp/wabt 12 | key: ${{ runner.os }}-wabt 13 | 14 | - name: Install dependencies 15 | if: steps.yarn-cache.outputs.cache-hit != 'true' 16 | run: yarn install --immutable 17 | shell: bash 18 | 19 | - name: Build WABT 20 | if: steps.cache-binary.outputs.cache-hit != 'true' 21 | run: | 22 | cd /tmp 23 | git clone --recursive https://github.com/WebAssembly/wabt 24 | cd wabt 25 | git submodule update --init 26 | cmake -B build -S . 27 | cmake --build build 28 | shell: bash 29 | 30 | - name: Install WABT on the system 31 | run: | 32 | export PATH="$PATH:/tmp/wabt/build" 33 | shell: bash 34 | -------------------------------------------------------------------------------- /.github/actions/setup/action.yml: -------------------------------------------------------------------------------- 1 | name: Setup 2 | description: Setup Node.js and install dependencies 3 | 4 | runs: 5 | using: composite 6 | steps: 7 | - name: Setup Node.js 8 | uses: actions/setup-node@v4 9 | with: 10 | node-version-file: .nvmrc 11 | cache: 'yarn' 12 | 13 | - name: Cache turbo build setup 14 | uses: actions/cache@v4 15 | with: 16 | path: .turbo 17 | key: ${{ runner.os }}-turbo-${{ github.sha }} 18 | restore-keys: | 19 | ${{ runner.os }}-turbo- 20 | 21 | - name: Install dependencies 22 | run: yarn install --immutable 23 | shell: bash 24 | -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: Deploy to GitHub Pages 2 | 3 | on: 4 | push: 5 | branches: 6 | - master 7 | paths: 8 | - 'docs/**' 9 | workflow_dispatch: 10 | 11 | permissions: 12 | contents: write 13 | 14 | jobs: 15 | build: 16 | name: Builds docs 17 | runs-on: ubuntu-latest 18 | steps: 19 | - uses: actions/checkout@v4 20 | with: 21 | fetch-depth: 0 22 | 23 | - name: Get yarn cache directory path 24 | id: yarn-cache-dir-path 25 | run: echo "dir=$(yarn config get cacheFolder)" >> $GITHUB_OUTPUT 26 | 27 | - uses: actions/cache@v4 28 | id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`) 29 | with: 30 | path: | 31 | ${{ steps.yarn-cache-dir-path.outputs.dir }} 32 | docs/.next/cache 33 | key: ${{ runner.os }}-docs-${{ hashFiles('docs/yarn.lock') }}-${{ hashFiles('docs/**/*.js', 'docs/**/*.jsx', 'docs/**/*.ts', 'docs/**/*.tsx', 'docs/**/*.jsm', 'docs/**/*.mdx?', 'docs/**/*.json') }} 34 | restore-keys: | 35 | ${{ runner.os }}-docs-${{ hashFiles('docs/yarn.lock') }} 36 | 37 | - name: Download deps 38 | working-directory: ./docs 39 | run: yarn install --immutable 40 | #if: steps.yarn-cache.outputs.cache-hit != 'true' 41 | 42 | - name: Build docs 43 | working-directory: ./docs 44 | run: DOCS_BASE_PATH=/polygen yarn build 45 | 46 | - name: Upload docs as artifact 47 | id: deployment 48 | uses: actions/upload-pages-artifact@v3 49 | with: 50 | path: ./docs/out/ 51 | 52 | deploy: 53 | name: Deploy to GitHub Pages 54 | runs-on: ubuntu-latest 55 | needs: build 56 | 57 | # Grant GITHUB_TOKEN the permissions required to make a Pages deployment 58 | permissions: 59 | pages: write # to deploy to Pages 60 | id-token: write # to verify the deployment originates from an appropriate source 61 | 62 | # Deploy to the github-pages environment 63 | environment: 64 | name: github-pages 65 | url: ${{ steps.deployment.outputs.page_url }} 66 | 67 | steps: 68 | - name: Deploy to GitHub Pages 69 | id: deployment 70 | uses: actions/deploy-pages@v4 71 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: workflow_dispatch 4 | 5 | concurrency: ${{ github.workflow }}-${{ github.ref }} 6 | 7 | jobs: 8 | release: 9 | permissions: 10 | contents: write # to create release (changesets/action) 11 | id-token: write # Required for provenance 12 | pull-requests: write # to create pull request (changesets/action) 13 | name: Release 14 | runs-on: ubuntu-latest 15 | steps: 16 | - name: Checkout Repo 17 | uses: actions/checkout@v4 18 | 19 | - name: Setup Node.js 20 20 | uses: actions/setup-node@v4 21 | with: 22 | node-version: 20 23 | 24 | - name: Install Dependencies 25 | run: yarn 26 | 27 | - name: Create Release Pull Request or Publish to NPM 28 | uses: changesets/action@v1 29 | with: 30 | publish: yarn publish-packages 31 | commit: "chore(release): version packages" 32 | title: "chore(release): version packages" 33 | env: 34 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 35 | NPM_CONFIG_PROVENANCE: true 36 | NPM_TOKEN: ${{ secrets.NPM_TOKEN }} 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # XDE 6 | .expo/ 7 | 8 | # VSCode 9 | .vscode/ 10 | jsconfig.json 11 | 12 | # Xcode 13 | # 14 | build/ 15 | *.pbxuser 16 | !default.pbxuser 17 | *.mode1v3 18 | !default.mode1v3 19 | *.mode2v3 20 | !default.mode2v3 21 | *.perspectivev3 22 | !default.perspectivev3 23 | xcuserdata 24 | *.xccheckout 25 | *.moved-aside 26 | DerivedData 27 | *.hmap 28 | *.ipa 29 | *.xcuserstate 30 | project.xcworkspace 31 | 32 | # Android/IJ 33 | # 34 | .classpath 35 | .cxx 36 | .gradle 37 | .idea 38 | .project 39 | .settings 40 | local.properties 41 | android.iml 42 | 43 | # Cocoapods 44 | # 45 | apps/*/ios/Pods 46 | apps/*/ios/build 47 | 48 | # Ruby 49 | example/vendor/ 50 | 51 | # node.js 52 | # 53 | node_modules/ 54 | npm-debug.log 55 | yarn-debug.log 56 | yarn-error.log 57 | 58 | # BUCK 59 | buck-out/ 60 | \.buckd/ 61 | android/app/libs 62 | android/keystores/debug.keystore 63 | 64 | # Yarn 65 | .yarn/* 66 | !.yarn/patches 67 | !.yarn/plugins 68 | !.yarn/releases 69 | !.yarn/sdks 70 | !.yarn/versions 71 | 72 | # Expo 73 | .expo/ 74 | 75 | # Turborepo 76 | .turbo/ 77 | 78 | # generated by bob 79 | lib/ 80 | !packages/codegen/templates/lib 81 | 82 | # React Native Codegen 83 | ios/generated 84 | android/generated 85 | 86 | packages/*/dist 87 | 88 | !docs/lib 89 | -------------------------------------------------------------------------------- /.nvmrc: -------------------------------------------------------------------------------- 1 | v22.12 2 | -------------------------------------------------------------------------------- /.release-it.json: -------------------------------------------------------------------------------- 1 | { 2 | "hooks": { 3 | "before:init": ["yarn typecheck", "yarn test", "yarn lint"], 4 | "after:bump": "yarn build", 5 | "after:release": "echo Successfully released ${name} v${version} to ${repo.repository}." 6 | }, 7 | "git": { 8 | "commitMessage": "chore: release ${version}", 9 | "tagName": "v${version}" 10 | }, 11 | "npm": { 12 | "publish": true 13 | }, 14 | "github": { 15 | "release": true, 16 | "releaseName": "v${version}" 17 | }, 18 | "plugins": { 19 | "@release-it/conventional-changelog": { 20 | "preset": "angular" 21 | } 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /.yarnrc.yml: -------------------------------------------------------------------------------- 1 | nodeLinker: node-modules 2 | 3 | yarnPath: .yarn/releases/yarn-4.5.3.cjs 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 Callstack 4 | Permission is hereby granted, free of charge, to any person obtaining a copy 5 | of this software and associated documentation files (the "Software"), to deal 6 | in the Software without restriction, including without limitation the rights 7 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8 | copies of the Software, and to permit persons to whom the Software is 9 | furnished to do so, subject to the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be included in all 12 | copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 20 | SOFTWARE. 21 | -------------------------------------------------------------------------------- /apps/example/.gitignore: -------------------------------------------------------------------------------- 1 | # OSX 2 | # 3 | .DS_Store 4 | 5 | # Xcode 6 | # 7 | ios/build/ 8 | ios/Pods 9 | *.pbxuser 10 | !default.pbxuser 11 | *.mode1v3 12 | !default.mode1v3 13 | *.mode2v3 14 | !default.mode2v3 15 | *.perspectivev3 16 | !default.perspectivev3 17 | xcuserdata 18 | *.xccheckout 19 | *.moved-aside 20 | DerivedData 21 | *.hmap 22 | *.ipa 23 | *.xcuserstate 24 | .xcode.env 25 | .xcode.env.local 26 | 27 | # Android/IntelliJ 28 | # 29 | build/ 30 | .idea 31 | .gradle 32 | local.properties 33 | *.iml 34 | *.hprof 35 | .cxx/ 36 | *.keystore 37 | !debug.keystore 38 | 39 | # node.js 40 | # 41 | node_modules/ 42 | npm-debug.log 43 | yarn-error.log 44 | 45 | # fastlane 46 | # 47 | # It is recommended to not store the screenshots in the git repo. Instead, use fastlane to re-generate the 48 | # screenshots whenever they are needed. 49 | # For more information about the recommended setup visit: 50 | # https://docs.fastlane.tools/best-practices/source-control/ 51 | 52 | **/fastlane/report.xml 53 | **/fastlane/Preview.html 54 | **/fastlane/screenshots 55 | **/fastlane/test_output 56 | 57 | # Bundle artifact 58 | *.jsbundle 59 | 60 | # Ruby / CocoaPods 61 | ios/Pods/ 62 | **/Pods/ 63 | /vendor/bundle/ 64 | -------------------------------------------------------------------------------- /apps/example/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /apps/example/android/build.gradle: -------------------------------------------------------------------------------- 1 | buildscript { 2 | apply(from: { 3 | def searchDir = rootDir.toPath() 4 | do { 5 | def p = searchDir.resolve("node_modules/react-native-test-app/android/dependencies.gradle") 6 | if (p.toFile().exists()) { 7 | return p.toRealPath().toString() 8 | } 9 | } while (searchDir = searchDir.getParent()) 10 | throw new GradleException("Could not find `react-native-test-app`"); 11 | }()) 12 | 13 | repositories { 14 | mavenCentral() 15 | google() 16 | } 17 | 18 | dependencies { 19 | getReactNativeDependencies().each { dependency -> 20 | classpath(dependency) 21 | } 22 | } 23 | } 24 | 25 | allprojects { 26 | repositories { 27 | maven { 28 | // All of React Native (JS, Obj-C sources, Android binaries) is installed from npm 29 | url({ 30 | def searchDir = rootDir.toPath() 31 | do { 32 | def p = searchDir.resolve("node_modules/react-native/android") 33 | if (p.toFile().exists()) { 34 | return p.toRealPath().toString() 35 | } 36 | } while (searchDir = searchDir.getParent()) 37 | throw new GradleException("Could not find `react-native`"); 38 | }()) 39 | } 40 | mavenCentral() 41 | google() 42 | } 43 | } 44 | 45 | 46 | react { 47 | bundleCommand = "webpack-bundle" 48 | } 49 | -------------------------------------------------------------------------------- /apps/example/android/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the Gradle Daemon. The setting is 11 | # particularly useful for configuring JVM memory settings for build performance. 12 | # This does not affect the JVM settings for the Gradle client VM. 13 | # The default is `-Xmx512m -XX:MaxMetaspaceSize=256m`. 14 | org.gradle.jvmargs=-Xmx2g -XX:MaxMetaspaceSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 15 | 16 | # When configured, Gradle will fork up to org.gradle.workers.max JVMs to execute 17 | # projects in parallel. To learn more about parallel task execution, see the 18 | # section on Gradle build performance: 19 | # https://docs.gradle.org/current/userguide/performance.html#parallel_execution. 20 | # Default is `false`. 21 | #org.gradle.parallel=true 22 | 23 | # AndroidX package structure to make it clearer which packages are bundled with the 24 | # Android operating system, and which are packaged with your app's APK 25 | # https://developer.android.com/topic/libraries/support-library/androidx-rn 26 | android.useAndroidX=true 27 | # Automatically convert third-party libraries to use AndroidX 28 | android.enableJetifier=false 29 | # Jetifier randomly fails on these libraries 30 | android.jetifier.ignorelist=hermes-android,react-android 31 | 32 | # Use this property to specify which architecture you want to build. 33 | # You can also override it from the CLI using 34 | # ./gradlew -PreactNativeArchitectures=x86_64 35 | reactNativeArchitectures=armeabi-v7a,arm64-v8a,x86,x86_64 36 | 37 | # Use this property to enable support to the new architecture. 38 | # This will allow you to use TurboModules and the Fabric render in 39 | # your application. You should enable this flag either if you want 40 | # to write custom TurboModules/Fabric components OR use libraries that 41 | # are providing them. 42 | # Note that this is incompatible with web debugging. 43 | #newArchEnabled=true 44 | #bridgelessEnabled=true 45 | 46 | # Uncomment the line below to build React Native from source. 47 | #react.buildFromSource=true 48 | 49 | # Version of Android NDK to build against. 50 | #ANDROID_NDK_VERSION=26.1.10909125 51 | 52 | # Version of Kotlin to build against. 53 | #KOTLIN_VERSION=1.8.22 54 | -------------------------------------------------------------------------------- /apps/example/android/gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/callstackincubator/polygen/01a331652c2e417bedd90a5cd23c41d58cacd184/apps/example/android/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /apps/example/android/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip 4 | networkTimeout=10000 5 | validateDistributionUrl=true 6 | zipStoreBase=GRADLE_USER_HOME 7 | zipStorePath=wrapper/dists 8 | -------------------------------------------------------------------------------- /apps/example/android/settings.gradle: -------------------------------------------------------------------------------- 1 | pluginManagement { 2 | repositories { 3 | gradlePluginPortal() 4 | mavenCentral() 5 | google() 6 | } 7 | } 8 | 9 | rootProject.name = "WasmExample" 10 | 11 | apply(from: { 12 | def searchDir = rootDir.toPath() 13 | do { 14 | def p = searchDir.resolve("node_modules/react-native-test-app/test-app.gradle") 15 | if (p.toFile().exists()) { 16 | return p.toRealPath().toString() 17 | } 18 | } while (searchDir = searchDir.getParent()) 19 | throw new GradleException("Could not find `react-native-test-app`"); 20 | }()) 21 | applyTestAppSettings(settings) 22 | -------------------------------------------------------------------------------- /apps/example/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "ReactNativePolygen", 3 | "displayName": "ReactNativePolygen", 4 | "singleApp": "polygen-example", 5 | "components": [ 6 | { 7 | "appKey": "ReactNativePolygen", 8 | "displayName": "ReactNativePolygen", 9 | "slug": "polygen-example" 10 | } 11 | ], 12 | "resources": { 13 | "android": ["dist/res", "dist/main.android.jsbundle"], 14 | "ios": ["dist/assets", "dist/main.ios.jsbundle"], 15 | "macos": ["dist/assets", "dist/main.macos.jsbundle"], 16 | "visionos": ["dist/assets", "dist/main.visionos.jsbundle"], 17 | "windows": ["dist/assets", "dist/main.windows.bundle"] 18 | }, 19 | "android": { 20 | "package": "com.callstack.polygen.example" 21 | }, 22 | "ios": { 23 | "bundleIdentifier": "com.callstack.polygen.example", 24 | "codeSignEntitlements": { 25 | "com.apple.developer.game-center": true 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /apps/example/babel.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | presets: ['module:@react-native/babel-preset'], 3 | }; 4 | -------------------------------------------------------------------------------- /apps/example/index.js: -------------------------------------------------------------------------------- 1 | import { AppRegistry } from 'react-native'; 2 | import { name as appName } from './app.json'; 3 | import App from './src/App'; 4 | 5 | AppRegistry.registerComponent(appName, () => App); 6 | -------------------------------------------------------------------------------- /apps/example/ios/Podfile: -------------------------------------------------------------------------------- 1 | ENV['RCT_NEW_ARCH_ENABLED'] = '1' 2 | 3 | ws_dir = Pathname.new(__dir__) 4 | ws_dir = ws_dir.parent until 5 | File.exist?("#{ws_dir}/node_modules/react-native-test-app/test_app.rb") || 6 | ws_dir.expand_path.to_s == '/' 7 | require "#{ws_dir}/node_modules/react-native-test-app/test_app.rb" 8 | require "#{ws_dir}/node_modules/@callstack/polygen/polygen.rb" 9 | 10 | workspace 'WasmExample.xcworkspace' 11 | 12 | options = { 13 | :bridgeless_enabled => true, 14 | :fabric_enabled => true, 15 | :hermes_enabled => true, 16 | } 17 | 18 | use_test_app! options do |target| 19 | target.app do 20 | install_polygen 21 | end 22 | end 23 | -------------------------------------------------------------------------------- /apps/example/ios/WasmExample.xcworkspace/contents.xcworkspacedata: -------------------------------------------------------------------------------- 1 | 2 | 4 | 6 | 7 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /apps/example/ios/WasmExample.xcworkspace/xcshareddata/IDEWorkspaceChecks.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | IDEDidComputeMac32BitWarning 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /apps/example/metro.config.js: -------------------------------------------------------------------------------- 1 | const path = require('path'); 2 | const { getDefaultConfig, mergeConfig } = require('@react-native/metro-config'); 3 | const { withPolygenConfig } = require('@callstack/polygen-metro-config'); 4 | 5 | const root = path.resolve(__dirname, '..', '..'); 6 | 7 | /** 8 | * Metro configuration 9 | * https://facebook.github.io/metro/docs/configuration 10 | * 11 | * @type {import('metro-config').MetroConfig} 12 | */ 13 | const config = { 14 | resolver: { 15 | // unstable_enablePackageExports: true, 16 | }, 17 | watchFolders: [root], 18 | transformer: { 19 | getTransformOptions: async () => ({ 20 | transform: { 21 | experimentalImportSupport: false, 22 | inlineRequires: true, 23 | }, 24 | }), 25 | }, 26 | }; 27 | 28 | module.exports = withPolygenConfig( 29 | mergeConfig(getDefaultConfig(__dirname), config) 30 | ); 31 | -------------------------------------------------------------------------------- /apps/example/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "polygen-example", 3 | "description": "Example app for React Native", 4 | "license": "MIT", 5 | "homepage": "https://github.com/callstackincubator/polygen", 6 | "version": "0.0.1", 7 | "author": "Robert Pasiński ", 8 | "private": true, 9 | "repository": { 10 | "type": "git", 11 | "url": "https://github.com/callstackincubator/polygen.git" 12 | }, 13 | "scripts": { 14 | "dev": "true", 15 | "android": "react-native run-android", 16 | "build:android": "npm run mkdist && react-native bundle --entry-file index.js --platform android --dev true --bundle-output dist/main.android.jsbundle --assets-dest dist && react-native build-android --extra-params \"--no-daemon --console=plain -PreactNativeArchitectures=arm64-v8a\"", 17 | "build:ios": "npm run mkdist && react-native bundle --entry-file index.js --platform ios --dev true --bundle-output dist/main.ios.jsbundle --assets-dest dist && react-native build-ios --scheme ReactNativePolygen --mode Debug --extra-params \"-sdk iphonesimulator CC=clang CPLUSPLUS=clang++ LD=clang LDPLUSPLUS=clang++ GCC_OPTIMIZATION_LEVEL=0 GCC_PRECOMPILE_PREFIX_HEADER=YES ASSETCATALOG_COMPILER_OPTIMIZATION=time DEBUG_INFORMATION_FORMAT=dwarf COMPILER_INDEX_STORE_ENABLE=NO\"", 18 | "ios": "react-native run-ios", 19 | "mkdist": "node -e \"require('node:fs').mkdirSync('dist', { recursive: true, mode: 0o755 })\"", 20 | "start": "react-native start" 21 | }, 22 | "dependencies": { 23 | "@bacons/text-decoder": "^0.0.0", 24 | "@callstack/polygen-config": "workspace:^", 25 | "@react-navigation/native": "^7.0.13", 26 | "@react-navigation/native-stack": "^7.1.14", 27 | "@react-navigation/stack": "^7.0.18", 28 | "react": "18.3.1", 29 | "react-native": "0.75.4", 30 | "react-native-gesture-handler": "^2.21.2", 31 | "react-native-safe-area-context": "^5.0.0", 32 | "react-native-screens": "^4.3.0", 33 | "simple-sha256-wasm": "^0.1.2" 34 | }, 35 | "devDependencies": { 36 | "@babel/core": "^7.20.0", 37 | "@babel/preset-env": "^7.20.0", 38 | "@babel/runtime": "^7.20.0", 39 | "@callstack/polygen": "workspace:^", 40 | "@callstack/polygen-cli": "workspace:^", 41 | "@callstack/polygen-metro-config": "workspace:^", 42 | "@react-native/babel-preset": "0.75.4", 43 | "@react-native/metro-config": "0.75.4", 44 | "@react-native/typescript-config": "0.75.4", 45 | "@rnx-kit/metro-config": "^2.0.0", 46 | "react-native-builder-bob": "^0.30.2", 47 | "react-native-test-app": "^3.10.22" 48 | }, 49 | "engines": { 50 | "node": ">=18" 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /apps/example/polygen.config.mjs: -------------------------------------------------------------------------------- 1 | import { 2 | externalModule, 3 | localModule, 4 | polygenConfig, 5 | } from '@callstack/polygen-config'; 6 | 7 | /** 8 | * @type {import('@callstack/polygen/config').PolygenConfig} 9 | */ 10 | export default polygenConfig({ 11 | /** 12 | * Output configuration 13 | */ 14 | output: { 15 | /** 16 | * Directory where the output files will be stored. 17 | */ 18 | // directory: 'node_modules/.polygen-out' 19 | }, 20 | 21 | /** 22 | * Configuration for the `scan` command. 23 | */ 24 | scan: { 25 | /** 26 | * List of paths to scan for modules. 27 | * 28 | * Each item is a glob pattern that can use wildcards, or be used 29 | * to ignore specific element by prefixing it by `!`. 30 | */ 31 | // paths: [ 32 | // "src/**/*.wasm", 33 | // ] 34 | }, 35 | 36 | /** 37 | * List of modules to be used in the project. 38 | * 39 | * Each module can be individually configured, by passing options object as a second 40 | * argument (or 3rd, for external modules). 41 | */ 42 | modules: [ 43 | localModule('src/example.wasm'), 44 | localModule('src/table_test.wasm'), 45 | externalModule('simple-sha256-wasm', 'simple_sha256_wasm_bg.wasm'), 46 | // localModule('src/wasm/module.wasm') 47 | ], 48 | }); 49 | -------------------------------------------------------------------------------- /apps/example/react-native.config.js: -------------------------------------------------------------------------------- 1 | const { configureProjects } = require('react-native-test-app'); 2 | 3 | module.exports = { 4 | project: configureProjects({ 5 | android: { 6 | sourceDir: 'android', 7 | }, 8 | ios: { 9 | sourceDir: 'ios', 10 | automaticPodsInstallation: false, 11 | }, 12 | }), 13 | }; 14 | -------------------------------------------------------------------------------- /apps/example/src/example-wasm-buffer.ts: -------------------------------------------------------------------------------- 1 | /** 2 | * Example WASM module buffer. 3 | */ 4 | export default new Uint8Array([ 5 | 0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00, 0x01, 0x0c, 0x02, 0x60, 0x02, 6 | 0x7f, 0x7f, 0x01, 7 | 8 | 0x7f, 0x60, 0x01, 0x7f, 0x01, 0x7f, 0x02, 0x0c, 0x01, 0x04, 0x68, 0x6f, 0x73, 9 | 0x74, 0x03, 0x61, 10 | 11 | 0x64, 0x64, 0x00, 0x00, 0x03, 0x02, 0x01, 0x01, 0x05, 0x03, 0x01, 0x00, 0x00, 12 | 0x07, 0x10, 0x02, 13 | 14 | 0x03, 0x66, 0x69, 0x62, 0x00, 0x01, 0x06, 0x6d, 0x65, 0x6d, 0x6f, 0x72, 0x79, 15 | 0x02, 0x00, 0x0a, 16 | 17 | 0x36, 0x01, 0x34, 0x01, 0x03, 0x7f, 0x41, 0x01, 0x21, 0x01, 0x20, 0x00, 0x41, 18 | 0x00, 0x4a, 0x04, 19 | 20 | 0x40, 0x03, 0x40, 0x20, 0x00, 0x41, 0x01, 0x6b, 0x22, 0x00, 0x04, 0x40, 0x20, 21 | 0x02, 0x20, 0x01, 22 | 23 | 0x10, 0x00, 0x21, 0x03, 0x20, 0x01, 0x21, 0x02, 0x20, 0x03, 0x21, 0x01, 0x0c, 24 | 0x01, 0x0b, 0x0b, 25 | 26 | 0x20, 0x01, 0x0f, 0x0b, 0x41, 0x00, 0x0b, 27 | ]).buffer; 28 | -------------------------------------------------------------------------------- /apps/example/src/example.wasm: -------------------------------------------------------------------------------- 1 | asm `` hostaddfibmemory 2 | 64A! AJ@@ Ak"@  ! ! !   A -------------------------------------------------------------------------------- /apps/example/src/examples/ExternalModuleExample.tsx: -------------------------------------------------------------------------------- 1 | // For this project we need TextDecoder polyfill 2 | import '@bacons/text-decoder/install'; 3 | 4 | import { useReducer } from 'react'; 5 | import { Button, StyleSheet, Text, View } from 'react-native'; 6 | import { initSync, sha256 } from 'simple-sha256-wasm'; 7 | import module from 'simple-sha256-wasm/simple_sha256_wasm_bg.wasm'; 8 | 9 | let loaded = false; 10 | 11 | export default function ExternalModuleExample() { 12 | const [_, dispatch] = useReducer(() => {}, 0); 13 | 14 | return ( 15 | 16 | 17 | This example loads a WebAssembly module from external npm package. 18 | 19 | Module loaded: {loaded ? 'true' : 'false'} 20 |