dart-archive / wasm

Utilities for loading and running WASM modules from Dart code
https://pub.dev/packages/wasm
BSD 3-Clause "New" or "Revised" License
309 stars 25 forks source link

Failed "clang --target=wasm32 -nostdlib "-Wl,--export-all" "-Wl,--no-entry" -o square.wasm square.cc" #75

Closed hotmanga closed 2 years ago

hotmanga commented 2 years ago

Hi, when I use this "clang --target=wasm32 -nostdlib "-Wl,--export-all" "-Wl,--no-entry" -o square.wasm square.cc"

It reports error, error message is "error: unable to create target: 'No available targets are compatible with triple "wasm32"' 1 error generated."

I have do step by step this page "wasm basic usage".

And I have done (1),(2), (3), (4), and they are correct.

But, when I try to do (5) and run this command "clang --target=wasm32 -nostdlib "-Wl,--export-all" "-Wl,--no-entry" -o square.wasm square.cc", it is Failed.

Maybe, I think the target "wasm32" is not exists.

So, I run these command, 1, "rustup target add wasm32-wasi" 2, "rustup target add wasm32-unknown-unknown" 3, "rustup target add wasm32-unknown-emscripten" by this page platform-support

These run correct, when I run "rustup target list", it shows "installed"

But, when I run "clang --print-targets", it shows Registered Targets:

So, is something not correct about my operation?

hotmanga commented 2 years ago

My system info is (sw_vers): sw_vers ProductName: macOS ProductVersion: 12.3 BuildVersion: 21E5206e

My dart, rust, clang versions: dart --version Dart SDK version: 2.15.1 (stable) (Tue Dec 14 13:32:21 2021 +0100) on "macos_x64"

rustc --version rustc 1.58.1 (db9d1b20b 2022-01-20)

clang --version Apple clang version 13.0.0 (clang-1300.0.29.30) Target: x86_64-apple-darwin21.4.0 Thread model: posix InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

liamappelbe commented 2 years ago

I didn't test the example on mac, just linux. I think clang for mac is a little bit different than other platforms. From your clang --print-targets, it looks like your version of clang doesn't support compiling to wasm. You might be able to get a different version of clang for mac that supports wasm.

Another way to fix it would be to try a different compiler. There are a lot of compilers that can generate wasm. You could try following this example instead, which uses wasienv. Wasienv is a more complete compiler, because it includes wasi, which is how wasm talks to the OS.

If you just want something quick and simple to get the basic example working, you could try WasmFiddle. This is the tool I used to generate most of the tests.