├── .github └── workflows │ ├── build-libs-bundle_wlr.yaml │ ├── build-libs-bzip2.yaml │ ├── build-libs-libjpeg.yaml │ ├── build-libs-libpng.yaml │ ├── build-libs-libuuid.yaml │ ├── build-libs-libxml2.yaml │ ├── build-libs-oniguruma.yaml │ ├── build-libs-sqlite.yaml │ ├── build-libs-zlib.yaml │ ├── build-php-nightly.yaml │ ├── build-php.yaml │ ├── build-python.yaml │ ├── build-ruby.yaml │ ├── release-libs-bundle_wlr.yaml │ ├── release-libs-bzip2.yaml │ ├── release-libs-libjpeg.yaml │ ├── release-libs-libpng.yaml │ ├── release-libs-libuuid.yaml │ ├── release-libs-libxml2.yaml │ ├── release-libs-oniguruma.yaml │ ├── release-libs-sqlite.yaml │ ├── release-libs-zlib.yaml │ ├── release-php.yaml │ ├── release-python.yaml │ ├── release-ruby.yaml │ ├── reusable-build-lib.yaml │ ├── reusable-build-runtime-flavor.yaml │ ├── reusable-publish-assets.yaml │ ├── reusable-release-external-lib.yaml │ └── reusable-release-internal-lib.yaml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING_CLA.md ├── Dockerfile.wasi-builder ├── Dockerfile.wasm-base ├── LICENSE ├── Makefile ├── Makefile.builders ├── Makefile.helpers ├── NOTICE ├── README.md ├── docs └── developers.md ├── images ├── php │ ├── Dockerfile.cli │ ├── Dockerfile.server │ └── docroot │ │ ├── favicon.ico │ │ └── index.php └── python │ └── Dockerfile ├── libs ├── Makefile ├── README.md ├── bundle_wlr │ ├── Makefile │ ├── README.md │ ├── wlr-build.sh │ ├── wlr-env-local.sh │ ├── wlr-info.json │ └── wlr-tag.sh ├── bzip2 │ ├── Makefile │ ├── README.md │ └── v1.0.8 │ │ ├── patches │ │ └── 0001-chore-Add-libinstall-to-Makefile.patch │ │ ├── wlr-build.sh │ │ ├── wlr-env-repo.sh │ │ └── wlr-tag.sh ├── examples │ ├── sqlite_example │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── build.sh │ │ └── main.c │ └── uuid_zlib_example │ │ ├── CMakeLists.txt │ │ ├── README.md │ │ ├── build.sh │ │ └── main.c ├── icu │ ├── Makefile │ ├── README.md │ └── v.72.1 │ │ ├── wlr-build.sh │ │ └── wlr-env-repo.sh ├── libjpeg │ ├── Makefile │ ├── README.md │ └── v2.1.5.1 │ │ ├── wlr-build.sh │ │ ├── wlr-env-repo.sh │ │ └── wlr-tag.sh ├── libpng │ ├── Makefile │ ├── README.md │ └── v1.6.39 │ │ ├── patches │ │ └── 0001-Avoid-setjmp-longjmp-for-WASI.patch │ │ ├── wlr-build.sh │ │ ├── wlr-env-repo.sh │ │ ├── wlr-info.json │ │ └── wlr-tag.sh ├── libuuid │ ├── Makefile │ ├── README.md │ └── v1.0.3 │ │ ├── patches │ │ └── 0001-fix-Mock-umask-and-getuid-when-missing.patch │ │ ├── wlr-build.sh │ │ ├── wlr-env-repo.sh │ │ └── wlr-tag.sh ├── libxml2 │ ├── Makefile │ ├── README.md │ ├── v2.10.3 │ │ ├── wlr-build.sh │ │ ├── wlr-env-repo.sh │ │ └── wlr-tag.sh │ └── v2.11.4 │ │ ├── wlr-build.sh │ │ ├── wlr-env-repo.sh │ │ └── wlr-tag.sh ├── oniguruma │ ├── Makefile │ ├── README.md │ └── v6.9.8 │ │ ├── wlr-build.sh │ │ ├── wlr-env-repo.sh │ │ └── wlr-tag.sh ├── sqlite │ ├── Makefile │ ├── README.md │ ├── v3.39.2 │ │ ├── patches │ │ │ ├── 0001-Patch-to-build-sqlite-3.39.2-for-wasm32-wasi.patch │ │ │ ├── 0002-Exclude-pwd-popen-and-passwd-code-for-__wasi__.patch │ │ │ └── 0900-Allow-install-headers-and-pc-files.patch │ │ ├── wlr-build.sh │ │ ├── wlr-env-repo.sh │ │ └── wlr-tag.sh │ ├── v3.41.2 │ │ ├── patches │ │ │ └── 0001-Allow-installation-of-headers-and-pkg-config-files-w.patch │ │ ├── wlr-build.sh │ │ ├── wlr-env-repo.sh │ │ └── wlr-tag.sh │ ├── v3.42.0 │ │ ├── patches │ │ │ └── 0001-Allow-installation-of-headers-and-pkg-config-files-w.patch │ │ ├── wlr-build.sh │ │ ├── wlr-env-repo.sh │ │ └── wlr-tag.sh │ └── wasi-patches │ │ └── wlr-build.sh ├── wasmedge_sock │ ├── .clang-format │ ├── CMakeLists.txt │ ├── Makefile │ ├── README.md │ ├── include │ │ ├── netdb.h │ │ └── wasi_socket_ext.h │ ├── netdb.c │ ├── wasi_snapshot_preview1.h │ ├── wasi_socket_ext.c │ ├── wlr-build.sh │ └── wlr-env-local.sh └── zlib │ ├── Makefile │ ├── README.md │ └── v1.2.13 │ ├── wlr-build.sh │ ├── wlr-env-repo.sh │ └── wlr-tag.sh ├── php ├── Dockerfile ├── Makefile ├── README.md ├── examples │ ├── mysql │ │ ├── run_me.sh │ │ └── test_mysql_pdo.php │ └── wp-nginx-php-fcgi-mysql │ │ ├── README.md │ │ ├── docker-compose.yml │ │ ├── php-cgi-wasmedge │ │ └── Dockerfile │ │ ├── proxy-nginx │ │ └── default.conf.template │ │ └── run_me.sh ├── master │ ├── patches │ │ ├── 0001-Add-support-for-building-to-the-wasm32-wasi-target.patch │ │ └── 0002-Implement-WebAssembly-WASI-GH-actions.patch │ ├── wlr-build.sh │ ├── wlr-env-repo.sh │ ├── wlr-info.json │ └── wlr-test.sh ├── v7.3.33 │ └── README.md ├── v7.4.32 │ └── README.md ├── v8.1.11 │ ├── README.md │ ├── patches │ │ ├── 0001-Initial-port-of-the-php-7.4.32-patch-for-php-8.1.11.patch │ │ └── 0002-feat-Incapacitate-fibers-when-compiling-for-WASI.patch │ ├── wlr-build.sh │ ├── wlr-env-repo.sh │ ├── wlr-info.json │ ├── wlr-tag.sh │ └── wlr-test.sh ├── v8.2.0 │ ├── patches │ │ ├── 0001-Initial-port-of-the-php-7.4.32-patch-for-php-8.2.11.patch │ │ ├── 0002-feat-Incapacitate-fibers-when-compiling-for-WASI.patch │ │ ├── 0003-fix-Add-more-ifdefs-for-php-8.2.0.patch │ │ ├── 0004-fix-Fix-memory-issues-and-introduce-WASM_WASMEDGE.patch │ │ ├── 0005-feat-Server-sockets-via-with-wasm-runtime-wasmedge.patch │ │ ├── 0006-fix-Avoid-include-syslog.h-since-it-is-not-part-of-w.patch │ │ ├── 0007-fix-Avoid-setjmp-longjmp-in-gd_jpeg.patch │ │ ├── 0008-fix-Avoid-tmpfile-in-gd_bmp.patch │ │ ├── 0009-fix-Avoid-jmp_buf-in-gd_jpeg.patch │ │ ├── 0010-chore-Add-more-logs-in-wasi_socket_ext.patch │ │ ├── 0011-fix-fastcgi-server-in-php-cgi-for-wasmedge.patch │ │ ├── 0012-chore-Add-debug-logging-in-fastcgi.patch │ │ ├── 0013-chore-Fixes-logs-getnameinfo-in-wasi-sock-sdk.patch │ │ ├── 0014-fix-implicit-function-declaration-in-syslog.patch │ │ ├── 0015-feat-Enable-mysqlnd-and-more-network-functions-with-.patch │ │ ├── 0016-fix-implicit-function-declaration-for-bind-when-not-.patch │ │ ├── 0017-fix-is_writable-with-stat-bypass.patch │ │ └── 0018-fix-random_bytes-failing-on-Windows.patch │ ├── wlr-build.sh │ ├── wlr-env-repo.sh │ ├── wlr-info.json │ ├── wlr-tag.sh │ └── wlr-test.sh └── v8.2.6 │ ├── patches │ ├── 0001-Initial-port-of-the-php-7.4.32-patch-for-php-8.2.6.patch │ ├── 0002-feat-Incapacitate-fibers-when-compiling-for-WASI.patch │ ├── 0003-fix-Add-more-ifdefs-for-php-8.2.0.patch │ ├── 0004-fix-Fix-memory-issues-and-introduce-WASM_WASMEDGE.patch │ ├── 0005-feat-Server-sockets-via-with-wasm-runtime-wasmedge.patch │ ├── 0006-fix-Avoid-include-syslog.h-since-it-is-not-part-of-w.patch │ ├── 0007-fix-Avoid-setjmp-longjmp-in-gd_jpeg.patch │ ├── 0008-fix-Avoid-tmpfile-in-gd_bmp.patch │ ├── 0009-fix-Avoid-jmp_buf-in-gd_jpeg.patch │ ├── 0010-chore-Add-more-logs-in-wasi_socket_ext.patch │ ├── 0011-fix-fastcgi-server-in-php-cgi-for-wasmedge.patch │ ├── 0012-chore-Add-debug-logging-in-fastcgi.patch │ ├── 0013-chore-Fixes-logs-getnameinfo-in-wasi-sock-sdk.patch │ ├── 0014-fix-implicit-function-declaration-in-syslog.patch │ ├── 0015-feat-Enable-mysqlnd-and-more-network-functions-with-.patch │ ├── 0016-fix-implicit-function-declaration-for-bind-when-not-.patch │ ├── 0017-fix-Patch-for-is_readable-and-is_writable-to-bypass-.patch │ ├── 0018-fix-random_bytes-failing-on-Windows.patch │ └── 0019-chore-Remove-wasmedge_stubs-and-use-libwasmedge_sock.patch │ ├── wlr-build.sh │ ├── wlr-env-repo.sh │ ├── wlr-info.json │ ├── wlr-tag.sh │ └── wlr-test.sh ├── python ├── Dockerfile ├── Makefile ├── README.md ├── examples │ ├── .gitignore │ ├── README.md │ ├── basic │ │ ├── README.md │ │ ├── run_all_snippets.sh │ │ └── workdir │ │ │ ├── emojize_text.py │ │ │ ├── source_text.txt │ │ │ └── text_histogram.py │ ├── bindings │ │ └── se2-bindings │ │ │ ├── README.md │ │ │ ├── console-output.png │ │ │ ├── py-plugin │ │ │ └── plugin.py │ │ │ ├── run_me.sh │ │ │ ├── se2-mock-runtime.drawio.png │ │ │ ├── se2-mock-runtime │ │ │ ├── bin │ │ │ │ └── runtime.js │ │ │ ├── mem-utils.js │ │ │ ├── package-lock.json │ │ │ └── package.json │ │ │ └── wasm-wrapper-c │ │ │ ├── CMakeLists.txt │ │ │ ├── build-wasm.sh │ │ │ ├── main.c │ │ │ ├── pyhost.c │ │ │ ├── pyhost.h │ │ │ ├── sdk_module.c │ │ │ ├── sdk_module.h │ │ │ ├── utils.c │ │ │ ├── utils.h │ │ │ ├── wasm_shim.c │ │ │ └── wasm_shim.h │ └── embedding │ │ ├── README.md │ │ ├── wasi-py-rs-cpython │ │ ├── .cargo │ │ │ └── config.toml │ │ ├── Cargo.lock │ │ ├── Cargo.toml │ │ ├── README.md │ │ ├── build.rs │ │ ├── run_me.cmd │ │ ├── run_me.sh │ │ └── src │ │ │ └── main.rs │ │ └── wasi-py-rs-pyo3 │ │ ├── .cargo │ │ └── config.toml │ │ ├── Cargo.lock │ │ ├── Cargo.toml │ │ ├── README.md │ │ ├── build.rs │ │ ├── run_me.cmd │ │ ├── run_me.sh │ │ └── src │ │ ├── bin │ │ ├── py-func-caller.rs │ │ ├── py-func.py │ │ └── py-wrapper.rs │ │ ├── lib.rs │ │ └── py_module.rs ├── test │ ├── run_me.sh │ └── sqlite │ │ ├── .gitignore │ │ ├── test.py │ │ └── test.stdout ├── tools │ └── wlr-libpy │ │ ├── Cargo.lock │ │ ├── Cargo.toml │ │ ├── README.md │ │ └── src │ │ ├── bld_cfg.rs │ │ ├── lib.rs │ │ └── py_main.rs ├── v3.11.1 │ ├── wlr-build.sh │ ├── wlr-env-repo.sh │ ├── wlr-info.json │ └── wlr-tag.sh ├── v3.11.3 │ ├── wlr-build.sh │ ├── wlr-env-repo.sh │ ├── wlr-info.json │ └── wlr-tag.sh ├── v3.11.4 │ ├── wlr-build.sh │ ├── wlr-env-repo.sh │ ├── wlr-info.json │ ├── wlr-tag.sh │ └── wlr-test.sh └── v3.12.0 │ ├── wlr-build.sh │ ├── wlr-env-repo.sh │ ├── wlr-info.json │ ├── wlr-tag.sh │ └── wlr-test.sh ├── ruby ├── Dockerfile ├── Makefile ├── README.md ├── v3.2.0 │ ├── wlr-build.sh │ ├── wlr-env-repo.sh │ └── wlr-tag.sh └── v3.2.2 │ ├── wlr-build.sh │ ├── wlr-env-repo.sh │ └── wlr-tag.sh ├── scripts ├── README.md ├── build-helpers │ ├── README.md │ ├── patch_wasmedge_wat_sock_accept.sh │ ├── wlr_autoconf.sh │ ├── wlr_cmake.sh │ ├── wlr_dependencies.sh │ ├── wlr_package.sh │ ├── wlr_pkg_config.sh │ └── wlr_wasi_vfs.sh ├── wlr-build.sh ├── wlr-env.sh ├── wlr-setup-repo.sh ├── wlr-tag.sh ├── wlr-test.sh ├── wlr-update-patches.sh └── wrappers │ ├── wasm-opt │ ├── wasmedge.sh │ └── wasmtime.sh ├── tools └── wlr-assets │ ├── Cargo.lock │ ├── Cargo.toml │ ├── README.md │ └── src │ ├── bld_cfg.rs │ └── lib.rs └── wlr-make.sh /.github/workflows/build-libs-bundle_wlr.yaml: -------------------------------------------------------------------------------- 1 | name: Build libs-bundle_wlr 2 | on: 3 | push: 4 | # By specifying branches explicitly, we avoid this workflow from 5 | # running on tag push. We have a dedicated workflow to be ran when 6 | # a tag is pushed. 7 | branches: 8 | - main 9 | paths: 10 | - ".github/**" 11 | - "libs/bundle_wlr/**" 12 | - "libs/*" 13 | - "scripts/**" 14 | - "Makefile*" 15 | - "*.sh" 16 | pull_request: 17 | jobs: 18 | build-libs-bundle_wlr: 19 | strategy: 20 | fail-fast: false 21 | uses: ./.github/workflows/reusable-build-lib.yaml 22 | with: 23 | target: bundle_wlr 24 | -------------------------------------------------------------------------------- /.github/workflows/build-libs-bzip2.yaml: -------------------------------------------------------------------------------- 1 | name: Build libs-bzip2 2 | on: 3 | push: 4 | # By specifying branches explicitly, we avoid this workflow from 5 | # running on tag push. We have a dedicated workflow to be ran when 6 | # a tag is pushed. 7 | branches: 8 | - main 9 | paths: 10 | - ".github/**" 11 | - "libs/bzip2/**" 12 | - "libs/*" 13 | - "scripts/**" 14 | - "Makefile*" 15 | - "*.sh" 16 | pull_request: 17 | jobs: 18 | build-libs-bzip2: 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | include: 23 | - version: 1.0.8 24 | uses: ./.github/workflows/reusable-build-lib.yaml 25 | with: 26 | target: bzip2/v${{ matrix.version }} 27 | -------------------------------------------------------------------------------- /.github/workflows/build-libs-libjpeg.yaml: -------------------------------------------------------------------------------- 1 | name: Build libs-libjpeg 2 | on: 3 | push: 4 | # By specifying branches explicitly, we avoid this workflow from 5 | # running on tag push. We have a dedicated workflow to be ran when 6 | # a tag is pushed. 7 | branches: 8 | - main 9 | paths: 10 | - ".github/**" 11 | - "libs/libjpeg/**" 12 | - "libs/*" 13 | - "scripts/**" 14 | - "Makefile*" 15 | - "*.sh" 16 | pull_request: 17 | jobs: 18 | build-libs-libjpeg: 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | include: 23 | - version: 2.1.5.1 24 | uses: ./.github/workflows/reusable-build-lib.yaml 25 | with: 26 | target: libjpeg/v${{ matrix.version }} 27 | -------------------------------------------------------------------------------- /.github/workflows/build-libs-libpng.yaml: -------------------------------------------------------------------------------- 1 | name: Build libs-libpng 2 | on: 3 | push: 4 | # By specifying branches explicitly, we avoid this workflow from 5 | # running on tag push. We have a dedicated workflow to be ran when 6 | # a tag is pushed. 7 | branches: 8 | - main 9 | paths: 10 | - ".github/**" 11 | - "libs/libpng/**" 12 | - "libs/*" 13 | - "scripts/**" 14 | - "Makefile*" 15 | - "*.sh" 16 | pull_request: 17 | jobs: 18 | build-libs-libpng: 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | include: 23 | - version: 1.6.39 24 | uses: ./.github/workflows/reusable-build-lib.yaml 25 | with: 26 | target: libpng/v${{ matrix.version }} 27 | -------------------------------------------------------------------------------- /.github/workflows/build-libs-libuuid.yaml: -------------------------------------------------------------------------------- 1 | name: Build libs-libuuid 2 | on: 3 | push: 4 | # By specifying branches explicitly, we avoid this workflow from 5 | # running on tag push. We have a dedicated workflow to be ran when 6 | # a tag is pushed. 7 | branches: 8 | - main 9 | paths: 10 | - ".github/**" 11 | - "libs/libuuid/**" 12 | - "libs/*" 13 | - "scripts/**" 14 | - "Makefile*" 15 | - "*.sh" 16 | pull_request: 17 | jobs: 18 | build-libs-libuuid: 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | include: 23 | - version: 1.0.3 24 | uses: ./.github/workflows/reusable-build-lib.yaml 25 | with: 26 | target: libuuid/v${{ matrix.version }} 27 | -------------------------------------------------------------------------------- /.github/workflows/build-libs-libxml2.yaml: -------------------------------------------------------------------------------- 1 | name: Build libs-libxml2 2 | on: 3 | push: 4 | # By specifying branches explicitly, we avoid this workflow from 5 | # running on tag push. We have a dedicated workflow to be ran when 6 | # a tag is pushed. 7 | branches: 8 | - main 9 | paths: 10 | - ".github/**" 11 | - "libs/libxml2/**" 12 | - "libs/*" 13 | - "scripts/**" 14 | - "Makefile*" 15 | - "*.sh" 16 | pull_request: 17 | jobs: 18 | build-libs-libxml2: 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | include: 23 | - version: 2.10.3 24 | uses: ./.github/workflows/reusable-build-lib.yaml 25 | with: 26 | target: libxml2/v${{ matrix.version }} 27 | -------------------------------------------------------------------------------- /.github/workflows/build-libs-oniguruma.yaml: -------------------------------------------------------------------------------- 1 | name: Build libs-oniguruma 2 | on: 3 | push: 4 | # By specifying branches explicitly, we avoid this workflow from 5 | # running on tag push. We have a dedicated workflow to be ran when 6 | # a tag is pushed. 7 | branches: 8 | - main 9 | paths: 10 | - ".github/**" 11 | - "libs/oniguruma/**" 12 | - "libs/*" 13 | - "scripts/**" 14 | - "Makefile*" 15 | - "*.sh" 16 | pull_request: 17 | jobs: 18 | build-libs-oniguruma: 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | include: 23 | - version: 6.9.8 24 | uses: ./.github/workflows/reusable-build-lib.yaml 25 | with: 26 | target: oniguruma/v${{ matrix.version }} 27 | -------------------------------------------------------------------------------- /.github/workflows/build-libs-sqlite.yaml: -------------------------------------------------------------------------------- 1 | name: Build libs-sqlite 2 | on: 3 | push: 4 | # By specifying branches explicitly, we avoid this workflow from 5 | # running on tag push. We have a dedicated workflow to be ran when 6 | # a tag is pushed. 7 | branches: 8 | - main 9 | paths: 10 | - ".github/**" 11 | - "libs/sqlite/**" 12 | - "libs/*" 13 | - "scripts/**" 14 | - "Makefile*" 15 | - "*.sh" 16 | pull_request: 17 | jobs: 18 | build-libs-sqlite: 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | version: [3.39.2, 3.41.2] 23 | uses: ./.github/workflows/reusable-build-lib.yaml 24 | with: 25 | target: sqlite/v${{ matrix.version }} 26 | -------------------------------------------------------------------------------- /.github/workflows/build-libs-zlib.yaml: -------------------------------------------------------------------------------- 1 | name: Build libs-zlib 2 | on: 3 | push: 4 | # By specifying branches explicitly, we avoid this workflow from 5 | # running on tag push. We have a dedicated workflow to be ran when 6 | # a tag is pushed. 7 | branches: 8 | - main 9 | paths: 10 | - ".github/**" 11 | - "libs/zlib/**" 12 | - "libs/*" 13 | - "scripts/**" 14 | - "Makefile*" 15 | - "*.sh" 16 | pull_request: 17 | jobs: 18 | build-libs-zlib: 19 | strategy: 20 | fail-fast: false 21 | matrix: 22 | include: 23 | - version: 1.2.13 24 | uses: ./.github/workflows/reusable-build-lib.yaml 25 | with: 26 | target: zlib/v${{ matrix.version }} 27 | -------------------------------------------------------------------------------- /.github/workflows/build-php-nightly.yaml: -------------------------------------------------------------------------------- 1 | name: Build PHP master (nightly) 2 | on: 3 | workflow_dispatch: 4 | schedule: 5 | - cron: "0 0 * * *" 6 | jobs: 7 | build-php: 8 | strategy: 9 | fail-fast: false 10 | matrix: 11 | # TODO (ereslibre): the PHP cli is conditionally compiled 12 | # because it has the ability to open a listening socket-- only 13 | # supported on wasmedge --. Remove build-php-cli from here and 14 | # make the PHP CLI conditionally compile local server code out 15 | # on all versions. 16 | include: 17 | - name: "" 18 | suffix: "" 19 | build-php-cli: false 20 | version: master 21 | runs-on: ubuntu-latest 22 | steps: 23 | - name: Checkout repository 24 | uses: actions/checkout@v3 25 | - name: Build PHP 26 | run: make php/${{ matrix.name }}${{ matrix.version }} 27 | - name: Rename artifacts 28 | shell: bash 29 | run: | 30 | sudo mv build-output/php/${{ matrix.version }}/bin/php-cgi{${{ matrix.suffix }},-${{ matrix.version }}${{ matrix.suffix }}}.wasm 31 | - name: Rename artifacts 32 | shell: bash 33 | if: ${{ matrix.build-php-cli }} 34 | run: | 35 | sudo mv build-output/php/${{ matrix.version }}/bin/php{${{ matrix.suffix }},-${{ matrix.version }}${{ matrix.suffix }}}.wasm 36 | - name: Upload php-${{ matrix.version }}${{ matrix.suffix }}.wasm artifact 37 | uses: actions/upload-artifact@v3 38 | if: ${{ matrix.build-php-cli }} 39 | with: 40 | name: php-${{ matrix.version }}${{ matrix.suffix }}.wasm 41 | path: build-output/php/${{ matrix.version }}/bin/php-${{ matrix.version }}${{ matrix.suffix }}.wasm 42 | if-no-files-found: error 43 | - name: Upload php-cgi-${{ matrix.version }}${{ matrix.suffix }}.wasm artifact 44 | uses: actions/upload-artifact@v3 45 | with: 46 | name: php-cgi-${{ matrix.version }}${{ matrix.suffix }}.wasm 47 | path: build-output/php/${{ matrix.version }}/bin/php-cgi-${{ matrix.version }}${{ matrix.suffix }}.wasm 48 | if-no-files-found: error 49 | -------------------------------------------------------------------------------- /.github/workflows/build-php.yaml: -------------------------------------------------------------------------------- 1 | name: Build PHP 2 | on: 3 | push: 4 | # By specifying branches explicitly, we avoid this workflow from 5 | # running on tag push. We have a dedicated workflow to be ran when 6 | # a tag is pushed. 7 | branches: 8 | - main 9 | pull_request: 10 | jobs: 11 | build-php: 12 | strategy: 13 | fail-fast: false 14 | matrix: 15 | flavor: ["", "-wasmedge", "-slim"] 16 | version: [8.1.11, 8.2.0, 8.2.6] 17 | exclude: 18 | - flavor: "-wasmedge" 19 | version: 8.1.11 20 | - flavor: "-slim" 21 | version: 8.1.11 22 | runs-on: ubuntu-latest 23 | steps: 24 | - name: Checkout repository 25 | uses: actions/checkout@v3 26 | - name: Build PHP 27 | run: make php/v${{ matrix.version }}${{ matrix.flavor }} 28 | - name: Upload php-${{ matrix.version }} assets 29 | uses: actions/upload-artifact@v3 30 | with: 31 | name: php-${{ matrix.version }}.zip 32 | path: | 33 | build-output/*.gz 34 | build-output/*.wasm 35 | build-output/*.txt 36 | if-no-files-found: error 37 | -------------------------------------------------------------------------------- /.github/workflows/build-python.yaml: -------------------------------------------------------------------------------- 1 | name: Build Python 2 | on: 3 | push: 4 | # By specifying branches explicitly, we avoid this workflow from 5 | # running on tag push. We have a dedicated workflow to be ran when 6 | # a tag is pushed. 7 | branches: 8 | - main 9 | pull_request: 10 | jobs: 11 | build-python: 12 | strategy: 13 | fail-fast: false 14 | matrix: 15 | flavor: ["", "-wasmedge", "-aio", "-aio-wasmedge"] 16 | version: ["3.11.3", "3.11.4", "3.12.0"] 17 | runs-on: ubuntu-latest 18 | steps: 19 | - name: Checkout repository 20 | uses: actions/checkout@v3 21 | - name: Build Python 22 | run: make python/v${{ matrix.version }}${{ matrix.flavor }} 23 | - name: Upload python-${{ matrix.version }} assets 24 | uses: actions/upload-artifact@v3 25 | with: 26 | name: python-${{ matrix.version }}.zip 27 | path: | 28 | build-output/*.gz 29 | build-output/*.wasm 30 | build-output/*.txt 31 | if-no-files-found: error 32 | -------------------------------------------------------------------------------- /.github/workflows/build-ruby.yaml: -------------------------------------------------------------------------------- 1 | name: Build Ruby 2 | on: 3 | push: 4 | # By specifying branches explicitly, we avoid this workflow from 5 | # running on tag push. We have a dedicated workflow to be ran when 6 | # a tag is pushed. 7 | branches: 8 | - main 9 | pull_request: 10 | jobs: 11 | build-ruby: 12 | strategy: 13 | fail-fast: false 14 | matrix: 15 | flavor: ["", "-slim"] 16 | version: ["3.2.0", "3.2.2"] 17 | runs-on: ubuntu-latest 18 | steps: 19 | - name: Checkout repository 20 | uses: actions/checkout@v3 21 | - name: Build Ruby 22 | run: make ruby/v${{ matrix.version }}${{ matrix.flavor }} 23 | - name: Upload ruby-${{ matrix.version }} assets 24 | uses: actions/upload-artifact@v3 25 | with: 26 | name: ruby-${{ matrix.version }}.zip 27 | path: | 28 | build-output/*.gz 29 | build-output/*.wasm 30 | build-output/*.txt 31 | if-no-files-found: error 32 | -------------------------------------------------------------------------------- /.github/workflows/release-libs-bundle_wlr.yaml: -------------------------------------------------------------------------------- 1 | # Note that for this workflow to be triggered, the tag needs to be 2 | # created of the form `libs/bundle_wlr/+`, where 3 | # by convention is YYYYMMDD- (short SHA can be calculated 4 | # with `git rev-parse --short HEAD`). 5 | name: Release libs-bundle_wlr 6 | on: 7 | push: 8 | tags: 9 | - libs/bundle_wlr/* 10 | jobs: 11 | release-libs-bundle_wlr: 12 | uses: ./.github/workflows/reusable-release-internal-lib.yaml 13 | with: 14 | target-name: "bundle_wlr" 15 | -------------------------------------------------------------------------------- /.github/workflows/release-libs-bzip2.yaml: -------------------------------------------------------------------------------- 1 | # Note that for this workflow to be triggered, the tag needs to be 2 | # created of the form `libs/bzip2/+`, where 3 | # by convention is YYYYMMDD- (short SHA can be calculated 4 | # with `git rev-parse --short HEAD`). 5 | name: Release libs-bzip2 6 | on: 7 | push: 8 | tags: 9 | - libs/bzip2/* 10 | jobs: 11 | release-libs-bzip2: 12 | uses: ./.github/workflows/reusable-release-external-lib.yaml 13 | with: 14 | target-name: "bzip2" 15 | trigger: ${{ github.event.ref }} 16 | -------------------------------------------------------------------------------- /.github/workflows/release-libs-libjpeg.yaml: -------------------------------------------------------------------------------- 1 | # Note that for this workflow to be triggered, the tag needs to be 2 | # created of the form `libs/libjpeg/+`, where 3 | # by convention is YYYYMMDD- (short SHA can be calculated 4 | # with `git rev-parse --short HEAD`). 5 | name: Release libs-libjpeg 6 | on: 7 | push: 8 | tags: 9 | - libs/libjpeg/* 10 | jobs: 11 | release-libs-libjpeg: 12 | uses: ./.github/workflows/reusable-release-external-lib.yaml 13 | with: 14 | target-name: "libjpeg" 15 | trigger: ${{ github.event.ref }} 16 | -------------------------------------------------------------------------------- /.github/workflows/release-libs-libpng.yaml: -------------------------------------------------------------------------------- 1 | # Note that for this workflow to be triggered, the tag needs to be 2 | # created of the form `libs/libpng/+`, where 3 | # by convention is YYYYMMDD- (short SHA can be calculated 4 | # with `git rev-parse --short HEAD`). 5 | name: Release libs-libpng 6 | on: 7 | push: 8 | tags: 9 | - libs/libpng/* 10 | jobs: 11 | release-libs-libpng: 12 | uses: ./.github/workflows/reusable-release-external-lib.yaml 13 | with: 14 | target-name: "libpng" 15 | trigger: ${{ github.event.ref }} 16 | -------------------------------------------------------------------------------- /.github/workflows/release-libs-libuuid.yaml: -------------------------------------------------------------------------------- 1 | # Note that for this workflow to be triggered, the tag needs to be 2 | # created of the form `libs/libuuid/+`, where 3 | # by convention is YYYYMMDD- (short SHA can be calculated 4 | # with `git rev-parse --short HEAD`). 5 | name: Release libs-libuuid 6 | on: 7 | push: 8 | tags: 9 | - libs/libuuid/* 10 | jobs: 11 | release-libs-libuuid: 12 | uses: ./.github/workflows/reusable-release-external-lib.yaml 13 | with: 14 | target-name: "libuuid" 15 | trigger: ${{ github.event.ref }} 16 | -------------------------------------------------------------------------------- /.github/workflows/release-libs-libxml2.yaml: -------------------------------------------------------------------------------- 1 | # Note that for this workflow to be triggered, the tag needs to be 2 | # created of the form `libs/libxml2/+`, where 3 | # by convention is YYYYMMDD- (short SHA can be calculated 4 | # with `git rev-parse --short HEAD`). 5 | name: Release libs-libxml2 6 | on: 7 | push: 8 | tags: 9 | - libs/libxml2/* 10 | jobs: 11 | release-libs-libxml2: 12 | uses: ./.github/workflows/reusable-release-external-lib.yaml 13 | with: 14 | target-name: "libxml2" 15 | trigger: ${{ github.event.ref }} 16 | -------------------------------------------------------------------------------- /.github/workflows/release-libs-oniguruma.yaml: -------------------------------------------------------------------------------- 1 | # Note that for this workflow to be triggered, the tag needs to be 2 | # created of the form `libs/oniguruma/+`, where 3 | # by convention is YYYYMMDD- (short SHA can be calculated 4 | # with `git rev-parse --short HEAD`). 5 | name: Release libs-oniguruma 6 | on: 7 | push: 8 | tags: 9 | - libs/oniguruma/* 10 | jobs: 11 | release-libs-oniguruma: 12 | uses: ./.github/workflows/reusable-release-external-lib.yaml 13 | with: 14 | target-name: "oniguruma" 15 | trigger: ${{ github.event.ref }} 16 | -------------------------------------------------------------------------------- /.github/workflows/release-libs-sqlite.yaml: -------------------------------------------------------------------------------- 1 | # Note that for this workflow to be triggered, the tag needs to be 2 | # created of the form `libs/sqlite/+`, where 3 | # by convention is YYYYMMDD- (short SHA can be calculated 4 | # with `git rev-parse --short HEAD`). 5 | name: Release libs-sqlite 6 | on: 7 | push: 8 | tags: 9 | - libs/sqlite/* 10 | jobs: 11 | release-libs-sqlite: 12 | uses: ./.github/workflows/reusable-release-external-lib.yaml 13 | with: 14 | target-name: "sqlite" 15 | trigger: ${{ github.event.ref }} 16 | -------------------------------------------------------------------------------- /.github/workflows/release-libs-zlib.yaml: -------------------------------------------------------------------------------- 1 | # Note that for this workflow to be triggered, the tag needs to be 2 | # created of the form `libs/zlib/+`, where 3 | # by convention is YYYYMMDD- (short SHA can be calculated 4 | # with `git rev-parse --short HEAD`). 5 | name: Release libs-zlib 6 | on: 7 | push: 8 | tags: 9 | - libs/zlib/* 10 | jobs: 11 | release-libs-zlib: 12 | uses: ./.github/workflows/reusable-release-external-lib.yaml 13 | with: 14 | target-name: "zlib" 15 | trigger: ${{ github.event.ref }} 16 | -------------------------------------------------------------------------------- /.github/workflows/release-php.yaml: -------------------------------------------------------------------------------- 1 | # Note that for this workflow to be triggered, the tag needs to be 2 | # created of the form `php/+`, where 3 | # by convention is YYYYMMDD- (short SHA can be calculated 4 | # with `git rev-parse --short HEAD`). An example of a tag following 5 | # the convention that triggers automation would be 6 | # `php/7.3.33+20221123-8dfe8b9`. 7 | name: Release PHP 8 | on: 9 | push: 10 | tags: 11 | - php/* 12 | jobs: 13 | build-default: 14 | uses: ./.github/workflows/reusable-build-runtime-flavor.yaml 15 | with: 16 | target-name: "php" 17 | trigger: ${{ github.event.ref }} 18 | flavor: "" 19 | build-wasmedge: 20 | uses: ./.github/workflows/reusable-build-runtime-flavor.yaml 21 | with: 22 | target-name: "php" 23 | trigger: ${{ github.event.ref }} 24 | flavor: "-wasmedge" 25 | build-slim: 26 | uses: ./.github/workflows/reusable-build-runtime-flavor.yaml 27 | with: 28 | target-name: "php" 29 | trigger: ${{ github.event.ref }} 30 | flavor: "-slim" 31 | publish: 32 | uses: ./.github/workflows/reusable-publish-assets.yaml 33 | needs: [build-default, build-wasmedge, build-slim] 34 | with: 35 | target-name: "php" 36 | -------------------------------------------------------------------------------- /.github/workflows/release-python.yaml: -------------------------------------------------------------------------------- 1 | # Note that for this workflow to be triggered, the tag needs to be 2 | # created of the form `python/+`, where 3 | # by convention is YYYYMMDD- (short SHA can be calculated 4 | # with `git rev-parse --short HEAD`). An example of a tag following 5 | # the convention that triggers automation would be 6 | # `python/3.11.1+20221123-8dfe8b9`. 7 | name: Release Python 8 | on: 9 | push: 10 | tags: 11 | - python/* 12 | jobs: 13 | build-default: 14 | uses: ./.github/workflows/reusable-build-runtime-flavor.yaml 15 | with: 16 | target-name: "python" 17 | trigger: ${{ github.event.ref }} 18 | flavor: "" 19 | build-wasmedge: 20 | uses: ./.github/workflows/reusable-build-runtime-flavor.yaml 21 | with: 22 | target-name: "python" 23 | trigger: ${{ github.event.ref }} 24 | flavor: "-wasmedge" 25 | build-aio: 26 | uses: ./.github/workflows/reusable-build-runtime-flavor.yaml 27 | with: 28 | target-name: "python" 29 | trigger: ${{ github.event.ref }} 30 | flavor: "-aio" 31 | build-aio-wasmedge: 32 | uses: ./.github/workflows/reusable-build-runtime-flavor.yaml 33 | with: 34 | target-name: "python" 35 | trigger: ${{ github.event.ref }} 36 | flavor: "-aio-wasmedge" 37 | publish: 38 | uses: ./.github/workflows/reusable-publish-assets.yaml 39 | needs: [build-default, build-wasmedge, build-aio, build-aio-wasmedge] 40 | with: 41 | target-name: "python" 42 | 43 | -------------------------------------------------------------------------------- /.github/workflows/release-ruby.yaml: -------------------------------------------------------------------------------- 1 | # Note that for this workflow to be triggered, the tag needs to be 2 | # created of the form `ruby/+`, where 3 | # by convention is YYYYMMDD- (short SHA can be calculated 4 | # with `git rev-parse --short HEAD`). An example of a tag following 5 | # the convention that triggers automation would be 6 | # `ruby/3.2.0+20221123-8dfe8b9`. 7 | name: Release Ruby 8 | on: 9 | push: 10 | tags: 11 | - ruby/* 12 | jobs: 13 | build-default: 14 | uses: ./.github/workflows/reusable-build-runtime-flavor.yaml 15 | with: 16 | target-name: "ruby" 17 | trigger: ${{ github.event.ref }} 18 | flavor: "" 19 | build-slim: 20 | uses: ./.github/workflows/reusable-build-runtime-flavor.yaml 21 | with: 22 | target-name: "ruby" 23 | trigger: ${{ github.event.ref }} 24 | flavor: "-slim" 25 | publish: 26 | uses: ./.github/workflows/reusable-publish-assets.yaml 27 | needs: [build-default, build-slim] 28 | with: 29 | target-name: "ruby" 30 | -------------------------------------------------------------------------------- /.github/workflows/reusable-build-lib.yaml: -------------------------------------------------------------------------------- 1 | # Used to build an external library 2 | # Example: 3 | # jobs: 4 | # build-libs-bzip2: 5 | # strategy: 6 | # fail-fast: false 7 | # uses: ./.github/workflows/reusable-build-lib.yaml 8 | # with: 9 | # target: bzip2/v1.0.8 10 | 11 | name: Build an external library 12 | on: 13 | workflow_call: 14 | inputs: 15 | target: 16 | required: true 17 | type: string 18 | jobs: 19 | build-lib: 20 | strategy: 21 | fail-fast: false 22 | runs-on: ubuntu-latest 23 | steps: 24 | - name: Checkout repository 25 | uses: actions/checkout@v3 26 | - name: Build ${{ inputs.target }} 27 | run: make libs/${{ inputs.target }} 28 | - name: Upload the ${{ inputs.target }} artifact 29 | uses: actions/upload-artifact@v3 30 | with: 31 | path: build-output/*.gz 32 | if-no-files-found: error 33 | -------------------------------------------------------------------------------- /.github/workflows/reusable-build-runtime-flavor.yaml: -------------------------------------------------------------------------------- 1 | # Used to build a language runtime flavor 2 | # Example: 3 | # jobs: 4 | # build-php-my-flavor: 5 | # uses: ./.github/workflows/reusable-build-runtime-flavor.yaml 6 | # with: 7 | # target-name: "php" 8 | # trigger: ${{ github.event.ref }} 9 | # flavor: "-my-flavor" 10 | 11 | # Note: This workflow should be refactored into a custom GH action. 12 | # This will allow us to call it in job steps and have more flexibility. 13 | # Currently we can only call it as a separate job/ Thus we cannot populate 14 | # its inputs from a matrix, but need to do explicit calls. 15 | name: Build a runtime target 16 | on: 17 | workflow_call: 18 | inputs: 19 | target-name: 20 | required: true 21 | type: string 22 | trigger: 23 | required: true 24 | type: string 25 | flavor: 26 | required: false 27 | type: string 28 | default: "" 29 | jobs: 30 | build-runtime: 31 | strategy: 32 | fail-fast: false 33 | runs-on: ubuntu-latest 34 | steps: 35 | - name: Determine version 36 | id: determineVersion 37 | run: | 38 | VERSION=$(echo ${{ inputs.trigger }} | sed 's,refs/tags/${{ inputs.target-name }}/,,g' | cut -f 1 -d \+) 39 | echo "value=${VERSION}" >> $GITHUB_OUTPUT 40 | - name: Checkout repository 41 | uses: actions/checkout@v3 42 | - name: Build ${{ inputs.target-name }} 43 | run: | 44 | make ${{ inputs.target-name }}/v${{ steps.determineVersion.outputs.value }}${{ inputs.flavor }} 45 | - name: Upload ${{ inputs.target-name }}-${{ steps.determineVersion.outputs.value }} artifact 46 | uses: actions/upload-artifact@v3 47 | with: 48 | name: ${{ inputs.target-name }}.zip 49 | path: | 50 | build-output/*.gz 51 | build-output/*.wasm 52 | build-output/*.txt 53 | if-no-files-found: error -------------------------------------------------------------------------------- /.github/workflows/reusable-publish-assets.yaml: -------------------------------------------------------------------------------- 1 | # Used to publish release assets uploaded by a previous job (e.g.`reusable-build-runtime-flavor.yaml)` 2 | # Example 3 | # jobs: 4 | # build-job: 5 | # ... 6 | # steps: 7 | # - uses: actions/upload-artifact@v3 8 | # with: 9 | # name: php.zip 10 | # ... 11 | # publish: 12 | # uses: ./.github/workflows/reusable-publish-assets.yaml 13 | # needs: build-job 14 | # with: 15 | # target-name: "php" 16 | 17 | # Note: This workflow should be refactored into a custom GH action. 18 | # This will allow us to call it in job steps and have more flexibility. 19 | on: 20 | workflow_call: 21 | inputs: 22 | target-name: 23 | required: true 24 | type: string 25 | jobs: 26 | publish-release-assets: 27 | strategy: 28 | fail-fast: true 29 | runs-on: ubuntu-latest 30 | steps: 31 | - name: Checkout repository 32 | uses: actions/checkout@v3 33 | - name: Create release 34 | env: 35 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 36 | run: | 37 | gh release create --verify-tag ${{ github.ref_name }} || true 38 | - name: Download ${{ inputs.target-name }} artifact 39 | uses: actions/download-artifact@v3 40 | with: 41 | name: ${{ inputs.target-name }}.zip 42 | path: build-output 43 | - name: List downloaded assets 44 | run: | 45 | ls -lrt -R build-output 46 | - name: Append ${{ inputs.target-name }} release assets 47 | env: 48 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 49 | run: | 50 | shopt -s nullglob 51 | gh release upload ${{ github.ref_name }} build-output/*.{gz,wasm,txt} 52 | - name: Generate release assets digests 53 | env: 54 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 55 | run: | 56 | shopt -s nullglob 57 | for asset in build-output/*.{gz,wasm}; do 58 | sha256sum "${asset}" | sudo tee "${asset}.sha256sum" > /dev/null 59 | done 60 | - name: Append release assets digests 61 | env: 62 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 63 | run: | 64 | gh release upload ${{ github.ref_name }} build-output/*.sha256sum 65 | 66 | 67 | -------------------------------------------------------------------------------- /.github/workflows/reusable-release-external-lib.yaml: -------------------------------------------------------------------------------- 1 | name: Release a library 2 | on: 3 | workflow_call: 4 | inputs: 5 | target-name: 6 | required: true 7 | type: string 8 | trigger: 9 | required: true 10 | type: string 11 | jobs: 12 | release-lib: 13 | strategy: 14 | fail-fast: false 15 | runs-on: ubuntu-latest 16 | steps: 17 | - name: Determine version 18 | id: determineVersion 19 | run: | 20 | VERSION=$(echo ${{ inputs.trigger }} | sed 's,refs/tags/libs/${{ inputs.target-name }}/,,g' | cut -f 1 -d \+) 21 | echo "value=${VERSION}" >> $GITHUB_OUTPUT 22 | - name: Checkout repository 23 | uses: actions/checkout@v3 24 | - name: Build ${{ inputs.target-name }} 25 | run: | 26 | make libs/${{ inputs.target-name }}/v${{ steps.determineVersion.outputs.value }} 27 | - name: Create release 28 | env: 29 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 30 | run: | 31 | gh release create --generate-notes ${{ github.ref_name }} || true 32 | - name: Append ${{ inputs.target-name }} release assets 33 | env: 34 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 35 | run: | 36 | gh release upload ${{ github.ref_name }} build-output/*.gz 37 | - name: Generate release assets digests 38 | env: 39 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 40 | run: | 41 | for asset in build-output/*.gz; do 42 | sha256sum "$asset" | sudo tee "$asset.sha256sum" > /dev/null 43 | done 44 | - name: Append release assets digests 45 | env: 46 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 47 | run: | 48 | gh release upload ${{ github.ref_name }} build-output/*.gz.sha256sum 49 | 50 | -------------------------------------------------------------------------------- /.github/workflows/reusable-release-internal-lib.yaml: -------------------------------------------------------------------------------- 1 | name: Release an internal library 2 | on: 3 | workflow_call: 4 | inputs: 5 | target-name: 6 | required: true 7 | type: string 8 | jobs: 9 | release-lib: 10 | strategy: 11 | fail-fast: false 12 | runs-on: ubuntu-latest 13 | steps: 14 | - name: Checkout repository 15 | uses: actions/checkout@v3 16 | - name: Build ${{ inputs.target-name }} 17 | run: | 18 | make libs/${{ inputs.target-name }} 19 | - name: Create release 20 | env: 21 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 22 | run: | 23 | gh release create --generate-notes ${{ github.ref_name }} || true 24 | - name: Append ${{ inputs.target-name }} release assets 25 | env: 26 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 27 | run: | 28 | gh release upload ${{ github.ref_name }} build-output/*.gz 29 | - name: Generate release assets digests 30 | env: 31 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 32 | run: | 33 | for asset in build-output/*.gz; do 34 | sha256sum "$asset" | sudo tee "$asset.sha256sum" > /dev/null 35 | done 36 | - name: Append release assets digests 37 | env: 38 | GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} 39 | run: | 40 | gh release upload ${{ github.ref_name }} build-output/*.gz.sha256sum 41 | 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore everything in these directories 2 | __pycache__ 3 | build-output 4 | build-staging 5 | node_modules 6 | target 7 | .vscode/** 8 | .python-version 9 | *.log 10 | # Except this file 11 | !.gitignore 12 | .wlr-local-conf.sh 13 | wlr-tmp 14 | -------------------------------------------------------------------------------- /CONTRIBUTING_CLA.md: -------------------------------------------------------------------------------- 1 | # Contributing to webassembly-language-runtimes 2 | 3 | We welcome contributions from the community and first want to thank you for taking the time to contribute! 4 | 5 | Please familiarize yourself with the [Code of Conduct](https://github.com/vmware/.github/blob/main/CODE_OF_CONDUCT.md) before contributing. 6 | 7 | Before you start working with webassembly-language-runtimes, please read and sign our Contributor License Agreement [CLA](https://cla.vmware.com/cla/1/preview). If you wish to contribute code and you have not signed our contributor license agreement (CLA), our bot will prompt you to do so when you open a Pull Request. For any questions about the CLA process, please refer to our [FAQ]([https://cla.vmware.com/faq](https://cla.vmware.com/faq)). 8 | -------------------------------------------------------------------------------- /Dockerfile.wasm-base: -------------------------------------------------------------------------------- 1 | FROM docker.io/library/ubuntu:22.04 2 | ARG BINARYEN_VERSION 3 | ENV BINARYEN_PATH=/opt 4 | RUN apt update && \ 5 | DEBIAN_FRONTEND=noninteractive apt install -y \ 6 | wget && \ 7 | wget https://github.com/WebAssembly/binaryen/releases/download/version_${BINARYEN_VERSION}/binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz && \ 8 | tar -xf binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz --strip-components=1 -C /opt && \ 9 | rm binaryen-version_${BINARYEN_VERSION}-x86_64-linux.tar.gz && \ 10 | mkdir -p /opt/priority-bin 11 | 12 | # We may need to intercept the execution of some tools. 13 | # So, for convenience, one may use the /opt/priority-bin to do that. 14 | RUN mkdir -p /opt/priority-bin 15 | 16 | ENV PATH="/opt/priority-bin:$PATH:/opt/bin" 17 | -------------------------------------------------------------------------------- /Makefile.builders: -------------------------------------------------------------------------------- 1 | BUILDER_ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) 2 | 3 | include Makefile.helpers 4 | 5 | .PHONY: wasm-base 6 | WASM_BASE_NAME := ghcr.io/vmware-labs/wasmlabs/wasm-base:latest 7 | wasm-base: 8 | @echo Building $(WASM_BASE_NAME) in $(BUILDER_ROOT_DIR) ... && \ 9 | docker build \ 10 | --platform linux/amd64 \ 11 | --build-arg BINARYEN_VERSION=111 \ 12 | -f $(BUILDER_ROOT_DIR)/Dockerfile.wasm-base \ 13 | -t $(WASM_BASE_NAME) \ 14 | $(BUILDER_ROOT_DIR) 15 | 16 | .PHONY: push-wasm-base 17 | push-wasm-base: 18 | @$(call push_container_image,$(WASM_BASE_NAME)) 19 | 20 | .PHONY: wasi-builder 21 | WASI_BUILDER_NAME := ghcr.io/vmware-labs/wasmlabs/wasi-builder:$(WASI_SDK_VERSION) 22 | wasi-builder: 23 | @echo Building $(WASI_BUILDER_NAME) in $(BUILDER_ROOT_DIR) ... && \ 24 | docker build \ 25 | --platform linux/amd64 \ 26 | --build-arg WASI_SDK_RELEASE_NAME=wasi-sdk-$(word 1,$(subst ., ,$(WASI_SDK_VERSION))) \ 27 | --build-arg WASI_SDK_VERSION=$(WASI_SDK_VERSION) \ 28 | -f $(BUILDER_ROOT_DIR)/Dockerfile.wasi-builder \ 29 | -t $(WASI_BUILDER_NAME) \ 30 | $(BUILDER_ROOT_DIR) 31 | 32 | .PHONY: update-wasi-builder 33 | update-wasi-builder: wasi-builder 34 | @$(call push_container_image,$(WASI_BUILDER_NAME)) 35 | 36 | 37 | .PHONY: update-all-builders 38 | update-all-builders: update-wasi-builder 39 | make -f php/Makefile update-php-builder 40 | make -f python/Makefile update-python-builder 41 | make -f ruby/Makefile update-ruby-builder 42 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | Copyright 2022 VMware, Inc. 2 | 3 | This product is licensed to you under the Apache License, V2.0 (the "License"). You may not use this product except in compliance with the License. 4 | 5 | This product may include a number of subcomponents with separate copyright notices and license terms. Your use of these subcomponents is subject to the terms and conditions of the subcomponent's license, as noted in the LICENSE file. -------------------------------------------------------------------------------- /images/php/Dockerfile.cli: -------------------------------------------------------------------------------- 1 | FROM scratch 2 | ARG PHP_TAG=php-7.4.32 3 | ARG PHP_BINARY=php 4 | COPY build-output/php/${PHP_TAG}/bin/${PHP_BINARY} /php.wasm 5 | 6 | ENTRYPOINT [ "php.wasm" ] 7 | -------------------------------------------------------------------------------- /images/php/Dockerfile.server: -------------------------------------------------------------------------------- 1 | FROM scratch 2 | ARG PHP_TAG=php-7.4.32 3 | ARG PHP_BINARY=php 4 | ARG PHP_DOCROOT=images/php/docroot 5 | COPY build-output/php/${PHP_TAG}/bin/${PHP_BINARY} /php.wasm 6 | COPY ${PHP_DOCROOT} /docroot/ 7 | 8 | ENTRYPOINT [ "php.wasm" , "-S", "0.0.0.0:8080", "-t", "/docroot"] 9 | -------------------------------------------------------------------------------- /images/php/docroot/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webassemblylabs/webassembly-language-runtimes/5a40c308763309d227dd1dd85fe3e9397282c6d9/images/php/docroot/favicon.ico -------------------------------------------------------------------------------- /images/php/docroot/index.php: -------------------------------------------------------------------------------- 1 | 2 | 3 |

