This is an automated email from the ASF dual-hosted git repository.
tqchen pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tvm.git
The following commit(s) were added to refs/heads/main by this push:
new ef80af65dd [Web] Support building tvm/web on Windows (#16810)
ef80af65dd is described below
commit ef80af65dd584f28472f9c0d17f105cc65a15d34
Author: Jiawei Shao <[email protected]>
AuthorDate: Wed Apr 3 07:43:31 2024 +0800
[Web] Support building tvm/web on Windows (#16810)
* [Web] Support building tvm/web on Windows
---
python/tvm/contrib/emcc.py | 4 +++-
web/Makefile | 2 +-
web/package.json | 4 ++--
web/run_jest.py | 24 ++++++++++++++++++++++++
web/tests/python/websock_rpc_test.py | 2 +-
5 files changed, 31 insertions(+), 5 deletions(-)
diff --git a/python/tvm/contrib/emcc.py b/python/tvm/contrib/emcc.py
index 325be6fa9c..3beb096b67 100644
--- a/python/tvm/contrib/emcc.py
+++ b/python/tvm/contrib/emcc.py
@@ -16,6 +16,7 @@
# under the License.
"""Util to invoke emscripten compilers in the system."""
# pylint: disable=invalid-name
+import os
import subprocess
from pathlib import Path
@@ -93,7 +94,8 @@ def create_tvmjs_wasm(output, objects, options=None,
cc="emcc", libs=None):
if options:
cmd += options
- proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)
+ is_windows = os.name == "nt"
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT, shell=is_windows)
(out, _) = proc.communicate()
if proc.returncode != 0:
diff --git a/web/Makefile b/web/Makefile
index 317438842b..5abd72b598 100644
--- a/web/Makefile
+++ b/web/Makefile
@@ -15,7 +15,7 @@
# specific language governing permissions and limitations
# under the License.
-TVM_ROOT=$(shell cd ..; pwd)
+TVM_ROOT=$(realpath $(shell dirname $(firstword $(MAKEFILE_LIST))))/../
INCLUDE_FLAGS = -I$(TVM_ROOT) -I$(TVM_ROOT)/include\
-I$(TVM_ROOT)/3rdparty/dlpack/include
-I$(TVM_ROOT)/3rdparty/dmlc-core/include\
diff --git a/web/package.json b/web/package.json
index 2e8de05971..49404b62e1 100644
--- a/web/package.json
+++ b/web/package.json
@@ -9,11 +9,11 @@
"main": "lib/index.js",
"types": "lib/index.d.ts",
"scripts": {
- "prepwasm": "make && python3 tests/python/prepare_test_libs.py",
+ "prepwasm": "make && python tests/python/prepare_test_libs.py",
"build": "rollup -c",
"lint": "eslint -c .eslintrc.json .",
"typedoc": "typedoc src/index.ts --plugin typedoc-plugin-missing-exports",
- "test": "node --experimental-wasm-eh node_modules/.bin/jest",
+ "test": "python run_jest.py",
"bundle": "npm run build && cp lib/index.js dist/index.js && cp
lib/index.js dist/tvmjs.bundle.js",
"example": "npm run bundle && node apps/node/example.js",
"example:wasi": "npm run bundle && node
--experimental-wasi-unstable-preview1 --experimental-wasm-bigint
apps/node/wasi_example.js",
diff --git a/web/run_jest.py b/web/run_jest.py
new file mode 100644
index 0000000000..9c932fdedb
--- /dev/null
+++ b/web/run_jest.py
@@ -0,0 +1,24 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+# Run jest based on current OS
+
+import os
+
+if os.name == "nt":
+ os.system("node_modules\\.bin\\jest")
+else:
+ os.system("node node_modules/.bin/jest")
diff --git a/web/tests/python/websock_rpc_test.py
b/web/tests/python/websock_rpc_test.py
index dc18dfd6d2..f7011cef47 100644
--- a/web/tests/python/websock_rpc_test.py
+++ b/web/tests/python/websock_rpc_test.py
@@ -48,7 +48,7 @@ def test_rpc():
temp = utils.tempdir()
wasm_path = temp.relpath("addone.wasm")
- fadd.export_library(wasm_path, fcompile=emcc.create_tvmjs_wasm)
+ fadd.export_library(wasm_path, fcompile=tvmjs.create_tvmjs_wasm)
wasm_binary = open(wasm_path, "rb").read()