WebAssembly / wasi-sdk

WASI-enabled WebAssembly C/C++ toolchain
Apache License 2.0
1.28k stars 192 forks source link

Unable to compile for `wasm32-wasi` using standalone sysroot: "no available targets are compatible" #172

Closed anp closed 3 years ago

anp commented 3 years ago

I'm trying out the SDK and have downloaded only the sysroot. It's extracted to /Users/adam/code/wasi-sysroot, but when I pass it to clang I get an error:

❯ clang --target=wasm32-wasi --sysroot=/Users/adam/code/wasi-sysroot main.cc
error: unable to create target: 'No available targets are compatible with triple "wasm32-unknown-wasi"'
1 error generated.

The contents of main.cc don't seem to matter but the error above came from a file with int main() {} as its contents.

I see that your release tarballs are using clang 11, whereas the xcode tools seem to have given me 12:

❯ clang --version
Apple clang version 12.0.0 (clang-1200.0.32.29)
Target: arm64-apple-darwin20.3.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Maybe that's the issue?

This error was one of several others I was seeing in the larger project from which I pulled this command. The contents of the sysroot seem valid on disk, as the other errors disappeared when I began passing --sysroot=....

sbc100 commented 3 years ago

It looks like perhaps your clang binary doesn't have support for WebAssembly. Although then I would expect to see an error message more like this:

clang --target=foo hello.c
error: unknown target triple 'foo', please use -triple or -arch

You can see the targets that are included by running llc --version. For example on my system:

$ llc --version
LLVM (http://llvm.org/):
  LLVM version 11.0.1

  Optimized build.
  Default target: x86_64-pc-linux-gnu
  Host CPU: broadwell

  Registered Targets:
    aarch64    - AArch64 (little endian)
    aarch64_32 - AArch64 (little endian ILP32)
    aarch64_be - AArch64 (big endian)
    amdgcn     - AMD GCN GPUs
    arm        - ARM
    arm64      - ARM64 (little endian)
    arm64_32   - ARM64 (little endian ILP32)
    armeb      - ARM (big endian)
    avr        - Atmel AVR Microcontroller
    bpf        - BPF (host endian)
    bpfeb      - BPF (big endian)
    bpfel      - BPF (little endian)
    hexagon    - Hexagon
    lanai      - Lanai
    mips       - MIPS (32-bit big endian)
    mips64     - MIPS (64-bit big endian)
    mips64el   - MIPS (64-bit little endian)
    mipsel     - MIPS (32-bit little endian)
    msp430     - MSP430 [experimental]
    nvptx      - NVIDIA PTX 32-bit
    nvptx64    - NVIDIA PTX 64-bit
    ppc32      - PowerPC 32
    ppc64      - PowerPC 64
    ppc64le    - PowerPC 64 LE
    r600       - AMD GPUs HD2XXX-HD6XXX
    riscv32    - 32-bit RISC-V
    riscv64    - 64-bit RISC-V
    sparc      - Sparc
    sparcel    - Sparc LE
    sparcv9    - Sparc V9
    systemz    - SystemZ
    thumb      - Thumb
    thumbeb    - Thumb (big endian)
    wasm32     - WebAssembly 32-bity-xxx-yy'
    wasm64     - WebAssembly 64-bit
    x86        - 32-bit X86: Pentium-Pro and above
    x86-64     - 64-bit X86: EM64T and AMD64
    xcore      - XCore
anp commented 3 years ago

Right, surprising to have such a recent clang version without wasm, but makes sense. The xcode CLI tools also didn't seem to come with a standalone llc binary, which is a bit more confusing.

I'll try using the prebuilt clang's y'all have in releases and see if I can make progress that way.

jedisct1 commented 3 years ago

You need to install llvm from Homebrew. Xcode's clang doesn't have support for WebAssembly.

anp commented 3 years ago

Indeed, thanks!

IgorKhomenko commented 6 months ago
brew install llvm
echo 'export PATH="/opt/homebrew/opt/llvm/bin:$PATH"' >> ~/.zshrc

works for me