emscripten icon indicating copy to clipboard operation
emscripten copied to clipboard

std::filesystem::temp_directory_path() failure with NODERAWFS on Windows

Open matthewcpp opened this issue 2 weeks ago • 2 comments

I am encountering an issue when running a program compiled with NODERAWFS on Windows. The same compiled program works fine on MacOS and Linux.

The minimal reproduction case:

#include <filesystem>
#include <iostream>

int main(int argc, char** argv) {
	std::cout << std::filesystem::temp_directory_path() << std::endl;
	return 0;
}

#25291 also failed on windows, and drawing inspiration from the author of that issue, I looked at the implementation of this method in system/lib/libcxx/src/filesystem/operations.cpp. Unfortunately am not sure if the implementation of this method is a problem. Note: I did try compiling and running the program on windows and also received the same error. I would interested in doing additional investigation if anyone has any guidance on possible approaches to resolving this issue.

The output I see in the terminal:

Aborted(native code called abort())
D:\mlarocca\tempdir\tempdir_debug.js:619
  var e = new WebAssembly.RuntimeError(what);
          ^

RuntimeError: Aborted(native code called abort())
    at abort (D:\mlarocca\tempdir\tempdir_debug.js:619:11)
    at __abort_js (D:\mlarocca\tempdir\tempdir_debug.js:4075:7)
    at tempdir_debug.wasm.abort (wasm://wasm/tempdir_debug.wasm-00b8152e:wasm-function[74]:0x2c68)
    at tempdir_debug.wasm.void std::__2::filesystem::__throw_filesystem_error[abi:nn200100]<std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char>>&, std::__2::error_code const&>(std::__2::basic_string<char, std::__2::char_traits<char>, std::__2::allocator<char>>&, std::__2::error_code const&) (wasm://wasm/tempdir_debug.wasm-00b8152e:wasm-function[1640]:0x28ab1)
    at tempdir_debug.wasm.std::__2::filesystem::detail::ErrorHandler<std::__2::filesystem::path>::report_impl(std::__2::error_code const&, char const*, void*) const (wasm://wasm/tempdir_debug.wasm-00b8152e:wasm-function[1662]:0x28f66)
    at tempdir_debug.wasm.std::__2::filesystem::detail::ErrorHandler<std::__2::filesystem::path>::report(std::__2::errc const&, char const*, ...) const (wasm://wasm/tempdir_debug.wasm-00b8152e:wasm-function[1667]:0x291bf)
    at tempdir_debug.wasm.std::__2::filesystem::__temp_directory_path(std::__2::error_code*) (wasm://wasm/tempdir_debug.wasm-00b8152e:wasm-function[1664]:0x29138)
    at tempdir_debug.wasm.std::__2::filesystem::temp_directory_path[abi:ne200100]() (wasm://wasm/tempdir_debug.wasm-00b8152e:wasm-function[15]:0xf83)
    at tempdir_debug.wasm.main (wasm://wasm/tempdir_debug.wasm-00b8152e:wasm-function[14]:0xee6)
    at D:\mlarocca\tempdir\tempdir_debug.js:634:12

Node.js v24.11.1

Version of emscripten/emsdk: emcc (Emscripten gcc/clang-like replacement + linker emulating GNU ld) 4.0.10 (b7dc6e5747465580df5984e723b9d1f10d8e804b)

Failing command line in full: em++ tempdir.cpp -sNODERAWFS=1 -g -v -o tempdir.js

Full link command and output with -v appended:

em++ tempdir.cpp -sNODERAWFS=1 -v -o tempdir.js
 "/Users/mlarocca/development/tools/emsdk/upstream/bin/clang++" -target wasm32-unknown-emscripten -fignore-exceptions -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr --sysroot=/Users/mlarocca/development/tools/emsdk/upstream/emscripten/cache/sysroot -DEMSCRIPTEN -Xclang -iwithsysroot/include/fakesdl -Xclang -iwithsysroot/include/compat -v -c tempdir.cpp -o /var/folders/lj/mvyhg6tj4734mmxr89r4xpkw0006yr/T/emscripten_temp_egsugsf5/tempdir_0.o
clang version 21.0.0git (https:/github.com/llvm/llvm-project 8f7e57485ee73205e108d74abb5565d5c63beaca)
Target: wasm32-unknown-emscripten
Thread model: posix
InstalledDir: /Users/mlarocca/development/tools/emsdk/upstream/bin
 (in-process)
 "/Users/mlarocca/development/tools/emsdk/upstream/bin/clang-21" -cc1 -triple wasm32-unknown-emscripten -emit-obj -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name tempdir.cpp -mrelocation-model static -mframe-pointer=none -ffp-contract=on -fno-rounding-math -mconstructor-aliases -target-cpu generic -fvisibility=hidden -debugger-tuning=gdb -fdebug-compilation-dir=/Users/mlarocca/development/scratch/wasm -v -fcoverage-compilation-dir=/Users/mlarocca/development/scratch/wasm -resource-dir /Users/mlarocca/development/tools/emsdk/upstream/lib/clang/21 -D EMSCRIPTEN -isysroot /Users/mlarocca/development/tools/emsdk/upstream/emscripten/cache/sysroot -internal-isystem /Users/mlarocca/development/tools/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1 -internal-isystem /Users/mlarocca/development/tools/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1 -internal-isystem /Users/mlarocca/development/tools/emsdk/upstream/lib/clang/21/include -internal-isystem /Users/mlarocca/development/tools/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten -internal-isystem /Users/mlarocca/development/tools/emsdk/upstream/emscripten/cache/sysroot/include -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcxx-exceptions -fignore-exceptions -fexceptions -fcolor-diagnostics -iwithsysroot/include/fakesdl -iwithsysroot/include/compat -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr -o /var/folders/lj/mvyhg6tj4734mmxr89r4xpkw0006yr/T/emscripten_temp_egsugsf5/tempdir_0.o -x c++ tempdir.cpp
clang -cc1 version 21.0.0git based upon LLVM 21.0.0git default target x86_64-apple-darwin24.6.0
ignoring nonexistent directory "/Users/mlarocca/development/tools/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten/c++/v1"
ignoring nonexistent directory "/Users/mlarocca/development/tools/emsdk/upstream/emscripten/cache/sysroot/include/wasm32-emscripten"
#include "..." search starts here:
#include <...> search starts here:
 /Users/mlarocca/development/tools/emsdk/upstream/emscripten/cache/sysroot/include/fakesdl
 /Users/mlarocca/development/tools/emsdk/upstream/emscripten/cache/sysroot/include/compat
 /Users/mlarocca/development/tools/emsdk/upstream/emscripten/cache/sysroot/include/c++/v1
 /Users/mlarocca/development/tools/emsdk/upstream/lib/clang/21/include
 /Users/mlarocca/development/tools/emsdk/upstream/emscripten/cache/sysroot/include
End of search list.
 /Users/mlarocca/development/tools/emsdk/upstream/bin/clang --version
 /Users/mlarocca/development/tools/emsdk/upstream/bin/wasm-ld -o tempdir.wasm /var/folders/lj/mvyhg6tj4734mmxr89r4xpkw0006yr/T/emscripten_temp_egsugsf5/tempdir_0.o -L/Users/mlarocca/development/tools/emsdk/upstream/emscripten/cache/sysroot/lib/wasm32-emscripten -L/Users/mlarocca/development/tools/emsdk/upstream/emscripten/src/lib -lGL-getprocaddr -lal -lhtml5 -lstubs-debug -lnoexit -lc-debug -ldlmalloc-debug -lcompiler_rt -lc++-noexcept -lc++abi-debug-noexcept -lsockets -mllvm -combiner-global-alias-analysis=false -mllvm -enable-emscripten-sjlj -mllvm -disable-lsr /var/folders/lj/mvyhg6tj4734mmxr89r4xpkw0006yr/T/tmpn8b5qbmblibemscripten_js_symbols.so --strip-debug --export=emscripten_stack_get_end --export=emscripten_stack_get_free --export=emscripten_stack_get_base --export=emscripten_stack_get_current --export=emscripten_stack_init --export=_emscripten_stack_alloc --export=__wasm_call_ctors --export=_emscripten_stack_restore --export-if-defined=__start_em_asm --export-if-defined=__stop_em_asm --export-if-defined=__start_em_lib_deps --export-if-defined=__stop_em_lib_deps --export-if-defined=__start_em_js --export-if-defined=__stop_em_js --export-if-defined=main --export-if-defined=__main_argc_argv --export-if-defined=fflush --export-table -z stack-size=65536 --no-growable-memory --initial-heap=16777216 --no-entry --stack-first --table-base=1
 /Users/mlarocca/development/tools/emsdk/upstream/bin/llvm-objcopy tempdir.wasm tempdir.wasm '--remove-section=.debug*' --remove-section=producers --remove-section=name
 /Users/mlarocca/development/tools/emsdk/node/22.16.0_64bit/bin/node /Users/mlarocca/development/tools/emsdk/upstream/emscripten/tools/compiler.mjs -

tempdir_debug.zip

matthewcpp avatar Nov 13 '25 22:11 matthewcpp

Can you build with -g or --profiling-funcs so we can see a more useful backtrace?

sbc100 avatar Nov 13 '25 22:11 sbc100

My apologies, I have updated the original post with a debug stack trace and binary.

matthewcpp avatar Nov 14 '25 00:11 matthewcpp

Oh, I see what is happening. The default in __temp_directory_path is /tmp and I guess that path does not exist on windows.

__temp_directory_path will also check for "TMPDIR", "TMP", "TEMP", "TEMPDIR" environment variables, so perhaps we need to have the environment variables from OS available under NODERAWFS. There is an old PR to do that which I think might solve this: #18820.

sbc100 avatar Nov 18 '25 01:11 sbc100