Issue 167669
Summary [Question] Emscripten include paths missing in Clang WebAssembly toolchain ?
Labels clang
Assignees
Reporter anutosh491
    Hey @sbc100 , I have a simple question that possibly you could clarify for me 

Question : Should Clang’s WebAssembly toolchain handle Emscripten-specific include paths like /include/compat when targeting wasm32-unknown-emscripten?

When compiling Emscripten-targeted code with emcc, the driver invokes Clang with additional Emscripten-specific include paths.
For example, compiling a trivial file:
```
emcc -v b.cpp -o b.html

// prints
/Users/.../clang -target wasm32-unknown-emscripten \
  -fignore-exceptions \
  -mllvm -combiner-global-alias-analysis=false \
  -mllvm -enable-emscripten-sjlj \
  -mllvm -disable-lsr \
  --sysroot=/Users/.../emscripten/cache/sysroot \
  -DEMSCRIPTEN \
  -Xclang -iwithsysroot/include/fakesdl \
  -Xclang -iwithsysroot/include/compat \
  -v -c b.cpp -o ...
```

The cc1 command as a result shows 

` "/Users/anutosh491/work/emsdk/upstream/bin/clang-22" -cc1 -triple wasm32-unknown-emscripten -..... -resource-dir /Users/anutosh491/work/emsdk/upstream/lib/clang/22 -D EMSCRIPTEN -isysroot /Users/anutosh491/work/emsdk/upstream/emscripten/cache/sysroot -internal-isystem /Users/anutosh491/work/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1 -internal-isystem /Users/anutosh491/work/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1 -internal-isystem /Users/anutosh491/work/emsdk/upstream/lib/clang/22/include -internal-isystem /Users/anutosh491/work/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten -internal-isystem /Users/anutosh491/work/emsdk/upstream/emscripten/cache/sysroot/include ...... -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o /var/folders/m1/cdn74f917994jd99d_2cpf440000gn/T/emscripten_temp_2brpcg03/b.o -x c++ b.cpp`

This ensures that headers such as `<xlocale.h> `(under `/include/compat`) are found correctly.

However, when invoking Clang directly (or using `clang-repl` / embedded use cases) with the same target:
```
clang --target=wasm32-unknown-emscripten -v -c b.cpp
```
the default cc1 invocation does not include those -iwithsysroot/include/... directories, and headers like <xlocale.h> are not found.

Looking at [clang/lib/Driver/ToolChains/WebAssembly.cpp](https://github.com/llvm/llvm-project/blob/main/clang/lib/Driver/ToolChains/WebAssembly.cpp)
there is no explicit handling for `/include/compat` or other Emscripten SDK-specific paths.
This toolchain is generic for WebAssembly and not Emscripten-specific, although it already handles Emscripten-specific backend flags such as:
```
-mllvm -enable-emscripten-cxx-exceptions
-mllvm -enable-emscripten-sjlj
```

So I wanted to clarify 
Should Emscripten-specific include directories (e.g. /include/compat, /include/fakesdl) be added automatically by Clang’s WebAssembly toolchain when the target triple is wasm32-unknown-emscripten or are they considered the responsibility of the emcc wrapper?

Essentially:

i) clang --target=wasm32-unknown-emscripten → should it behave the same as emcc, or

ii) should users explicitly pass these -iwithsysroot flags when using Clang standalone?





_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to