Hello from PHP running on ""

4 | 5 |

List env variable names

6 | $value) { 10 | echo $key . " "; 11 | } 12 | echo "\n"; 13 | ?> 14 | 15 |

Hello

16 | 24 | 25 |

Contents of '/'

26 | $value) { 28 | echo $value . " "; 29 | } 30 | echo "\n"; 31 | ?> 32 | 33 | 34 | 35 | -------------------------------------------------------------------------------- /images/python/Dockerfile: -------------------------------------------------------------------------------- 1 | FROM scratch 2 | 3 | ARG NAME 4 | ARG SUMMARY 5 | LABEL description="${SUMMARY}" \ 6 | app.kubernetes.io/name="${NAME}" \ 7 | org.opencontainers.image.title="${NAME}" \ 8 | org.opencontainers.image.vendor="wasmlabs.dev" \ 9 | org.opencontainers.image.description="${SUMMARY}" \ 10 | org.opencontainers.image.source="https://github.com/vmware-labs/webassembly-language-runtimes" \ 11 | org.opencontainers.artifact.description="${SUMMARY}" 12 | 13 | ARG ARTIFACTS_BASE_DIR 14 | ARG PYTHON_BINARY 15 | COPY ${ARTIFACTS_BASE_DIR}/bin/${PYTHON_BINARY} /python.wasm 16 | COPY ${ARTIFACTS_BASE_DIR}/usr/ /usr 17 | 18 | # Shadow the default linux PATH, which is irrelevant for Wasm 19 | ENV PATH= 20 | 21 | ENTRYPOINT [ "python.wasm" ] 22 | -------------------------------------------------------------------------------- /libs/Makefile: -------------------------------------------------------------------------------- 1 | .PHONY: clean 2 | clean: 3 | make -C bundle_wlr clean 4 | make -C bzip2 clean 5 | make -C icu clean 6 | make -C libjpeg clean 7 | make -C libpng clean 8 | make -C libuuid clean 9 | make -C libxml2 clean 10 | make -C oniguruma clean 11 | make -C sqlite clean 12 | make -C wasmedge_sock clean 13 | make -C zlib clean 14 | -------------------------------------------------------------------------------- /libs/bundle_wlr/Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) 2 | REPO_ROOT := $(ROOT_DIR)../.. 3 | 4 | default_target: all 5 | .PHONY : default_target 6 | 7 | include $(REPO_ROOT)/Makefile.helpers 8 | 9 | $(eval $(call create_default_local_lib_targets,$(REPO_ROOT),bundle_wlr,$(WASI_SDK_VERSION))) 10 | -------------------------------------------------------------------------------- /libs/bundle_wlr/README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | This folder builds assets of the bundle_wlr project. 4 | 5 | The list of bundled libraries can be deduced from the `"deps"` section in [wlr-info.json](./wlr-info.sh). The main project page is at [https://www.zlib.net/](https://www.zlib.net/). 6 | -------------------------------------------------------------------------------- /libs/bundle_wlr/wlr-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]]; then 4 | echo "WLR build environment is not set" 5 | exit 1 6 | fi 7 | 8 | logStatus "Preparing artifacts..." 9 | 10 | cp -TRv ${WLR_DEPS_ROOT}/build-output/include ${WLR_OUTPUT}/include || exit 1 11 | cp -TRv ${WLR_DEPS_ROOT}/build-output/lib ${WLR_OUTPUT}/lib || exit 1 12 | 13 | wlr_package_lib 14 | 15 | logStatus "DONE. Artifacts in ${WLR_OUTPUT}" 16 | -------------------------------------------------------------------------------- /libs/bundle_wlr/wlr-env-local.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_ENV_NAME 6 | unset WLR_PACKAGE_NAME 7 | unset WLR_PACKAGE_VERSION 8 | return 9 | fi 10 | 11 | export WLR_ENV_NAME=bundle_wlr/0.1.0 12 | export WLR_PACKAGE_NAME=bundle_wlr 13 | export WLR_PACKAGE_VERSION=0.1.0 14 | -------------------------------------------------------------------------------- /libs/bundle_wlr/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="libs/bundle_wlr/0.1.0" 2 | -------------------------------------------------------------------------------- /libs/bzip2/Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) 2 | REPO_ROOT := $(ROOT_DIR)../.. 3 | 4 | include $(REPO_ROOT)/Makefile.helpers 5 | 6 | $(eval $(call create_default_external_lib_targets,$(REPO_ROOT),bzip2,$(WASI_SDK_VERSION))) 7 | -------------------------------------------------------------------------------- /libs/bzip2/README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | This folder builds assets of the bzip2 project. 4 | 5 | The main project page is at [https://www.sourceware.org/bzip2/](https://www.sourceware.org/bzip2/). 6 | -------------------------------------------------------------------------------- /libs/bzip2/v1.0.8/patches/0001-chore-Add-libinstall-to-Makefile.patch: -------------------------------------------------------------------------------- 1 | From e493fcd0205797c266e10b5d50402d49f4bd97fc Mon Sep 17 00:00:00 2001 2 | From: Asen Alexandrov 3 | Date: Mon, 24 Apr 2023 11:45:59 +0300 4 | Subject: [PATCH] chore: Add libinstall to Makefile 5 | 6 | 7 | diff --git a/Makefile b/Makefile 8 | index f8a1772..2889612 100644 9 | --- a/Makefile 10 | +++ b/Makefile 11 | @@ -25,6 +25,7 @@ CFLAGS=-Wall -Winline -O2 -g $(BIGFILES) 12 | 13 | # Where you want it installed when you do 'make install' 14 | PREFIX=/usr/local 15 | +LIBDIR=$(PREFIX)/lib 16 | 17 | 18 | OBJS= blocksort.o \ 19 | @@ -69,12 +70,18 @@ test: bzip2 20 | cmp sample3.tst sample3.ref 21 | @cat words3 22 | 23 | -install: bzip2 bzip2recover 24 | +libinstall: libbz2.a 25 | + if ( test ! -d $(LIBDIR) ) ; then mkdir -p $(LIBDIR) ; fi 26 | + if ( test ! -d $(PREFIX)/include ) ; then mkdir -p $(PREFIX)/include ; fi 27 | + cp -f bzlib.h $(PREFIX)/include 28 | + chmod a+r $(PREFIX)/include/bzlib.h 29 | + cp -f libbz2.a $(LIBDIR) 30 | + chmod a+r $(LIBDIR)/libbz2.a 31 | + 32 | +install: bzip2 bzip2recover libinstall 33 | if ( test ! -d $(PREFIX)/bin ) ; then mkdir -p $(PREFIX)/bin ; fi 34 | - if ( test ! -d $(PREFIX)/lib ) ; then mkdir -p $(PREFIX)/lib ; fi 35 | if ( test ! -d $(PREFIX)/man ) ; then mkdir -p $(PREFIX)/man ; fi 36 | if ( test ! -d $(PREFIX)/man/man1 ) ; then mkdir -p $(PREFIX)/man/man1 ; fi 37 | - if ( test ! -d $(PREFIX)/include ) ; then mkdir -p $(PREFIX)/include ; fi 38 | cp -f bzip2 $(PREFIX)/bin/bzip2 39 | cp -f bzip2 $(PREFIX)/bin/bunzip2 40 | cp -f bzip2 $(PREFIX)/bin/bzcat 41 | @@ -85,10 +92,6 @@ install: bzip2 bzip2recover 42 | chmod a+x $(PREFIX)/bin/bzip2recover 43 | cp -f bzip2.1 $(PREFIX)/man/man1 44 | chmod a+r $(PREFIX)/man/man1/bzip2.1 45 | - cp -f bzlib.h $(PREFIX)/include 46 | - chmod a+r $(PREFIX)/include/bzlib.h 47 | - cp -f libbz2.a $(PREFIX)/lib 48 | - chmod a+r $(PREFIX)/lib/libbz2.a 49 | cp -f bzgrep $(PREFIX)/bin/bzgrep 50 | ln -s -f $(PREFIX)/bin/bzgrep $(PREFIX)/bin/bzegrep 51 | ln -s -f $(PREFIX)/bin/bzgrep $(PREFIX)/bin/bzfgrep 52 | -- 53 | 2.38.1 54 | 55 | -------------------------------------------------------------------------------- /libs/bzip2/v1.0.8/wlr-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | export CFLAGS_CONFIG="-O0" 10 | 11 | export CFLAGS_WASI="--sysroot=${WASI_SYSROOT}" 12 | 13 | export CFLAGS_BUILD='-Werror -Wno-error=format -Wno-error=deprecated-non-prototype -Wno-error=unknown-warning-option' 14 | 15 | export CFLAGS="${CFLAGS_CONFIG} ${CFLAGS_WASI} ${CFLAGS_BUILD}" 16 | 17 | cd "${WLR_SOURCE_PATH}" 18 | 19 | source ${WLR_REPO_ROOT}/scripts/build-helpers/wlr_pkg_config.sh 20 | 21 | BZIP2_MAKE_ARGS="CC=${CC} AR=${AR} RANLIB=${RANLIB} PREFIX=${WLR_OUTPUT} LIBDIR=${WLR_OUTPUT}/lib/wasm32-wasi" 22 | 23 | logStatus "Building... " 24 | make ${BZIP2_MAKE_ARGS} -j libbz2.a || exit 1 25 | 26 | logStatus "Preparing artifacts... " 27 | make ${BZIP2_MAKE_ARGS} libinstall || exit 1 28 | 29 | logStatus "Generating pkg-config file for libbz2.a" 30 | DESCRIPTION="libbzip2 is a library for lossless, block-sorting data compression" 31 | EXTRA_LINK_FLAGS="-lbz2" 32 | 33 | wlr_pkg_config_create_pc_file "bzip2" "${WLR_PACKAGE_VERSION}" "${DESCRIPTION}" "${EXTRA_LINK_FLAGS}" || exit 1 34 | 35 | wlr_package_lib 36 | 37 | logStatus "DONE. Artifacts in ${WLR_OUTPUT}" 38 | -------------------------------------------------------------------------------- /libs/bzip2/v1.0.8/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | return 11 | fi 12 | 13 | export WLR_REPO=https://gitlab.com/bzip2/bzip2 14 | export WLR_REPO_BRANCH=bzip2-1.0.8 15 | export WLR_ENV_NAME=bzip2/v1.0.8 16 | export WLR_PACKAGE_VERSION=1.0.8 17 | export WLR_PACKAGE_NAME=bzip2 18 | -------------------------------------------------------------------------------- /libs/bzip2/v1.0.8/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="libs/bzip2/1.0.8" 2 | -------------------------------------------------------------------------------- /libs/examples/sqlite_example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | 3 | project(sqlite_example) 4 | 5 | if(${CMAKE_SYSTEM_NAME} STREQUAL "WASI") 6 | set(CMAKE_EXECUTABLE_SUFFIX ".wasm") 7 | endif() 8 | 9 | add_executable( 10 | sqlite_example 11 | main.c 12 | ) 13 | 14 | find_package(PkgConfig REQUIRED) 15 | 16 | pkg_search_module(SQLITE3 REQUIRED IMPORTED_TARGET "sqlite3>=3") 17 | 18 | include_directories(AFTER 19 | ${SQLITE3_INCLUDE_DIRS} 20 | ) 21 | 22 | target_link_libraries(sqlite_example PUBLIC 23 | PkgConfig::SQLITE3 24 | ) 25 | -------------------------------------------------------------------------------- /libs/examples/uuid_zlib_example/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | 3 | project(uuid_zlib_example) 4 | 5 | if(${CMAKE_SYSTEM_NAME} STREQUAL "WASI") 6 | set(CMAKE_EXECUTABLE_SUFFIX ".wasm") 7 | endif() 8 | 9 | add_executable( 10 | uuid_zlib_example 11 | main.c 12 | ) 13 | 14 | find_package(PkgConfig REQUIRED) 15 | 16 | pkg_search_module(UUID REQUIRED IMPORTED_TARGET "uuid>=1.0.0") 17 | pkg_search_module(ZLIB REQUIRED IMPORTED_TARGET "zlib>=1.1.0") 18 | 19 | include_directories(AFTER 20 | ${UUID_INCLUDE_DIRS} 21 | ${ZLIB_INCLUDE_DIRS} 22 | ) 23 | 24 | target_link_libraries(uuid_zlib_example PUBLIC 25 | PkgConfig::UUID 26 | PkgConfig::ZLIB 27 | ) 28 | -------------------------------------------------------------------------------- /libs/examples/uuid_zlib_example/main.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | 7 | static char *USAGE_FMT = 8 | "Usage: %s [compress|decompress] INPUT_FILE OUTPUT_FILE\n" 9 | " OUTPUT_FILE always gets overwritten.\n" 10 | "\n" 11 | "\n" 12 | "Usage: %s [genuuid]\n" 13 | " Generates UUID and prints it to STDOUT\n" 14 | "\n" 15 | "\n" 16 | "Program exits on any system error!\n" 17 | "\n"; 18 | 19 | static char BUF[1024]; 20 | 21 | int decompress_impl(char *input_file, char *ouput_file) 22 | { 23 | gzFile in = gzopen(input_file, "rb"); 24 | FILE *out = fopen(ouput_file, "wb"); 25 | if (!in || !out) 26 | return -1; 27 | 28 | int num_read = 0; 29 | while ((num_read = gzread(in, BUF, sizeof(BUF))) > 0) 30 | fwrite(BUF, 1, num_read, out); 31 | 32 | gzclose(in); 33 | fclose(out); 34 | 35 | return 0; 36 | } 37 | 38 | int compress_impl(char *input_file, char *ouput_file) 39 | { 40 | FILE *in = fopen(input_file, "rb"); 41 | gzFile out = gzopen(ouput_file, "wb"); 42 | if (!in || !out) 43 | return -1; 44 | 45 | int num_read = 0; 46 | while ((num_read = fread(BUF, 1, sizeof(BUF), in)) > 0) 47 | gzwrite(out, BUF, num_read); 48 | 49 | fclose(in); 50 | gzclose(out); 51 | 52 | return 0; 53 | } 54 | 55 | int genuuid_impl() 56 | { 57 | uuid_t generated; 58 | uuid_generate(generated); 59 | 60 | char buffer[64]; 61 | uuid_unparse_lower(generated, buffer); 62 | 63 | fprintf(stdout, "%s\n", buffer); 64 | 65 | return 0; 66 | } 67 | 68 | int main(int argc, char **argv) 69 | { 70 | if (0 == strcmp(argv[1], "genuuid") && argc == 2) 71 | return genuuid_impl(); 72 | 73 | if (argc != 4) 74 | { 75 | fprintf(stderr, USAGE_FMT, argv[0], argv[0]); 76 | return -1; 77 | } 78 | 79 | if (0 == strcmp(argv[1], "compress")) 80 | return compress_impl(argv[2], argv[3]); 81 | 82 | if (0 == strcmp(argv[1], "decompress")) 83 | return decompress_impl(argv[2], argv[3]); 84 | 85 | fprintf(stderr, USAGE_FMT, argv[0], argv[0]); 86 | return -1; 87 | } 88 | -------------------------------------------------------------------------------- /libs/icu/Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) 2 | REPO_ROOT := $(ROOT_DIR)../.. 3 | 4 | include $(REPO_ROOT)/Makefile.helpers 5 | 6 | $(eval $(call create_default_external_lib_targets,$(REPO_ROOT),icu,$(WASI_SDK_VERSION))) 7 | -------------------------------------------------------------------------------- /libs/icu/README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | This folder builds assets of the "International Components for Unicode" project. 4 | 5 | The main project page is at [https://icu.unicode.org/](https://icu.unicode.org/). 6 | -------------------------------------------------------------------------------- /libs/icu/v.72.1/wlr-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | logStatus "Building libs 'icu/release-72-1'" 3 | 4 | if [[ ! -v WLR_ENV ]] 5 | then 6 | echo "WLR build environment is not set" 7 | exit 1 8 | fi 9 | 10 | export CFLAGS_CONFIG="-O0" 11 | 12 | export CFLAGS_WASI="--sysroot=${WASI_SYSROOT}" 13 | export LDFLAGS_WASI="--sysroot=${WASI_SYSROOT}" 14 | 15 | export CFLAGS_ICU='' 16 | 17 | logStatus "Using ICU DEFINES: ${CFLAGS_ICU}" 18 | 19 | export CFLAGS_BUILD='' 20 | 21 | # We need to add LDFLAGS ot CFLAGS because autoconf compiles(+links) to binary when checking stuff 22 | export CFLAGS="${CFLAGS_CONFIG} ${CFLAGS_WASI} ${CFLAGS_ICU} ${CFLAGS_BUILD} ${LDFLAGS_WASI}" 23 | export LDFLAGS="${LDFLAGS_WASI}" 24 | 25 | cd "${WLR_SOURCE_PATH}"/icu4c/source 26 | 27 | if [[ -z "$WLR_SKIP_CONFIGURE" ]]; then 28 | export ICU_CONFIGURE='--enable-static --disable-shared' 29 | logStatus "Configuring build with '${ICU_CONFIGURE}'... " 30 | # ICU headers are enough for some builds (e.g.: PHP). 31 | # Uncomment for executing ./configure and generte the Makefile 32 | # ./runConfigureICU Linux --host=wasm32-wasi host_alias=wasm32-musl-wasi --target=wasm32-wasi target_alias=wasm32-musl-wasi ${ICU_CONFIGURE} || exit 1 33 | else 34 | logStatus "Skipping configure..." 35 | fi 36 | 37 | # ICU headers are enough for some builds (e.g.: PHP). 38 | # Uncomment for executing make and get the static libraries (lib/libicuXXXX.a) 39 | # logStatus "Building... " 40 | # make -j || exit 1 41 | 42 | logStatus "Preparing artifacts... " 43 | mkdir -p ${WLR_OUTPUT}/include/unicode 44 | cp -v common/unicode/*.h ${WLR_OUTPUT}/include/unicode || exit 1 45 | 46 | logStatus "DONE. Artifacts in ${WLR_OUTPUT}" 47 | -------------------------------------------------------------------------------- /libs/icu/v.72.1/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | return 11 | fi 12 | 13 | export WLR_REPO=https://github.com/unicode-org/icu.git 14 | export WLR_REPO_BRANCH=release-72-1 15 | export WLR_ENV_NAME=icu/release-72-1 16 | export WLR_PACKAGE_VERSION=72.1 17 | export WLR_PACKAGE_NAME=icu 18 | -------------------------------------------------------------------------------- /libs/libjpeg/Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) 2 | REPO_ROOT := $(ROOT_DIR)../.. 3 | 4 | include $(REPO_ROOT)/Makefile.helpers 5 | 6 | $(eval $(call create_default_external_lib_targets,$(REPO_ROOT),libjpeg,$(WASI_SDK_VERSION))) 7 | -------------------------------------------------------------------------------- /libs/libjpeg/README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | This folder builds assets of the libjpeg-turbo project, which comply to the API of the original libjpeg, but can leverage SIMD instructions to achieve better performance 4 | 5 | The main project page is at [https://libjpeg-turbo.org/](https://libjpeg-turbo.org/). 6 | 7 | The original libjpeg project page is at [https://libjpeg.sourceforge.net/](https://libjpeg.sourceforge.net/). 8 | -------------------------------------------------------------------------------- /libs/libjpeg/v2.1.5.1/wlr-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | export CFLAGS_CONFIG="-O0" 10 | 11 | export CFLAGS="${CFLAGS_CONFIG}" 12 | 13 | cd "${WLR_SOURCE_PATH}" 14 | 15 | source ${WLR_REPO_ROOT}/scripts/build-helpers/wlr_cmake.sh 16 | source ${WLR_REPO_ROOT}/scripts/build-helpers/wlr_pkg_config.sh 17 | 18 | if [[ -z "$WLR_SKIP_CONFIGURE" ]]; then 19 | 20 | export LIBJPEG_CONFIGURE="-DENABLE_SHARED=0 -DWITH_TURBOJPEG=0" 21 | logStatus "Configuring with cmake with '${LIBJPEG_CONFIGURE}' ..." 22 | wlr_cmake_configure ${LIBJPEG_CONFIGURE} 23 | 24 | else 25 | logStatus "Skipping configure..." 26 | fi 27 | 28 | logStatus "Building..." 29 | wlr_cmake_build || exit 1 30 | wlr_pkg_config_reset_pc_prefix ${WLR_CMAKE_TARGET_DIR}/pkgscripts/libjpeg.pc || exit 1 31 | 32 | logStatus "Preparing artifacts..." 33 | 34 | wlr_cmake_install || exit 1 35 | wlr_package_lib || exit 1 36 | wlr_package_bin || exit 1 37 | 38 | logStatus "DONE. Artifacts in ${WLR_OUTPUT}" 39 | -------------------------------------------------------------------------------- /libs/libjpeg/v2.1.5.1/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | return 11 | fi 12 | 13 | export WLR_REPO=https://github.com/libjpeg-turbo/libjpeg-turbo 14 | export WLR_REPO_BRANCH=2.1.5.1 15 | export WLR_ENV_NAME=libjpeg/2.1.5.1 16 | export WLR_PACKAGE_VERSION=2.1.5.1 17 | export WLR_PACKAGE_NAME=jpeg 18 | -------------------------------------------------------------------------------- /libs/libjpeg/v2.1.5.1/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="libs/libjpeg/2.1.5.1" 2 | -------------------------------------------------------------------------------- /libs/libpng/Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) 2 | REPO_ROOT := $(ROOT_DIR)../.. 3 | 4 | include $(REPO_ROOT)/Makefile.helpers 5 | 6 | $(eval $(call create_default_external_lib_targets,$(REPO_ROOT),libpng,$(WASI_SDK_VERSION))) 7 | -------------------------------------------------------------------------------- /libs/libpng/README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | This folder builds assets of the libpng project. 4 | 5 | The main project page is at [http://www.libpng.org/pub/png/libpng.html](http://www.libpng.org/pub/png/libpng.html). 6 | -------------------------------------------------------------------------------- /libs/libpng/v1.6.39/patches/0001-Avoid-setjmp-longjmp-for-WASI.patch: -------------------------------------------------------------------------------- 1 | From eda399b9adbddebedffa2233f4bcfe7223f9b6a4 Mon Sep 17 00:00:00 2001 2 | From: =?UTF-8?q?Jesu=CC=81s=20Gonza=CC=81lez?= 3 | Date: Tue, 14 Feb 2023 18:52:25 +0100 4 | Subject: [PATCH] feat: Avoid setjmp/longjmp for WASI 5 | 6 | --- 7 | pngconf.h | 10 ++++++---- 8 | pngusr.h | 6 ++++++ 9 | 2 files changed, 12 insertions(+), 4 deletions(-) 10 | create mode 100644 pngusr.h 11 | 12 | diff --git a/pngconf.h b/pngconf.h 13 | index 74bfe27ce..ba283fb04 100644 14 | --- a/pngconf.h 15 | +++ b/pngconf.h 16 | @@ -46,10 +46,12 @@ 17 | # include 18 | #endif 19 | 20 | -#ifdef PNG_SETJMP_SUPPORTED 21 | - /* Required for the definition of jmp_buf and the declaration of longjmp: */ 22 | -# include 23 | -#endif 24 | +#ifndef __wasi__ 25 | + #ifdef PNG_SETJMP_SUPPORTED 26 | + /* Required for the definition of jmp_buf and the declaration of longjmp: */ 27 | + # include 28 | + #endif 29 | +#endif /* __wasi__ */ 30 | 31 | #ifdef PNG_CONVERT_tIME_SUPPORTED 32 | /* Required for struct tm: */ 33 | diff --git a/pngusr.h b/pngusr.h 34 | new file mode 100644 35 | index 000000000..1337ac8a6 36 | --- /dev/null 37 | +++ b/pngusr.h 38 | @@ -0,0 +1,6 @@ 39 | +/* Private build information for pnligbconf.h */ 40 | +/* See scrips/pnglibconf.dfa for more information */ 41 | + 42 | +#define PNG_NO_SETJMP 43 | +#define PNG_NO_SIMPLIFIED_READ 44 | +#define PNG_NO_SIMPLIFIED_WRITE 45 | -- 46 | 2.37.0 47 | 48 | -------------------------------------------------------------------------------- /libs/libpng/v1.6.39/wlr-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | export CFLAGS_CONFIG="-O0" 10 | 11 | export CFLAGS_WASI="--sysroot=${WASI_SYSROOT}" 12 | export LDFLAGS_WASI="--sysroot=${WASI_SYSROOT}" 13 | 14 | CFLAGS_LIBPNG="-I${WLR_DEPS_INCLUDE}" 15 | LDFLAGS_LIBPNG="-L${WLR_DEPS_LIBDIR}" 16 | 17 | logStatus "Using LIBPNG CFLAGS: ${CFLAGS_LIBPNG}" 18 | logStatus "Using LIBPNG LDFLAGS: ${LDFLAGS_LIBPNG}" 19 | 20 | # Enabling private user build information from pngusr.h (see scripts/pnglibconf.dfa) 21 | export CPPFLAGS='-DPNG_USER_CONFIG' 22 | export CFLAGS_BUILD='' 23 | 24 | # We need to add LDFLAGS ot CFLAGS because autoconf compiles(+links) to binary when checking stuff 25 | export CFLAGS="${CFLAGS_CONFIG} ${CFLAGS_WASI} ${CFLAGS_LIBPNG} ${CFLAGS_BUILD} ${LDFLAGS_WASI}" 26 | export LDFLAGS="${LDFLAGS_WASI} ${LDFLAGS_LIBPNG}" 27 | 28 | cd "${WLR_SOURCE_PATH}" 29 | 30 | source ${WLR_REPO_ROOT}/scripts/build-helpers/wlr_pkg_config.sh 31 | 32 | if [[ -z "$WLR_SKIP_CONFIGURE" ]]; then 33 | export LIBPNG_CONFIGURE="${WLR_CONFIGURE_PREFIXES} --enable-static --disable-shared" 34 | logStatus "Configuring build with '${LIBPNG_CONFIGURE}'... " 35 | ./configure --config-cache --host=wasm32-wasi host_alias=wasm32-musl-wasi --target=wasm32-wasi target_alias=wasm32-musl-wasi ${LIBPNG_CONFIGURE} || exit 1 36 | else 37 | logStatus "Skipping configure..." 38 | fi 39 | 40 | logStatus "Building..." 41 | INCLUDES=${CFLAGS_LIBPNG} make -j libpng16.la || exit 1 42 | 43 | logStatus "Preparing artifacts..." 44 | make install-pkgincludeHEADERS ${WLR_INSTALL_PREFIXES} || exit 1 45 | make install-nodist_pkgincludeHEADERS ${WLR_INSTALL_PREFIXES} || exit 1 46 | make install-libLTLIBRARIES ${WLR_INSTALL_PREFIXES} || exit 1 47 | make install-pkgconfigDATA ${WLR_INSTALL_PREFIXES} || exit 1 48 | make install-header-links ${WLR_INSTALL_PREFIXES} || exit 1 49 | make install-libpng-pc ${WLR_INSTALL_PREFIXES} || exit 1 50 | make install-library-links ${WLR_INSTALL_PREFIXES} || exit 1 51 | 52 | wlr_package_lib 53 | 54 | logStatus "DONE. Artifacts in ${WLR_OUTPUT}" 55 | -------------------------------------------------------------------------------- /libs/libpng/v1.6.39/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | return 11 | fi 12 | 13 | export WLR_REPO=https://github.com/glennrp/libpng 14 | export WLR_REPO_BRANCH=v1.6.39 15 | export WLR_ENV_NAME=libpng/v1.6.39 16 | export WLR_PACKAGE_VERSION=1.6.39 17 | export WLR_PACKAGE_NAME=png 18 | 19 | -------------------------------------------------------------------------------- /libs/libpng/v1.6.39/wlr-info.json: -------------------------------------------------------------------------------- 1 | { 2 | "deps": { 3 | "zlib": { 4 | "build_target": "libs/zlib/v1.2.13", 5 | "required_file": "lib/wasm32-wasi/libz.a", 6 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Fzlib%2F1.2.13%2B20230623-2993864/libz-1.2.13-wasi-sdk-20.0.tar.gz" 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /libs/libpng/v1.6.39/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="libs/libpng/1.6.39" 2 | -------------------------------------------------------------------------------- /libs/libuuid/Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) 2 | REPO_ROOT := $(ROOT_DIR)../.. 3 | 4 | include $(REPO_ROOT)/Makefile.helpers 5 | 6 | $(eval $(call create_default_external_lib_targets,$(REPO_ROOT),libuuid,$(WASI_SDK_VERSION))) 7 | -------------------------------------------------------------------------------- /libs/libuuid/README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | This folder builds assets of the Libuuid project. 4 | 5 | The main project page is at [https://sourceforge.net/projects/libuuid/](https://sourceforge.net/projects/libuuid/). 6 | 7 | Note that there are several alternatives to this particular libuuid out there. 8 | -------------------------------------------------------------------------------- /libs/libuuid/v1.0.3/patches/0001-fix-Mock-umask-and-getuid-when-missing.patch: -------------------------------------------------------------------------------- 1 | From 2b2b9d2d8d3865f7671db158487a0254dd1578d2 Mon Sep 17 00:00:00 2001 2 | From: "no-reply@wasmlabs.dev" 3 | Date: Tue, 31 Jan 2023 15:55:52 +0200 4 | Subject: [PATCH] fix: Mock umask and getuid when missing 5 | 6 | 7 | diff --git a/configure.ac b/configure.ac 8 | index be62aa0..ab72f29 100644 9 | --- a/configure.ac 10 | +++ b/configure.ac 11 | @@ -34,7 +34,7 @@ AC_TYPE_UINT64_T 12 | AC_TYPE_UINT8_T 13 | 14 | # Checks for library functions. 15 | -AC_CHECK_FUNCS([ftruncate gettimeofday memset socket strtoul usleep srandom]) 16 | +AC_CHECK_FUNCS([ftruncate gettimeofday memset socket strtoul usleep srandom umask getuid]) 17 | 18 | dnl version details from .. 19 | PACKAGE_VERSION_MAJOR=$(echo $PACKAGE_VERSION | awk -F. '{print $1}') 20 | diff --git a/gen_uuid.c b/gen_uuid.c 21 | index c7b71f2..a2a6a2e 100644 22 | --- a/gen_uuid.c 23 | +++ b/gen_uuid.c 24 | @@ -59,6 +59,11 @@ 25 | #include 26 | #endif 27 | #include 28 | +#if ! HAVE_UMASK && defined(__wasi__) 29 | +static mode_t umask(mode_t mask) { 30 | + return 0755; 31 | +} 32 | +#endif 33 | #ifdef HAVE_SYS_FILE_H 34 | #include 35 | #endif 36 | diff --git a/randutils.c b/randutils.c 37 | index 80893d3..8c79ff1 100644 38 | --- a/randutils.c 39 | +++ b/randutils.c 40 | @@ -28,6 +28,13 @@ 41 | THREAD_LOCAL unsigned short ul_jrand_seed[3]; 42 | #endif 43 | 44 | +#if ! HAVE_GETUID && defined(__wasi__) 45 | +static int getuid (void) 46 | +{ 47 | + return 1; 48 | +} 49 | +#endif 50 | + 51 | int random_get_fd(void) 52 | { 53 | int i, fd; 54 | -- 55 | 2.38.1 56 | 57 | -------------------------------------------------------------------------------- /libs/libuuid/v1.0.3/wlr-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | export CFLAGS_CONFIG="-O0" 10 | 11 | export CFLAGS_WASI="--sysroot=${WASI_SYSROOT} -D_WASI_EMULATED_GETPID" 12 | export LDFLAGS_WASI="-lwasi-emulated-getpid" 13 | 14 | export CFLAGS_BUILD='-Werror -Wno-error=format' 15 | 16 | export CFLAGS="${CFLAGS_CONFIG} ${CFLAGS_WASI} ${CFLAGS_BUILD}" 17 | export LDFLAGS="${LDFLAGS_WASI}" 18 | 19 | cd "${WLR_SOURCE_PATH}" 20 | 21 | source ${WLR_REPO_ROOT}/scripts/build-helpers/wlr_pkg_config.sh 22 | 23 | if [[ -z "$WLR_SKIP_CONFIGURE" ]]; then 24 | 25 | logStatus "Generating configure" 26 | source ${WLR_REPO_ROOT}/scripts/build-helpers/wlr_autoconf.sh 27 | wlr_update_autoconf || exit 1 28 | 29 | autoreconf --verbose --install 30 | 31 | export UUID_CONFIGURE="${WLR_CONFIGURE_PREFIXES}" 32 | logStatus "Configuring build with '${UUID_CONFIGURE}'... " 33 | ./configure --host=wasm32-wasi host_alias=wasm32-musl-wasi --target=wasm32-wasi target_alias=wasm32-musl-wasi ${UUID_CONFIGURE} || exit 1 34 | else 35 | logStatus "Skipping configure..." 36 | fi 37 | 38 | logStatus "Building... " 39 | make || exit 1 40 | 41 | logStatus "Preparing artifacts... " 42 | make install ${WLR_INSTALL_PREFIXES} || exit 1 43 | 44 | add_pkg_config_Libs ${WLR_OUTPUT}/lib/wasm32-wasi/pkgconfig/uuid.pc ${LDFLAGS_WASI} 45 | 46 | wlr_package_lib 47 | 48 | logStatus "DONE. Artifacts in ${WLR_OUTPUT}" 49 | -------------------------------------------------------------------------------- /libs/libuuid/v1.0.3/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | return 11 | fi 12 | 13 | export WLR_REPO=https://git.code.sf.net/p/libuuid/code 14 | export WLR_REPO_BRANCH=libuuid-1.0.3 15 | export WLR_ENV_NAME=libuuid/libuuid-1.0.3 16 | export WLR_PACKAGE_VERSION=1.0.3 17 | export WLR_PACKAGE_NAME=uuid 18 | -------------------------------------------------------------------------------- /libs/libuuid/v1.0.3/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="libs/libuuid/1.0.3" 2 | -------------------------------------------------------------------------------- /libs/libxml2/Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) 2 | REPO_ROOT := $(ROOT_DIR)../.. 3 | 4 | include $(REPO_ROOT)/Makefile.helpers 5 | 6 | $(eval $(call create_default_external_lib_targets,$(REPO_ROOT),libxml2,$(WASI_SDK_VERSION))) 7 | -------------------------------------------------------------------------------- /libs/libxml2/README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | This folder builds assets of the libxml2 project. 4 | 5 | The main project page is at [http://xmlsoft.org/](http://xmlsoft.org/). 6 | -------------------------------------------------------------------------------- /libs/libxml2/v2.10.3/wlr-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "Wasmlabs environment is not set" 6 | exit 1 7 | fi 8 | 9 | export CFLAGS_CONFIG="-O0" 10 | 11 | export CFLAGS_WASI="--sysroot=${WASI_SYSROOT}" 12 | export LDFLAGS_WASI="--sysroot=${WASI_SYSROOT}" 13 | 14 | export CFLAGS_LIBXML2='' 15 | 16 | logStatus "Using LIBXML2 DEFINES: ${CFLAGS_LIBXML2}" 17 | 18 | export CFLAGS_BUILD='' 19 | 20 | # We need to add LDFLAGS ot CFLAGS because autoconf compiles(+links) to binary when checking stuff 21 | export CFLAGS="${CFLAGS_CONFIG} ${CFLAGS_WASI} ${CFLAGS_LIBXML2} ${CFLAGS_BUILD} ${LDFLAGS_WASI}" 22 | export LDFLAGS="${LDFLAGS_WASI}" 23 | 24 | cd "${WLR_SOURCE_PATH}" 25 | 26 | source ${WLR_REPO_ROOT}/scripts/build-helpers/wlr_pkg_config.sh 27 | 28 | if [[ -z "$WLR_SKIP_CONFIGURE" ]]; then 29 | ./autogen.sh 30 | export LIBXML2_CONFIGURE="${WLR_CONFIGURE_PREFIXES} --enable-static --disable-shared --with-minimum=yes --with-output=yes --with-schemas=yes --with-tree=yes --with-valid=yes --with-html=yes --with-xpath=yes --with-reader=yes --with-writer=yes --with-xinclude=yes --with-c14n=yes --with-sax1=yes" 31 | logStatus "Configuring build with '${LIBXML2_CONFIGURE}'..." 32 | ./configure --config-cache --host=wasm32-wasi host_alias=wasm32-musl-wasi --target=wasm32-wasi target_alias=wasm32-musl-wasi ${LIBXML2_CONFIGURE} || exit 1 33 | else 34 | logStatus "Skipping configure..." 35 | fi 36 | 37 | logStatus "Building..." 38 | make -j || exit 1 39 | 40 | logStatus "Preparing artifacts..." 41 | make install ${WLR_INSTALL_PREFIXES} || exit 1 42 | 43 | wlr_package_lib 44 | 45 | logStatus "DONE. Artifacts in ${WLR_OUTPUT}" 46 | -------------------------------------------------------------------------------- /libs/libxml2/v2.10.3/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | return 11 | fi 12 | 13 | export WLR_REPO=https://github.com/GNOME/libxml2.git 14 | export WLR_REPO_BRANCH=v2.10.3 15 | export WLR_ENV_NAME=libxml2/v2.10.3 16 | export WLR_PACKAGE_VERSION=2.10.3 17 | export WLR_PACKAGE_NAME=xml2 18 | 19 | -------------------------------------------------------------------------------- /libs/libxml2/v2.10.3/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="libs/libxml2/2.10.3" 2 | -------------------------------------------------------------------------------- /libs/libxml2/v2.11.4/wlr-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "Wasmlabs environment is not set" 6 | exit 1 7 | fi 8 | 9 | export CFLAGS_CONFIG="-O0" 10 | 11 | export CFLAGS_WASI="--sysroot=${WASI_SYSROOT}" 12 | export LDFLAGS_WASI="--sysroot=${WASI_SYSROOT}" 13 | 14 | export CFLAGS_LIBXML2='' 15 | 16 | logStatus "Using LIBXML2 DEFINES: ${CFLAGS_LIBXML2}" 17 | 18 | export CFLAGS_BUILD='' 19 | 20 | # We need to add LDFLAGS ot CFLAGS because autoconf compiles(+links) to binary when checking stuff 21 | export CFLAGS="${CFLAGS_CONFIG} ${CFLAGS_WASI} ${CFLAGS_LIBXML2} ${CFLAGS_BUILD} ${LDFLAGS_WASI}" 22 | export LDFLAGS="${LDFLAGS_WASI}" 23 | 24 | cd "${WLR_SOURCE_PATH}" 25 | 26 | source ${WLR_REPO_ROOT}/scripts/build-helpers/wlr_pkg_config.sh 27 | 28 | if [[ -z "$WLR_SKIP_CONFIGURE" ]]; then 29 | ./autogen.sh 30 | export LIBXML2_CONFIGURE="${WLR_CONFIGURE_PREFIXES} --enable-static --disable-shared --with-minimum=yes --with-output=yes --with-schemas=yes --with-tree=yes --with-valid=yes --with-html=yes --with-xpath=yes --with-reader=yes --with-writer=yes --with-xinclude=yes --with-c14n=yes --with-sax1=yes" 31 | logStatus "Configuring build with '${LIBXML2_CONFIGURE}'..." 32 | ./configure --config-cache --host=wasm32-wasi host_alias=wasm32-musl-wasi --target=wasm32-wasi target_alias=wasm32-musl-wasi ${LIBXML2_CONFIGURE} || exit 1 33 | else 34 | logStatus "Skipping configure..." 35 | fi 36 | 37 | logStatus "Building..." 38 | make -j || exit 1 39 | 40 | logStatus "Preparing artifacts..." 41 | make install ${WLR_INSTALL_PREFIXES} || exit 1 42 | 43 | wlr_package_lib 44 | 45 | logStatus "DONE. Artifacts in ${WLR_OUTPUT}" 46 | -------------------------------------------------------------------------------- /libs/libxml2/v2.11.4/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]]; then 4 | unset WLR_REPO 5 | unset WLR_REPO_BRANCH 6 | unset WLR_ENV_NAME 7 | unset WLR_PACKAGE_VERSION 8 | unset WLR_PACKAGE_NAME 9 | return 10 | fi 11 | 12 | export WLR_REPO=https://github.com/GNOME/libxml2.git 13 | export WLR_REPO_BRANCH=v2.11.4 14 | export WLR_ENV_NAME=libxml2/v2.11.4 15 | export WLR_PACKAGE_VERSION=2.11.4 16 | export WLR_PACKAGE_NAME=xml2 17 | -------------------------------------------------------------------------------- /libs/libxml2/v2.11.4/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="libs/libxml2/2.11.4" 2 | -------------------------------------------------------------------------------- /libs/oniguruma/Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) 2 | REPO_ROOT := $(ROOT_DIR)../.. 3 | 4 | include $(REPO_ROOT)/Makefile.helpers 5 | 6 | $(eval $(call create_default_external_lib_targets,$(REPO_ROOT),oniguruma,$(WASI_SDK_VERSION))) 7 | -------------------------------------------------------------------------------- /libs/oniguruma/README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | This folder builds assets of the oniguruma project. 4 | 5 | The main project page is at [https://github.com/kkos/oniguruma](https://github.com/kkos/oniguruma). 6 | -------------------------------------------------------------------------------- /libs/oniguruma/v6.9.8/wlr-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | export CFLAGS_CONFIG="-O0" 10 | 11 | export CFLAGS_WASI="--sysroot=${WASI_SYSROOT}" 12 | export LDFLAGS_WASI="--sysroot=${WASI_SYSROOT}" 13 | 14 | export CFLAGS_ONIGURUMA='' 15 | 16 | logStatus "Using ONIGURUMA DEFINES: ${CFLAGS_ONIGURUMA}" 17 | 18 | export CFLAGS_BUILD='' 19 | 20 | # We need to add LDFLAGS ot CFLAGS because autoconf compiles(+links) to binary when checking stuff 21 | export CFLAGS="${CFLAGS_CONFIG} ${CFLAGS_WASI} ${CFLAGS_ONIGURUMA} ${CFLAGS_BUILD} ${LDFLAGS_WASI}" 22 | export LDFLAGS="${LDFLAGS_WASI}" 23 | 24 | cd "${WLR_SOURCE_PATH}" 25 | 26 | source ${WLR_REPO_ROOT}/scripts/build-helpers/wlr_pkg_config.sh 27 | 28 | if [[ -z "$WLR_SKIP_CONFIGURE" ]]; then 29 | ./autogen.sh 30 | export ONIGURUMA_CONFIGURE="${WLR_CONFIGURE_PREFIXES} --enable-static --disable-shared" 31 | logStatus "Configuring build with '${ONIGURUMA_CONFIGURE}'... " 32 | ./configure --config-cache --host=wasm32-wasi host_alias=wasm32-musl-wasi --target=wasm32-wasi target_alias=wasm32-musl-wasi ${ONIGURUMA_CONFIGURE} || exit 1 33 | else 34 | logStatus "Skipping configure..." 35 | fi 36 | 37 | logStatus "Building..." 38 | make -j || exit 1 39 | 40 | logStatus "Preparing artifacts..." 41 | make install ${WLR_INSTALL_PREFIXES} || exit 1 42 | 43 | wlr_package_lib 44 | 45 | logStatus "DONE. Artifacts in ${WLR_OUTPUT}" 46 | -------------------------------------------------------------------------------- /libs/oniguruma/v6.9.8/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | return 11 | fi 12 | 13 | export WLR_REPO=https://github.com/kkos/oniguruma 14 | export WLR_REPO_BRANCH=v6.9.8 15 | export WLR_ENV_NAME=oniguruma/v6.9.8 16 | export WLR_PACKAGE_VERSION=6.9.8 17 | export WLR_PACKAGE_NAME=onig 18 | -------------------------------------------------------------------------------- /libs/oniguruma/v6.9.8/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="libs/oniguruma/6.9.8" 2 | -------------------------------------------------------------------------------- /libs/sqlite/Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) 2 | REPO_ROOT := $(ROOT_DIR)../.. 3 | 4 | include $(REPO_ROOT)/Makefile.helpers 5 | 6 | $(eval $(call create_default_external_lib_targets,$(REPO_ROOT),sqlite,$(WASI_SDK_VERSION))) 7 | -------------------------------------------------------------------------------- /libs/sqlite/README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | This folder builds assets of the SQLite project. 4 | 5 | The main project page is at [https://www.sqlite.org/index.html](https://www.sqlite.org/index.html). 6 | 7 | The patch and approach have been greatly influenced by the changes in [rcarmo/wasi-sqlite](https://github.com/rcarmo/wasi-sqlite) 8 | -------------------------------------------------------------------------------- /libs/sqlite/v3.39.2/patches/0002-Exclude-pwd-popen-and-passwd-code-for-__wasi__.patch: -------------------------------------------------------------------------------- 1 | From 18469c26e6e126d7944a13e20509fe6ac24ce4d5 Mon Sep 17 00:00:00 2001 2 | From: Asen Alexandrov 3 | Date: Thu, 10 Nov 2022 14:29:54 +0200 4 | Subject: [PATCH 2/2] Exclude pwd, popen and passwd code for __wasi__ 5 | 6 | 7 | 100.0% src/ 8 | diff --git a/src/shell.c.in b/src/shell.c.in 9 | index 4e921cb..b3efc82 100644 10 | --- a/src/shell.c.in 11 | +++ b/src/shell.c.in 12 | @@ -92,7 +92,7 @@ typedef unsigned char u8; 13 | 14 | #if !defined(_WIN32) && !defined(WIN32) 15 | # include 16 | -# if !defined(__RTP__) && !defined(_WRS_KERNEL) 17 | +# if !defined(__RTP__) && !defined(_WRS_KERNEL) && !defined(__wasi__) 18 | # include 19 | # endif 20 | #endif 21 | @@ -173,7 +173,7 @@ typedef unsigned char u8; 22 | /* Make sure isatty() has a prototype. */ 23 | extern int isatty(int); 24 | 25 | -# if !defined(__RTP__) && !defined(_WRS_KERNEL) 26 | +# if !defined(__RTP__) && !defined(_WRS_KERNEL) && !defined(__wasi__) 27 | /* popen and pclose are not C89 functions and so are 28 | ** sometimes omitted from the header */ 29 | extern FILE *popen(const char*,const char*); 30 | @@ -11727,7 +11727,7 @@ static char *find_home_dir(int clearFlag){ 31 | if( home_dir ) return home_dir; 32 | 33 | #if !defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE) \ 34 | - && !defined(__RTP__) && !defined(_WRS_KERNEL) 35 | + && !defined(__RTP__) && !defined(_WRS_KERNEL) && !defined(__wasi__) 36 | { 37 | struct passwd *pwent; 38 | uid_t uid = getuid(); 39 | -- 40 | 2.38.1 41 | 42 | -------------------------------------------------------------------------------- /libs/sqlite/v3.39.2/patches/0900-Allow-install-headers-and-pc-files.patch: -------------------------------------------------------------------------------- 1 | From 60ae74a4d98beb7c01e11c483232c8dcb3634cd9 Mon Sep 17 00:00:00 2001 2 | From: =?UTF-8?q?Jesu=CC=81s=20Gonza=CC=81lez?= 3 | Date: Sun, 12 Feb 2023 06:49:38 +0100 4 | Subject: [PATCH] Allow installation of headers and pkg-config files with the 5 | library 6 | 7 | --- 8 | Makefile.in | 7 ++++++- 9 | 1 file changed, 6 insertions(+), 1 deletion(-) 10 | 11 | diff --git a/Makefile.in b/Makefile.in 12 | index 2a71bd2c5..4784cccc9 100644 13 | --- a/Makefile.in 14 | +++ b/Makefile.in 15 | @@ -1450,9 +1450,14 @@ threadtest5: sqlite3.c $(TOP)/test/threadtest5.c 16 | 17 | # Standard install and cleanup targets 18 | # 19 | -lib_install: libsqlite3.la 20 | +lib_install: libsqlite3.la sqlite3.h sqlite3.pc ${HAVE_TCL:1=tcl_install} 21 | $(INSTALL) -d $(DESTDIR)$(libdir) 22 | $(LTINSTALL) libsqlite3.la $(DESTDIR)$(libdir) 23 | + $(INSTALL) -d $(DESTDIR)$(includedir) 24 | + $(INSTALL) -m 0644 sqlite3.h $(DESTDIR)$(includedir) 25 | + $(INSTALL) -m 0644 $(TOP)/src/sqlite3ext.h $(DESTDIR)$(includedir) 26 | + $(INSTALL) -d $(DESTDIR)$(pkgconfigdir) 27 | + $(INSTALL) -m 0644 sqlite3.pc $(DESTDIR)$(pkgconfigdir) 28 | 29 | install: sqlite3$(TEXE) lib_install sqlite3.h sqlite3.pc ${HAVE_TCL:1=tcl_install} 30 | $(INSTALL) -d $(DESTDIR)$(bindir) 31 | -- 32 | 2.37.0 33 | 34 | -------------------------------------------------------------------------------- /libs/sqlite/v3.39.2/wlr-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | export CFLAGS_CONFIG="-O0" 10 | 11 | export CFLAGS_WASI="--sysroot=${WASI_SYSROOT} -I./wlr-stubs -D_WASI_EMULATED_MMAN -D_WASI_EMULATED_GETPID -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_PROCESS_CLOCKS" 12 | export LDFLAGS_WASI="--sysroot=${WASI_SYSROOT} -lwasi-emulated-mman -lwasi-emulated-getpid -lwasi-emulated-signal -lwasi-emulated-process-clocks" 13 | 14 | export CFLAGS_SQLITE='-DSQLITE_OMIT_WAL=1 -DSQLITE_DEFAULT_SYNCHRONOUS=0 -DSQLITE_OMIT_RANDOMNESS -DLONGDOUBLE_TYPE=double -DSQLITE_BYTEORDER=1234 -DNDEBUG=1 -DSQLITE_OS_UNIX=1 -DSQLITE_DISABLE_LFS=1 -DSQLITE_ENABLE_JSON1=1 -DSQLITE_HAVE_ISNAN=1 -DSQLITE_HAVE_MALLOC_USABLE_SIZE=1 -DSQLITE_HAVE_STRCHRNUL=1 -DSQLITE_LIKE_DOESNT_MATCH_BLOBS=1 -DSQLITE_OMIT_DEPRECATED=1 -DSQLITE_OMIT_LOAD_EXTENSION=1 -DSQLITE_TEMP_STORE=2 -DSQLITE_THREADSAFE=0 -DSQLITE_USE_URI=1 -DSQLITE_ENABLE_RTREE=1 -DSQLITE_ENABLE_FTS5=1 -DSQLITE_HAVE_USLEEP=1 -DSQLITE_ENABLE_EXPLAIN_COMMENTS=1 -DSQLITE_NOHAVE_SYSTEM=1' 15 | 16 | logStatus "Using SQLITE DEFINES: ${CFLAGS_SQLITE}" 17 | 18 | export CFLAGS_BUILD='-D_POSIX_SOURCE=1 -D_GNU_SOURCE=1 -DHAVE_FORK=0 -DWASM_WASI' 19 | 20 | # We need to add LDFLAGS ot CFLAGS because autoconf compiles(+links) to binary when checking stuff 21 | export CFLAGS="${CFLAGS_CONFIG} ${CFLAGS_WASI} ${CFLAGS_SQLITE} ${CFLAGS_BUILD} ${LDFLAGS_WASI}" 22 | export LDFLAGS="${LDFLAGS_WASI}" 23 | 24 | cd "${WLR_SOURCE_PATH}" 25 | 26 | source ${WLR_REPO_ROOT}/scripts/build-helpers/wlr_pkg_config.sh 27 | 28 | if [[ -z "$WLR_SKIP_CONFIGURE" ]]; then 29 | export SQLITE_CONFIGURE="${WLR_CONFIGURE_PREFIXES} --disable-threadsafe --enable-tempstore=yes" 30 | logStatus "Configuring build with '${SQLITE_CONFIGURE}'..." 31 | ./configure --config-cache --host=wasm32-wasi host_alias=wasm32-musl-wasi --target=wasm32-wasi target_alias=wasm32-musl-wasi ${SQLITE_CONFIGURE} || exit 1 32 | else 33 | logStatus "Skipping configure..." 34 | fi 35 | 36 | logStatus "Building..." 37 | make -j libsqlite3.la || exit 1 38 | 39 | logStatus "Preparing artifacts..." 40 | make lib_install ${WLR_INSTALL_PREFIXES} || exit 1 41 | 42 | wlr_package_lib 43 | 44 | logStatus "DONE. Artifacts in ${WLR_OUTPUT}" 45 | -------------------------------------------------------------------------------- /libs/sqlite/v3.39.2/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | return 11 | fi 12 | 13 | export WLR_REPO=https://github.com/sqlite/sqlite.git 14 | export WLR_REPO_BRANCH=version-3.39.2 15 | export WLR_ENV_NAME=sqlite/v3.39.2 16 | export WLR_PACKAGE_VERSION=3.39.2 17 | export WLR_PACKAGE_NAME=sqlite 18 | -------------------------------------------------------------------------------- /libs/sqlite/v3.39.2/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="libs/sqlite/3.39.2" 2 | -------------------------------------------------------------------------------- /libs/sqlite/v3.41.2/patches/0001-Allow-installation-of-headers-and-pkg-config-files-w.patch: -------------------------------------------------------------------------------- 1 | From 13087ac2531143092f5218e86c23b36a85a34c1d Mon Sep 17 00:00:00 2001 2 | From: =?UTF-8?q?=3D=3FUTF-8=3Fq=3FJesu=3DCC=3D81s=3D20Gonza=3DCC=3D81lez?= 3 | =?UTF-8?q?=3F=3D?= 4 | Date: Wed, 29 Mar 2023 14:53:21 +0300 5 | Subject: [PATCH] Allow installation of headers and pkg-config files with the 6 | library 7 | 8 | 9 | diff --git a/Makefile.in b/Makefile.in 10 | index 2a71bd2..c9b0363 100644 11 | --- a/Makefile.in 12 | +++ b/Makefile.in 13 | @@ -1450,19 +1450,19 @@ threadtest5: sqlite3.c $(TOP)/test/threadtest5.c 14 | 15 | # Standard install and cleanup targets 16 | # 17 | -lib_install: libsqlite3.la 18 | +lib_install: libsqlite3.la sqlite3.h sqlite3.pc 19 | $(INSTALL) -d $(DESTDIR)$(libdir) 20 | $(LTINSTALL) libsqlite3.la $(DESTDIR)$(libdir) 21 | - 22 | -install: sqlite3$(TEXE) lib_install sqlite3.h sqlite3.pc ${HAVE_TCL:1=tcl_install} 23 | - $(INSTALL) -d $(DESTDIR)$(bindir) 24 | - $(LTINSTALL) sqlite3$(TEXE) $(DESTDIR)$(bindir) 25 | $(INSTALL) -d $(DESTDIR)$(includedir) 26 | $(INSTALL) -m 0644 sqlite3.h $(DESTDIR)$(includedir) 27 | $(INSTALL) -m 0644 $(TOP)/src/sqlite3ext.h $(DESTDIR)$(includedir) 28 | $(INSTALL) -d $(DESTDIR)$(pkgconfigdir) 29 | $(INSTALL) -m 0644 sqlite3.pc $(DESTDIR)$(pkgconfigdir) 30 | 31 | +install: sqlite3$(TEXE) lib_install ${HAVE_TCL:1=tcl_install} 32 | + $(INSTALL) -d $(DESTDIR)$(bindir) 33 | + $(LTINSTALL) sqlite3$(TEXE) $(DESTDIR)$(bindir) 34 | + 35 | pkgIndex.tcl: 36 | echo 'package ifneeded sqlite3 $(RELEASE) [list load [file join $$dir libtclsqlite3[info sharedlibextension]] sqlite3]' > $@ 37 | tcl_install: lib_install libtclsqlite3.la pkgIndex.tcl 38 | -- 39 | 2.38.1 40 | 41 | -------------------------------------------------------------------------------- /libs/sqlite/v3.41.2/wlr-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | export CFLAGS_CONFIG="-O0" 10 | 11 | 12 | # We need to add LDFLAGS ot CFLAGS because autoconf compiles(+links) to binary when checking stuff 13 | export CFLAGS="${CFLAGS_CONFIG}" 14 | 15 | cd "${WLR_SOURCE_PATH}" 16 | 17 | source ${WLR_REPO_ROOT}/scripts/build-helpers/wlr_pkg_config.sh 18 | 19 | unset WASI_SYSROOT 20 | unset CC 21 | unset LD 22 | unset CXX 23 | unset NM 24 | unset AR 25 | unset RANLIB 26 | 27 | if [[ -z "$WLR_SKIP_CONFIGURE" ]]; then 28 | export SQLITE_CONFIGURE="${WLR_CONFIGURE_PREFIXES} --enable-all --with-wasi-sdk=${WASI_SDK_PATH}" 29 | logStatus "Configuring build with '${SQLITE_CONFIGURE}'..." 30 | ./configure --config-cache ${SQLITE_CONFIGURE} || exit 1 31 | else 32 | logStatus "Skipping configure..." 33 | fi 34 | 35 | logStatus "Building... " 36 | make -j || exit 1 37 | 38 | logStatus "Preparing artifacts... " 39 | make lib_install ${WLR_INSTALL_PREFIXES} || exit 1 40 | 41 | wlr_package_lib 42 | 43 | logStatus "DONE. Artifacts in ${WLR_OUTPUT}" 44 | -------------------------------------------------------------------------------- /libs/sqlite/v3.41.2/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | return 11 | fi 12 | 13 | export WLR_REPO=https://github.com/sqlite/sqlite.git 14 | export WLR_REPO_BRANCH=version-3.41.2 15 | export WLR_ENV_NAME=sqlite/v3.41.2 16 | export WLR_PACKAGE_VERSION=3.41.2 17 | export WLR_PACKAGE_NAME=sqlite 18 | -------------------------------------------------------------------------------- /libs/sqlite/v3.41.2/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="libs/sqlite/3.41.2" 2 | -------------------------------------------------------------------------------- /libs/sqlite/v3.42.0/patches/0001-Allow-installation-of-headers-and-pkg-config-files-w.patch: -------------------------------------------------------------------------------- 1 | From 50027d770993b4bf5875e6cebf608151062765a9 Mon Sep 17 00:00:00 2001 2 | From: "no-reply@wasmlabs.dev" 3 | Date: Mon, 19 Jun 2023 14:58:12 +0300 4 | Subject: [PATCH] Allow installation of headers and pkg-config files with the 5 | library 6 | 7 | 8 | diff --git a/Makefile.in b/Makefile.in 9 | index 61cb3ef..68b0252 100644 10 | --- a/Makefile.in 11 | +++ b/Makefile.in 12 | @@ -1471,19 +1471,19 @@ threadtest5: sqlite3.c $(TOP)/test/threadtest5.c 13 | 14 | # Standard install and cleanup targets 15 | # 16 | -lib_install: libsqlite3.la 17 | +lib_install: libsqlite3.la sqlite3.h sqlite3.pc 18 | $(INSTALL) -d $(DESTDIR)$(libdir) 19 | $(LTINSTALL) libsqlite3.la $(DESTDIR)$(libdir) 20 | - 21 | -install: sqlite3$(TEXE) lib_install sqlite3.h sqlite3.pc ${HAVE_TCL:1=tcl_install} 22 | - $(INSTALL) -d $(DESTDIR)$(bindir) 23 | - $(LTINSTALL) sqlite3$(TEXE) $(DESTDIR)$(bindir) 24 | $(INSTALL) -d $(DESTDIR)$(includedir) 25 | $(INSTALL) -m 0644 sqlite3.h $(DESTDIR)$(includedir) 26 | $(INSTALL) -m 0644 $(TOP)/src/sqlite3ext.h $(DESTDIR)$(includedir) 27 | $(INSTALL) -d $(DESTDIR)$(pkgconfigdir) 28 | $(INSTALL) -m 0644 sqlite3.pc $(DESTDIR)$(pkgconfigdir) 29 | 30 | +install: sqlite3$(TEXE) lib_install ${HAVE_TCL:1=tcl_install} 31 | + $(INSTALL) -d $(DESTDIR)$(bindir) 32 | + $(LTINSTALL) sqlite3$(TEXE) $(DESTDIR)$(bindir) 33 | + 34 | pkgIndex.tcl: 35 | echo 'package ifneeded sqlite3 $(RELEASE) [list load [file join $$dir libtclsqlite3[info sharedlibextension]] sqlite3]' > $@ 36 | tcl_install: lib_install libtclsqlite3.la pkgIndex.tcl 37 | -- 38 | 2.38.1 39 | 40 | -------------------------------------------------------------------------------- /libs/sqlite/v3.42.0/wlr-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | export CFLAGS_CONFIG="-O0" 10 | 11 | 12 | # We need to add LDFLAGS ot CFLAGS because autoconf compiles(+links) to binary when checking stuff 13 | export CFLAGS="${CFLAGS_CONFIG}" 14 | 15 | cd "${WLR_SOURCE_PATH}" 16 | 17 | source ${WLR_REPO_ROOT}/scripts/build-helpers/wlr_pkg_config.sh 18 | 19 | unset WASI_SYSROOT 20 | unset CC 21 | unset LD 22 | unset CXX 23 | unset NM 24 | unset AR 25 | unset RANLIB 26 | 27 | if [[ -z "$WLR_SKIP_CONFIGURE" ]]; then 28 | export SQLITE_CONFIGURE="${WLR_CONFIGURE_PREFIXES} --enable-all --with-wasi-sdk=${WASI_SDK_PATH}" 29 | logStatus "Configuring build with '${SQLITE_CONFIGURE}'..." 30 | ./configure --config-cache ${SQLITE_CONFIGURE} || exit 1 31 | else 32 | logStatus "Skipping configure..." 33 | fi 34 | 35 | logStatus "Building... " 36 | make -j || exit 1 37 | 38 | logStatus "Preparing artifacts... " 39 | make lib_install ${WLR_INSTALL_PREFIXES} || exit 1 40 | 41 | wlr_package_lib 42 | 43 | logStatus "DONE. Artifacts in ${WLR_OUTPUT}" 44 | -------------------------------------------------------------------------------- /libs/sqlite/v3.42.0/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | return 11 | fi 12 | 13 | export WLR_REPO=https://github.com/sqlite/sqlite.git 14 | export WLR_REPO_BRANCH=version-3.42.0 15 | export WLR_ENV_NAME=sqlite/v3.42.0 16 | export WLR_PACKAGE_VERSION=3.42.0 17 | export WLR_PACKAGE_NAME=sqlite 18 | -------------------------------------------------------------------------------- /libs/sqlite/v3.42.0/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="libs/sqlite/3.42.0" 2 | -------------------------------------------------------------------------------- /libs/sqlite/wasi-patches/wlr-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | export CFLAGS_CONFIG="-O2" 10 | 11 | export CFLAGS_WASI="--sysroot=${WASI_SYSROOT} -I./wlr-stubs -D_WASI_EMULATED_MMAN -D_WASI_EMULATED_GETPID -D_WASI_EMULATED_SIGNAL -D_WASI_EMULATED_PROCESS_CLOCKS" 12 | export LDFLAGS_WASI="--sysroot=${WASI_SYSROOT} -lwasi-emulated-mman -lwasi-emulated-getpid -lwasi-emulated-signal -lwasi-emulated-process-clocks" 13 | 14 | export CFLAGS_SQLITE='' 15 | 16 | logStatus "Using SQLITE DEFINES: ${CFLAGS_SQLITE}" 17 | 18 | export SQLITE_CONFIGURE='--enable-all --disable-threadsafe' 19 | 20 | export CFLAGS_BUILD='' 21 | 22 | # We need to add LDFLAGS ot CFLAGS because autoconf compiles(+links) to binary when checking stuff 23 | export CFLAGS="${CFLAGS_CONFIG} ${CFLAGS_WASI} ${CFLAGS_SQLITE} ${CFLAGS_BUILD} ${LDFLAGS_WASI}" 24 | export LDFLAGS="${LDFLAGS_WASI}" 25 | 26 | cd "${WLR_SOURCE_PATH}" 27 | 28 | logStatus "Configuring build with '${SQLITE_CONFIGURE}'... " 29 | ./configure --host=wasm32-wasi host_alias=wasm32-musl-wasi --target=wasm32-wasi target_alias=wasm32-musl-wasi ${SQLITE_CONFIGURE} || exit 1 30 | 31 | logStatus "Building... " 32 | make -j libsqlite3.la || exit 1 33 | 34 | logStatus "Preparing artifacts... " 35 | cp sqlite3.h sqlite3ext.h sqlite3session.h ${WLR_OUTPUT}/include/ || exit 1 36 | cp .libs/libsqlite3.a ${WLR_OUTPUT}/lib/ || exit 1 37 | 38 | logStatus "DONE. Artifacts in ${WLR_OUTPUT}" 39 | -------------------------------------------------------------------------------- /libs/wasmedge_sock/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | 3 | project(wasmedge_sock) 4 | 5 | add_library( 6 | wasmedge_sock 7 | STATIC 8 | netdb.c 9 | wasi_socket_ext.c 10 | ) 11 | 12 | target_include_directories( 13 | wasmedge_sock 14 | PUBLIC 15 | ${CMAKE_CURRENT_SOURCE_DIR}/include 16 | ) 17 | -------------------------------------------------------------------------------- /libs/wasmedge_sock/Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) 2 | REPO_ROOT := $(ROOT_DIR)../.. 3 | 4 | default_target: all 5 | .PHONY : default_target 6 | 7 | include $(REPO_ROOT)/Makefile.helpers 8 | 9 | $(eval $(call create_default_local_lib_targets,$(REPO_ROOT),wasmedge_sock,$(WASI_SDK_VERSION))) 10 | -------------------------------------------------------------------------------- /libs/wasmedge_sock/README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | This library wraps the WasmEdge socket extended ABI into POSIX-compliant interfaces. 4 | 5 | It is based on https://github.com/hangedfish/wasmedge_wasi_socket_c, which was developed by a member of the WasmEdge team. 6 | 7 | The code is unpolished, work in progress. 8 | -------------------------------------------------------------------------------- /libs/wasmedge_sock/include/netdb.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | // Based on https://github.com/hangedfish/wasmedge_wasi_socket_c 3 | 4 | #include 5 | 6 | struct addrinfo { 7 | int ai_flags; 8 | int ai_family; 9 | int ai_socktype; 10 | int ai_protocol; 11 | socklen_t ai_addrlen; 12 | struct sockaddr *ai_addr; 13 | char *ai_canonname; 14 | int ai_canonnamelen; 15 | struct addrinfo *ai_next; 16 | }; 17 | 18 | #define AI_PASSIVE 0x00 19 | #define AI_CANONNAME 0x01 20 | #define AI_NUMERICHOST 0x02 21 | #define AI_NUMERICSERV 0x03 22 | #define AI_V4MAPPED 0x04 23 | #define AI_ALL 0x05 24 | #define AI_ADDRCONFIG 0x06 25 | 26 | #define NI_NUMERICHOST 0x01 27 | #define NI_NUMERICSERV 0x02 28 | #define NI_NOFQDN 0x04 29 | #define NI_NAMEREQD 0x08 30 | #define NI_DGRAM 0x10 31 | #define NI_NUMERICSCOPE 0x100 32 | 33 | #define EAI_BADFLAGS -1 34 | #define EAI_NONAME -2 35 | #define EAI_AGAIN -3 36 | #define EAI_FAIL -4 37 | #define EAI_FAMILY -6 38 | #define EAI_SOCKTYPE -7 39 | #define EAI_SERVICE -8 40 | #define EAI_MEMORY -10 41 | #define EAI_SYSTEM -11 42 | #define EAI_OVERFLOW -12 43 | 44 | #define EAI_NODATA -5 45 | #define EAI_ADDRFAMILY -9 46 | #define EAI_INPROGRESS -100 47 | #define EAI_CANCELED -101 48 | #define EAI_NOTCANCELED -102 49 | #define EAI_ALLDONE -103 50 | #define EAI_INTR -104 51 | #define EAI_IDN_ENCODE -105 52 | #define NI_MAXHOST 255 53 | #define NI_MAXSERV 32 54 | 55 | #ifdef __cplusplus 56 | extern "C" { 57 | #endif 58 | 59 | struct servent { 60 | char *s_name; 61 | char **s_aliases; 62 | int s_port; 63 | char *s_proto; 64 | }; 65 | 66 | struct hostent { 67 | char *h_name; 68 | char **h_aliases; 69 | int h_addrtype; 70 | int h_length; 71 | char **h_addr_list; 72 | }; 73 | #define h_addr h_addr_list[0] 74 | 75 | struct servent *getservbyname(const char *, const char *); 76 | 77 | int getaddrinfo(const char *__restrict, const char *__restrict, 78 | const struct addrinfo *__restrict, 79 | struct addrinfo **__restrict); 80 | void freeaddrinfo(struct addrinfo *); 81 | int getnameinfo(const struct sockaddr *__restrict addr, socklen_t addrlen, 82 | char *__restrict host, socklen_t hostlen, char *__restrict serv, 83 | socklen_t servlen, int flags); 84 | 85 | #ifdef __cplusplus 86 | } 87 | #endif -------------------------------------------------------------------------------- /libs/wasmedge_sock/netdb.c: -------------------------------------------------------------------------------- 1 | // #include "include/netdb.h" 2 | 3 | // #include "wasi_snapshot_preview1.h" 4 | 5 | // #include 6 | 7 | // int accept_instrumented(int fd, struct sockaddr *restrict addr, socklen_t 8 | // *restrict len) { 9 | // int new_sockfd; 10 | // int res = __imported_wasmedge_wasi_snapshot_preview1_sock_accept( 11 | // fd, (uint32_t *)&new_sockfd); 12 | // if (res != 0) { 13 | // errno = res; 14 | // return -1; 15 | // } 16 | // return new_sockfd; 17 | // } 18 | 19 | // // // ------------------ 20 | // // #undef h_errno 21 | // // int h_errno; 22 | 23 | // // int *__h_errno_location(void) 24 | // // { 25 | // // return &h_errno; 26 | // // } -------------------------------------------------------------------------------- /libs/wasmedge_sock/wasi_snapshot_preview1.h: -------------------------------------------------------------------------------- 1 | #include 2 | 3 | int32_t __imported_wasmedge_wasi_snapshot_preview1_sock_accept(uint32_t fd, 4 | uint32_t *fd2) 5 | __attribute__((__import_module__("wasi_snapshot_preview1"), 6 | __import_name__("sock_accept"))); 7 | 8 | -------------------------------------------------------------------------------- /libs/wasmedge_sock/wlr-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | export CFLAGS_CONFIG="-O0" 10 | 11 | export CFLAGS="${CFLAGS_CONFIG}" 12 | 13 | cd "${WLR_SOURCE_PATH}" 14 | 15 | source ${WLR_REPO_ROOT}/scripts/build-helpers/wlr_cmake.sh 16 | source ${WLR_REPO_ROOT}/scripts/build-helpers/wlr_pkg_config.sh 17 | 18 | if [[ -z "$WLR_SKIP_CONFIGURE" ]]; then 19 | 20 | logStatus "Configuring with cmake..." 21 | wlr_cmake_configure ${LIBJPEG_CONFIGURE} 22 | 23 | else 24 | logStatus "Skipping configure..." 25 | fi 26 | 27 | logStatus "Building..." 28 | wlr_cmake_build || exit 1 29 | 30 | logStatus "Preparing artifacts..." 31 | 32 | cp -TRv ${WLR_SOURCE_PATH}/include ${WLR_OUTPUT}/include || exit 1 33 | mkdir -p ${WLR_OUTPUT}/lib/wasm32-wasi 2>/dev/null 34 | cp -v ${WLR_CMAKE_TARGET_DIR}/libwasmedge_sock.a ${WLR_OUTPUT}/lib/wasm32-wasi/ || exit 1 35 | 36 | logStatus "Generating pkg-config file for libwasmedge_sock.a" 37 | DESCRIPTION="libwasmedge_sock is a partial POSIX wrapper over the WasmEdge socket ABI" 38 | EXTRA_LINK_FLAGS="-lwasmedge_sock" 39 | 40 | wlr_pkg_config_create_pc_file "wasmedge_sock" "${WLR_PACKAGE_VERSION}" "${DESCRIPTION}" "${EXTRA_LINK_FLAGS}" || exit 1 41 | 42 | wlr_package_lib || exit 1 43 | 44 | logStatus "DONE. Artifacts in ${WLR_OUTPUT}" 45 | -------------------------------------------------------------------------------- /libs/wasmedge_sock/wlr-env-local.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_ENV_NAME 6 | unset WLR_PACKAGE_NAME 7 | unset WLR_PACKAGE_VERSION 8 | return 9 | fi 10 | 11 | export WLR_ENV_NAME=wasmedge_sock/0.1.0 12 | export WLR_PACKAGE_NAME=wasmedge_sock 13 | export WLR_PACKAGE_VERSION=0.1.0 14 | -------------------------------------------------------------------------------- /libs/zlib/Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) 2 | REPO_ROOT := $(ROOT_DIR)../.. 3 | 4 | include $(REPO_ROOT)/Makefile.helpers 5 | 6 | $(eval $(call create_default_external_lib_targets,$(REPO_ROOT),zlib,$(WASI_SDK_VERSION))) 7 | -------------------------------------------------------------------------------- /libs/zlib/README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | This folder builds assets of the zlib project. 4 | 5 | The main project page is at [https://www.zlib.net/](https://www.zlib.net/). 6 | -------------------------------------------------------------------------------- /libs/zlib/v1.2.13/wlr-build.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | export CFLAGS_CONFIG="-O0" 10 | 11 | export CFLAGS_WASI="--sysroot=${WASI_SYSROOT}" 12 | 13 | export CFLAGS_BUILD='-Werror -Wno-error=format -Wno-error=deprecated-non-prototype -Wno-error=unknown-warning-option' 14 | 15 | export CFLAGS="${CFLAGS_CONFIG} ${CFLAGS_WASI} ${CFLAGS_BUILD}" 16 | 17 | cd "${WLR_SOURCE_PATH}" 18 | 19 | source ${WLR_REPO_ROOT}/scripts/build-helpers/wlr_pkg_config.sh 20 | 21 | if [[ -z "$WLR_SKIP_CONFIGURE" ]]; then 22 | export ZLIB_CONFIGURE="${WLR_CONFIGURE_PREFIXES}" 23 | logStatus "Configuring build with '${ZLIB_CONFIGURE}'... " 24 | ./configure ${ZLIB_CONFIGURE} || exit 1 25 | else 26 | logStatus "Skipping configure..." 27 | fi 28 | 29 | logStatus "Building... " 30 | make -j || exit 1 31 | 32 | logStatus "Preparing artifacts... " 33 | make install ${WLR_INSTALL_PREFIXES} || exit 1 34 | 35 | wlr_package_lib 36 | 37 | logStatus "DONE. Artifacts in ${WLR_OUTPUT}" 38 | -------------------------------------------------------------------------------- /libs/zlib/v1.2.13/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | return 11 | fi 12 | 13 | export WLR_REPO=https://github.com/madler/zlib 14 | export WLR_REPO_BRANCH=v1.2.13 15 | export WLR_ENV_NAME=zlib/v1.2.13 16 | export WLR_PACKAGE_VERSION=1.2.13 17 | export WLR_PACKAGE_NAME=z 18 | -------------------------------------------------------------------------------- /libs/zlib/v1.2.13/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="libs/zlib/1.2.13" 2 | -------------------------------------------------------------------------------- /php/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG WASI_SDK_VERSION 2 | FROM ghcr.io/vmware-labs/wasmlabs/wasi-builder:${WASI_SDK_VERSION} 3 | RUN DEBIAN_FRONTEND=noninteractive apt install -y \ 4 | bison \ 5 | re2c -------------------------------------------------------------------------------- /php/Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) 2 | REPO_ROOT := $(ROOT_DIR).. 3 | 4 | include $(REPO_ROOT)/Makefile.helpers 5 | 6 | .PHONY: php-builder 7 | PHP_BUILDER_NAME := ghcr.io/vmware-labs/wasmlabs/php-builder:wasi-$(WASI_SDK_VERSION) 8 | php-builder: 9 | @$(call make_builder_image,$(PHP_BUILDER_NAME),$(ROOT_DIR),$(WASI_SDK_VERSION)) 10 | 11 | .PHONY: update-php-builder 12 | update-php-builder: php-builder 13 | @$(call push_container_image,$(PHP_BUILDER_NAME)) 14 | 15 | .PHONY: v* 16 | v*: 17 | @$(call build_in_container,$(PHP_BUILDER_NAME),$(REPO_ROOT),php/$@) 18 | 19 | .PHONY: master 20 | master: 21 | @$(call build_in_container,$(PHP_BUILDER_NAME),$(REPO_ROOT),php/$@) 22 | 23 | .PHONY: clean 24 | clean: 25 | rm -rf $(REPO_ROOT)/build-output/php $(REPO_ROOT)/build-staging/php 26 | -------------------------------------------------------------------------------- /php/README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | ## Building 4 | 5 | You can build PHP by running the following Makefile targets: 6 | 7 | - `make v8.1.11` 8 | - `make v8.2.0` 9 | - `make v8.2.0-slim` 10 | - `make v8.2.6` 11 | - `make v8.2.6-slim` 12 | 13 | ## Running a script with php-cgi 14 | 15 | Don't forget to map the folder that contains the php script, which you want to run. For example: 16 | 17 | ```bash 18 | wasmtime --mapdir=./::./ -- php-cgi my-script.php 19 | ``` 20 | -------------------------------------------------------------------------------- /php/examples/mysql/test_mysql_pdo.php: -------------------------------------------------------------------------------- 1 | query("SHOW TABLES"); 17 | while ($row = $result->fetch(PDO::FETCH_NUM)) { 18 | $tableList[] = $row[0]; 19 | } 20 | print_r($tableList); 21 | 22 | 23 | # Create a new table 24 | print("\n"); 25 | $table_name="Sample"; 26 | print("Creating table '$table_name'...\n"); 27 | $sql_create_sample = " 28 | DROP TABLE IF EXISTS $table_name; 29 | CREATE TABLE $table_name( 30 | id INT(2) PRIMARY KEY NOT NULL AUTO_INCREMENT, 31 | name VARCHAR(30) NOT NULL, 32 | description VARCHAR(30) 33 | )"; 34 | $conn->exec($sql_create_sample); 35 | print("Table '$table_name' created!\n"); 36 | 37 | 38 | # Insert values into table 39 | print("\n"); 40 | print("Inserting three records into '$table_name'...\n"); 41 | $sql_insert_sample = " 42 | INSERT INTO Sample(Name, Description) VALUES('First', 'Original sample'); 43 | INSERT INTO Sample(Name, Description) VALUES('Second', 'Secondary sample'); 44 | INSERT INTO Sample(Name) VALUES('Third'); 45 | "; 46 | $conn->exec($sql_insert_sample); 47 | print("Inserted rows into $table_name!\n"); 48 | 49 | 50 | # Select values from table 51 | print("\n"); 52 | print("Selecting all from '$table_name'...\n"); 53 | $query = $conn->prepare("SELECT * FROM $table_name"); 54 | $query->execute(); 55 | 56 | $selection_result = $query->fetchAll(\PDO::FETCH_ASSOC); 57 | print_r($selection_result); 58 | ?> 59 | -------------------------------------------------------------------------------- /php/examples/wp-nginx-php-fcgi-mysql/docker-compose.yml: -------------------------------------------------------------------------------- 1 | services: 2 | proxy-nginx: 3 | container_name: wnpfm-proxy-nginx 4 | image: nginx:alpine 5 | ports: 6 | - ${WNPFM_HOST_PORT}:80 7 | volumes: 8 | - ${WNPFM_TEST_DIR}/wordpress:/var/www/wordpress 9 | - ${WNPFM_TEST_DIR}/logs/nginx:/var/log/nginx 10 | - ./proxy-nginx/default.conf.template:/etc/nginx/templates/default.conf.template 11 | environment: 12 | - WNPFM_PHP_FCGI_HOST=server-php-fcgi-wp 13 | - WNPFM_PHP_FCGI_PORT=${WNPFM_PHP_FCGI_PORT} 14 | depends_on: 15 | - server-php-fcgi-wp 16 | 17 | server-php-fcgi-wp: 18 | container_name: wnpfm-php-cgi-wasmedge 19 | image: wnpfm-php-cgi-wasmedge 20 | platform: wasi/wasm 21 | build: 22 | context: php-cgi-wasmedge 23 | ports: 24 | - ${WNPFM_PHP_FCGI_PORT}:9000 25 | volumes: 26 | - ${WNPFM_TEST_DIR}/wordpress:/var/www/wordpress 27 | restart: unless-stopped 28 | runtime: io.containerd.wasmedge.v1 29 | 30 | db-mysql: 31 | container_name: ${WNPFM_DB_CONTAINER_NAME} 32 | image: mysql 33 | environment: 34 | MYSQL_ROOT_PASSWORD: ${WNPFM_DB_ROOT_PASSWORD} 35 | ports: 36 | - 3306:3306 37 | volumes: 38 | - ${WNPFM_TEST_DIR}/db:/var/lib/mysql 39 | -------------------------------------------------------------------------------- /php/examples/wp-nginx-php-fcgi-mysql/php-cgi-wasmedge/Dockerfile: -------------------------------------------------------------------------------- 1 | # Downloads php-cgi.wasm and optimized it with wasmedgec for the current platform 2 | FROM --platform=$BUILDPLATFORM debian:buster-slim AS builder 3 | 4 | # curl - to download stuff 5 | # git, python3 - to install wasmedge 6 | RUN apt update && \ 7 | DEBIAN_FRONTEND=noninteractive apt install -y \ 8 | curl \ 9 | git \ 10 | python3 11 | 12 | RUN mkdir /opt/work 13 | WORKDIR /opt/work 14 | 15 | # Download php-cgi-wasmedge.wasm 16 | RUN curl -L -o php-cgi-wasmedge.wasm https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/php%2F8.2.6%2B20230714-11be424/php-8.2.6-wasmedge.wasm 17 | 18 | # Install wasmedgec 19 | RUN curl -sSf https://raw.githubusercontent.com/WasmEdge/WasmEdge/master/utils/install.sh | bash 20 | 21 | # Just doing AOT without optimizing as the binary is already optimized 22 | RUN /root/.wasmedge/bin/wasmedgec --optimize 0 /opt/work/php-cgi-wasmedge.wasm php-cgi-wasmedge-aot.wasm 23 | 24 | 25 | 26 | FROM scratch 27 | ENTRYPOINT [ "php-cgi-wasmedge.wasm", "-b", "0.0.0.0:9000", "-d", "ignore_user_abort=On"] 28 | COPY --link --from=builder /opt/work/php-cgi-wasmedge-aot.wasm /php-cgi-wasmedge.wasm 29 | -------------------------------------------------------------------------------- /php/examples/wp-nginx-php-fcgi-mysql/proxy-nginx/default.conf.template: -------------------------------------------------------------------------------- 1 | server { 2 | listen 80; 3 | listen [::]:80; 4 | server_name localhost; 5 | 6 | root /var/www/wordpress; 7 | 8 | error_log /var/log/nginx/error.log; 9 | access_log /var/log/nginx/access.log; 10 | 11 | location / { 12 | index index.php index.html; 13 | try_files $uri $uri/ =404; 14 | } 15 | 16 | location ~ \.php$ { 17 | fastcgi_pass ${WNPFM_PHP_FCGI_HOST}:${WNPFM_PHP_FCGI_PORT}; 18 | fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; 19 | include fastcgi_params; 20 | } 21 | 22 | keepalive_timeout 10m; 23 | 24 | fastcgi_send_timeout 3600s; 25 | fastcgi_read_timeout 3600s; 26 | } 27 | -------------------------------------------------------------------------------- /php/master/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | return 11 | fi 12 | 13 | export WLR_REPO=https://github.com/php/php-src.git 14 | export WLR_REPO_BRANCH=master 15 | export WLR_ENV_NAME=php/master 16 | export WLR_PACKAGE_VERSION=master 17 | export WLR_PACKAGE_NAME=php 18 | -------------------------------------------------------------------------------- /php/master/wlr-info.json: -------------------------------------------------------------------------------- 1 | { 2 | "deps": { 3 | "zlib": { 4 | "build_target": "libs/zlib/v1.2.13", 5 | "required_file": "lib/wasm32-wasi/libz.a", 6 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Fzlib%2F1.2.13%2B20230623-2993864/libz-1.2.13-wasi-sdk-20.0.tar.gz" 7 | }, 8 | "libpng": { 9 | "build_target": "libs/libpng/v1.6.39", 10 | "required_file": "lib/wasm32-wasi/libpng16.a", 11 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Flibpng%2F1.6.39%2B20230629-ccb4cb0/libpng-1.6.39-wasi-sdk-20.0.tar.gz" 12 | }, 13 | "libxml2": { 14 | "build_target": "libs/libxml2/v2.11.4", 15 | "required_file": "lib/wasm32-wasi/libxml2.a", 16 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Flibxml2%2F2.11.4%2B20230623-2993864/libxml2-2.11.4-wasi-sdk-20.0.tar.gz" 17 | }, 18 | "oniguruma": { 19 | "build_target": "libs/oniguruma/v6.9.8", 20 | "required_file": "lib/wasm32-wasi/libonig.a", 21 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Foniguruma%2F6.9.8%2B20230623-2993864/libonig-6.9.8-wasi-sdk-20.0.tar.gz" 22 | }, 23 | "SQLite": { 24 | "build_target": "libs/sqlite/v3.42.0", 25 | "required_file": "lib/wasm32-wasi/libsqlite3.a", 26 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Fsqlite%2F3.42.0%2B20230623-2993864/libsqlite-3.42.0-wasi-sdk-20.0.tar.gz" 27 | } 28 | } 29 | } -------------------------------------------------------------------------------- /php/master/wlr-test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | if ! [ -x "$(command -v php)" ] 10 | then 11 | echo "Native php is required in PATH on the host to act as orchestrator for php.wasm tests!" 12 | exit 1 13 | fi 14 | 15 | if [ -f "${WLR_OUTPUT}/bin/php${WLR_RUNTIME:+-$WLR_RUNTIME}" ] 16 | then 17 | export WLR_TESTED_MODULE="${WLR_OUTPUT}/bin/php${WLR_RUNTIME:+-$WLR_RUNTIME}" 18 | else 19 | export WLR_TESTED_MODULE="${WLR_OUTPUT}/bin/php-cgi${WLR_RUNTIME:+-$WLR_RUNTIME}" 20 | fi 21 | 22 | if ! [ -x "${WLR_TESTED_MODULE}" ] 23 | then 24 | echo "WASM module not found at '${WLR_TESTED_MODULE}'" 25 | exit 1 26 | fi 27 | 28 | cd "${WLR_SOURCE_PATH}" 29 | echo "Calling 'WLR_TESTED_MODULE=${WLR_TESTED_MODULE} php -f run-tests.php -- -p ${WLR_TEST_RUNTIME_WRAPPER} -j6' to run tests..." 30 | php -f run-tests.php -- -p ${WLR_TEST_RUNTIME_WRAPPER} -j6 \ 31 | tests/lang \ 32 | tests/output \ 33 | tests/strings \ 34 | Zend/tests/fibers 35 | -------------------------------------------------------------------------------- /php/v7.3.33/README.md: -------------------------------------------------------------------------------- 1 | # php-7.3.33 2 | 3 | PHP 7.3 is [EOL](https://www.php.net/eol.php) since 6 Dec 2021. 4 | 5 | You can find the latest built binaries 6 | [here](https://github.com/vmware-labs/webassembly-language-runtimes/releases/tag/php%2F7.3.33%2B20221124-2159d1c). 7 | -------------------------------------------------------------------------------- /php/v7.4.32/README.md: -------------------------------------------------------------------------------- 1 | # php-7.4.32 2 | 3 | PHP 7.4 is [EOL](https://www.php.net/eol.php) since 28 Nov 2022. 4 | 5 | You can find the latest built binaries 6 | [here](https://github.com/vmware-labs/webassembly-language-runtimes/releases/tag/php%2F7.4.32%2B20221124-2159d1c). 7 | -------------------------------------------------------------------------------- /php/v8.1.11/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | return 11 | fi 12 | 13 | export WLR_REPO=https://github.com/php/php-src.git 14 | export WLR_REPO_BRANCH=php-8.1.11 15 | export WLR_ENV_NAME=php/php-8.1.11 16 | export WLR_PACKAGE_VERSION=8.1.11 17 | export WLR_PACKAGE_NAME=php 18 | -------------------------------------------------------------------------------- /php/v8.1.11/wlr-info.json: -------------------------------------------------------------------------------- 1 | { 2 | "deps": { 3 | "SQLite": { 4 | "build_target": "libs/sqlite/v3.42.0", 5 | "required_file": "lib/wasm32-wasi/libsqlite3.a", 6 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Fsqlite%2F3.42.0%2B20230623-2993864/libsqlite-3.42.0-wasi-sdk-20.0.tar.gz" 7 | } 8 | } 9 | } -------------------------------------------------------------------------------- /php/v8.1.11/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="php/8.1.11" 2 | -------------------------------------------------------------------------------- /php/v8.1.11/wlr-test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | if ! [ -x "$(command -v php)" ] 10 | then 11 | echo "Native php is required in PATH on the host to act as orchestrator for php.wasm tests!" 12 | exit 1 13 | fi 14 | 15 | if [ -f "${WLR_OUTPUT}/bin/php${WLR_RUNTIME:+-$WLR_RUNTIME}" ] 16 | then 17 | export WLR_TESTED_MODULE="${WLR_OUTPUT}/bin/php${WLR_RUNTIME:+-$WLR_RUNTIME}" 18 | else 19 | export WLR_TESTED_MODULE="${WLR_OUTPUT}/bin/php-cgi${WLR_RUNTIME:+-$WLR_RUNTIME}" 20 | fi 21 | 22 | if ! [ -x "${WLR_TESTED_MODULE}" ] 23 | then 24 | echo "WASM module not found at '${WLR_TESTED_MODULE}'" 25 | exit 1 26 | fi 27 | 28 | cd "${WLR_SOURCE_PATH}" 29 | echo "Calling 'WLR_TESTED_MODULE=${WLR_TESTED_MODULE} php -f run-tests.php -- -p ${WLR_TEST_RUNTIME_WRAPPER} -j6' to run tests..." 30 | php -f run-tests.php -- -p ${WLR_TEST_RUNTIME_WRAPPER} -j6 \ 31 | tests/lang \ 32 | tests/output \ 33 | tests/strings \ 34 | Zend/tests/fibers 35 | -------------------------------------------------------------------------------- /php/v8.2.0/patches/0003-fix-Add-more-ifdefs-for-php-8.2.0.patch: -------------------------------------------------------------------------------- 1 | From 9ac2dea9a31b2a0a2f10a778c28b9a0b0a058b15 Mon Sep 17 00:00:00 2001 2 | From: "no-reply@wasmlabs.dev" 3 | Date: Fri, 6 Jan 2023 11:04:53 +0200 4 | Subject: [PATCH 3/9] fix: Add more ifdefs for php-8.2.0 5 | 6 | 43.3% ext/standard/ 7 | 56.6% main/ 8 | 9 | 43.3% ext/standard/ 10 | 56.6% main/ 11 | diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h 12 | index a5b7b9a0..adacedd9 100644 13 | --- a/ext/standard/basic_functions_arginfo.h 14 | +++ b/ext/standard/basic_functions_arginfo.h 15 | @@ -3634,6 +3634,7 @@ static void register_basic_functions_symbols(int module_number) 16 | REGISTER_LONG_CONSTANT("IMAGETYPE_AVIF", IMAGE_FILETYPE_AVIF, CONST_PERSISTENT); 17 | REGISTER_LONG_CONSTANT("IMAGETYPE_UNKNOWN", IMAGE_FILETYPE_UNKNOWN, CONST_PERSISTENT); 18 | REGISTER_LONG_CONSTANT("IMAGETYPE_COUNT", IMAGE_FILETYPE_COUNT, CONST_PERSISTENT); 19 | +#ifndef __wasi__ 20 | REGISTER_LONG_CONSTANT("LOG_EMERG", LOG_EMERG, CONST_PERSISTENT); 21 | REGISTER_LONG_CONSTANT("LOG_ALERT", LOG_ALERT, CONST_PERSISTENT); 22 | REGISTER_LONG_CONSTANT("LOG_CRIT", LOG_CRIT, CONST_PERSISTENT); 23 | @@ -3695,6 +3696,7 @@ static void register_basic_functions_symbols(int module_number) 24 | #if defined(LOG_PERROR) 25 | REGISTER_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_PERSISTENT); 26 | #endif 27 | +#endif // __wasi__ 28 | REGISTER_LONG_CONSTANT("STR_PAD_LEFT", PHP_STR_PAD_LEFT, CONST_PERSISTENT); 29 | REGISTER_LONG_CONSTANT("STR_PAD_RIGHT", PHP_STR_PAD_RIGHT, CONST_PERSISTENT); 30 | REGISTER_LONG_CONSTANT("STR_PAD_BOTH", PHP_STR_PAD_BOTH, CONST_PERSISTENT); 31 | diff --git a/main/network.c b/main/network.c 32 | index 6fb97865..683e11d0 100644 33 | --- a/main/network.c 34 | +++ b/main/network.c 35 | @@ -929,7 +929,9 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short 36 | #ifdef IP_BIND_ADDRESS_NO_PORT 37 | { 38 | int val = 1; 39 | +#ifndef __wasi__ 40 | (void) setsockopt(sock, SOL_IP, IP_BIND_ADDRESS_NO_PORT, &val, sizeof(val)); 41 | +#endif // !defined(__wasi__)o 42 | } 43 | #endif 44 | if (local_address_len == 0) { 45 | -- 46 | 2.38.1 47 | 48 | -------------------------------------------------------------------------------- /php/v8.2.0/patches/0004-fix-Fix-memory-issues-and-introduce-WASM_WASMEDGE.patch: -------------------------------------------------------------------------------- 1 | From 71de1e422175e7819d7f2c5dac76879b4e6f549c Mon Sep 17 00:00:00 2001 2 | From: "no-reply@wasmlabs.dev" 3 | Date: Fri, 6 Jan 2023 11:21:03 +0200 4 | Subject: [PATCH 4/9] fix: Fix memory issues and introduce WASM_WASMEDGE. 5 | 6 | 76.4% Zend/ 7 | 11.4% ext/posix/ 8 | 12.1% ext/standard/ 9 | 10 | 76.4% Zend/ 11 | 11.4% ext/posix/ 12 | 12.1% ext/standard/ 13 | diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c 14 | index 5e67345c..258766a5 100644 15 | --- a/Zend/zend_alloc.c 16 | +++ b/Zend/zend_alloc.c 17 | @@ -465,8 +465,8 @@ static void *zend_mm_mmap(size_t size) 18 | } 19 | return ptr; 20 | #elif ! HAVE_MMAP 21 | - void* ptr = malloc(size); 22 | - memset(ptr, 0, size); 23 | + void* ptr = malloc(size + ZEND_MMAP_AHEAD); 24 | + memset(ptr, 0, size + ZEND_MMAP_AHEAD); 25 | return ptr; 26 | #else 27 | void *ptr; 28 | @@ -697,8 +697,8 @@ static zend_always_inline void zend_mm_hugepage(void* ptr, size_t size) 29 | static void *zend_mm_chunk_alloc_int(size_t size, size_t alignment) 30 | { 31 | #if ! HAVE_MMAP 32 | - void* ptr = aligned_alloc(alignment, size); 33 | - memset(ptr, 0, size); 34 | + void* ptr = aligned_alloc(alignment, size + ZEND_MMAP_AHEAD); 35 | + memset(ptr, 0, size + ZEND_MMAP_AHEAD); 36 | return ptr; 37 | #else 38 | void *ptr = zend_mm_mmap(size); 39 | diff --git a/ext/posix/posix.c b/ext/posix/posix.c 40 | index 49806f2c..c5e5c4a0 100644 41 | --- a/ext/posix/posix.c 42 | +++ b/ext/posix/posix.c 43 | @@ -536,8 +536,12 @@ PHP_FUNCTION(posix_ttyname) 44 | RETURN_FALSE; 45 | } 46 | #endif 47 | +#else 48 | + p = emalloc(1); 49 | + *p = '\0'; 50 | #endif // WASM_WASI 51 | RETURN_STRING(""); 52 | + efree(p); 53 | } 54 | /* }}} */ 55 | 56 | diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c 57 | index e3e443b4..d367dd8e 100755 58 | --- a/ext/standard/basic_functions.c 59 | +++ b/ext/standard/basic_functions.c 60 | @@ -70,6 +70,8 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; 61 | #else 62 | #include "win32/inet.h" 63 | #endif 64 | +#elif defined(WASM_WASMEDGE) 65 | +# include 66 | #endif // WASM_WASI 67 | 68 | #ifdef HAVE_ARPA_INET_H 69 | -- 70 | 2.38.1 71 | 72 | -------------------------------------------------------------------------------- /php/v8.2.0/patches/0006-fix-Avoid-include-syslog.h-since-it-is-not-part-of-w.patch: -------------------------------------------------------------------------------- 1 | From 04142da98d41af8fca66d2447939e4e2be0f3f71 Mon Sep 17 00:00:00 2001 2 | From: =?UTF-8?q?Jesu=CC=81s=20Gonza=CC=81lez?= 3 | Date: Tue, 14 Feb 2023 19:09:34 +0100 4 | Subject: [PATCH 6/9] fix: Avoid `#include ` since it is not part of 5 | wasi-libc 6 | 7 | 8 | 100.0% ext/gd/libgd/ 9 | diff --git a/ext/gd/libgd/gd_errors.h b/ext/gd/libgd/gd_errors.h 10 | index 8a28bf60..e84cef45 100644 11 | --- a/ext/gd/libgd/gd_errors.h 12 | +++ b/ext/gd/libgd/gd_errors.h 13 | @@ -1,11 +1,13 @@ 14 | #ifndef GD_ERRORS_H 15 | #define GD_ERRORS_H 16 | 17 | -#ifndef _WIN32 18 | -# include 19 | -#else 20 | -# include "win32/syslog.h" 21 | -#endif 22 | +#ifndef __wasi__ 23 | + #ifndef _WIN32 24 | + # include 25 | + #else 26 | + # include "win32/syslog.h" 27 | + #endif 28 | +#endif /* __wasi__ */ 29 | 30 | /* 31 | LOG_EMERG system is unusable 32 | -- 33 | 2.38.1 34 | 35 | -------------------------------------------------------------------------------- /php/v8.2.0/patches/0008-fix-Avoid-tmpfile-in-gd_bmp.patch: -------------------------------------------------------------------------------- 1 | From ee153bf8366c87f7c1ebf03c8c96277cc3cab55a Mon Sep 17 00:00:00 2001 2 | From: =?UTF-8?q?Jesu=CC=81s=20Gonza=CC=81lez?= 3 | Date: Tue, 14 Feb 2023 22:01:33 +0100 4 | Subject: [PATCH 8/9] fix: Avoid tmpfile() in `gd_bmp` 5 | 6 | 7 | 100.0% ext/gd/libgd/ 8 | diff --git a/ext/gd/libgd/gd_bmp.c b/ext/gd/libgd/gd_bmp.c 9 | index 00903d5f..b7a9121d 100644 10 | --- a/ext/gd/libgd/gd_bmp.c 11 | +++ b/ext/gd/libgd/gd_bmp.c 12 | @@ -102,9 +102,15 @@ void gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression) 13 | compression = 0; 14 | } 15 | 16 | - if (compression == 1 && !out->seek) { 17 | + if (compression == 1 && !out->seek) { 18 | /* Try to create a temp file where we can seek */ 19 | - if ((tmpfile_for_compression = tmpfile()) == NULL) { 20 | + if ((tmpfile_for_compression = 21 | +#ifdef __wasi__ 22 | + NULL 23 | +#else 24 | + tmpfile() 25 | +#endif /* __wasi__ */ 26 | + ) == NULL) { 27 | compression = 0; 28 | } else { 29 | out_original = out; 30 | -- 31 | 2.38.1 32 | 33 | -------------------------------------------------------------------------------- /php/v8.2.0/patches/0009-fix-Avoid-jmp_buf-in-gd_jpeg.patch: -------------------------------------------------------------------------------- 1 | From afc998235d9f81a8790875a41248e71575ecb597 Mon Sep 17 00:00:00 2001 2 | From: "no-reply@wasmlabs.dev" 3 | Date: Wed, 8 Mar 2023 10:45:26 +0200 4 | Subject: [PATCH 9/9] fix: Avoid 'jmp_buf' in 'gd_jpeg' 5 | 6 | 7 | 100.0% ext/gd/libgd/ 8 | diff --git a/ext/gd/libgd/gd_jpeg.c b/ext/gd/libgd/gd_jpeg.c 9 | index f3aa6959..d9d613a3 100644 10 | --- a/ext/gd/libgd/gd_jpeg.c 11 | +++ b/ext/gd/libgd/gd_jpeg.c 12 | @@ -45,7 +45,9 @@ static const char *const GD_JPEG_VERSION = "1.0"; 13 | 14 | typedef struct _jmpbuf_wrapper 15 | { 16 | +#ifndef __wasi__ 17 | jmp_buf jmpbuf; 18 | +#endif // __wasi__ 19 | int ignore_warning; 20 | } jmpbuf_wrapper; 21 | 22 | -- 23 | 2.38.1 24 | 25 | -------------------------------------------------------------------------------- /php/v8.2.0/patches/0010-chore-Add-more-logs-in-wasi_socket_ext.patch: -------------------------------------------------------------------------------- 1 | From abac8566212b39d58a519240f2af2c374947e312 Mon Sep 17 00:00:00 2001 2 | From: Asen Alexandrov 3 | Date: Thu, 30 Mar 2023 09:29:55 +0300 4 | Subject: [PATCH 10/15] chore: Add more logs in wasi_socket_ext 5 | 6 | 100.0% wasmedge_stubs/ 7 | 8 | 100.0% wasmedge_stubs/ 9 | diff --git a/wasmedge_stubs/wasi_socket_ext.c b/wasmedge_stubs/wasi_socket_ext.c 10 | index 0c74c75a..5a2a3d26 100644 11 | --- a/wasmedge_stubs/wasi_socket_ext.c 12 | +++ b/wasmedge_stubs/wasi_socket_ext.c 13 | @@ -184,6 +184,7 @@ int32_t __imported_wasmedge_wasi_snapshot_preview1_sock_setsockopt( 14 | 15 | int socket(int domain, int type, int protocol) 16 | { 17 | + WSEDEBUG("WWSock| socket called: %d, %d, %d \n", domain, type, protocol); 18 | int fd; 19 | address_family_t af = (domain == AF_INET ? kInet4 : kInet6); 20 | socket_type_t st = (type == SOCK_STREAM ? kStream : kDatagram); 21 | @@ -191,6 +192,7 @@ int socket(int domain, int type, int protocol) 22 | if (0 != res) { 23 | errno = res; 24 | printf("socket err: %s \n", strerror(errno)); 25 | + WSEDEBUG("WWSock| socket failed with error: %s \n", strerror(errno)); 26 | return -1; 27 | } 28 | WSEDEBUG("WWSock| socket returning: %d \n", fd); 29 | @@ -271,8 +273,10 @@ int accept(int fd, struct sockaddr *restrict addr, socklen_t *restrict len) { 30 | fd, (uint32_t *)&new_sockfd); 31 | if (res != 0) { 32 | errno = res; 33 | + WSEDEBUG("WWSock| accept[%d]: failed=%d\n", __LINE__, errno); 34 | return -1; 35 | } 36 | + WSEDEBUG("WWSock| accept[%d]: client_fd=%d\n", __LINE__, new_sockfd); 37 | return new_sockfd; 38 | } 39 | 40 | -- 41 | 2.38.1 42 | 43 | -------------------------------------------------------------------------------- /php/v8.2.0/patches/0014-fix-implicit-function-declaration-in-syslog.patch: -------------------------------------------------------------------------------- 1 | From c681c872176a665656fa8d982bc17a66edbf09b4 Mon Sep 17 00:00:00 2001 2 | From: Asen Alexandrov 3 | Date: Wed, 5 Apr 2023 11:55:31 +0300 4 | Subject: [PATCH 14/15] fix: implicit-function-declaration in syslog 5 | 6 | 7 | 100.0% main/ 8 | diff --git a/main/php_syslog.c b/main/php_syslog.c 9 | index 68c7aac7..a1d6a23c 100644 10 | --- a/main/php_syslog.c 11 | +++ b/main/php_syslog.c 12 | @@ -32,6 +32,12 @@ 13 | #define syslog std_syslog 14 | #endif 15 | 16 | +#ifdef __wasi__ 17 | +#define syslog(...) 18 | +#define openlog(...) 19 | +#define closelog() 20 | +#endif 21 | + 22 | PHPAPI void php_syslog_str(int priority, const zend_string* message) 23 | { 24 | smart_string sbuf = {0}; 25 | -- 26 | 2.38.1 27 | 28 | -------------------------------------------------------------------------------- /php/v8.2.0/patches/0016-fix-implicit-function-declaration-for-bind-when-not-.patch: -------------------------------------------------------------------------------- 1 | From bc71c214b3296801741993748818ac112c424fe6 Mon Sep 17 00:00:00 2001 2 | From: "no-reply@wasmlabs.dev" 3 | Date: Fri, 7 Apr 2023 08:51:02 +0300 4 | Subject: [PATCH 16/16] fix: implicit-function-declaration for bind when not on 5 | a wasmedge build 6 | 7 | 8 | 100.0% main/ 9 | diff --git a/main/network.c b/main/network.c 10 | index bb39f27e..3c7b9be3 100644 11 | --- a/main/network.c 12 | +++ b/main/network.c 13 | @@ -836,6 +836,9 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short 14 | int *error_code, const char *bindto, unsigned short bindport, long sockopts 15 | ) 16 | { 17 | +#if defined(__wasi__) && !defined(WASM_RUNTIME_WASMEDGE) 18 | + return -1; 19 | +#else 20 | int num_addrs, n, fatal = 0; 21 | php_socket_t sock; 22 | struct sockaddr **sal, **psal, *sa; 23 | @@ -940,7 +943,7 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short 24 | int val = 1; 25 | #ifndef __wasi__ 26 | (void) setsockopt(sock, SOL_IP, IP_BIND_ADDRESS_NO_PORT, &val, sizeof(val)); 27 | -#endif // !defined(__wasi__)o 28 | +#endif // __wasi__ 29 | } 30 | #endif 31 | if (local_address_len == 0) { 32 | @@ -1021,6 +1024,7 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short 33 | php_network_freeaddresses(psal); 34 | 35 | return sock; 36 | +#endif // __wasi__ 37 | } 38 | /* }}} */ 39 | 40 | -- 41 | 2.38.1 42 | 43 | -------------------------------------------------------------------------------- /php/v8.2.0/patches/0017-fix-is_writable-with-stat-bypass.patch: -------------------------------------------------------------------------------- 1 | From d29ed6b1e87e18e437829bee97c6aa93f4999c3f Mon Sep 17 00:00:00 2001 2 | From: =?UTF-8?q?Jesu=CC=81s=20Gonza=CC=81lez?= 3 | Date: Wed, 12 Apr 2023 18:01:06 +0200 4 | Subject: [PATCH] fix: Patch for `is_readable()` and `is_writable()` to bypass 5 | WASI preview1 limitations with stating files 6 | 7 | --- 8 | ext/standard/filestat.c | 9 +++++++++ 9 | 1 file changed, 9 insertions(+) 10 | 11 | diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c 12 | index 2fdb9d76..6eddeb15 100644 13 | --- a/ext/standard/filestat.c 14 | +++ b/ext/standard/filestat.c 15 | @@ -950,12 +950,21 @@ PHPAPI void php_stat(zend_string *filename, int type, zval *return_value) 16 | } 17 | php_error_docref(NULL, E_NOTICE, "Unknown file type (%d)", ssb.sb.st_mode&S_IFMT); 18 | RETURN_STRING("unknown"); 19 | +#ifndef __wasi__ 20 | case FS_IS_W: 21 | RETURN_BOOL((ssb.sb.st_mode & wmask) != 0); 22 | case FS_IS_R: 23 | RETURN_BOOL((ssb.sb.st_mode&rmask)!=0); 24 | case FS_IS_X: 25 | RETURN_BOOL((ssb.sb.st_mode&xmask)!=0); 26 | +#else 27 | + case FS_IS_W: 28 | + RETURN_TRUE; 29 | + case FS_IS_R: 30 | + RETURN_TRUE; 31 | + case FS_IS_X: 32 | + RETURN_TRUE; 33 | +#endif /* __wasi__ */ 34 | case FS_IS_FILE: 35 | RETURN_BOOL(S_ISREG(ssb.sb.st_mode)); 36 | case FS_IS_DIR: 37 | -- 38 | 2.39.1 39 | 40 | -------------------------------------------------------------------------------- /php/v8.2.0/patches/0018-fix-random_bytes-failing-on-Windows.patch: -------------------------------------------------------------------------------- 1 | From 0b6d3fa928f5c6f0b77c5c77ca771a0260f2e8a4 Mon Sep 17 00:00:00 2001 2 | From: "no-reply@wasmlabs.dev" 3 | Date: Thu, 13 Apr 2023 10:21:04 +0200 4 | Subject: [PATCH 18/18] fix random_bytes failing on Windows 5 | 6 | 7 | 100.0% ext/random/ 8 | diff --git a/ext/random/random.c b/ext/random/random.c 9 | index 161eb8e6..12f431ca 100644 10 | --- a/ext/random/random.c 11 | +++ b/ext/random/random.c 12 | @@ -510,7 +510,7 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw) 13 | #else 14 | size_t read_bytes = 0; 15 | ssize_t n; 16 | -# if (defined(__linux__) && defined(SYS_getrandom)) || (defined(__FreeBSD__) && __FreeBSD_version >= 1200000) || (defined(__DragonFly__) && __DragonFly_version >= 500700) || defined(__sun) 17 | +# if (defined(__linux__) && defined(SYS_getrandom)) || (defined(__FreeBSD__) && __FreeBSD_version >= 1200000) || (defined(__DragonFly__) && __DragonFly_version >= 500700) || defined(__sun) || defined(__wasi__) 18 | /* Linux getrandom(2) syscall or FreeBSD/DragonFlyBSD getrandom(2) function*/ 19 | /* Keep reading until we get enough entropy */ 20 | while (read_bytes < size) { 21 | @@ -527,6 +527,14 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw) 22 | size_t amount_to_read = size - read_bytes; 23 | # if defined(__linux__) 24 | n = syscall(SYS_getrandom, bytes + read_bytes, amount_to_read, 0); 25 | +# elif defined(__wasi__) 26 | + // getentropy always reads the amount requested on success (0) 27 | + // and returns -1 otherwise 28 | + if (getentropy(bytes + read_bytes, amount_to_read) == 0) { 29 | + n = amount_to_read; 30 | + } else { 31 | + n = -1; 32 | + } 33 | # else 34 | n = getrandom(bytes + read_bytes, amount_to_read, 0); 35 | # endif 36 | @@ -560,7 +568,7 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw) 37 | 38 | if (fd < 0) { 39 | errno = 0; 40 | -# if HAVE_DEV_URANDOM 41 | +# if defined(HAVE_DEV_URANDOM) && !defined(__wasi__) 42 | fd = open("/dev/urandom", O_RDONLY); 43 | # endif 44 | if (fd < 0) { 45 | -- 46 | 2.40.0 47 | 48 | -------------------------------------------------------------------------------- /php/v8.2.0/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | return 11 | fi 12 | 13 | export WLR_REPO=https://github.com/php/php-src.git 14 | export WLR_REPO_BRANCH=php-8.2.0 15 | export WLR_ENV_NAME=php/php-8.2.0 16 | export WLR_PACKAGE_VERSION=8.2.0 17 | export WLR_PACKAGE_NAME=php 18 | -------------------------------------------------------------------------------- /php/v8.2.0/wlr-info.json: -------------------------------------------------------------------------------- 1 | { 2 | "deps": { 3 | "zlib": { 4 | "build_target": "libs/zlib/v1.2.13", 5 | "required_file": "lib/wasm32-wasi/libz.a", 6 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Fzlib%2F1.2.13%2B20230623-2993864/libz-1.2.13-wasi-sdk-20.0.tar.gz" 7 | }, 8 | "libpng": { 9 | "build_target": "libs/libpng/v1.6.39", 10 | "required_file": "lib/wasm32-wasi/libpng16.a", 11 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Flibpng%2F1.6.39%2B20230629-ccb4cb0/libpng-1.6.39-wasi-sdk-20.0.tar.gz" 12 | }, 13 | "libjpeg": { 14 | "build_target": "libs/libjpeg/v2.1.5.1", 15 | "required_file": "lib/wasm32-wasi/libjpeg.a", 16 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Flibjpeg%2F2.1.5.1%2B20230623-2993864/libjpeg-2.1.5.1-wasi-sdk-20.0.tar.gz" 17 | }, 18 | "libxml2": { 19 | "build_target": "libs/libxml2/v2.11.4", 20 | "required_file": "lib/wasm32-wasi/libxml2.a", 21 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Flibxml2%2F2.11.4%2B20230623-2993864/libxml2-2.11.4-wasi-sdk-20.0.tar.gz" 22 | }, 23 | "oniguruma": { 24 | "build_target": "libs/oniguruma/v6.9.8", 25 | "required_file": "lib/wasm32-wasi/libonig.a", 26 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Foniguruma%2F6.9.8%2B20230623-2993864/libonig-6.9.8-wasi-sdk-20.0.tar.gz" 27 | }, 28 | "SQLite": { 29 | "build_target": "libs/sqlite/v3.42.0", 30 | "required_file": "lib/wasm32-wasi/libsqlite3.a", 31 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Fsqlite%2F3.42.0%2B20230623-2993864/libsqlite-3.42.0-wasi-sdk-20.0.tar.gz" 32 | } 33 | }, 34 | "flavors": { 35 | "slim": { 36 | "deps": {} 37 | } 38 | } 39 | } -------------------------------------------------------------------------------- /php/v8.2.0/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="php/8.2.0" 2 | -------------------------------------------------------------------------------- /php/v8.2.0/wlr-test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | if ! [ -x "$(command -v php)" ] 10 | then 11 | echo "Native php is required in PATH on the host to act as orchestrator for php.wasm tests!" 12 | exit 1 13 | fi 14 | 15 | if [[ "${WLR_BUILD_FLAVOR}" == *"wasmedge"* ]] 16 | then 17 | WLR_BINARY_WUFFIX=-wasmedge 18 | fi 19 | 20 | if [ -f "${WLR_OUTPUT}/bin/php${WLR_BINARY_WUFFIX}" ] 21 | then 22 | export WLR_TESTED_MODULE="${WLR_OUTPUT}/bin/php${WLR_BINARY_WUFFIX}.wasm" 23 | else 24 | export WLR_TESTED_MODULE="${WLR_OUTPUT}/bin/php-cgi${WLR_BINARY_WUFFIX}.wasm" 25 | fi 26 | 27 | if ! [ -f "${WLR_TESTED_MODULE}" ] 28 | then 29 | echo "WASM module not found at '${WLR_TESTED_MODULE}'" 30 | exit 1 31 | fi 32 | 33 | cd "${WLR_SOURCE_PATH}" 34 | echo "Calling 'WLR_TESTED_MODULE=${WLR_TESTED_MODULE} php -f run-tests.php -- -p ${WLR_TEST_RUNTIME_WRAPPER} -j6' to run tests..." 35 | php -f run-tests.php -- -p ${WLR_TEST_RUNTIME_WRAPPER} -j6 \ 36 | tests/lang \ 37 | tests/output \ 38 | tests/strings \ 39 | Zend/tests/fibers 40 | -------------------------------------------------------------------------------- /php/v8.2.6/patches/0003-fix-Add-more-ifdefs-for-php-8.2.0.patch: -------------------------------------------------------------------------------- 1 | From a6741ecf983131d31c3f70d5c96c3127c5af1aef Mon Sep 17 00:00:00 2001 2 | From: "no-reply@wasmlabs.dev" 3 | Date: Fri, 6 Jan 2023 11:04:53 +0200 4 | Subject: [PATCH 03/18] fix: Add more ifdefs for php-8.2.0 5 | 6 | 43.3% ext/standard/ 7 | 56.6% main/ 8 | 9 | 43.3% ext/standard/ 10 | 56.6% main/ 11 | 12 | 43.3% ext/standard/ 13 | 56.6% main/ 14 | diff --git a/ext/standard/basic_functions_arginfo.h b/ext/standard/basic_functions_arginfo.h 15 | index d7eb83b5569..ffe3f0b1ece 100644 16 | --- a/ext/standard/basic_functions_arginfo.h 17 | +++ b/ext/standard/basic_functions_arginfo.h 18 | @@ -3634,6 +3634,7 @@ static void register_basic_functions_symbols(int module_number) 19 | REGISTER_LONG_CONSTANT("IMAGETYPE_AVIF", IMAGE_FILETYPE_AVIF, CONST_PERSISTENT); 20 | REGISTER_LONG_CONSTANT("IMAGETYPE_UNKNOWN", IMAGE_FILETYPE_UNKNOWN, CONST_PERSISTENT); 21 | REGISTER_LONG_CONSTANT("IMAGETYPE_COUNT", IMAGE_FILETYPE_COUNT, CONST_PERSISTENT); 22 | +#ifndef __wasi__ 23 | REGISTER_LONG_CONSTANT("LOG_EMERG", LOG_EMERG, CONST_PERSISTENT); 24 | REGISTER_LONG_CONSTANT("LOG_ALERT", LOG_ALERT, CONST_PERSISTENT); 25 | REGISTER_LONG_CONSTANT("LOG_CRIT", LOG_CRIT, CONST_PERSISTENT); 26 | @@ -3695,6 +3696,7 @@ static void register_basic_functions_symbols(int module_number) 27 | #if defined(LOG_PERROR) 28 | REGISTER_LONG_CONSTANT("LOG_PERROR", LOG_PERROR, CONST_PERSISTENT); 29 | #endif 30 | +#endif // __wasi__ 31 | REGISTER_LONG_CONSTANT("STR_PAD_LEFT", PHP_STR_PAD_LEFT, CONST_PERSISTENT); 32 | REGISTER_LONG_CONSTANT("STR_PAD_RIGHT", PHP_STR_PAD_RIGHT, CONST_PERSISTENT); 33 | REGISTER_LONG_CONSTANT("STR_PAD_BOTH", PHP_STR_PAD_BOTH, CONST_PERSISTENT); 34 | diff --git a/main/network.c b/main/network.c 35 | index 6fb97865cb7..683e11d03d6 100644 36 | --- a/main/network.c 37 | +++ b/main/network.c 38 | @@ -929,7 +929,9 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short 39 | #ifdef IP_BIND_ADDRESS_NO_PORT 40 | { 41 | int val = 1; 42 | +#ifndef __wasi__ 43 | (void) setsockopt(sock, SOL_IP, IP_BIND_ADDRESS_NO_PORT, &val, sizeof(val)); 44 | +#endif // !defined(__wasi__)o 45 | } 46 | #endif 47 | if (local_address_len == 0) { 48 | -- 49 | 2.38.1 50 | 51 | -------------------------------------------------------------------------------- /php/v8.2.6/patches/0004-fix-Fix-memory-issues-and-introduce-WASM_WASMEDGE.patch: -------------------------------------------------------------------------------- 1 | From bf357d349d3c9075c4c38f7146298cf77e91ce26 Mon Sep 17 00:00:00 2001 2 | From: "no-reply@wasmlabs.dev" 3 | Date: Fri, 6 Jan 2023 11:21:03 +0200 4 | Subject: [PATCH 04/18] fix: Fix memory issues and introduce WASM_WASMEDGE. 5 | 6 | 76.4% Zend/ 7 | 11.4% ext/posix/ 8 | 12.1% ext/standard/ 9 | 10 | 76.4% Zend/ 11 | 11.4% ext/posix/ 12 | 12.1% ext/standard/ 13 | 14 | 86.2% Zend/ 15 | 13.7% ext/standard/ 16 | diff --git a/Zend/zend_alloc.c b/Zend/zend_alloc.c 17 | index 3f71eb22a32..c0184439fa4 100644 18 | --- a/Zend/zend_alloc.c 19 | +++ b/Zend/zend_alloc.c 20 | @@ -513,8 +513,8 @@ static void *zend_mm_mmap(size_t size) 21 | } 22 | return ptr; 23 | #elif ! HAVE_MMAP 24 | - void* ptr = malloc(size); 25 | - memset(ptr, 0, size); 26 | + void* ptr = malloc(size + ZEND_MMAP_AHEAD); 27 | + memset(ptr, 0, size + ZEND_MMAP_AHEAD); 28 | return ptr; 29 | #else 30 | void *ptr; 31 | @@ -726,8 +726,8 @@ static zend_always_inline void zend_mm_hugepage(void* ptr, size_t size) 32 | static void *zend_mm_chunk_alloc_int(size_t size, size_t alignment) 33 | { 34 | #if ! HAVE_MMAP 35 | - void* ptr = aligned_alloc(alignment, size); 36 | - memset(ptr, 0, size); 37 | + void* ptr = aligned_alloc(alignment, size + ZEND_MMAP_AHEAD); 38 | + memset(ptr, 0, size + ZEND_MMAP_AHEAD); 39 | return ptr; 40 | #else 41 | void *ptr = zend_mm_mmap(size); 42 | diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c 43 | index ad88b7b3a2e..82409e2377a 100755 44 | --- a/ext/standard/basic_functions.c 45 | +++ b/ext/standard/basic_functions.c 46 | @@ -70,6 +70,8 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; 47 | #else 48 | #include "win32/inet.h" 49 | #endif 50 | +#elif defined(WASM_WASMEDGE) 51 | +# include 52 | #endif // WASM_WASI 53 | 54 | #ifdef HAVE_ARPA_INET_H 55 | -- 56 | 2.38.1 57 | 58 | -------------------------------------------------------------------------------- /php/v8.2.6/patches/0006-fix-Avoid-include-syslog.h-since-it-is-not-part-of-w.patch: -------------------------------------------------------------------------------- 1 | From 547ab191f123a4a7cf157bf0e20a5eb4ae4222b9 Mon Sep 17 00:00:00 2001 2 | From: =?UTF-8?q?Jesu=CC=81s=20Gonza=CC=81lez?= 3 | Date: Tue, 14 Feb 2023 19:09:34 +0100 4 | Subject: [PATCH 06/18] fix: Avoid `#include ` since it is not part 5 | of wasi-libc 6 | 7 | 100.0% ext/gd/libgd/ 8 | 9 | 100.0% ext/gd/libgd/ 10 | diff --git a/ext/gd/libgd/gd_errors.h b/ext/gd/libgd/gd_errors.h 11 | index 8a28bf60519..e84cef4578b 100644 12 | --- a/ext/gd/libgd/gd_errors.h 13 | +++ b/ext/gd/libgd/gd_errors.h 14 | @@ -1,11 +1,13 @@ 15 | #ifndef GD_ERRORS_H 16 | #define GD_ERRORS_H 17 | 18 | -#ifndef _WIN32 19 | -# include 20 | -#else 21 | -# include "win32/syslog.h" 22 | -#endif 23 | +#ifndef __wasi__ 24 | + #ifndef _WIN32 25 | + # include 26 | + #else 27 | + # include "win32/syslog.h" 28 | + #endif 29 | +#endif /* __wasi__ */ 30 | 31 | /* 32 | LOG_EMERG system is unusable 33 | -- 34 | 2.38.1 35 | 36 | -------------------------------------------------------------------------------- /php/v8.2.6/patches/0008-fix-Avoid-tmpfile-in-gd_bmp.patch: -------------------------------------------------------------------------------- 1 | From bb7f3d60d80d938869d0e3a9c8ab5d58b8ff9f6f Mon Sep 17 00:00:00 2001 2 | From: =?UTF-8?q?Jesu=CC=81s=20Gonza=CC=81lez?= 3 | Date: Tue, 14 Feb 2023 22:01:33 +0100 4 | Subject: [PATCH 08/18] fix: Avoid tmpfile() in `gd_bmp` 5 | 6 | 100.0% ext/gd/libgd/ 7 | 8 | 100.0% ext/gd/libgd/ 9 | diff --git a/ext/gd/libgd/gd_bmp.c b/ext/gd/libgd/gd_bmp.c 10 | index 00903d5ff8d..b7a9121d15a 100644 11 | --- a/ext/gd/libgd/gd_bmp.c 12 | +++ b/ext/gd/libgd/gd_bmp.c 13 | @@ -102,9 +102,15 @@ void gdImageBmpCtx(gdImagePtr im, gdIOCtxPtr out, int compression) 14 | compression = 0; 15 | } 16 | 17 | - if (compression == 1 && !out->seek) { 18 | + if (compression == 1 && !out->seek) { 19 | /* Try to create a temp file where we can seek */ 20 | - if ((tmpfile_for_compression = tmpfile()) == NULL) { 21 | + if ((tmpfile_for_compression = 22 | +#ifdef __wasi__ 23 | + NULL 24 | +#else 25 | + tmpfile() 26 | +#endif /* __wasi__ */ 27 | + ) == NULL) { 28 | compression = 0; 29 | } else { 30 | out_original = out; 31 | -- 32 | 2.38.1 33 | 34 | -------------------------------------------------------------------------------- /php/v8.2.6/patches/0009-fix-Avoid-jmp_buf-in-gd_jpeg.patch: -------------------------------------------------------------------------------- 1 | From b1d7bc69013a079a2df2d1c774df11d9cdbbd1a0 Mon Sep 17 00:00:00 2001 2 | From: "no-reply@wasmlabs.dev" 3 | Date: Wed, 8 Mar 2023 10:45:26 +0200 4 | Subject: [PATCH 09/18] fix: Avoid 'jmp_buf' in 'gd_jpeg' 5 | 6 | 100.0% ext/gd/libgd/ 7 | 8 | 100.0% ext/gd/libgd/ 9 | diff --git a/ext/gd/libgd/gd_jpeg.c b/ext/gd/libgd/gd_jpeg.c 10 | index f3aa695967c..d9d613a3bc8 100644 11 | --- a/ext/gd/libgd/gd_jpeg.c 12 | +++ b/ext/gd/libgd/gd_jpeg.c 13 | @@ -45,7 +45,9 @@ static const char *const GD_JPEG_VERSION = "1.0"; 14 | 15 | typedef struct _jmpbuf_wrapper 16 | { 17 | +#ifndef __wasi__ 18 | jmp_buf jmpbuf; 19 | +#endif // __wasi__ 20 | int ignore_warning; 21 | } jmpbuf_wrapper; 22 | 23 | -- 24 | 2.38.1 25 | 26 | -------------------------------------------------------------------------------- /php/v8.2.6/patches/0010-chore-Add-more-logs-in-wasi_socket_ext.patch: -------------------------------------------------------------------------------- 1 | From d1708155a319ff39788a7b9fbe6b84618b1c059a Mon Sep 17 00:00:00 2001 2 | From: Asen Alexandrov 3 | Date: Thu, 30 Mar 2023 09:29:55 +0300 4 | Subject: [PATCH 10/18] chore: Add more logs in wasi_socket_ext 5 | 6 | 100.0% wasmedge_stubs/ 7 | 8 | 100.0% wasmedge_stubs/ 9 | 10 | 100.0% wasmedge_stubs/ 11 | diff --git a/wasmedge_stubs/wasi_socket_ext.c b/wasmedge_stubs/wasi_socket_ext.c 12 | index 0c74c75a5ec..5a2a3d26573 100644 13 | --- a/wasmedge_stubs/wasi_socket_ext.c 14 | +++ b/wasmedge_stubs/wasi_socket_ext.c 15 | @@ -184,6 +184,7 @@ int32_t __imported_wasmedge_wasi_snapshot_preview1_sock_setsockopt( 16 | 17 | int socket(int domain, int type, int protocol) 18 | { 19 | + WSEDEBUG("WWSock| socket called: %d, %d, %d \n", domain, type, protocol); 20 | int fd; 21 | address_family_t af = (domain == AF_INET ? kInet4 : kInet6); 22 | socket_type_t st = (type == SOCK_STREAM ? kStream : kDatagram); 23 | @@ -191,6 +192,7 @@ int socket(int domain, int type, int protocol) 24 | if (0 != res) { 25 | errno = res; 26 | printf("socket err: %s \n", strerror(errno)); 27 | + WSEDEBUG("WWSock| socket failed with error: %s \n", strerror(errno)); 28 | return -1; 29 | } 30 | WSEDEBUG("WWSock| socket returning: %d \n", fd); 31 | @@ -271,8 +273,10 @@ int accept(int fd, struct sockaddr *restrict addr, socklen_t *restrict len) { 32 | fd, (uint32_t *)&new_sockfd); 33 | if (res != 0) { 34 | errno = res; 35 | + WSEDEBUG("WWSock| accept[%d]: failed=%d\n", __LINE__, errno); 36 | return -1; 37 | } 38 | + WSEDEBUG("WWSock| accept[%d]: client_fd=%d\n", __LINE__, new_sockfd); 39 | return new_sockfd; 40 | } 41 | 42 | -- 43 | 2.38.1 44 | 45 | -------------------------------------------------------------------------------- /php/v8.2.6/patches/0014-fix-implicit-function-declaration-in-syslog.patch: -------------------------------------------------------------------------------- 1 | From 5addc7b01c06ea6d0af0ac4e6a7dfa50ade903b8 Mon Sep 17 00:00:00 2001 2 | From: Asen Alexandrov 3 | Date: Wed, 5 Apr 2023 11:55:31 +0300 4 | Subject: [PATCH 14/18] fix: implicit-function-declaration in syslog 5 | 6 | 100.0% main/ 7 | 8 | 100.0% main/ 9 | diff --git a/main/php_syslog.c b/main/php_syslog.c 10 | index 68c7aac7072..a1d6a23c92c 100644 11 | --- a/main/php_syslog.c 12 | +++ b/main/php_syslog.c 13 | @@ -32,6 +32,12 @@ 14 | #define syslog std_syslog 15 | #endif 16 | 17 | +#ifdef __wasi__ 18 | +#define syslog(...) 19 | +#define openlog(...) 20 | +#define closelog() 21 | +#endif 22 | + 23 | PHPAPI void php_syslog_str(int priority, const zend_string* message) 24 | { 25 | smart_string sbuf = {0}; 26 | -- 27 | 2.38.1 28 | 29 | -------------------------------------------------------------------------------- /php/v8.2.6/patches/0016-fix-implicit-function-declaration-for-bind-when-not-.patch: -------------------------------------------------------------------------------- 1 | From e4dc97b18b02098b21883132c3d07c883ad11c59 Mon Sep 17 00:00:00 2001 2 | From: "no-reply@wasmlabs.dev" 3 | Date: Fri, 7 Apr 2023 08:51:02 +0300 4 | Subject: [PATCH 16/18] fix: implicit-function-declaration for bind when not on 5 | a wasmedge build 6 | 7 | 100.0% main/ 8 | 9 | 100.0% main/ 10 | diff --git a/main/network.c b/main/network.c 11 | index bb39f27e04b..3c7b9be3e3e 100644 12 | --- a/main/network.c 13 | +++ b/main/network.c 14 | @@ -836,6 +836,9 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short 15 | int *error_code, const char *bindto, unsigned short bindport, long sockopts 16 | ) 17 | { 18 | +#if defined(__wasi__) && !defined(WASM_RUNTIME_WASMEDGE) 19 | + return -1; 20 | +#else 21 | int num_addrs, n, fatal = 0; 22 | php_socket_t sock; 23 | struct sockaddr **sal, **psal, *sa; 24 | @@ -940,7 +943,7 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short 25 | int val = 1; 26 | #ifndef __wasi__ 27 | (void) setsockopt(sock, SOL_IP, IP_BIND_ADDRESS_NO_PORT, &val, sizeof(val)); 28 | -#endif // !defined(__wasi__)o 29 | +#endif // __wasi__ 30 | } 31 | #endif 32 | if (local_address_len == 0) { 33 | @@ -1021,6 +1024,7 @@ php_socket_t php_network_connect_socket_to_host(const char *host, unsigned short 34 | php_network_freeaddresses(psal); 35 | 36 | return sock; 37 | +#endif // __wasi__ 38 | } 39 | /* }}} */ 40 | 41 | -- 42 | 2.38.1 43 | 44 | -------------------------------------------------------------------------------- /php/v8.2.6/patches/0017-fix-Patch-for-is_readable-and-is_writable-to-bypass-.patch: -------------------------------------------------------------------------------- 1 | From b87bd9c6bc1ee596da66eb1757bc3d3c8a2d371c Mon Sep 17 00:00:00 2001 2 | From: =?UTF-8?q?Jesu=CC=81s=20Gonza=CC=81lez?= 3 | Date: Wed, 12 Apr 2023 18:01:06 +0200 4 | Subject: [PATCH 17/18] fix: Patch for `is_readable()` and `is_writable()` to 5 | bypass WASI preview1 limitations with stating files 6 | 7 | 8 | 100.0% ext/standard/ 9 | diff --git a/ext/standard/filestat.c b/ext/standard/filestat.c 10 | index 2fdb9d765c6..6eddeb15a74 100644 11 | --- a/ext/standard/filestat.c 12 | +++ b/ext/standard/filestat.c 13 | @@ -950,12 +950,21 @@ PHPAPI void php_stat(zend_string *filename, int type, zval *return_value) 14 | } 15 | php_error_docref(NULL, E_NOTICE, "Unknown file type (%d)", ssb.sb.st_mode&S_IFMT); 16 | RETURN_STRING("unknown"); 17 | +#ifndef __wasi__ 18 | case FS_IS_W: 19 | RETURN_BOOL((ssb.sb.st_mode & wmask) != 0); 20 | case FS_IS_R: 21 | RETURN_BOOL((ssb.sb.st_mode&rmask)!=0); 22 | case FS_IS_X: 23 | RETURN_BOOL((ssb.sb.st_mode&xmask)!=0); 24 | +#else 25 | + case FS_IS_W: 26 | + RETURN_TRUE; 27 | + case FS_IS_R: 28 | + RETURN_TRUE; 29 | + case FS_IS_X: 30 | + RETURN_TRUE; 31 | +#endif /* __wasi__ */ 32 | case FS_IS_FILE: 33 | RETURN_BOOL(S_ISREG(ssb.sb.st_mode)); 34 | case FS_IS_DIR: 35 | -- 36 | 2.38.1 37 | 38 | -------------------------------------------------------------------------------- /php/v8.2.6/patches/0018-fix-random_bytes-failing-on-Windows.patch: -------------------------------------------------------------------------------- 1 | From 5ac48070ba9f27c2f3f02a39788406d13b0ec954 Mon Sep 17 00:00:00 2001 2 | From: "no-reply@wasmlabs.dev" 3 | Date: Thu, 13 Apr 2023 10:21:04 +0200 4 | Subject: [PATCH 18/18] fix random_bytes failing on Windows 5 | 6 | 100.0% ext/random/ 7 | 8 | 100.0% ext/random/ 9 | diff --git a/ext/random/random.c b/ext/random/random.c 10 | index dda57f0fe7d..687ab43a34c 100644 11 | --- a/ext/random/random.c 12 | +++ b/ext/random/random.c 13 | @@ -510,7 +510,7 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw) 14 | #else 15 | size_t read_bytes = 0; 16 | ssize_t n; 17 | -# if (defined(__linux__) && defined(SYS_getrandom)) || (defined(__FreeBSD__) && __FreeBSD_version >= 1200000) || (defined(__DragonFly__) && __DragonFly_version >= 500700) || defined(__sun) 18 | +# if (defined(__linux__) && defined(SYS_getrandom)) || (defined(__FreeBSD__) && __FreeBSD_version >= 1200000) || (defined(__DragonFly__) && __DragonFly_version >= 500700) || defined(__sun) || defined(__wasi__) 19 | /* Linux getrandom(2) syscall or FreeBSD/DragonFlyBSD getrandom(2) function*/ 20 | /* Keep reading until we get enough entropy */ 21 | while (read_bytes < size) { 22 | @@ -527,6 +527,14 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw) 23 | size_t amount_to_read = size - read_bytes; 24 | # if defined(__linux__) 25 | n = syscall(SYS_getrandom, bytes + read_bytes, amount_to_read, 0); 26 | +# elif defined(__wasi__) 27 | + // getentropy always reads the amount requested on success (0) 28 | + // and returns -1 otherwise 29 | + if (getentropy(bytes + read_bytes, amount_to_read) == 0) { 30 | + n = amount_to_read; 31 | + } else { 32 | + n = -1; 33 | + } 34 | # else 35 | n = getrandom(bytes + read_bytes, amount_to_read, 0); 36 | # endif 37 | @@ -560,7 +568,7 @@ PHPAPI int php_random_bytes(void *bytes, size_t size, bool should_throw) 38 | 39 | if (fd < 0) { 40 | errno = 0; 41 | -# if HAVE_DEV_URANDOM 42 | +# if defined(HAVE_DEV_URANDOM) && !defined(__wasi__) 43 | fd = open("/dev/urandom", O_RDONLY); 44 | # endif 45 | if (fd < 0) { 46 | -- 47 | 2.38.1 48 | 49 | -------------------------------------------------------------------------------- /php/v8.2.6/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | return 11 | fi 12 | 13 | export WLR_REPO=https://github.com/php/php-src.git 14 | export WLR_REPO_BRANCH=php-8.2.6 15 | export WLR_ENV_NAME=php/php-8.2.6 16 | export WLR_PACKAGE_VERSION=8.2.6 17 | export WLR_PACKAGE_NAME=php 18 | -------------------------------------------------------------------------------- /php/v8.2.6/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="php/8.2.6" 2 | -------------------------------------------------------------------------------- /php/v8.2.6/wlr-test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | if ! [ -x "$(command -v php)" ] 10 | then 11 | echo "Native php is required in PATH on the host to act as orchestrator for php.wasm tests!" 12 | exit 1 13 | fi 14 | 15 | if [[ "${WLR_BUILD_FLAVOR}" == *"wasmedge"* ]] 16 | then 17 | WLR_BINARY_WUFFIX=-wasmedge 18 | fi 19 | 20 | if [ -f "${WLR_OUTPUT}/bin/php${WLR_BINARY_WUFFIX}" ] 21 | then 22 | export WLR_TESTED_MODULE="${WLR_OUTPUT}/bin/php${WLR_BINARY_WUFFIX}.wasm" 23 | else 24 | export WLR_TESTED_MODULE="${WLR_OUTPUT}/bin/php-cgi${WLR_BINARY_WUFFIX}.wasm" 25 | fi 26 | 27 | if ! [ -f "${WLR_TESTED_MODULE}" ] 28 | then 29 | echo "WASM module not found at '${WLR_TESTED_MODULE}'" 30 | exit 1 31 | fi 32 | 33 | cd "${WLR_SOURCE_PATH}" 34 | echo "Calling 'WLR_TESTED_MODULE=${WLR_TESTED_MODULE} php -f run-tests.php -- -p ${WLR_TEST_RUNTIME_WRAPPER} -j6' to run tests..." 35 | php -f run-tests.php -- -p ${WLR_TEST_RUNTIME_WRAPPER} -j6 \ 36 | tests/lang \ 37 | tests/output \ 38 | tests/strings \ 39 | Zend/tests/fibers 40 | -------------------------------------------------------------------------------- /python/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG WASI_SDK_VERSION 2 | ARG PY_VERSIONS="3.12.0 3.11.4" 3 | ARG PY_DEFAULT_VERSION=3.12.0 4 | 5 | FROM ghcr.io/vmware-labs/wasmlabs/wasi-builder:${WASI_SDK_VERSION} 6 | ARG PY_VERSIONS 7 | ARG PY_DEFAULT_VERSION 8 | # If more capabilities are required from the python-builder, consult this 9 | # github workflow configuration for a list of possible dependencies - 10 | # https://github.com/python/cpython/blob/main/.github/workflows/posix-deps-apt.sh 11 | RUN DEBIAN_FRONTEND=noninteractive apt update && \ 12 | apt install -y --no-install-recommends \ 13 | libssl-dev \ 14 | tcl \ 15 | zlib1g-dev 16 | 17 | ENV HOME="/root" 18 | WORKDIR ${HOME} 19 | RUN git clone --depth=1 https://github.com/pyenv/pyenv.git .pyenv 20 | ENV PYENV_ROOT="${HOME}/.pyenv" 21 | ENV PATH="${PYENV_ROOT}/shims:${PYENV_ROOT}/bin:${PATH}" 22 | 23 | RUN pyenv install ${PY_VERSIONS} 24 | RUN pyenv global ${PY_DEFAULT_VERSION} 25 | 26 | WORKDIR /wlr 27 | -------------------------------------------------------------------------------- /python/Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) 2 | REPO_ROOT := $(ROOT_DIR).. 3 | 4 | include $(REPO_ROOT)/Makefile.helpers 5 | 6 | .PHONY: python-builder 7 | PYTHON_BUILDER_NAME := ghcr.io/vmware-labs/wasmlabs/python-builder:wasi-$(WASI_SDK_VERSION) 8 | python-builder: 9 | @$(call make_builder_image,$(PYTHON_BUILDER_NAME),$(ROOT_DIR),$(WASI_SDK_VERSION)) 10 | 11 | .PHONY: update-python-builder 12 | update-python-builder: python-builder 13 | @$(call push_container_image,$(PYTHON_BUILDER_NAME)) 14 | 15 | .PHONY: v* 16 | v*: 17 | @$(call build_in_container,$(PYTHON_BUILDER_NAME),$(REPO_ROOT),python/$@) 18 | 19 | .PHONY: clean 20 | clean: 21 | rm -rf $(REPO_ROOT)/build-output/python $(REPO_ROOT)/build-staging/python 22 | -------------------------------------------------------------------------------- /python/examples/.gitignore: -------------------------------------------------------------------------------- 1 | tmp 2 | -------------------------------------------------------------------------------- /python/examples/README.md: -------------------------------------------------------------------------------- 1 | This folder offers various examples of how to use Python in wasm modules. 2 | 3 | - [./basic](./basic/) is a collection of small snippets that demonstrate how to run `python.wasm` from the command line or via [Docker](https://docs.docker.com/get-docker/) 4 | - [./embedding/](./embedding/) shows how one can embed the static wasm32-wasi `libpython` into a WASI command module 5 | - [./bindings](./bindings/) is a sample application that demonstrates how one can use host-to-python and python-to-host bindings 6 | 7 | Note: `build.rs` does not have any download or performance optimization - the necessary `wasm32-wasi` dependencies are fetched and unpacked on each build run. 8 | -------------------------------------------------------------------------------- /python/examples/basic/workdir/emojize_text.py: -------------------------------------------------------------------------------- 1 | """ 2 | Sample script that replaces words with their emoji codes, 3 | if there are any. Depends on the `emoji` module. 4 | 5 | "The rabbit is eating a carrot." will be transformed to: 6 | "The 🐇 is eating a 🥕." 7 | 8 | Prints on stdout if no OUTPUT_FILE is given. 9 | 10 | Usage: 11 | emojize_text.py SOURCE_FILE [OUTPUT_FILE] 12 | """ 13 | import sys; 14 | from emoji import unicode_codes; 15 | 16 | # Open source file 17 | source_file_path = sys.argv[1] 18 | source_file = open(source_file_path, 'r') 19 | 20 | # Prepare output file 21 | out_file = open(sys.argv[2], 'w') if len(sys.argv) > 2 else sys.stdout 22 | 23 | # Transform text 24 | emoji_dict = unicode_codes.get_emoji_unicode_dict('en') 25 | output = '' 26 | for line in source_file.readlines(): 27 | output_line = [] 28 | for word in line.split(): 29 | output_line.append(emoji_dict.get(f':{word}:', word)) 30 | out_file.write(" ".join(output_line)) 31 | out_file.write('\n') 32 | 33 | # Print output 34 | print(output) 35 | -------------------------------------------------------------------------------- /python/examples/basic/workdir/source_text.txt: -------------------------------------------------------------------------------- 1 | The rabbit woke up with a smile. 2 | The sunrise was shining on his face. 3 | A carrot was waiting for him on the table. 4 | He will put on his jeans and get out of the house for a walk. 5 | -------------------------------------------------------------------------------- /python/examples/basic/workdir/text_histogram.py: -------------------------------------------------------------------------------- 1 | """ 2 | Sample script that generates a letter histogram for 3 | a given text and renders it as an SVG bar chart. Depends 4 | on the 'pygal' module. 5 | 6 | Prints on stdout if no OUTPUT_FILE is given. 7 | 8 | Usage: 9 | text_histogram.py SOURCE_FILE [OUTPUT_FILE] 10 | """ 11 | import pygal 12 | import string 13 | import sys 14 | 15 | # Open source file 16 | source_file_path = sys.argv[1] 17 | source_file = open(source_file_path, 'r') 18 | 19 | # Prime the histogram 20 | histogram = dict.fromkeys(string.ascii_lowercase, 0) 21 | 22 | # Populate the histogram 23 | for line in source_file.readlines(): 24 | for character in line: 25 | normalized_character = character.lower 26 | if character in histogram: 27 | histogram[character] += 1 28 | 29 | # Prepare the bar chart 30 | histogram_chart = pygal.Bar() 31 | histogram_chart.title = f'Letter histogram of "{source_file_path}"' 32 | for k, v in histogram.items(): 33 | histogram_chart.add(k, v) 34 | 35 | # Write the output 36 | out_file = open(sys.argv[2], 'w') if len(sys.argv) > 2 else sys.stdout 37 | out_file.write(histogram_chart.render(is_unicode=True)) 38 | -------------------------------------------------------------------------------- /python/examples/bindings/se2-bindings/console-output.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webassemblylabs/webassembly-language-runtimes/5a40c308763309d227dd1dd85fe3e9397282c6d9/python/examples/bindings/se2-bindings/console-output.png -------------------------------------------------------------------------------- /python/examples/bindings/se2-bindings/py-plugin/plugin.py: -------------------------------------------------------------------------------- 1 | import sdk 2 | import re 3 | 4 | def log(msg, id=None): 5 | print(f'\033[35m [plugin.py]\033[0m | id={id} | {msg}', flush = True) 6 | 7 | def reverse(s): 8 | str = "" 9 | for i in s: 10 | str = i + str 11 | return str 12 | 13 | def process_word(word): 14 | # Reverse only words without non-letter signs 15 | return word if re.match(r"\w+[.,'!?\"]\w*", word) else reverse(word) 16 | 17 | def run_e(payload, ident): 18 | log(f'Called run_e("{payload}", {ident})', ident) 19 | 20 | text_words = payload.split(' ') 21 | result = ' '.join([process_word(w) for w in text_words]) 22 | 23 | log(f'Calling sdk.return_result("{result}", {ident})', ident) 24 | sdk.return_result(result, ident) 25 | 26 | log(f'Result returned for "{ident}"', ident) 27 | -------------------------------------------------------------------------------- /python/examples/bindings/se2-bindings/run_me.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ "$1" == "--local" ]]; then 4 | if [[ ! -v WASI_SDK_PATH ]]; then 5 | echo "WASI_SDK_PATH is required. Download wasi-sdk and set the variable" 6 | exit 1 7 | fi 8 | 9 | check() { 10 | if ! command -v $1 &>/dev/null; then 11 | echo "$1 is required. Install it and ensure its on PATH" 12 | exit 1 13 | fi 14 | } 15 | 16 | check cmake 17 | check curl 18 | check tar 19 | check gzip 20 | 21 | check npm 22 | check node 23 | else 24 | WASI_SDK_VERSION=20.0 25 | WASI_CMD="docker run -t -v$(pwd):/workdir -w /workdir ghcr.io/vmware-labs/wasmlabs/wasi-builder:${WASI_SDK_VERSION}" 26 | NODE_CMD="docker run -t -v$(pwd):/workdir -w /workdir node:16.20" 27 | fi 28 | 29 | fail() { 30 | echo "Command failed" 31 | exit 1 32 | } 33 | 34 | echo -e "\n\n------------------------------------" | tee -a build.log 35 | echo "$(date --iso-8601=ns) Running '$0'" | tee -a build.log 36 | 37 | echo -e "$(date --iso-8601=ns) | Building wasm-wrapper-c ${WASI_CMD:+with '$WASI_CMD' }(logs silenced to build.log)..." | tee -a build.log 38 | ${WASI_CMD} bash -c "cd wasm-wrapper-c; ./build-wasm.sh --clean >>../build.log 2>&1" || fail 39 | 40 | echo -e "$(date --iso-8601=ns) | Building se2-mock-runtime ${NODE_CMD:+with '$NODE_CMD' }(logs silenced to build.log)..." | tee -a build.log 41 | ${NODE_CMD} bash -c "cd se2-mock-runtime; npm i >>../build.log 2>&1" || fail 42 | 43 | echo -e "$(date --iso-8601=ns) | Running se2-mock-runtime ${NODE_CMD:+with '$NODE_CMD' }..." | tee -a build.log 44 | ${NODE_CMD} bash -c "cd se2-mock-runtime; set -x; \ 45 | node --experimental-wasi-unstable-preview1 . \ 46 | --wrapper ../wasm-wrapper-c/target/wasm32-wasi/wasm-wrapper-c.wasm \ 47 | --plugin-root ../py-plugin/ \ 48 | --python-usr-root ../wasm-wrapper-c/target/wasm32-wasi/deps/" 49 | -------------------------------------------------------------------------------- /python/examples/bindings/se2-bindings/se2-mock-runtime.drawio.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/webassemblylabs/webassembly-language-runtimes/5a40c308763309d227dd1dd85fe3e9397282c6d9/python/examples/bindings/se2-bindings/se2-mock-runtime.drawio.png -------------------------------------------------------------------------------- /python/examples/bindings/se2-bindings/se2-mock-runtime/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "se2-mock-runtime", 3 | "version": "1.0.0", 4 | "description": "Mock of the SE2 runtime to test basic plugins", 5 | "main": "bin/runtime.js", 6 | "scripts": { 7 | "test": "echo \"Error: no test specified\" && exit 1" 8 | }, 9 | "author": "WasmLabs", 10 | "license": "Apache-2.0", 11 | "bin": { 12 | "node.app": "./bin/runtime.js" 13 | }, 14 | "dependencies": { 15 | "yargs": "17.7.2" 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /python/examples/bindings/se2-bindings/wasm-wrapper-c/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.16) 2 | 3 | project(wasm-wrapper-c) 4 | 5 | if(${CMAKE_SYSTEM_NAME} STREQUAL "WASI") 6 | set(CMAKE_EXECUTABLE_SUFFIX ".wasm") 7 | endif() 8 | 9 | add_executable( 10 | wasm-wrapper-c 11 | main.c 12 | sdk_module.c 13 | pyhost.c 14 | utils.c 15 | wasm_shim.c 16 | ) 17 | 18 | find_package(PkgConfig REQUIRED) 19 | 20 | pkg_search_module(LIBPYTHON REQUIRED IMPORTED_TARGET "libpython3.12>=3.12.0") 21 | 22 | include_directories(AFTER 23 | ${LIBPYTHON_INCLUDE_DIRS} 24 | ) 25 | 26 | target_link_libraries(wasm-wrapper-c PUBLIC 27 | PkgConfig::LIBPYTHON 28 | ) 29 | -------------------------------------------------------------------------------- /python/examples/bindings/se2-bindings/wasm-wrapper-c/build-wasm.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WASI_SDK_PATH ]]; then 4 | echo "WASI_SDK_PATH is required. Download wasi-sdk and set the variable" 5 | exit 1 6 | fi 7 | 8 | export TARGET_DIR=target/wasm32-wasi 9 | if [[ "$1" == "--clean" ]]; then 10 | rm -rf ${TARGET_DIR} 11 | fi 12 | 13 | mkdir -p ${TARGET_DIR}/deps 2>/dev/null 14 | if [ -f ${TARGET_DIR}/deps/include/python3.12/Python.h -a -f ${TARGET_DIR}/deps/lib/wasm32-wasi/libpython3.12.a ]; then 15 | echo "Dependencies already downloaded. Reusing..." 16 | else 17 | curl -sL https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/python%2F3.12.0%2B20231211-040d5a6/libpython-3.12.0-wasi-sdk-20.0.tar.gz | tar xzv -C ${TARGET_DIR}/deps 18 | fi 19 | 20 | export FULL_TARGET_DIR=$(realpath ${TARGET_DIR}) 21 | 22 | export PKG_CONFIG_ALLOW_SYSTEM_CFLAGS=1 23 | export PKG_CONFIG_ALLOW_SYSTEM_LIBS=1 24 | export PKG_CONFIG_PATH="" 25 | export PKG_CONFIG_SYSROOT_DIR=${FULL_TARGET_DIR}/deps 26 | export PKG_CONFIG_LIBDIR=${FULL_TARGET_DIR}/deps/lib/wasm32-wasi/pkgconfig 27 | 28 | # Note: The target/wasm32-wasi/deps/lib/wasm32-wasi/pkgconfig/libpython3.12.pc file 29 | # contains all additional link options for libpython3.12 30 | # "-Wl,-z,stack-size=524288 -Wl,--initial-memory=10485760 -Wl,--stack-first" for proper handling of stack overflows 31 | # "-lwasi-emulated-getpid -lwasi-emulated-signal -lwasi-emulated-process-clocks" for wasi-libc emulations 32 | 33 | export CMAKE_EXTRA_ARGS="-DWASI_SDK_PREFIX=${WASI_SDK_PATH} -DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_PATH}/share/cmake/wasi-sdk.cmake" 34 | 35 | cmake -B${TARGET_DIR} ${CMAKE_EXTRA_ARGS} . || exit 1 36 | cmake --build ${TARGET_DIR} --verbose || exit 1 37 | 38 | echo "Module built in $(realpath ${TARGET_DIR}/wasm-wrapper-c.wasm)" 39 | -------------------------------------------------------------------------------- /python/examples/bindings/se2-bindings/wasm-wrapper-c/main.c: -------------------------------------------------------------------------------- 1 | #define PY_SSIZE_T_CLEAN 2 | 3 | #include "pyhost.h" 4 | #include "utils.h" 5 | #include "wasm_shim.h" 6 | 7 | int main(int argc, char *argv[]) 8 | { 9 | _initialize(); 10 | return 0; 11 | } 12 | -------------------------------------------------------------------------------- /python/examples/bindings/se2-bindings/wasm-wrapper-c/pyhost.c: -------------------------------------------------------------------------------- 1 | #include "pyhost.h" 2 | 3 | #include "sdk_module.h" 4 | 5 | int pyhost_initialize(int argc) 6 | { 7 | if (0 != init_sdk_module()) 8 | { 9 | fprintf(stderr, "[pyhost.c]:Failed to register \"%s\" module for init.\n", SDK_MODULE); 10 | return -1; 11 | } 12 | 13 | Py_Initialize(); 14 | return 0; 15 | } 16 | 17 | PyObject *pyhost_load_module(char *module_name) 18 | { 19 | PyObject *pName = PyUnicode_DecodeFSDefault(module_name); 20 | /* Error checking of pName left out */ 21 | 22 | PyObject *pModule = PyImport_Import(pName); 23 | Py_DECREF(pName); 24 | return pModule; 25 | } 26 | -------------------------------------------------------------------------------- /python/examples/bindings/se2-bindings/wasm-wrapper-c/pyhost.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #define PY_SSIZE_T_CLEAN 4 | #include 5 | 6 | int pyhost_initialize(int argc); 7 | 8 | // Loads module (looking in PYTHONPATH) 9 | PyObject *pyhost_load_module(char *module_name); 10 | -------------------------------------------------------------------------------- /python/examples/bindings/se2-bindings/wasm-wrapper-c/sdk_module.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | // Simple python module that offers python-host functions 4 | #define PY_SSIZE_T_CLEAN 5 | #include 6 | 7 | #define SDK_MODULE "sdk" 8 | 9 | #define SDK_RETURN_RESULT "return_result" 10 | #define SDK_RETURN_ERROR "return_error" 11 | 12 | int init_sdk_module(); 13 | -------------------------------------------------------------------------------- /python/examples/bindings/se2-bindings/wasm-wrapper-c/utils.c: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | 10 | #define __FILENAME__ (strrchr(__FILE__, '/') ? strrchr(__FILE__, '/') + 1 : __FILE__) 11 | 12 | #define PATH_MAX 4096 13 | 14 | void print_current_dir() 15 | { 16 | char cwd[PATH_MAX]; 17 | if (getcwd(cwd, sizeof(cwd)) != NULL) 18 | LOG_MSG(__FILENAME__, "Current working dir: %s", cwd); 19 | } 20 | 21 | void list_current_dir() 22 | { 23 | #define _XOPEN_SOURCE 700 24 | 25 | DIR *dp; 26 | struct dirent *ep; 27 | dp = opendir("./"); 28 | if (dp != NULL) 29 | { 30 | while ((ep = readdir(dp)) != NULL) 31 | LOG_MSG(__FILENAME__, " - %s", ep->d_name); 32 | 33 | LOG_MSG(__FILENAME__, "\n"); 34 | (void)closedir(dp); 35 | } 36 | else 37 | { 38 | perror("utils.c | E | Couldn't open the current directory"); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /python/examples/bindings/se2-bindings/wasm-wrapper-c/utils.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | void print_current_dir(); 4 | void list_current_dir(); 5 | 6 | #define LOG_PREFIX "\033[32m [%s]\033[0m | " 7 | 8 | #define LOG_MSG(fname, fmt, ...) \ 9 | fprintf(stdout, LOG_PREFIX fmt "\n", fname __VA_OPT__(, ) __VA_ARGS__) 10 | -------------------------------------------------------------------------------- /python/examples/bindings/se2-bindings/wasm-wrapper-c/wasm_shim.h: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include 4 | 5 | #ifdef __wasi__ 6 | 7 | typedef uint8_t u8; 8 | typedef uint16_t u16; 9 | typedef uint32_t u32; 10 | typedef uint64_t u64; 11 | 12 | typedef int8_t i8; 13 | typedef int16_t i16; 14 | typedef int32_t i32; 15 | typedef int64_t i64; 16 | 17 | typedef float f32; 18 | typedef double f64; 19 | 20 | // __attribute__((export_name("_initialize"))) 21 | void _initialize(); 22 | 23 | // SubOrbital Plugin API 24 | __attribute__((export_name("allocate"))) u8 *allocate(i32 size); 25 | __attribute__((export_name("deallocate"))) void deallocate(u8 *pointer, i32 size); 26 | __attribute__((export_name("run_e"))) void run_e(u8 *pointer, i32 size, i32 ident); 27 | 28 | void env_return_result(u8 *result_pointer, i32 result_size, i32 ident) 29 | __attribute__((__import_module__("env"), 30 | __import_name__("return_result"))); 31 | void env_return_error(i32 code, u8 *result_pointer, i32 result_size, i32 ident) 32 | __attribute__((__import_module__("env"), 33 | __import_name__("return_error"))); 34 | 35 | #endif -------------------------------------------------------------------------------- /python/examples/embedding/README.md: -------------------------------------------------------------------------------- 1 | This folder shows examples of embedding Python in a Wasm module. 2 | 3 | For Rust, we show how you can use the [`wlr-libpy`](../../tools/wlr-libpy) crate to get a pre-built `libpython` for wasm32-wasi. You can combine this with any typical Rust bindings for the C API by CPython. 4 | 5 | We have examples based on two different crates, which both offer Python bindings: 6 | 7 | - [./wasi-py-rs-cpython](./wasi-py-rs-cpython/) using `wlr-libpy` along with the bindings by the [`cpython`](https://github.com/dgrunwald/rust-cpython) crate 8 | - [./wasi-py-rs-pyo3](./wasi-py-rs-pyo3/) using `wlr-libpy` along with the bindings by the [`pyo3`](https://pyo3.rs/) crate 9 | -------------------------------------------------------------------------------- /python/examples/embedding/wasi-py-rs-cpython/.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | target = "wasm32-wasi" 3 | -------------------------------------------------------------------------------- /python/examples/embedding/wasi-py-rs-cpython/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wasi-py-rs-cpython" 3 | version = "0.1.1" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | cpython = { version = "0.7", features = ["extension-module"] } 8 | wlr-libpy = { git = "https://github.com/vmware-labs/webassembly-language-runtimes.git", features = [ 9 | "py_main", 10 | ] } 11 | 12 | [build-dependencies] 13 | wlr-libpy = { git = "https://github.com/vmware-labs/webassembly-language-runtimes.git", features = [ 14 | "build", 15 | ] } 16 | -------------------------------------------------------------------------------- /python/examples/embedding/wasi-py-rs-cpython/README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | Example that embeds CPython via libpython into a Wasm module written in Rust. 4 | 5 | Uses the [cpython](http://dgrunwald.github.io/rust-cpython/doc/cpython/index.html) crate. For disambiguation purposes, let's note that this crate offers Rust bindings for the C API by CPython and is not part of the official CPython implementation. 6 | 7 | Take a look at the similar example in [../wasi-py-rs-pyo3](../wasi-py-rs-pyo3) to see how this works with the [pyo3](https://pyo3.rs/v0.19.0/) crate, which is an alternative to `cpython` that also provides Rust bindings on top of the C API implemented by `libpython`. 8 | 9 | # How to run 10 | 11 | Make sure you have `cargo` with the `wasm32-wasi` target. For running we use `wasmtime`, but the module will work with any WASI-compliant runtime. 12 | 13 | Just run `./run_me.sh` in the current folder. You will see something like this 14 | 15 | ``` 16 | wlr/python/examples/embedding/wasi-py-rs-cpython $$ ./run_me.sh 17 | Compiling cpython v0.7.1 18 | ... 19 | Finished dev [unoptimized + debuginfo] target(s) in 26.43s 20 | 21 | Calling a WASI Command which demonstrates usage of the 'cpython' crate : 22 | + wasmtime --mapdir /usr::target/wasm32-wasi/wasi-deps/usr target/wasm32-wasi/debug/wasi-py-rs-cpython.wasm 23 | Hello! I'm Python 3.11.3 (tags/v3.11.3:f3909b8, Apr 28 2023, 09:45:45) [Clang 15.0.7 ], running on wasi/posix 24 | + set +x 25 | ``` 26 | 27 | # About the code 28 | 29 | The code is adapted from [cpython crate's docs](https://github.com/dgrunwald/rust-cpython#usage). 30 | 31 | # Build and dependencies 32 | 33 | For `cpython` to work the final binary needs to link to `libpython3.11.a`. To get a wasm32-wasi version of `libpython` we provide a helper crate [wlr-libpy](../../../tools/wlr-libpy/), which can be used to fetch the pre-built library that this repository publishes. 34 | 35 | Note that the `cpython` crate's build requires that `python3` is installed on the build machine (even if we actually link to the wasm32-wasi `libpython` fetched by `wlr-libpy`). 36 | 37 | The build process and dependencies are described in detail with the similar example in [../wasi-py-rs-pyo3](../wasi-py-rs-pyo3). 38 | -------------------------------------------------------------------------------- /python/examples/embedding/wasi-py-rs-cpython/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | use wlr_libpy::bld_cfg::configure_static_libs; 3 | configure_static_libs().unwrap().emit_link_flags(); 4 | } 5 | -------------------------------------------------------------------------------- /python/examples/embedding/wasi-py-rs-cpython/run_me.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rustup target list | find "installed" | find "wasm32-wasi" 4 | if errorlevel 1 ( 5 | echo "Please run 'rustup target add wasm32-wasi' first" 6 | exit /b 7 | ) 8 | 9 | python3 --version >nul 2>&1 || ( 10 | echo "python3 is required by 'rust-cpython'. Install it and ensure its on PATH" 11 | exit /b 12 | ) 13 | 14 | setlocal 15 | set PYO3_NO_PYTHON=1 16 | cargo build --target=wasm32-wasi 17 | endlocal 18 | echo on 19 | 20 | @echo 21 | @echo Calling a WASI Command which demonstrates usage of the 'cpython' crate:  22 | wasmtime ^ 23 | --mapdir /usr::target/wasm32-wasi/wasi-deps/usr ^ 24 | target/wasm32-wasi/debug/wasi-py-rs-cpython.wasm 25 | -------------------------------------------------------------------------------- /python/examples/embedding/wasi-py-rs-cpython/run_me.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if ! (rustup target list | grep "installed" | grep -q "wasm32-wasi"); then 4 | echo "Please run 'rustup target add wasm32-wasi' first" 5 | exit 1 6 | fi 7 | 8 | check() { 9 | if ! command -v $1 &>/dev/null; then 10 | echo "$1 is required by 'rust-cpython'. Install it and ensure its on PATH" 11 | exit 1 12 | fi 13 | } 14 | 15 | check python3 16 | 17 | set -e 18 | 19 | PYO3_NO_PYTHON=1 cargo build --target=wasm32-wasi 20 | echo -e "\n\033[35mCalling a WASI Command which demonstrates usage of the 'cpython' crate :\033[0m" 21 | set -x 22 | wasmtime \ 23 | --mapdir /usr::target/wasm32-wasi/wasi-deps/usr \ 24 | target/wasm32-wasi/debug/wasi-py-rs-cpython.wasm 25 | set +x 26 | -------------------------------------------------------------------------------- /python/examples/embedding/wasi-py-rs-cpython/src/main.rs: -------------------------------------------------------------------------------- 1 | // Adapted from the Usage example for the cpython crate 2 | // https://github.com/dgrunwald/rust-cpython#usage 3 | 4 | use cpython::{Python, PyDict, PyResult}; 5 | 6 | fn main() { 7 | let gil = Python::acquire_gil(); 8 | hello(gil.python()).unwrap(); 9 | } 10 | 11 | fn hello(py: Python) -> PyResult<()> { 12 | let sys = py.import("sys")?; 13 | let version: String = sys.get(py, "version")?.extract(py)?; 14 | let platform: String = sys.get(py, "platform")?.extract(py)?; 15 | 16 | let locals = PyDict::new(py); 17 | locals.set_item(py, "os", py.import("os")?)?; 18 | let os_name: String = py.eval("os.name", None, Some(&locals))?.extract(py)?; 19 | 20 | println!("Hello! I'm Python {}, running on {}/{}", version, platform, os_name); 21 | Ok(()) 22 | } 23 | -------------------------------------------------------------------------------- /python/examples/embedding/wasi-py-rs-pyo3/.cargo/config.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | target = "wasm32-wasi" 3 | -------------------------------------------------------------------------------- /python/examples/embedding/wasi-py-rs-pyo3/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wasi-py-rs-pyo3" 3 | version = "0.1.1" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | pyo3 = { version = "0.19.0", features = ["abi3-py311"] } 8 | wlr-libpy = { git = "https://github.com/vmware-labs/webassembly-language-runtimes.git", features = [ 9 | "py_main", 10 | ] } 11 | 12 | [build-dependencies] 13 | wlr-libpy = { git = "https://github.com/vmware-labs/webassembly-language-runtimes.git", features = [ 14 | "build", 15 | ] } 16 | -------------------------------------------------------------------------------- /python/examples/embedding/wasi-py-rs-pyo3/build.rs: -------------------------------------------------------------------------------- 1 | fn main() { 2 | use wlr_libpy::bld_cfg::configure_static_libs; 3 | configure_static_libs().unwrap().emit_link_flags(); 4 | } 5 | -------------------------------------------------------------------------------- /python/examples/embedding/wasi-py-rs-pyo3/run_me.cmd: -------------------------------------------------------------------------------- 1 | @echo off 2 | 3 | rustup target list | find "installed" | find "wasm32-wasi" 4 | if errorlevel 1 ( 5 | echo "Please run 'rustup target add wasm32-wasi' first" 6 | exit /b 7 | ) 8 | 9 | setlocal 10 | set PYO3_NO_PYTHON=1 11 | cargo build --target=wasm32-wasi 12 | endlocal 13 | echo on 14 | 15 | @echo 16 | @echo Calling a WASI Command which embeds Python (adding a custom module implemented in Rust) and calls a custom function:  17 | wasmtime ^ 18 | --mapdir /usr::target/wasm32-wasi/wasi-deps/usr ^ 19 | target/wasm32-wasi/debug/py-func-caller.wasm 20 | 21 | @echo 22 | @echo Calling a WASI Command which wraps the Python binary (adding a custom module implemented in Rust):  23 | wasmtime ^ 24 | --mapdir /usr::target/wasm32-wasi/wasi-deps/usr ^ 25 | target/wasm32-wasi/debug/py-wrapper.wasm ^ 26 | -- -c ^ 27 | "import person as p; pp = [p.Person('a', 1), p.Person('b', 2)]; pp[0].add_tag('X'); print('Filtered: ', p.filter_by_tag(pp, 'X'))" 28 | -------------------------------------------------------------------------------- /python/examples/embedding/wasi-py-rs-pyo3/run_me.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if ! (rustup target list | grep "installed" | grep -q "wasm32-wasi"); then 4 | echo "Please run 'rustup target add wasm32-wasi' first" 5 | exit 1 6 | fi 7 | 8 | set -e 9 | 10 | PYO3_NO_PYTHON=1 cargo build --target=wasm32-wasi 11 | echo -e "\n\033[35mCalling a WASI Command which embeds Python (adding a custom module implemented in Rust) and calls a custom function:\033[0m" 12 | set -x 13 | wasmtime \ 14 | --mapdir /usr::target/wasm32-wasi/wasi-deps/usr \ 15 | target/wasm32-wasi/debug/py-func-caller.wasm 16 | set +x 17 | 18 | echo -e "\n\033[35mCalling a WASI Command which wraps the Python binary (adding a custom module implemented in Rust):\033[0m" 19 | set -x 20 | read -r -d '\0' SAMPLE_SCRIPT <<- EOF 21 | import person as p 22 | pp = [p.Person('a', 1), p.Person('b', 2)] 23 | pp[0].add_tag('X') 24 | print('Filtered: ', p.filter_by_tag(pp, 'X')) 25 | \0 26 | EOF 27 | 28 | wasmtime \ 29 | --mapdir /usr::target/wasm32-wasi/wasi-deps/usr \ 30 | target/wasm32-wasi/debug/py-wrapper.wasm \ 31 | -- -c "${SAMPLE_SCRIPT}" 32 | set +x 33 | -------------------------------------------------------------------------------- /python/examples/embedding/wasi-py-rs-pyo3/src/bin/py-func-caller.rs: -------------------------------------------------------------------------------- 1 | use pyo3::{append_to_inittab, PyResult}; 2 | 3 | use wasi_py_rs_pyo3::call_function; 4 | use wasi_py_rs_pyo3::py_module::make_person_module; 5 | 6 | pub fn main() -> PyResult<()> { 7 | append_to_inittab!(make_person_module); 8 | 9 | let function_code = include_str!("py-func.py"); 10 | call_function( 11 | "my_func", 12 | function_code, 13 | ( 14 | ("John", 21, ["funny", "student"]), 15 | ("Jane", 22, ["thoughtful", "student"]), 16 | ("George", 75, ["wise", "retired"]), 17 | ), 18 | ) 19 | } 20 | -------------------------------------------------------------------------------- /python/examples/embedding/wasi-py-rs-pyo3/src/bin/py-func.py: -------------------------------------------------------------------------------- 1 | 2 | def my_func(*args, **kwargs): 3 | import sys 4 | print(f'Hello from Python (libpython3.11.a / {sys.version}) in Wasm(Rust).\nargs={args}\n') 5 | 6 | import person 7 | people = [] 8 | for name, age, tags in args: 9 | p = person.Person(name, age) 10 | for t in tags: 11 | p.add_tag(t) 12 | people.append(p) 13 | 14 | from pprint import pprint as pp 15 | filter_tag = 'student' 16 | filtered = person.filter_by_tag(people, filter_tag) 17 | print('Original people:') 18 | pp(people) 19 | print(f'Filtered people by `{filter_tag}`:') 20 | pp(filtered) 21 | -------------------------------------------------------------------------------- /python/examples/embedding/wasi-py-rs-pyo3/src/bin/py-wrapper.rs: -------------------------------------------------------------------------------- 1 | use pyo3::append_to_inittab; 2 | use wasi_py_rs_pyo3::py_module::make_person_module; 3 | use wlr_libpy::py_main::py_main; 4 | 5 | pub fn main() { 6 | append_to_inittab!(make_person_module); 7 | 8 | py_main(std::env::args().collect()); 9 | } 10 | -------------------------------------------------------------------------------- /python/examples/embedding/wasi-py-rs-pyo3/src/lib.rs: -------------------------------------------------------------------------------- 1 | use pyo3::types::{PyModule, PyTuple}; 2 | use pyo3::{IntoPy, Py, PyAny, PyResult, Python}; 3 | 4 | pub mod py_module; 5 | use py_module::make_person_module; 6 | 7 | pub fn call_function>>( 8 | function_name: &str, 9 | function_code: &str, 10 | args: T, 11 | ) -> PyResult<()> { 12 | pyo3::append_to_inittab!(make_person_module); 13 | 14 | pyo3::prepare_freethreaded_python(); 15 | 16 | Python::with_gil(|py| -> PyResult<()> { 17 | let fun: Py = PyModule::from_code(py, function_code, "", "")? 18 | .getattr(function_name)? 19 | .into(); 20 | 21 | fun.call1(py, args)?; 22 | Ok(()) 23 | }) 24 | } 25 | -------------------------------------------------------------------------------- /python/examples/embedding/wasi-py-rs-pyo3/src/py_module.rs: -------------------------------------------------------------------------------- 1 | use pyo3::{types::PyModule, PyResult, Python}; 2 | 3 | #[derive(Clone)] 4 | #[pyo3::pyclass] 5 | #[pyo3(name = "Person")] 6 | pub struct Person { 7 | #[pyo3(get, set)] 8 | name: String, 9 | #[pyo3(get, set)] 10 | age: u16, 11 | #[pyo3(get)] 12 | tags: Vec, 13 | } 14 | 15 | #[pyo3::pymethods] 16 | impl Person { 17 | #[new] 18 | fn new(name: String, age: u16) -> Self { 19 | Self { 20 | name, 21 | age, 22 | tags: vec![], 23 | } 24 | } 25 | 26 | fn add_tag(&mut self, tag: String) { 27 | self.tags.push(tag); 28 | } 29 | 30 | fn __str__(&self) -> PyResult { 31 | Ok(format!( 32 | "Person(Name: \"{}\", Age: {}, Tags:{:?})", 33 | self.name, self.age, self.tags 34 | )) 35 | } 36 | 37 | fn __repr__(&self) -> PyResult { 38 | self.__str__() 39 | } 40 | } 41 | 42 | #[pyo3::pyfunction] 43 | pub fn filter_by_tag(people: Vec, tag: String) -> Vec { 44 | let mut result: Vec = vec![]; 45 | for p in people.iter() { 46 | if p.tags.iter().any(|t| t == &tag) { 47 | result.push(p.clone()); 48 | } 49 | } 50 | result 51 | } 52 | 53 | #[pyo3::pymodule] 54 | #[pyo3(name = "person")] 55 | pub fn make_person_module(_py: Python<'_>, module: &PyModule) -> PyResult<()> { 56 | module.add_function(pyo3::wrap_pyfunction!(filter_by_tag, module)?)?; 57 | module.add_class::() 58 | } 59 | -------------------------------------------------------------------------------- /python/test/run_me.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ "$(realpath $PWD)" != "$(realpath $(dirname $BASH_SOURCE))" ]] 4 | then 5 | echo "This script works only if called from its location as PWD" 6 | exit 1 7 | fi 8 | 9 | TESTS=$(for t in */test.py; do echo $(dirname $t); done) 10 | 11 | status=0 12 | 13 | for test_dir in ${TESTS}; do 14 | echo "Running test in '${test_dir}'..." 15 | if diff ${test_dir}/test.stdout <($WLR_TEST_RUNTIME \ 16 | --mapdir /usr::${WLR_OUTPUT}/usr \ 17 | --mapdir /test::./${test_dir} \ 18 | --mapdir .::./${test_dir} \ 19 | ${WLR_TESTED_MODULE} \ 20 | /test/test.py); then 21 | echo "${test_dir}/test.py passed!" 22 | else 23 | echo "${test_dir}/test.py failed!" 24 | status=$(expr ${status} + 1) 25 | fi 26 | done 27 | 28 | exit $status 29 | -------------------------------------------------------------------------------- /python/test/sqlite/.gitignore: -------------------------------------------------------------------------------- 1 | *.db -------------------------------------------------------------------------------- /python/test/sqlite/test.py: -------------------------------------------------------------------------------- 1 | import traceback 2 | 3 | import sqlite3 4 | import sys 5 | 6 | DB_FILE_NAME = 'test.db' 7 | 8 | def create_table(con, name, schema): 9 | cursorObj = con.cursor() 10 | cursorObj.execute(f"CREATE TABLE {name}{schema}") 11 | con.commit() 12 | 13 | def populate_table(con, name): 14 | cursorObj = con.cursor() 15 | cursorObj.execute(f"INSERT INTO {name} VALUES(1, 'John', 700, 'TheDarkMaster')") 16 | cursorObj.execute(f"INSERT INTO {name} VALUES(2, 'Jane', 710, 'AngelOfBenevolence')") 17 | cursorObj.execute(f"INSERT INTO {name} VALUES(3, 'George', 623, 'MagiFromTheDeep')") 18 | con.commit() 19 | 20 | def select_table(con, name): 21 | cursorObj = con.cursor() 22 | cursorObj.execute(f"SELECT * FROM {name}") 23 | rows = cursorObj.fetchall() 24 | for row in rows: 25 | print(row) 26 | 27 | def sql_version(con): 28 | cursor = con.cursor() 29 | 30 | sqlite_select_Query = "select sqlite_version();" 31 | cursor.execute(sqlite_select_Query) 32 | record = cursor.fetchall() 33 | print("SQLite Database Version is: ", record) 34 | cursor.close() 35 | 36 | connection = None 37 | try: 38 | connection = sqlite3.connect(DB_FILE_NAME) 39 | print("Database created and Successfully Connected to SQLite") 40 | 41 | sql_version(connection) 42 | 43 | try: 44 | create_table(connection, "players", "(id integer PRIMARY KEY, name text, score real, nickname text)") 45 | except sqlite3.Error as e: 46 | print("Error while trying to create table: ", e) 47 | 48 | try: 49 | populate_table(connection, "players") 50 | except sqlite3.Error as e: 51 | print("Error while trying to create table: ", e) 52 | 53 | 54 | try: 55 | select_table(connection, "players") 56 | 57 | except sqlite3.Error as e: 58 | print("Error while trying to fetch table: ", e) 59 | 60 | 61 | except sqlite3.Error as error: 62 | print("Error while connecting to sqlite", error) 63 | 64 | print(traceback.format_exc()) 65 | 66 | finally: 67 | if connection: 68 | connection.close() 69 | print("The SQLite connection is closed") 70 | import os 71 | if os.path.isfile(DB_FILE_NAME): 72 | os.remove(DB_FILE_NAME) 73 | print(f"File '{DB_FILE_NAME}' deleted!") 74 | 75 | -------------------------------------------------------------------------------- /python/test/sqlite/test.stdout: -------------------------------------------------------------------------------- 1 | Database created and Successfully Connected to SQLite 2 | SQLite Database Version is: [('3.42.0',)] 3 | (1, 'John', 700.0, 'TheDarkMaster') 4 | (2, 'Jane', 710.0, 'AngelOfBenevolence') 5 | (3, 'George', 623.0, 'MagiFromTheDeep') 6 | The SQLite connection is closed 7 | File 'test.db' deleted! 8 | -------------------------------------------------------------------------------- /python/tools/wlr-libpy/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wlr-libpy" 3 | version = "0.2.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | wlr-assets = { path = "../../../tools/wlr-assets", optional = true } 8 | 9 | [features] 10 | 11 | py311 = [] 12 | py312 = [] 13 | 14 | default = ["py311"] 15 | 16 | build = ["dep:wlr-assets"] 17 | py_main = [] 18 | -------------------------------------------------------------------------------- /python/tools/wlr-libpy/src/lib.rs: -------------------------------------------------------------------------------- 1 | #[cfg(feature = "build")] 2 | pub mod bld_cfg; 3 | 4 | #[cfg(feature = "py_main")] 5 | pub mod py_main; 6 | -------------------------------------------------------------------------------- /python/tools/wlr-libpy/src/py_main.rs: -------------------------------------------------------------------------------- 1 | use std::ffi::CString; 2 | use std::os::raw::{c_char, c_int}; 3 | 4 | mod cpython { 5 | use std::os::raw::{c_char, c_int}; 6 | extern "C" { 7 | pub fn Py_BytesMain(argc: c_int, argv: *mut *mut c_char) -> c_int; 8 | } 9 | } 10 | 11 | fn to_raw_args(args: Vec) -> Vec<*mut c_char> { 12 | let mut raw_args: Vec<_> = args 13 | .into_iter() 14 | .map(|x| CString::new(x).unwrap().into_raw()) 15 | .collect(); 16 | raw_args.push(std::ptr::null_mut()); 17 | raw_args 18 | } 19 | 20 | pub fn py_main(args: Vec) -> i32 { 21 | let mut argv = to_raw_args(args); 22 | let argc = (argv.len() - 1) as c_int; 23 | unsafe { cpython::Py_BytesMain(argc, argv.as_mut_ptr()) } 24 | } 25 | -------------------------------------------------------------------------------- /python/v3.11.1/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | unset WLR_PY_BUILDER_VERSION 11 | return 12 | fi 13 | 14 | export WLR_REPO=https://github.com/python/cpython 15 | export WLR_REPO_BRANCH=v3.11.1 16 | export WLR_ENV_NAME=python/v3.11.1 17 | export WLR_PACKAGE_VERSION=3.11.1 18 | export WLR_PACKAGE_NAME=python 19 | export WLR_PY_BUILDER_VERSION=3.11.4 20 | -------------------------------------------------------------------------------- /python/v3.11.1/wlr-info.json: -------------------------------------------------------------------------------- 1 | { 2 | "deps": { 3 | "zlib": { 4 | "build_target": "libs/zlib/v1.2.13", 5 | "required_file": "lib/wasm32-wasi/libz.a", 6 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Fzlib%2F1.2.13%2B20230623-2993864/libz-1.2.13-wasi-sdk-20.0.tar.gz" 7 | }, 8 | "libuuid": { 9 | "build_target": "libs/libuuid/v1.0.3", 10 | "required_file": "lib/wasm32-wasi/libuuid.a", 11 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Flibuuid%2F1.0.3%2B20230623-2993864/libuuid-1.0.3-wasi-sdk-20.0.tar.gz" 12 | }, 13 | "bzip2": { 14 | "build_target": "libs/bzip2/v1.0.8", 15 | "required_file": "lib/wasm32-wasi/libbz2.a", 16 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Fbzip2%2F1.0.8%2B20230623-2993864/libbzip2-1.0.8-wasi-sdk-20.0.tar.gz" 17 | } 18 | } 19 | } -------------------------------------------------------------------------------- /python/v3.11.1/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="python/3.11.1" 2 | -------------------------------------------------------------------------------- /python/v3.11.3/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | unset WLR_PY_BUILDER_VERSION 11 | return 12 | fi 13 | 14 | export WLR_REPO=https://github.com/python/cpython 15 | export WLR_REPO_BRANCH=v3.11.3 16 | export WLR_ENV_NAME=python/v3.11.3 17 | export WLR_PACKAGE_VERSION=3.11.3 18 | export WLR_PACKAGE_NAME=python 19 | export WLR_PY_BUILDER_VERSION=3.11.4 20 | -------------------------------------------------------------------------------- /python/v3.11.3/wlr-info.json: -------------------------------------------------------------------------------- 1 | { 2 | "deps": { 3 | "zlib": { 4 | "build_target": "libs/zlib/v1.2.13", 5 | "required_file": "lib/wasm32-wasi/libz.a", 6 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Fzlib%2F1.2.13%2B20230623-2993864/libz-1.2.13-wasi-sdk-20.0.tar.gz" 7 | }, 8 | "SQLite": { 9 | "build_target": "libs/sqlite/v3.42.0", 10 | "required_file": "lib/wasm32-wasi/libsqlite3.a", 11 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Fsqlite%2F3.42.0%2B20230623-2993864/libsqlite-3.42.0-wasi-sdk-20.0.tar.gz" 12 | }, 13 | "libuuid": { 14 | "build_target": "libs/libuuid/v1.0.3", 15 | "required_file": "lib/wasm32-wasi/libuuid.a", 16 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Flibuuid%2F1.0.3%2B20230623-2993864/libuuid-1.0.3-wasi-sdk-20.0.tar.gz" 17 | }, 18 | "bzip2": { 19 | "build_target": "libs/bzip2/v1.0.8", 20 | "required_file": "lib/wasm32-wasi/libbz2.a", 21 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Fbzip2%2F1.0.8%2B20230623-2993864/libbzip2-1.0.8-wasi-sdk-20.0.tar.gz" 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /python/v3.11.3/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="python/3.11.3" 2 | -------------------------------------------------------------------------------- /python/v3.11.4/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | unset WLR_PY_BUILDER_VERSION 11 | return 12 | fi 13 | 14 | export WLR_REPO=https://github.com/python/cpython 15 | export WLR_REPO_BRANCH=v3.11.4 16 | export WLR_ENV_NAME=python/v3.11.4 17 | export WLR_PACKAGE_VERSION=3.11.4 18 | export WLR_PACKAGE_NAME=python 19 | export WLR_PY_BUILDER_VERSION=3.11.4 20 | -------------------------------------------------------------------------------- /python/v3.11.4/wlr-info.json: -------------------------------------------------------------------------------- 1 | { 2 | "deps": { 3 | "libuuid": { 4 | "build_target": "libs/libuuid/v1.0.3", 5 | "required_file": "lib/wasm32-wasi/libuuid.a", 6 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Flibuuid%2F1.0.3%2B20230623-2993864/libuuid-1.0.3-wasi-sdk-20.0.tar.gz" 7 | }, 8 | "zlib": { 9 | "build_target": "libs/zlib/v1.2.13", 10 | "required_file": "lib/wasm32-wasi/libz.a", 11 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Fzlib%2F1.2.13%2B20230623-2993864/libz-1.2.13-wasi-sdk-20.0.tar.gz" 12 | }, 13 | "SQLite": { 14 | "build_target": "libs/sqlite/v3.42.0", 15 | "required_file": "lib/wasm32-wasi/libsqlite3.a", 16 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Fsqlite%2F3.42.0%2B20230623-2993864/libsqlite-3.42.0-wasi-sdk-20.0.tar.gz" 17 | }, 18 | "bzip2": { 19 | "build_target": "libs/bzip2/v1.0.8", 20 | "required_file": "lib/wasm32-wasi/libbz2.a", 21 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Fbzip2%2F1.0.8%2B20230623-2993864/libbzip2-1.0.8-wasi-sdk-20.0.tar.gz" 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /python/v3.11.4/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="python/3.11.4" 2 | -------------------------------------------------------------------------------- /python/v3.11.4/wlr-test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | if [[ "${WLR_BUILD_FLAVOR}" == *"wasmedge"* ]] 10 | then 11 | WLR_BINARY_WUFFIX=-wasmedge 12 | fi 13 | 14 | export WLR_TESTED_MODULE="${WLR_OUTPUT}/bin/python${WLR_BINARY_WUFFIX}.wasm" 15 | export TEST_ROOT=${WLR_ENV}/../test 16 | 17 | (cd ${TEST_ROOT}; ./run_me.sh) 18 | 19 | 20 | # if ! [ -x "$(command -v php)" ] 21 | # then 22 | # echo "Native php is required in PATH on the host to act as orchestrator for php.wasm tests!" 23 | # exit 1 24 | # fi 25 | 26 | 27 | 28 | # if [ -f "${WLR_OUTPUT}/bin/php${WLR_BINARY_WUFFIX}" ] 29 | # then 30 | # export WLR_TESTED_MODULE="${WLR_OUTPUT}/bin/php${WLR_BINARY_WUFFIX}.wasm" 31 | # else 32 | # export WLR_TESTED_MODULE="${WLR_OUTPUT}/bin/php-cgi${WLR_BINARY_WUFFIX}.wasm" 33 | # fi 34 | 35 | # if ! [ -f "${WLR_TESTED_MODULE}" ] 36 | # then 37 | # echo "WASM module not found at '${WLR_TESTED_MODULE}'" 38 | # exit 1 39 | # fi 40 | 41 | # cd "${WLR_SOURCE_PATH}" 42 | # echo "Calling 'WLR_TESTED_MODULE=${WLR_TESTED_MODULE} php -f run-tests.php -- -p ${WLR_TEST_RUNTIME_WRAPPER} -j6' to run tests..." 43 | # php -f run-tests.php -- -p ${WLR_TEST_RUNTIME_WRAPPER} -j6 \ 44 | # tests/lang \ 45 | # tests/output \ 46 | # tests/strings \ 47 | # Zend/tests/fibers 48 | -------------------------------------------------------------------------------- /python/v3.12.0/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | unset WLR_PY_BUILDER_VERSION 11 | return 12 | fi 13 | 14 | export WLR_REPO=https://github.com/python/cpython 15 | export WLR_REPO_BRANCH=v3.12.0 16 | export WLR_ENV_NAME=python/v3.12.0 17 | export WLR_PACKAGE_VERSION=3.12.0 18 | export WLR_PACKAGE_NAME=python 19 | export WLR_PY_BUILDER_VERSION=3.12.0 20 | -------------------------------------------------------------------------------- /python/v3.12.0/wlr-info.json: -------------------------------------------------------------------------------- 1 | { 2 | "deps": { 3 | "libuuid": { 4 | "build_target": "libs/libuuid/v1.0.3", 5 | "required_file": "lib/wasm32-wasi/libuuid.a", 6 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Flibuuid%2F1.0.3%2B20230623-2993864/libuuid-1.0.3-wasi-sdk-20.0.tar.gz" 7 | }, 8 | "zlib": { 9 | "build_target": "libs/zlib/v1.2.13", 10 | "required_file": "lib/wasm32-wasi/libz.a", 11 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Fzlib%2F1.2.13%2B20230623-2993864/libz-1.2.13-wasi-sdk-20.0.tar.gz" 12 | }, 13 | "SQLite": { 14 | "build_target": "libs/sqlite/v3.42.0", 15 | "required_file": "lib/wasm32-wasi/libsqlite3.a", 16 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Fsqlite%2F3.42.0%2B20230623-2993864/libsqlite-3.42.0-wasi-sdk-20.0.tar.gz" 17 | }, 18 | "bzip2": { 19 | "build_target": "libs/bzip2/v1.0.8", 20 | "required_file": "lib/wasm32-wasi/libbz2.a", 21 | "url": "https://github.com/vmware-labs/webassembly-language-runtimes/releases/download/libs%2Fbzip2%2F1.0.8%2B20230623-2993864/libbzip2-1.0.8-wasi-sdk-20.0.tar.gz" 22 | } 23 | } 24 | } -------------------------------------------------------------------------------- /python/v3.12.0/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="python/3.12.0" 2 | -------------------------------------------------------------------------------- /python/v3.12.0/wlr-test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | if [[ "${WLR_BUILD_FLAVOR}" == *"wasmedge"* ]] 10 | then 11 | WLR_BINARY_WUFFIX=-wasmedge 12 | fi 13 | 14 | export WLR_TESTED_MODULE="${WLR_OUTPUT}/bin/python-${WLR_PACKAGE_VERSION}${WLR_BINARY_WUFFIX}.wasm" 15 | export TEST_ROOT=${WLR_ENV}/../test 16 | 17 | (cd ${TEST_ROOT}; ./run_me.sh) 18 | -------------------------------------------------------------------------------- /ruby/Dockerfile: -------------------------------------------------------------------------------- 1 | ARG WASI_SDK_VERSION 2 | FROM ghcr.io/vmware-labs/wasmlabs/wasi-builder:${WASI_SDK_VERSION} 3 | RUN DEBIAN_FRONTEND=noninteractive apt install -y \ 4 | ruby \ 5 | bison \ 6 | gperf 7 | -------------------------------------------------------------------------------- /ruby/Makefile: -------------------------------------------------------------------------------- 1 | ROOT_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST)))) 2 | REPO_ROOT := $(ROOT_DIR).. 3 | 4 | include $(REPO_ROOT)/Makefile.helpers 5 | 6 | .PHONY: ruby-builder 7 | RUBY_BUILDER_NAME := ghcr.io/vmware-labs/wasmlabs/ruby-builder:wasi-$(WASI_SDK_VERSION) 8 | ruby-builder: 9 | @$(call make_builder_image,$(RUBY_BUILDER_NAME),$(ROOT_DIR),$(WASI_SDK_VERSION)) 10 | 11 | .PHONY: update-ruby-builder 12 | update-ruby-builder: ruby-builder 13 | @$(call push_container_image,$(RUBY_BUILDER_NAME)) 14 | 15 | .PHONY: v* 16 | v*: 17 | @$(call build_in_container,$(RUBY_BUILDER_NAME),$(REPO_ROOT),ruby/$@) 18 | 19 | .PHONY: clean 20 | clean: 21 | rm -rf $(REPO_ROOT)/build-output/ruby $(REPO_ROOT)/build-staging/ruby 22 | -------------------------------------------------------------------------------- /ruby/README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | ## Building 4 | 5 | You can build Ruby by running the following Makefile targets: 6 | 7 | - `make v3.2.0` 8 | 9 | ## Running a script with ruby 10 | 11 | Don't forget to map the folder that contains the ruby script, which you want to run. For example: 12 | 13 | ```bash 14 | wasmtime --mapdir=./::./ -- ruby my-script.rb 15 | ``` 16 | -------------------------------------------------------------------------------- /ruby/v3.2.0/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | return 11 | fi 12 | 13 | export WLR_REPO=https://github.com/ruby/ruby.git 14 | export WLR_REPO_BRANCH=v3_2_0 15 | export WLR_ENV_NAME=ruby/v3_2_0 16 | export WLR_PACKAGE_VERSION=3.2.0 17 | export WLR_PACKAGE_NAME=ruby 18 | -------------------------------------------------------------------------------- /ruby/v3.2.0/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="ruby/3.2.0" 2 | -------------------------------------------------------------------------------- /ruby/v3.2.2/wlr-env-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ $1 == "--unset" ]] 4 | then 5 | unset WLR_REPO 6 | unset WLR_REPO_BRANCH 7 | unset WLR_ENV_NAME 8 | unset WLR_PACKAGE_VERSION 9 | unset WLR_PACKAGE_NAME 10 | return 11 | fi 12 | 13 | export WLR_REPO=https://github.com/ruby/ruby.git 14 | export WLR_REPO_BRANCH=v3_2_2 15 | export WLR_ENV_NAME=ruby/v3_2_2 16 | export WLR_PACKAGE_VERSION=3.2.2 17 | export WLR_PACKAGE_NAME=ruby 18 | -------------------------------------------------------------------------------- /ruby/v3.2.2/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | export WLR_TAG="ruby/3.2.2" 2 | -------------------------------------------------------------------------------- /scripts/README.md: -------------------------------------------------------------------------------- 1 | [build-helpers](./build-helpers/) contains scripts for reuse in the various `${TARGET_FOLDER}/wlr-build.sh` scripts 2 | 3 | The purpose of the most important from the rest of the scripts is briefly discussed in [developers.md#build-execution](../docs/developers.md#build-execution). 4 | -------------------------------------------------------------------------------- /scripts/build-helpers/README.md: -------------------------------------------------------------------------------- 1 | These are all scripts which are intended for sourcing within the `wlr-build.sh` scripts for build targets. 2 | 3 | They abstract common operations via exported bash functions. 4 | -------------------------------------------------------------------------------- /scripts/build-helpers/patch_wasmedge_wat_sock_accept.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # This script patches a wasm binary passed as first argument. 4 | # It changes the signature of the imported sock_accept method from WASI 5 | # to the signature defined by WasmEdge 6 | # 7 | # Note: the script assumes that it is working on an optimized binary 8 | # with stripped function names. The used regexes won't work otherwise. 9 | 10 | if [[ ! -f "$1" ]] 11 | then 12 | echo "Pass target file as argument. Could not find a file at '$1'" 13 | exit 1 14 | fi 15 | 16 | export TARGET_FILE=$1 17 | export WAT_FILE=/tmp/python.wat 18 | 19 | 20 | echo "Converting to wat at ${WAT_FILE}... " 21 | ${WABT_ROOT}/bin/wasm2wat ${TARGET_FILE} -o ${WAT_FILE} || exit 1 22 | cp ${WAT_FILE} ${WAT_FILE}_original.txt 23 | 24 | echo "Patching wat..." 25 | export WASMEDGE_SOCK_ACCEPT_TYPE="(func (param i32 i32) (result i32))" 26 | 27 | # Find a type that matches the sock_accept signature in wasmedge 28 | export TARGET_TYPE=$(grep "(type (;.*;) ${WASMEDGE_SOCK_ACCEPT_TYPE})" ${WAT_FILE} | cut -f 2 -d \;) 29 | 30 | # Find the index of the sock_accept imported function 31 | export FUNC_IDX=$(grep '(import "wasi_snapshot_preview1" "sock_accept" (func (;.*;) (type .*)))' $WAT_FILE | cut -f 2 -d \;) 32 | 33 | # Change the type based on the function index 34 | sed -i -e "s/(func (;${FUNC_IDX};) (type .*)))/(func (;${FUNC_IDX};) (type ${TARGET_TYPE})))/g" ${WAT_FILE} || exit 1 35 | 36 | # Delete the line before each call to the function index to ignore the passed parameter 37 | # Obviously this way sock_accept will not work correctly, but will at least run 38 | sed -ni "/call ${FUNC_IDX}\$/{x;d;};1h;1!{x;p;};\${x;p;}" ${WAT_FILE} || exit 1 39 | 40 | echo "Converting to wasm..." 41 | cp ${TARGET_FILE} ${TARGET_FILE}_original 42 | ${WABT_ROOT}/bin/wat2wasm ${WAT_FILE} -o ${TARGET_FILE} --debug-names || exit 1 43 | -------------------------------------------------------------------------------- /scripts/build-helpers/wlr_autoconf.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ "${BASH_SOURCE-}" = "$0" ]; then 4 | echo "You must source this script: \$ source $0" >&2 5 | return 6 | fi 7 | logStatus "Ensure we're using the latest config.guess and config.sub ... " 8 | 9 | function wlr_update_autoconf { 10 | if [[ ! -f config.guess && "$1" != "--force" ]]; then 11 | cp ${WASI_SDK_PATH}/share/misc/config.guess . || return 1 12 | chmod +x config.guess 13 | fi 14 | 15 | if [[ ! -f config.sub && "$1" != "--force" ]]; then 16 | cp ${WASI_SDK_PATH}/share/misc/config.sub . || return 1 17 | chmod +x config.sub 18 | fi 19 | } 20 | -------------------------------------------------------------------------------- /scripts/build-helpers/wlr_cmake.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ "${BASH_SOURCE-}" = "$0" ]; then 4 | echo "You must source this script: \$ source $0" >&2 5 | return 1 6 | fi 7 | 8 | if [[ -v WLR_CMAKE_TARGET_DIR ]]; then 9 | echo "WLR_CMAKE_TARGET_DIR is already defined as '${WLR_CMAKE_TARGET_DIR}'" 10 | return 1 11 | fi 12 | 13 | export WLR_CMAKE_TARGET_DIR=${WLR_STAGING}/target 14 | 15 | function wlr_cmake_configure { 16 | local CMAKE_WASI_ARGS="-DWASI_SDK_PREFIX=${WASI_SDK_PATH} -DCMAKE_TOOLCHAIN_FILE=${WASI_SDK_PATH}/share/cmake/wasi-sdk.cmake" 17 | local CMAKE_WLR_ARGS="-DCMAKE_INSTALL_PREFIX=${WLR_OUTPUT} -DCMAKE_INSTALL_LIBDIR=${WLR_OUTPUT}/lib/wasm32-wasi" 18 | if [[ ! -d $WLR_CMAKE_TARGET_DIR ]]; then 19 | mkdir -p $WLR_CMAKE_TARGET_DIR 20 | fi 21 | cmake -B${WLR_CMAKE_TARGET_DIR} ${CMAKE_WASI_ARGS} ${CMAKE_WLR_ARGS} $@ . 22 | } 23 | 24 | function wlr_cmake_build { 25 | cmake --build ${WLR_CMAKE_TARGET_DIR} $@ 26 | } 27 | 28 | function wlr_cmake_install { 29 | cmake --install ${WLR_CMAKE_TARGET_DIR} ${CMAKE_WLR_ARGS} $@ 30 | } 31 | -------------------------------------------------------------------------------- /scripts/build-helpers/wlr_package.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ "${BASH_SOURCE-}" = "$0" ]; then 4 | echo "You must source this script: \$ source $0" >&2 5 | return 6 | fi 7 | 8 | if [[ ! -v WLR_ENV ]]; then 9 | echo "WLR build environment is not set" 10 | exit 1 11 | fi 12 | 13 | function wlr_package_lib { 14 | local _PACKAGE=${WLR_OUTPUT_BASE}/lib${WLR_PACKAGE_NAME}-${WLR_PACKAGE_VERSION}${WLR_BUILD_FLAVOR:+-$WLR_BUILD_FLAVOR}-${WASI_SDK_ASSET_NAME}.tar 15 | logStatus "Packaging... ${_PACKAGE}" 16 | tar -cvf ${_PACKAGE} \ 17 | -C ${WLR_OUTPUT}/ \ 18 | --exclude=*.la \ 19 | --exclude=lib/wasm32-wasi/cmake \ 20 | include \ 21 | lib ${WLR_PACKAGE_EXTRA_DIRS} 22 | gzip -f ${_PACKAGE} 23 | } 24 | 25 | function wlr_package_bin { 26 | local _PACKAGE=${WLR_OUTPUT_BASE}/${WLR_PACKAGE_NAME}-bin-${WLR_PACKAGE_VERSION}${WLR_BUILD_FLAVOR:+-$WLR_BUILD_FLAVOR}-${WASI_SDK_ASSET_NAME}.tar 27 | logStatus "Packaging... ${_PACKAGE}" 28 | tar -cvf ${_PACKAGE} \ 29 | -C ${WLR_OUTPUT}/ \ 30 | bin 31 | gzip -f ${_PACKAGE} 32 | } 33 | 34 | function wlr_package { 35 | local _PACKAGE=${WLR_OUTPUT_BASE}/${WLR_PACKAGE_NAME}-${WLR_PACKAGE_VERSION}${WLR_BUILD_FLAVOR:+-$WLR_BUILD_FLAVOR}-${WASI_SDK_ASSET_NAME}.tar 36 | logStatus "Packaging... ${_PACKAGE}" 37 | tar -cvf ${_PACKAGE} \ 38 | -C ${WLR_OUTPUT}/ \ 39 | ${WLR_PACKAGE_LIST} 40 | gzip -f ${_PACKAGE} 41 | } 42 | -------------------------------------------------------------------------------- /scripts/build-helpers/wlr_pkg_config.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ "${BASH_SOURCE-}" = "$0" ]; then 4 | echo "You must source this script: \$ source $0" >&2 5 | return 6 | fi 7 | 8 | export WLR_CONFIGURE_PREFIXES="--prefix= --libdir=\${exec_prefix}/lib/wasm32-wasi" 9 | export WLR_INSTALL_PREFIXES="\ 10 | prefix=${WLR_OUTPUT} \ 11 | libdir=${WLR_OUTPUT}/lib/wasm32-wasi \ 12 | pkgconfigdir=${WLR_OUTPUT}/lib/wasm32-wasi/pkgconfig" 13 | 14 | function add_pkg_config_Libs { 15 | local TARGET_FILE="$1" 16 | local EXTRA_LIBS="$2" 17 | 18 | sed -i "s/\(^Libs:.*$\)/\1 ${EXTRA_LIBS}/g" ${TARGET_FILE} 19 | } 20 | 21 | function wlr_pkg_config_reset_pc_prefix { 22 | local TARGET_FILE="$1" 23 | 24 | sed -i "s/\(^prefix=\).*$/\1/g" ${TARGET_FILE} 25 | sed -i "s|${WLR_OUTPUT}|\$\{prefix\}|g" ${TARGET_FILE} 26 | } 27 | 28 | function wlr_pkg_config_create_pc_file { 29 | local LIBRARY_NAME="$1" 30 | local VERSION="$2" 31 | local DESCRIPTION="$3" 32 | local LINK_FLAGS="$4" 33 | 34 | mkdir -p ${WLR_OUTPUT}/lib/wasm32-wasi/pkgconfig 2>/dev/null || exit 1 35 | local TARGET_FILE=${WLR_OUTPUT}/lib/wasm32-wasi/pkgconfig/${LIBRARY_NAME}.pc 36 | 37 | mkdir -p ${WLR_OUTPUT}/lib/wasm32-wasi/pkgconfig 2>/dev/null 38 | cat >$TARGET_FILE <&2 8 | return 9 | fi 10 | 11 | if [[ ! -v WASI_VFS_ROOT ]] 12 | then 13 | echo "WASI_VFS_ROOT is not set" 14 | exit 1 15 | fi 16 | 17 | function wlr_wasi_vfs_get_link_flags { 18 | echo "-L${WASI_VFS_ROOT}/lib -lwasi_vfs" 19 | } 20 | 21 | function wlr_wasi_vfs_setup_dependencies { 22 | export LDFLAGS_DEPENDENCIES="${LDFLAGS_DEPENDENCIES} -L${WASI_VFS_ROOT}/lib -lwasi_vfs " 23 | } 24 | 25 | function wlr_wasi_vfs_cli { 26 | ${WASI_VFS_ROOT}/bin/wasi-vfs $@ 27 | } 28 | 29 | export -f wlr_wasi_vfs_setup_dependencies 30 | export -f wlr_wasi_vfs_cli 31 | -------------------------------------------------------------------------------- /scripts/wlr-setup-repo.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | if [[ ! -v WLR_REPO ]] 10 | then 11 | echo "Building from current repository" 12 | exit 0 13 | fi 14 | 15 | if git clone --depth=1 -b ${WLR_REPO_BRANCH} ${WLR_REPO} ${WLR_SOURCE_PATH} 16 | then 17 | cd ${WLR_SOURCE_PATH} || exit 1 18 | git config user.email "Wasm Labs Team" 19 | git config user.name "no-reply@wasmlabs.dev" 20 | if [ -d ${WLR_ENV}/patches/ ] 21 | then 22 | git am --no-gpg-sign --ignore-space-change --ignore-whitespace ${WLR_ENV}/patches/*.patch 23 | fi 24 | else 25 | echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" 26 | echo "!!! Reusing previous contents of ${WLR_SOURCE_PATH} " 27 | echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" 28 | fi 29 | -------------------------------------------------------------------------------- /scripts/wlr-tag.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # This script allows you to tag a runtime that lives inside of this 4 | # project. It only accepts one parameter, that is the path to the 5 | # project to be tagged. A tag will be created locally that contains 6 | # the date and a the short SHA of HEAD. 7 | # 8 | # When the tag is pushed to the remote repository, automation will 9 | # take care of running the tests and generating the public artifacts. 10 | 11 | set -e 12 | 13 | TAG_DATE=$(date -u '+%Y%m%d') 14 | SHORT_SHA=$(git rev-parse --short HEAD) 15 | 16 | if [ $# -ne 1 ]; then 17 | echo "$0 usage: $0 path/to/project" 18 | exit 1 19 | fi 20 | 21 | if [ ! -f $1/wlr-tag.sh ]; then 22 | echo "cannot tag $1; missing $1/wlr-tag.sh" 23 | exit 1 24 | fi 25 | 26 | if [ "$(git branch --show-current)" != "main" ] && [ "${WLR_TAG_ANY_BRANCH}" != "1" ]; then 27 | echo "can only tag/release from 'main' branch. To force run with 'WLR_TAG_ANY_BRANCH=1 $0'" 28 | exit 1 29 | fi 30 | 31 | source $1/wlr-tag.sh 32 | WLR_FINAL_TAG="${WLR_TAG}+${TAG_DATE}-${SHORT_SHA}" 33 | 34 | git tag -s $WLR_FINAL_TAG -m "Release $WLR_TAG" 35 | 36 | echo "tag created: $WLR_FINAL_TAG" 37 | -------------------------------------------------------------------------------- /scripts/wlr-test.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | set_available_runtime() { 10 | if [ -x "$(command -v $1)" ] 11 | then 12 | export WLR_TEST_RUNTIME=$1 13 | return 0 14 | fi 15 | return 1 16 | } 17 | 18 | if [[ "${WLR_BUILD_FLAVOR}" == *"wasmedge"* ]] 19 | then 20 | set_available_runtime wasmedge || \ 21 | exit 1 22 | else 23 | # Checking first for wasmtime as the reference implementation 24 | set_available_runtime wasmtime || \ 25 | set_available_runtime wasmedge || \ 26 | exit 1 27 | fi 28 | 29 | if ! [[ -v WLR_TEST_RUNTIME ]] 30 | then 31 | echo "No wasm runtime in PATH." 32 | fi 33 | 34 | export WLR_TEST_RUNTIME_WRAPPER=${WLR_REPO_ROOT}/scripts/wrappers/${WLR_TEST_RUNTIME}.sh 35 | 36 | if ! [ -x ${WLR_TEST_RUNTIME_WRAPPER} ] 37 | then 38 | echo "Missing test runtime wrapper in '${WLR_TEST_RUNTIME_WRAPPER}'" 39 | exit 1 40 | fi 41 | 42 | if [ -f ${WLR_ENV}/wlr-test.sh ] 43 | then 44 | source ${WLR_ENV}/wlr-test.sh 45 | else 46 | echo "No tests for '${WLR_ENV}'" 47 | fi 48 | -------------------------------------------------------------------------------- /scripts/wlr-update-patches.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_ENV ]] 4 | then 5 | echo "WLR build environment is not set" 6 | exit 1 7 | fi 8 | 9 | cd ${WLR_SOURCE_PATH} || exit 1 10 | mv -f ${WLR_ENV}/patches/* /tmp/ 11 | git format-patch -X ${WLR_REPO_BRANCH} -o ${WLR_ENV}/patches || exit 1 12 | -------------------------------------------------------------------------------- /scripts/wrappers/wasm-opt: -------------------------------------------------------------------------------- 1 | #!//usr/bin/env bash 2 | # Inspired by 3 | # https://raw.githubusercontent.com/ruby/ruby/df6b72b8ff7af16a56fa48f3b4abb1d8850f4d1c/wasm/wasm-opt 4 | # 5 | # A fake wasm-opt, which does nothing at all 6 | # See also: tool/wasm-clangw 7 | 8 | function logStatus { 9 | if [[ -n "${WLR_OUTPUT}" ]]; then 10 | echo "$(date --iso-8601=ns) | $@" >> $WLR_OUTPUT/wlr-build-progress.log 11 | else 12 | echo "$(date --iso-8601=ns) | $@" 13 | fi 14 | } 15 | 16 | if [[ -z "${WLR_SKIP_WASM_OPT}" ]]; then 17 | logStatus "wasm-opt (with args \"$@\") was intercepted; executing $BINARYEN_PATH/bin/wasm-opt" 18 | exec $BINARYEN_PATH/bin/wasm-opt "$@" 19 | fi 20 | 21 | logStatus "wasm-opt (with args \"$@\") was intercepted; this invocation will be a no-op" 22 | 23 | set -e 24 | input= 25 | output= 26 | while [ $# -ne 0 ]; do 27 | case "$1" in 28 | -o) 29 | shift 30 | output=$1 31 | ;; 32 | -*) 33 | # ignore other options 34 | ;; 35 | *) 36 | input=$1 37 | ;; 38 | esac 39 | shift 40 | done 41 | 42 | if [ -z "$input" ]; then 43 | echo "missing input binary" 44 | exit 1 45 | fi 46 | 47 | if [ -z "$output" ]; then 48 | echo "missing output binary" 49 | exit 1 50 | fi 51 | 52 | if [ "$input" != "$output" ]; then 53 | cp "$input" "$output" 54 | fi -------------------------------------------------------------------------------- /scripts/wrappers/wasmedge.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_TESTED_MODULE ]] 4 | then 5 | echo "WLR tested module is not set" 6 | exit 1 7 | fi 8 | 9 | wasmedge --dir /:/ ${WLR_TESTED_MODULE} $@ 10 | -------------------------------------------------------------------------------- /scripts/wrappers/wasmtime.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [[ ! -v WLR_TESTED_MODULE ]] 4 | then 5 | echo "WLR tested module is not set" 6 | exit 1 7 | fi 8 | 9 | wasmtime --mapdir /::/ ${WLR_TESTED_MODULE} -- $@ 10 | -------------------------------------------------------------------------------- /tools/wlr-assets/Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "wlr-assets" 3 | version = "0.2.0" 4 | edition = "2021" 5 | 6 | [dependencies] 7 | flate2 = "1.0.28" 8 | reqwest = { version = "0.11.22", default-features = false, features = ["blocking", "rustls-tls"] } 9 | tar = "0.4.40" 10 | bytes = "1.5.0" 11 | path-absolutize = "3.1.1" 12 | -------------------------------------------------------------------------------- /tools/wlr-assets/README.md: -------------------------------------------------------------------------------- 1 | # About 2 | 3 | Helper crate for downloading build assets from WebAssembly Language Runtimes. 4 | -------------------------------------------------------------------------------- /tools/wlr-assets/src/bld_cfg.rs: -------------------------------------------------------------------------------- 1 | use path_absolutize::*; 2 | use std::path::Path; 3 | 4 | pub struct LibsConfig { 5 | lib_paths: Vec, 6 | libs: Vec, 7 | } 8 | 9 | impl LibsConfig { 10 | pub fn new() -> LibsConfig { 11 | LibsConfig { 12 | lib_paths: vec![], 13 | libs: vec![], 14 | } 15 | } 16 | 17 | pub fn add_lib_path(&mut self, lib_path: String) { 18 | self.lib_paths.push( 19 | Path::new(&lib_path) 20 | .absolutize() 21 | .unwrap() 22 | .to_str() 23 | .unwrap() 24 | .to_string(), 25 | ); 26 | } 27 | 28 | pub fn add(&mut self, lib: &str) { 29 | self.libs.push(lib.to_string()); 30 | } 31 | 32 | pub fn emit_link_flags(&self) { 33 | for lib_path in &self.lib_paths { 34 | println!("cargo:rustc-link-search=native={lib_path}"); 35 | } 36 | 37 | for lib in &self.libs { 38 | println!("cargo:rustc-link-lib={lib}"); 39 | } 40 | } 41 | } 42 | -------------------------------------------------------------------------------- /tools/wlr-assets/src/lib.rs: -------------------------------------------------------------------------------- 1 | pub mod bld_cfg; 2 | 3 | use std::error::Error; 4 | use std::fmt::{Display, Formatter, Result as FmtResult}; 5 | use std::path::Path; 6 | 7 | type BoxedError = Box; 8 | 9 | pub fn download_asset(asset_url: &str, target_folder: &Path) -> Result<(), BoxedError> { 10 | use std::fs; 11 | fs::create_dir_all(&target_folder)?; 12 | 13 | let archive = fetch_asset(asset_url)?; 14 | unpack_archive(archive, target_folder) 15 | } 16 | 17 | #[derive(Debug, Clone)] 18 | struct AssetsError { 19 | msg: String, 20 | } 21 | 22 | impl Display for AssetsError { 23 | fn fmt(&self, f: &mut Formatter) -> FmtResult { 24 | write!(f, "{}", self.msg) 25 | } 26 | } 27 | 28 | impl Error for AssetsError {} 29 | 30 | fn fetch_asset(asset_url: &str) -> Result { 31 | let response = reqwest::blocking::get(asset_url)?; 32 | 33 | if !response.status().is_success() { 34 | return Err(AssetsError { 35 | msg: format!( 36 | "Failed to download '{}': HTTP {}", 37 | asset_url, 38 | response.status() 39 | ), 40 | } 41 | .into()); 42 | } 43 | 44 | Ok(response.bytes()?) 45 | } 46 | 47 | fn unpack_archive(archive: bytes::Bytes, target_folder: &Path) -> Result<(), BoxedError> { 48 | use flate2::read::GzDecoder; 49 | use std::io::Cursor; 50 | use tar::Archive; 51 | 52 | let decoder = GzDecoder::new(Cursor::new(archive)); 53 | let mut archive = Archive::new(decoder); 54 | archive.unpack(target_folder)?; 55 | 56 | Ok(()) 57 | } 58 | -------------------------------------------------------------------------------- /wlr-make.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | if [ "${BASH_SOURCE-}" != "$0" ] 4 | then 5 | echo "You must not source this script! Only call it in a new bash shell" >&2 6 | return 7 | fi 8 | 9 | wlr-env-unset 2>/dev/null 10 | 11 | THIS_REPO_ROOT="$(git rev-parse --show-toplevel)" 12 | 13 | source ${THIS_REPO_ROOT}/scripts/wlr-env.sh $1 14 | if [ "$2" != "--test" ] 15 | then 16 | ${THIS_REPO_ROOT}/scripts/wlr-setup-repo.sh || exit 1 17 | ${THIS_REPO_ROOT}/scripts/wlr-build.sh || exit 1 18 | else 19 | ${THIS_REPO_ROOT}/scripts/wlr-test.sh || exit 1 20 | fi 21 | --------------------------------------------------------------------------------