Skip to content

[Question] Emscripten include paths missing in Clang WebAssembly toolchain ? #167669

@anutosh491

Description

@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
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?

Metadata

Metadata

Assignees

No one assigned

    Labels

    clangClang issues not falling into any other category

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions