emscripten-core / emscripten

Emscripten: An LLVM-to-WebAssembly Compiler
Other
25.72k stars 3.3k forks source link

fatal error: 'wasm_simd128.h' file not found #20399

Open juj opened 1 year ago

juj commented 1 year ago

Attempting to use SIMD, I get

"emscripten-win-x64_66c3/emscripten/emcc.bat" -Wno-warn-absolute-paths -Wno-c++11-extensions -Wno-nonportable-include-path -ffunction-sections -fno-unwind-tables -fomit-frame-pointer -fno-exceptions -fno-threadsafe-statics -std=c++17 -Wno-missing-braces -Wno-sign-compare -Wno-int-to-pointer-cast -Wno-format -Wno-conversion -Wno-format-security -Wno-unused-function -Wno-comment -Wno-reorder -Wno-logical-op-parentheses -Wno-unnamed-type-template-args -Wno-unused-private-field -Wno-constant-logical-operand -Wno-unused-local-typedef -Werror=nonportable-include-path -Wno-deprecated-declarations -Wno-undefined-var-template -Werror=switch -Werror=enum-compare -Werror=char-subscripts -Werror=write-strings -Werror=return-type -Werror=parentheses -Werror=tautological-pointer-compare -Werror=self-assign -Werror=dynamic-class-memaccess -Werror=absolute-value -Werror=sometimes-uninitialized -Werror=tautological-constant-out-of-range-compare -Werror=dangling-else -Werror=deprecated-register -Werror=unused-comparison -Werror=missing-field-initializers -Werror=shift-op-parentheses -Werror=conditional-uninitialized -Werror=incompatible-pointer-types -Werror=vexing-parse -Werror=infinite-recursion -Werror=undefined-internal -Werror=macro-redefined -Werror=overloaded-virtual -Werror=null-arithmetic -Werror=inconsistent-missing-override -Werror=extra-tokens -Werror=pointer-bool-conversion -Wno-parentheses-equality -Werror=shift-negative-value -Werror=mismatched-tags -Werror=gnu-alignof-expression -Wno-return-type-c-linkage -Werror=uninitialized -Wno-unknown-warning-option -Wno-uninitialized-const-reference -fvisibility=hidden -fno-exceptions -fno-rtti -O2 -fno-strict-aliasing -fstrict-overflow -ffunction-sections -fdata-sections -fmessage-length=0 -pipe -DNDEBUG -I"." -o "artifacts/modules/UnityPlayer.Core/WebGL_wasm_dev_i_r_nothreads/obj/CoreBindings.gen_wwcko.o" -fcolor-diagnostics -fdiagnostics-absolute-paths -msimd128 -msse4.2 -msimd128 -msse4.2 -c -xc++ "artifacts/WebGL/Modules/WebGL_wasm_dev_i_r_nothreads/Bindings/CoreBindings.gen.cpp"
##### Custom Environment Variables
EM_CONFIG=C:\unity\emscripten-win-x64_66c3\.emscripten
EMSDK_PYTHON=emscripten-win-x64_66c3\python\python.exe
EMCC_SKIP_SANITY_CHECK=1
EM_FROZEN_CACHE=1
EM_WORKAROUND_PYTHON_BUG_34780=1
EM_WORKAROUND_WIN7_BAD_ERRORLEVEL_BUG=1
##### ExitCode
1
##### Output
In file included from artifacts/WebGL/Modules/WebGL_wasm_dev_i_r_nothreads/Bindings/CoreBindings.gen.cpp:4:
In file included from artifacts/WebGL/Modules/WebGL_wasm_dev_i_r_nothreads/Bindings/CoreBindings.gen.h:3:
In file included from .\Runtime/Scripting/Marshalling/Marshalling.h:3:
In file included from .\Runtime/Scripting/Marshalling/PrimitiveMarshalling.h:109:
In file included from .\Runtime/Scripting/Marshalling/StringMarshalling.h:9:
In file included from .\Runtime/Utilities/TextUtil.h:17:
In file included from .\Runtime/Math/Rect.h:5:
In file included from .\Runtime/Math/Matrix4x4.h:12:
In file included from .\Runtime/Math/Simd/SimdMath.h:14:
In file included from C:\unity\emscripten-win-x64_66c3\emscripten\cache\sysroot/include\compat\xmmintrin.h:10:
C:\unity\emscripten-win-x64_66c3\emscripten\cache\sysroot\include\wasm_simd128.h:10:15: fatal error: 'wasm_simd128.h' file not found
#include_next <wasm_simd128.h>
              ^~~~~~~~~~~~~~~~
1 error generated.
emcc: error: 'C:/unity/artifacts/Stevedore/emscripten-win-x64_66c3/llvm\clang++.exe -target wasm32-unknown-emscripten -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -DEMSCRIPTEN --sysroot=C:\unity\emscripten-win-x64_66c3\emscripten\cache\sysroot -D__SSE__=1 -D__SSE2__=1 -D__SSE3__=1 -D__SSSE3__=1 -D__SSE4_1__=1 -D__SSE4_2__=1 -Xclang -iwithsysroot/include\fakesdl -Xclang -iwithsysroot/include\compat -Wno-c++11-extensions -Wno-nonportable-include-path -ffunction-sections -fno-unwind-tables -fomit-frame-pointer -fno-exceptions -fno-threadsafe-statics -std=c++17 -Wno-missing-braces -Wno-sign-compare -Wno-int-to-pointer-cast -Wno-format -Wno-conversion -Wno-format-security -Wno-unused-function -Wno-comment -Wno-reorder -Wno-logical-op-parentheses -Wno-unnamed-type-template-args -Wno-unused-private-field -Wno-constant-logical-operand -Wno-unused-local-typedef -Werror=nonportable-include-path -Wno-deprecated-declarations -Wno-undefined-var-template -Werror=switch -Werror=enum-compare -Werror=char-subscripts -Werror=write-strings -Werror=return-type -Werror=parentheses -Werror=tautological-pointer-compare -Werror=self-assign -Werror=dynamic-class-memaccess -Werror=absolute-value -Werror=sometimes-uninitialized -Werror=tautological-constant-out-of-range-compare -Werror=dangling-else -Werror=deprecated-register -Werror=unused-comparison -Werror=missing-field-initializers -Werror=shift-op-parentheses -Werror=conditional-uninitialized -Werror=incompatible-pointer-types -Werror=vexing-parse -Werror=infinite-recursion -Werror=undefined-internal -Werror=macro-redefined -Werror=overloaded-virtual -Werror=null-arithmetic -Werror=inconsistent-missing-override -Werror=extra-tokens -Werror=pointer-bool-conversion -Wno-parentheses-equality -Werror=shift-negative-value -Werror=mismatched-tags -Werror=gnu-alignof-expression -Wno-return-type-c-linkage -Werror=uninitialized -Wno-unknown-warning-option -Wno-uninitialized-const-reference -fvisibility=hidden -fno-exceptions -fno-rtti -O2 -fno-strict-aliasing -fstrict-overflow -ffunction-sections -fdata-sections -fmessage-length=0 -pipe -DNDEBUG -I. -fcolor-diagnostics -fdiagnostics-absolute-paths -msimd128 -msimd128 -c -xc++ artifacts/WebGL/Modules/WebGL_wasm_dev_i_r_nothreads/Bindings/CoreBindings.gen.cpp -o artifacts/modules/UnityPlayer.Core/WebGL_wasm_dev_i_r_nothreads/obj/CoreBindings.gen_wwcko.o' failed (returned 1)

The root issue here is that I am using a custom script that compiles and bundles Emsdk from source, but that script does not bundle LLVM's wasm_simd128.h header.

So I'd like to fix that, and include the header in our own bundles.

But I am slightly stumped as to where I should place it. I.e. how does LLVM find wasm_simd128.h to include, when there are no -Idir directives that it are passed on the command line?

I see in the latest Emscripten precompiled version (emsdk install latest), there is a directory structure

.
..
bin/
bin/clang.exe
lib/
lib/clang/
lib/clang/17/
lib/clang/17/include/
lib/clang/17/include/wasm_simd128.h

but when compiling, there is nothing along the lines of -I<path_to_llvm>/lib/clang/17/include/ being said to clang.

Does clang.exe have some kind of internal hardcoded -I../lib/clang/17/include/ at play? If I am bundling manually, should I expect to hardcode such a sibling directory path next to where clang.exe lives in? @tlively would you know?

sbc100 commented 1 year ago

Yes, I believe clang is able to find its own headers relative to the clang binary.

If you run tjhe compiler (emcc or clang) with -v you can see the internal includes paths being injected when running the internal compile phase:

$ ./emcc -c ~/test//hello.c -v
 "/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/clang" --version
 "/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/clang" -target wasm32-unknown-emscripten -fignore-exceptions -fvisibility=default -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -DEMSCRIPTEN -Werror=implicit-function-declaration --sysroot=/usr/local/google/home/sbc/dev/wasm/emscripten/cache/sysroot -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -c -v /usr/local/google/home/sbc/test//hello.c -o hello.o
clang version 18.0.0 (https://github.com/sbc100/llvm-project 66c19167f127013f6834ea1a316b783e57490939)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /usr/local/google/home/sbc/dev/wasm/llvm-build/bin
 (in-process)
 "/usr/local/google/home/sbc/dev/wasm/llvm-build/bin/clang-16" -cc1 -triple wasm32-unknown-emscripten -emit-obj -mrelax-all -disable-free -clear-ast-before-backend -main-file-name hello.c -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -debugger-tuning=gdb -fdebug-compilation-dir=/usr/local/google/home/sbc/dev/wasm/emscripten -v -fcoverage-compilation-dir=/usr/local/google/home/sbc/dev/wasm/emscripten -resource-dir /usr/local/google/home/sbc/dev/wasm/llvm-build/lib/clang/18 -D EMSCRIPTEN -isysroot /usr/local/google/home/sbc/dev/wasm/emscripten/cache/sysroot -internal-isystem /usr/local/google/home/sbc/dev/wasm/llvm-build/lib/clang/18/include -internal-isystem /usr/local/google/home/sbc/dev/wasm/emscripten/cache/sysroot/include/wasm32-emscripten -internal-isystem /usr/local/google/home/sbc/dev/wasm/emscripten/cache/sysroot/include -Werror=implicit-function-declaration -ferror-limit 19 -fvisibility=default -fgnuc-version=4.2.1 -fignore-exceptions -fcolor-diagnostics -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o hello.o -x c /usr/local/google/home/sbc/test//hello.c
clang -cc1 version 18.0.0 based upon LLVM 18.0.0git default target x86_64-unknown-linux-gnu
ignoring nonexistent directory "/usr/local/google/home/sbc/dev/wasm/emscripten/cache/sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
 /usr/local/google/home/sbc/dev/wasm/emscripten/cache/sysroot/include/fakesdl
 /usr/local/google/home/sbc/dev/wasm/emscripten/cache/sysroot/include/compat
 /usr/local/google/home/sbc/dev/wasm/llvm-build/lib/clang/18/include
 /usr/local/google/home/sbc/dev/wasm/emscripten/cache/sysroot/include
End of search list.

Here you can see that emcc runs clang without /usr/local/google/home/sbc/dev/wasm/llvm-build/lib/clang/18/include anywhere in the command and then then clang -cc1 is internally executed with /usr/local/google/home/sbc/dev/wasm/llvm-build/lib/clang/18/include injected into the include path.

Does your clang build directory not contain lib/clang/18/include?

Here is where that include path gets added in the clang driver: https://github.com/llvm/llvm-project/blob/5082e827c1670f5c98d320d08979b8855253d0cc/clang/lib/Driver/ToolChains/WebAssembly.cpp#L407-L411