Repository: apache/tvm

Issue:
[BUG] `wasm-standalone` app cannot work
When @mssun and me try to rebuild [wasm-standalone app](https://github.com/apache/tvm/tree/main/apps/wasm-standalone), we encountered several problems. Some of them were fixed TEMPORARILY, and we failed to get over some problems.

## My environment

TVM: e3e03df3b6ad35ca81671284d229d1b37b032a27, default config, except `USE_LLVM ON`
rustc: 1.53.0
LLVM: 12.0.0
Python: 3.9.5

## Problem 1: `build_graph_lib.py` doesn't work

An error occurs when I tried to run the script (`LLVM_AR=llvm-ar python ./build_graph_lib.py -O3 ./resnet50v1.onnx 
`). The error message is:
```sh
Traceback (most recent call last):
  File "/home/ya0guang/Code/tvm/apps/wasm-standalone/wasm-graph/tools/./build_graph_lib.py", line 79, in <module>
    build_graph_lib(args.model_file, args.opt_level)
  File "/home/ya0guang/Code/tvm/apps/wasm-standalone/wasm-graph/tools/./build_graph_lib.py", line 47, in build_graph_lib
    mod, params = _get_mod_and_params(model_file)
  File "/home/ya0guang/Code/tvm/apps/wasm-standalone/wasm-graph/tools/./build_graph_lib.py", line 37, in _get_mod_and_params
    return relay.frontend.from_onnx(onnx_model, shape_dict)
  File "/home/ya0guang/Code/tvm/python/tvm/relay/frontend/onnx.py", line 3820, in from_onnx
    mod, params = g.from_onnx(graph, opset)
  File "/home/ya0guang/Code/tvm/python/tvm/relay/frontend/onnx.py", line 3559, in from_onnx
    assert all(
AssertionError: User specified the shape for inputs that weren't found in the graph: {'data': [1, 3, 224, 224], 'resnetv17_conv0_weight': [64, 3, 7, 7], 'resnetv17_batchnorm0_gamma': [64], 'resnetv17_batchnorm0_beta': [64], 'resnetv17_batchnorm0_running_mean': [64], 'resnetv17_batchnorm0_running_var': [64], 'resnetv17_stage1_conv0_weight': [64, 64, 1, 1], 'resnetv17_stage1_conv0_bias': [64], 'resnetv17_stage1_batchnorm0_gamma': [64], 'resnetv17_stage1_batchnorm0_beta': [64], 'resnetv17_stage1_batchnorm0_running_mean': [64], 'resnetv17_stage1_batchnorm0_running_var': [64], 'resnetv17_stage1_conv1_weight': [64, 64, 3, 3], 'resnetv17_stage1_batchnorm1_gamma': [64], 'resnetv17_stage1_batchnorm1_beta': [64], 'resnetv17_stage1_batchnorm1_running_mean': [64], 'resnetv17_stage1_batchnorm1_running_var': [64], 'resnetv17_stage1_conv2_weight': [256, 64, 1, 1], 'resnetv17_stage1_conv2_bias': [256], 'resnetv17_stage1_batchnorm2_gamma': [256], 'resnetv17_stage1_batchnorm2_beta': [256], 'resnetv17_stage1_batchnorm2_running_mean': [256], 'resnetv17_stage1_batchnorm2_running_var': [256], 'resnetv17_stage1_conv3_weight': [256, 64, 1, 1], 'resnetv17_stage1_batchnorm3_gamma': [256], 'resnetv17_stage1_batchnorm3_beta': [256], 'resnetv17_stage1_batchnorm3_running_mean': [256], 'resnetv17_stage1_batchnorm3_running_var': [256], 'resnetv17_stage1_conv4_weight': [64, 256, 1, 1], 'resnetv17_stage1_conv4_bias': [64], 'resnetv17_stage1_batchnorm4_gamma': [64], 'resnetv17_stage1_batchnorm4_beta': [64], 'resnetv17_stage1_batchnorm4_running_mean': [64], 'resnetv17_stage1_batchnorm4_running_var': [64], 'resnetv17_stage1_conv5_weight': [64, 64, 3, 3], 'resnetv17_stage1_batchnorm5_gamma': [64], 'resnetv17_stage1_batchnorm5_beta': [64], 'resnetv17_stage1_batchnorm5_running_mean': [64], 'resnetv17_stage1_batchnorm5_running_var': [64], 'resnetv17_stage1_conv6_weight': [256, 64, 1, 1], 'resnetv17_stage1_conv6_bias': [256], 'resnetv17_stage1_batchnorm6_gamma': [256], 'resnetv17_stage1_batchnorm6_beta': [256], 'resnetv17_stage1_batchnorm6_running_mean': [256], 'resnetv17_stage1_batchnorm6_running_var': [256], 'resnetv17_stage1_conv7_weight': [64, 256, 1, 1], 'resnetv17_stage1_conv7_bias': [64], 'resnetv17_stage1_batchnorm7_gamma': [64], 'resnetv17_stage1_batchnorm7_beta': [64], 'resnetv17_stage1_batchnorm7_running_mean': [64], 'resnetv17_stage1_batchnorm7_running_var': [64], 'resnetv17_stage1_conv8_weight': [64, 64, 3, 3], 'resnetv17_stage1_batchnorm8_gamma': [64], 'resnetv17_stage1_batchnorm8_beta': [64], 'resnetv17_stage1_batchnorm8_running_mean': [64], 'resnetv17_stage1_batchnorm8_running_var': [64], 'resnetv17_stage1_conv9_weight': [256, 64, 1, 1], 'resnetv17_stage1_conv9_bias': [256], 'resnetv17_stage1_batchnorm9_gamma': [256], 'resnetv17_stage1_batchnorm9_beta': [256], 'resnetv17_stage1_batchnorm9_running_mean': [256], 'resnetv17_stage1_batchnorm9_running_var': [256], 'resnetv17_stage2_conv0_weight': [128, 256, 1, 1], 'resnetv17_stage2_conv0_bias': [128], 'resnetv17_stage2_batchnorm0_gamma': [128], 'resnetv17_stage2_batchnorm0_beta': [128], 'resnetv17_stage2_batchnorm0_running_mean': [128], 'resnetv17_stage2_batchnorm0_running_var': [128], 'resnetv17_stage2_conv1_weight': [128, 128, 3, 3], 'resnetv17_stage2_batchnorm1_gamma': [128], 'resnetv17_stage2_batchnorm1_beta': [128], 'resnetv17_stage2_batchnorm1_running_mean': [128], 'resnetv17_stage2_batchnorm1_running_var': [128], 'resnetv17_stage2_conv2_weight': [512, 128, 1, 1], 'resnetv17_stage2_conv2_bias': [512], 'resnetv17_stage2_batchnorm2_gamma': [512], 'resnetv17_stage2_batchnorm2_beta': [512], 'resnetv17_stage2_batchnorm2_running_mean': [512], 'resnetv17_stage2_batchnorm2_running_var': [512], 'resnetv17_stage2_conv3_weight': [512, 256, 1, 1], 'resnetv17_stage2_batchnorm3_gamma': [512], 'resnetv17_stage2_batchnorm3_beta': [512], 'resnetv17_stage2_batchnorm3_running_mean': [512], 'resnetv17_stage2_batchnorm3_running_var': [512], 'resnetv17_stage2_conv4_weight': [128, 512, 1, 1], 'resnetv17_stage2_conv4_bias': [128], 'resnetv17_stage2_batchnorm4_gamma': [128], 'resnetv17_stage2_batchnorm4_beta': [128], 'resnetv17_stage2_batchnorm4_running_mean': [128], 'resnetv17_stage2_batchnorm4_running_var': [128], 'resnetv17_stage2_conv5_weight': [128, 128, 3, 3], 'resnetv17_stage2_batchnorm5_gamma': [128], 'resnetv17_stage2_batchnorm5_beta': [128], 'resnetv17_stage2_batchnorm5_running_mean': [128], 'resnetv17_stage2_batchnorm5_running_var': [128], 'resnetv17_stage2_conv6_weight': [512, 128, 1, 1], 'resnetv17_stage2_conv6_bias': [512], 'resnetv17_stage2_batchnorm6_gamma': [512], 'resnetv17_stage2_batchnorm6_beta': [512], 'resnetv17_stage2_batchnorm6_running_mean': [512], 'resnetv17_stage2_batchnorm6_running_var': [512], 'resnetv17_stage2_conv7_weight': [128, 512, 1, 1], 'resnetv17_stage2_conv7_bias': [128], 'resnetv17_stage2_batchnorm7_gamma': [128], 'resnetv17_stage2_batchnorm7_beta': [128], 'resnetv17_stage2_batchnorm7_running_mean': [128], 'resnetv17_stage2_batchnorm7_running_var': [128], 'resnetv17_stage2_conv8_weight': [128, 128, 3, 3], 'resnetv17_stage2_batchnorm8_gamma': [128], 'resnetv17_stage2_batchnorm8_beta': [128], 'resnetv17_stage2_batchnorm8_running_mean': [128], 'resnetv17_stage2_batchnorm8_running_var': [128], 'resnetv17_stage2_conv9_weight': [512, 128, 1, 1], 'resnetv17_stage2_conv9_bias': [512], 'resnetv17_stage2_batchnorm9_gamma': [512], 'resnetv17_stage2_batchnorm9_beta': [512], 'resnetv17_stage2_batchnorm9_running_mean': [512], 'resnetv17_stage2_batchnorm9_running_var': [512], 'resnetv17_stage2_conv10_weight': [128, 512, 1, 1], 'resnetv17_stage2_conv10_bias': [128], 'resnetv17_stage2_batchnorm10_gamma': [128], 'resnetv17_stage2_batchnorm10_beta': [128], 'resnetv17_stage2_batchnorm10_running_mean': [128], 'resnetv17_stage2_batchnorm10_running_var': [128], 'resnetv17_stage2_conv11_weight': [128, 128, 3, 3], 'resnetv17_stage2_batchnorm11_gamma': [128], 'resnetv17_stage2_batchnorm11_beta': [128], 'resnetv17_stage2_batchnorm11_running_mean': [128], 'resnetv17_stage2_batchnorm11_running_var': [128], 'resnetv17_stage2_conv12_weight': [512, 128, 1, 1], 'resnetv17_stage2_conv12_bias': [512], 'resnetv17_stage2_batchnorm12_gamma': [512], 'resnetv17_stage2_batchnorm12_beta': [512], 'resnetv17_stage2_batchnorm12_running_mean': [512], 'resnetv17_stage2_batchnorm12_running_var': [512], 'resnetv17_stage3_conv0_weight': [256, 512, 1, 1], 'resnetv17_stage3_conv0_bias': [256], 'resnetv17_stage3_batchnorm0_gamma': [256], 'resnetv17_stage3_batchnorm0_beta': [256], 'resnetv17_stage3_batchnorm0_running_mean': [256], 'resnetv17_stage3_batchnorm0_running_var': [256], 'resnetv17_stage3_conv1_weight': [256, 256, 3, 3], 'resnetv17_stage3_batchnorm1_gamma': [256], 'resnetv17_stage3_batchnorm1_beta': [256], 'resnetv17_stage3_batchnorm1_running_mean': [256], 'resnetv17_stage3_batchnorm1_running_var': [256], 'resnetv17_stage3_conv2_weight': [1024, 256, 1, 1], 'resnetv17_stage3_conv2_bias': [1024], 'resnetv17_stage3_batchnorm2_gamma': [1024], 'resnetv17_stage3_batchnorm2_beta': [1024], 'resnetv17_stage3_batchnorm2_running_mean': [1024], 'resnetv17_stage3_batchnorm2_running_var': [1024], 'resnetv17_stage3_conv3_weight': [1024, 512, 1, 1], 'resnetv17_stage3_batchnorm3_gamma': [1024], 'resnetv17_stage3_batchnorm3_beta': [1024], 'resnetv17_stage3_batchnorm3_running_mean': [1024], 'resnetv17_stage3_batchnorm3_running_var': [1024], 'resnetv17_stage3_conv4_weight': [256, 1024, 1, 1], 'resnetv17_stage3_conv4_bias': [256], 'resnetv17_stage3_batchnorm4_gamma': [256], 'resnetv17_stage3_batchnorm4_beta': [256], 'resnetv17_stage3_batchnorm4_running_mean': [256], 'resnetv17_stage3_batchnorm4_running_var': [256], 'resnetv17_stage3_conv5_weight': [256, 256, 3, 3], 'resnetv17_stage3_batchnorm5_gamma': [256], 'resnetv17_stage3_batchnorm5_beta': [256], 'resnetv17_stage3_batchnorm5_running_mean': [256], 'resnetv17_stage3_batchnorm5_running_var': [256], 'resnetv17_stage3_conv6_weight': [1024, 256, 1, 1], 'resnetv17_stage3_conv6_bias': [1024], 'resnetv17_stage3_batchnorm6_gamma': [1024], 'resnetv17_stage3_batchnorm6_beta': [1024], 'resnetv17_stage3_batchnorm6_running_mean': [1024], 'resnetv17_stage3_batchnorm6_running_var': [1024], 'resnetv17_stage3_conv7_weight': [256, 1024, 1, 1], 'resnetv17_stage3_conv7_bias': [256], 'resnetv17_stage3_batchnorm7_gamma': [256], 'resnetv17_stage3_batchnorm7_beta': [256], 'resnetv17_stage3_batchnorm7_running_mean': [256], 'resnetv17_stage3_batchnorm7_running_var': [256], 'resnetv17_stage3_conv8_weight': [256, 256, 3, 3], 'resnetv17_stage3_batchnorm8_gamma': [256], 'resnetv17_stage3_batchnorm8_beta': [256], 'resnetv17_stage3_batchnorm8_running_mean': [256], 'resnetv17_stage3_batchnorm8_running_var': [256], 'resnetv17_stage3_conv9_weight': [1024, 256, 1, 1], 'resnetv17_stage3_conv9_bias': [1024], 'resnetv17_stage3_batchnorm9_gamma': [1024], 'resnetv17_stage3_batchnorm9_beta': [1024], 'resnetv17_stage3_batchnorm9_running_mean': [1024], 'resnetv17_stage3_batchnorm9_running_var': [1024], 'resnetv17_stage3_conv10_weight': [256, 1024, 1, 1], 'resnetv17_stage3_conv10_bias': [256], 'resnetv17_stage3_batchnorm10_gamma': [256], 'resnetv17_stage3_batchnorm10_beta': [256], 'resnetv17_stage3_batchnorm10_running_mean': [256], 'resnetv17_stage3_batchnorm10_running_var': [256], 'resnetv17_stage3_conv11_weight': [256, 256, 3, 3], 'resnetv17_stage3_batchnorm11_gamma': [256], 'resnetv17_stage3_batchnorm11_beta': [256], 'resnetv17_stage3_batchnorm11_running_mean': [256], 'resnetv17_stage3_batchnorm11_running_var': [256], 'resnetv17_stage3_conv12_weight': [1024, 256, 1, 1], 'resnetv17_stage3_conv12_bias': [1024], 'resnetv17_stage3_batchnorm12_gamma': [1024], 'resnetv17_stage3_batchnorm12_beta': [1024], 'resnetv17_stage3_batchnorm12_running_mean': [1024], 'resnetv17_stage3_batchnorm12_running_var': [1024], 'resnetv17_stage3_conv13_weight': [256, 1024, 1, 1], 'resnetv17_stage3_conv13_bias': [256], 'resnetv17_stage3_batchnorm13_gamma': [256], 'resnetv17_stage3_batchnorm13_beta': [256], 'resnetv17_stage3_batchnorm13_running_mean': [256], 'resnetv17_stage3_batchnorm13_running_var': [256], 'resnetv17_stage3_conv14_weight': [256, 256, 3, 3], 'resnetv17_stage3_batchnorm14_gamma': [256], 'resnetv17_stage3_batchnorm14_beta': [256], 'resnetv17_stage3_batchnorm14_running_mean': [256], 'resnetv17_stage3_batchnorm14_running_var': [256], 'resnetv17_stage3_conv15_weight': [1024, 256, 1, 1], 'resnetv17_stage3_conv15_bias': [1024], 'resnetv17_stage3_batchnorm15_gamma': [1024], 'resnetv17_stage3_batchnorm15_beta': [1024], 'resnetv17_stage3_batchnorm15_running_mean': [1024], 'resnetv17_stage3_batchnorm15_running_var': [1024], 'resnetv17_stage3_conv16_weight': [256, 1024, 1, 1], 'resnetv17_stage3_conv16_bias': [256], 'resnetv17_stage3_batchnorm16_gamma': [256], 'resnetv17_stage3_batchnorm16_beta': [256], 'resnetv17_stage3_batchnorm16_running_mean': [256], 'resnetv17_stage3_batchnorm16_running_var': [256], 'resnetv17_stage3_conv17_weight': [256, 256, 3, 3], 'resnetv17_stage3_batchnorm17_gamma': [256], 'resnetv17_stage3_batchnorm17_beta': [256], 'resnetv17_stage3_batchnorm17_running_mean': [256], 'resnetv17_stage3_batchnorm17_running_var': [256], 'resnetv17_stage3_conv18_weight': [1024, 256, 1, 1], 'resnetv17_stage3_conv18_bias': [1024], 'resnetv17_stage3_batchnorm18_gamma': [1024], 'resnetv17_stage3_batchnorm18_beta': [1024], 'resnetv17_stage3_batchnorm18_running_mean': [1024], 'resnetv17_stage3_batchnorm18_running_var': [1024], 'resnetv17_stage4_conv0_weight': [512, 1024, 1, 1], 'resnetv17_stage4_conv0_bias': [512], 'resnetv17_stage4_batchnorm0_gamma': [512], 'resnetv17_stage4_batchnorm0_beta': [512], 'resnetv17_stage4_batchnorm0_running_mean': [512], 'resnetv17_stage4_batchnorm0_running_var': [512], 'resnetv17_stage4_conv1_weight': [512, 512, 3, 3], 'resnetv17_stage4_batchnorm1_gamma': [512], 'resnetv17_stage4_batchnorm1_beta': [512], 'resnetv17_stage4_batchnorm1_running_mean': [512], 'resnetv17_stage4_batchnorm1_running_var': [512], 'resnetv17_stage4_conv2_weight': [2048, 512, 1, 1], 'resnetv17_stage4_conv2_bias': [2048], 'resnetv17_stage4_batchnorm2_gamma': [2048], 'resnetv17_stage4_batchnorm2_beta': [2048], 'resnetv17_stage4_batchnorm2_running_mean': [2048], 'resnetv17_stage4_batchnorm2_running_var': [2048], 'resnetv17_stage4_conv3_weight': [2048, 1024, 1, 1], 'resnetv17_stage4_batchnorm3_gamma': [2048], 'resnetv17_stage4_batchnorm3_beta': [2048], 'resnetv17_stage4_batchnorm3_running_mean': [2048], 'resnetv17_stage4_batchnorm3_running_var': [2048], 'resnetv17_stage4_conv4_weight': [512, 2048, 1, 1], 'resnetv17_stage4_conv4_bias': [512], 'resnetv17_stage4_batchnorm4_gamma': [512], 'resnetv17_stage4_batchnorm4_beta': [512], 'resnetv17_stage4_batchnorm4_running_mean': [512], 'resnetv17_stage4_batchnorm4_running_var': [512], 'resnetv17_stage4_conv5_weight': [512, 512, 3, 3], 'resnetv17_stage4_batchnorm5_gamma': [512], 'resnetv17_stage4_batchnorm5_beta': [512], 'resnetv17_stage4_batchnorm5_running_mean': [512], 'resnetv17_stage4_batchnorm5_running_var': [512], 'resnetv17_stage4_conv6_weight': [2048, 512, 1, 1], 'resnetv17_stage4_conv6_bias': [2048], 'resnetv17_stage4_batchnorm6_gamma': [2048], 'resnetv17_stage4_batchnorm6_beta': [2048], 'resnetv17_stage4_batchnorm6_running_mean': [2048], 'resnetv17_stage4_batchnorm6_running_var': [2048], 'resnetv17_stage4_conv7_weight': [512, 2048, 1, 1], 'resnetv17_stage4_conv7_bias': [512], 'resnetv17_stage4_batchnorm7_gamma': [512], 'resnetv17_stage4_batchnorm7_beta': [512], 'resnetv17_stage4_batchnorm7_running_mean': [512], 'resnetv17_stage4_batchnorm7_running_var': [512], 'resnetv17_stage4_conv8_weight': [512, 512, 3, 3], 'resnetv17_stage4_batchnorm8_gamma': [512], 'resnetv17_stage4_batchnorm8_beta': [512], 'resnetv17_stage4_batchnorm8_running_mean': [512], 'resnetv17_stage4_batchnorm8_running_var': [512], 'resnetv17_stage4_conv9_weight': [2048, 512, 1, 1], 'resnetv17_stage4_conv9_bias': [2048], 'resnetv17_stage4_batchnorm9_gamma': [2048], 'resnetv17_stage4_batchnorm9_beta': [2048], 'resnetv17_stage4_batchnorm9_running_mean': [2048], 'resnetv17_stage4_batchnorm9_running_var': [2048], 'resnetv17_dense0_weight': [1000, 2048], 'resnetv17_dense0_bias': [1000]}
```

### Hot fix

We eliminate this error by modifying the function `_get_mod_and_params`: adding a line before return.

```sh
def _get_mod_and_params(model_file):
    onnx_model = onnx.load(model_file)
    shape_dict = {}
    for input in onnx_model.graph.input:
        shape_dict[input.name] = [dim.dim_value for dim in input.type.tensor_type.shape.dim]

    shape_dict = {"data": shape_dict["data"]}
    return relay.frontend.from_onnx(onnx_model, shape_dict)
```

## Problem 2: Cargo cannot build `wasm-graph`

The second problem is occurs while cargo trying to compile and link. (`cd wasm-graph && cargo build --release`)

```sh
error: linking with `rust-lld` failed: exit status: 1
  |
  = note: "rust-lld" "-flavor" "wasm" "--rsp-quoting=posix" "-z" "stack-size=1048576" "--stack-first" "--allow-undefined" "--fatal-warnings" "--no-demangle" "-L" "/home/ya0guang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-wasi/lib" "-L" "/home/ya0guang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-wasi/lib/self-contained" "/home/ya0guang/Code/tvm/apps/wasm-standalone/wasm-graph/target/wasm32-wasi/release/deps/wasm_graph.wasm_graph.9d8qt5z6-cgu.0.rcgu.o" "-o" "/home/ya0guang/Code/tvm/apps/wasm-standalone/wasm-graph/target/wasm32-wasi/release/deps/wasm_graph.wasm" "--export" "run" "--export" "TVMAPISetLastError" "--export" "TVMBackendAllocWorkspace" "--export" "TVMBackendFreeWorkspace" "--export" "TVMBackendParallelBarrier" "--export" "TVMBackendParallelLaunch" "--export" "TVMBackendRegisterSystemLibSymbol" "--export" "TVMGetLastError" "--export=__heap_base" "--export=__data_end" "--gc-sections" "--no-entry" "-O2" "-L" "/home/ya0guang/Code/tvm/apps/wasm-standalone/wasm-graph/target/wasm32-wasi/release/deps" "-L" "/home/ya0guang/Code/tvm/apps/wasm-standalone/wasm-graph/target/release/deps" "-L" "/home/ya0guang/Code/tvm/apps/wasm-standalone/wasm-graph/lib" "-L" "/home/ya0guang/Code/tvm/build" "-L" "/home/ya0guang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-wasi/lib" "/tmp/rustcB2Rq3f/liblibc-dd6fd16fbeb0b6c9.rlib" "/home/ya0guang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/wasm32-wasi/lib/libcompiler_builtins-55f71868fddeb6d1.rlib" "-l" "tvm" "--whole-archive" "-lgraph_wasm32"
  = note: rust-lld: error: unable to find library -ltvm
          

error: aborting due to previous error

error: could not compile `wasm-graph`

To learn more, run the command again with --verbose.
```

Actually the library `libtvm.so` does EXIST. However, it's a 64bit elf SO, which may not be linked to a WASM bytecode directly. 

### Hot fix

This error comes from a dependency in `rust/tvm-sys`. We comment the snippet linking the **tvm** library in `build.rs` like this:
```rs
    // if cfg!(feature = "static-linking") {
    //     println!("cargo:rustc-link-lib=static=tvm");
    //     // TODO(@jroesch): move this to tvm-build as library_path?
    //     println!(
    //         "cargo:rustc-link-search=native={}/build",
    //         build_path.display()
    //     );
    // }

    // if cfg!(feature = "dynamic-linking") {
    //     println!("cargo:rustc-link-lib=dylib=tvm");
    //     println!(
    //         "cargo:rustc-link-search=native={}/build",
    //         build_path.display()
    //     );
    // }
```
then it compiles. We cooment these lines because the code seems only use some data structures from the `tvm-sys`.

## Problem 3

After the WASM file and test runtime have been successfully generated, the test program doens't work. 

```sh
$ RUST_BACKTRACE=1 ./target/debug/test_graph_resnet50 -g ./wasm_graph_resnet50.wasm -i ./cat.png -l ./synset.csv 
original image dimensions: (256, 256)
resized image dimensions: (224, 224)
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: stack operand type mismatch (at offset 227760)', src/main.rs:82:45
stack backtrace:
   0: rust_begin_unwind
             at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/std/src/panicking.rs:493:5
   1: core::panicking::panic_fmt
             at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/core/src/panicking.rs:92:14
   2: core::result::unwrap_failed
             at /rustc/53cb7b09b00cbea8754ffb78e7e3cb521cb8af4b/library/core/src/result.rs:1355:5
   3: core::result::Result<T,E>::unwrap
             at /home/ya0guang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/result.rs:1037:23
   4: test_graph_resnet50::main
             at ./src/main.rs:82:5
   5: core::ops::function::FnOnce::call_once
             at /home/ya0guang/.rustup/toolchains/stable-x86_64-unknown-linux-gnu/lib/rustlib/src/rust/library/core/src/ops/function.rs:227:5
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
```

It seems like the WASM module cannot be instantiated successfully.

## Summary

I have no confidence that all these hot fixes are correct. If someone can fix them and let it work, we will be more than grateful! 


Discussion:
Hopefully, the initial committer of this app can help us @leonwanghui .
@ya0guang Sorry for the late reply, this app has not been maintained since https://github.com/apache/tvm/pull/6862, if you want to make the demo work, it's highly suggested to downgrade the version of TVM to `44ff1f3b5ed0751fee39537a0e6e3870a74c930b`, and the demo was only tested on LLVM 10.0
> @ya0guang Sorry for the late reply, this app has not been maintained since #6862, if you want to make the demo work, it's highly suggested to downgrade the version of TVM to `44ff1f3b5ed0751fee39537a0e6e3870a74c930b`, and the demo was only tested on LLVM 10.0

Thanks a lot for your reply!

However, the problem still exists after I switch to the specific commit and LLVM 10. The Python script doesn't work and complains about "Invalid target". Then I checked the source code [`src/target/target_id.cc`](https://github.com/apache/tvm/blob/44ff1f3b5ed0751fee39537a0e6e3870a74c930b/src/target/target_id.cc#L351) and found that it doesn't accept `target` as an attribute. I add a line, `    .add_attr_option<String>("target")`, then the script can generate `.o` and `.a` files successfully, but the static library was rejected by `wasm-graph`. I think this is because the generated library is **ELF 64** rather than WASM bytecode, and it cannot be linked to wasi32 `wasm-graph`.

Can you build the project at your end? If you or anyone else in this community can give me some advice and finally I build that application, I'll be happy to commit a PR and help polish this part. 

Resolving patch:
diff --git a/apps/wasm-standalone/wasm-graph/tools/build_graph_lib.py b/apps/wasm-standalone/wasm-graph/tools/build_graph_lib.py
old mode 100644
new mode 100755
--- a/apps/wasm-standalone/wasm-graph/tools/build_graph_lib.py
+++ b/apps/wasm-standalone/wasm-graph/tools/build_graph_lib.py
@@ -16,7 +16,7 @@
 # specific language governing permissions and limitations
 # under the License.
 
-"""Builds a simple graph for testing."""
+"""Builds a simple resnet50 graph for testing."""
 import argparse
 import os
 import subprocess
@@ -25,47 +25,78 @@
 import onnx
 import tvm
 from tvm import relay, runtime
+from tvm.contrib.download import download_testdata
+from tvm.contrib import graph_executor
 
+from PIL import Image
+import numpy as np
+import tvm.relay as relay
 
-def _get_mod_and_params(model_file):
-    onnx_model = onnx.load(model_file)
-    shape_dict = {}
-    for input in onnx_model.graph.input:
-        shape_dict[input.name] = [dim.dim_value for dim in input.type.tensor_type.shape.dim]
+# This example uses resnet50-v2-7 model
+model_url = "".join(
+    [
+        "https://github.com/onnx/models/raw/",
+        "master/vision/classification/resnet/model/",
+        "resnet50-v2-7.onnx",
+    ]
+)
 
-    return relay.frontend.from_onnx(onnx_model, shape_dict)
 
-
-def build_graph_lib(model_file, opt_level):
+def build_graph_lib(opt_level):
     """Compiles the pre-trained model with TVM"""
     out_dir = os.path.join(sys.path[0], "../lib")
     if not os.path.exists(out_dir):
         os.makedirs(out_dir)
 
-    # Compile the relay mod
-    mod, params = _get_mod_and_params(model_file)
+    # Follow the tutorial to download and compile the model
+    model_path = download_testdata(model_url, "resnet50-v2-7.onnx", module="onnx")
+    onnx_model = onnx.load(model_path)
+
+    img_url = "https://s3.amazonaws.com/model-server/inputs/kitten.jpg"
+    img_path = download_testdata(img_url, "imagenet_cat.png", module="data")
+
+    # Resize it to 224x224
+    resized_image = Image.open(img_path).resize((224, 224))
+    img_data = np.asarray(resized_image).astype("float32")
+
+    # Our input image is in HWC layout while ONNX expects CHW input, so convert the array
+    img_data = np.transpose(img_data, (2, 0, 1))
+
+    # Normalize according to the ImageNet input specification
+    imagenet_mean = np.array([0.485, 0.456, 0.406]).reshape((3, 1, 1))
+    imagenet_stddev = np.array([0.229, 0.224, 0.225]).reshape((3, 1, 1))
+    norm_img_data = (img_data / 255 - imagenet_mean) / imagenet_stddev
+
+    # Add the batch dimension, as we are expecting 4-dimensional input: NCHW.
+    img_data = np.expand_dims(norm_img_data, axis=0)
+
+    input_name = "data"
+    shape_dict = {input_name: img_data.shape}
+
+    mod, params = relay.frontend.from_onnx(onnx_model, shape_dict)
     target = "llvm -mtriple=wasm32-unknown-unknown -mattr=+simd128 --system-lib"
+
     with tvm.transform.PassContext(opt_level=opt_level):
-        graph_json, lib, params = relay.build(mod, target=target, params=params)
+        factory = relay.build(mod, target=target, params=params)
 
     # Save the model artifacts to obj_file
     obj_file = os.path.join(out_dir, "graph.o")
-    lib.save(obj_file)
+    factory.get_lib().save(obj_file)
+
     # Run llvm-ar to archive obj_file into lib_file
     lib_file = os.path.join(out_dir, "libgraph_wasm32.a")
     cmds = [os.environ.get("LLVM_AR", "llvm-ar-10"), "rcs", lib_file, obj_file]
     subprocess.run(cmds)
 
+    # Save the json and params
     with open(os.path.join(out_dir, "graph.json"), "w") as f_graph:
-        f_graph.write(graph_json)
-
+        f_graph.write(factory.get_graph_json())
     with open(os.path.join(out_dir, "graph.params"), "wb") as f_params:
-        f_params.write(runtime.save_param_dict(params))
+        f_params.write(runtime.save_param_dict(factory.get_params()))
 
 
 if __name__ == "__main__":
     parser = argparse.ArgumentParser(description="ONNX model build example")
-    parser.add_argument("model_file", type=str, help="the path of onnx model file")
     parser.add_argument(
         "-O",
         "--opt-level",
@@ -75,4 +106,4 @@ def build_graph_lib(model_file, opt_level):
     )
     args = parser.parse_args()
 
-    build_graph_lib(args.model_file, args.opt_level)
+    build_graph_lib(args.opt_level)


Test patch: