Skip to content

Commit ef80af6

Browse files
authored
[Web] Support building tvm/web on Windows (#16810)
* [Web] Support building tvm/web on Windows
1 parent 3a42361 commit ef80af6

File tree

5 files changed

+31
-5
lines changed

5 files changed

+31
-5
lines changed

python/tvm/contrib/emcc.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
# under the License.
1717
"""Util to invoke emscripten compilers in the system."""
1818
# pylint: disable=invalid-name
19+
import os
1920
import subprocess
2021
from pathlib import Path
2122

@@ -93,7 +94,8 @@ def create_tvmjs_wasm(output, objects, options=None, cc="emcc", libs=None):
9394
if options:
9495
cmd += options
9596

96-
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
97+
is_windows = os.name == "nt"
98+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=is_windows)
9799
(out, _) = proc.communicate()
98100

99101
if proc.returncode != 0:

web/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# specific language governing permissions and limitations
1616
# under the License.
1717

18-
TVM_ROOT=$(shell cd ..; pwd)
18+
TVM_ROOT=$(realpath $(shell dirname $(firstword $(MAKEFILE_LIST))))/../
1919

2020
INCLUDE_FLAGS = -I$(TVM_ROOT) -I$(TVM_ROOT)/include\
2121
-I$(TVM_ROOT)/3rdparty/dlpack/include -I$(TVM_ROOT)/3rdparty/dmlc-core/include\

web/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
"main": "lib/index.js",
1010
"types": "lib/index.d.ts",
1111
"scripts": {
12-
"prepwasm": "make && python3 tests/python/prepare_test_libs.py",
12+
"prepwasm": "make && python tests/python/prepare_test_libs.py",
1313
"build": "rollup -c",
1414
"lint": "eslint -c .eslintrc.json .",
1515
"typedoc": "typedoc src/index.ts --plugin typedoc-plugin-missing-exports",
16-
"test": "node --experimental-wasm-eh node_modules/.bin/jest",
16+
"test": "python run_jest.py",
1717
"bundle": "npm run build && cp lib/index.js dist/index.js && cp lib/index.js dist/tvmjs.bundle.js",
1818
"example": "npm run bundle && node apps/node/example.js",
1919
"example:wasi": "npm run bundle && node --experimental-wasi-unstable-preview1 --experimental-wasm-bigint apps/node/wasi_example.js",

web/run_jest.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# Licensed to the Apache Software Foundation (ASF) under one
2+
# or more contributor license agreements. See the NOTICE file
3+
# distributed with this work for additional information
4+
# regarding copyright ownership. The ASF licenses this file
5+
# to you under the Apache License, Version 2.0 (the
6+
# "License"); you may not use this file except in compliance
7+
# with the License. You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing,
12+
# software distributed under the License is distributed on an
13+
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
# KIND, either express or implied. See the License for the
15+
# specific language governing permissions and limitations
16+
# under the License.
17+
# Run jest based on current OS
18+
19+
import os
20+
21+
if os.name == "nt":
22+
os.system("node_modules\\.bin\\jest")
23+
else:
24+
os.system("node node_modules/.bin/jest")

web/tests/python/websock_rpc_test.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def test_rpc():
4848
temp = utils.tempdir()
4949

5050
wasm_path = temp.relpath("addone.wasm")
51-
fadd.export_library(wasm_path, fcompile=emcc.create_tvmjs_wasm)
51+
fadd.export_library(wasm_path, fcompile=tvmjs.create_tvmjs_wasm)
5252

5353
wasm_binary = open(wasm_path, "rb").read()
5454

0 commit comments

Comments
 (0)