Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can we enable LIBCXX_ENABLE_FILESYSTEM in libcxx? #125

Open
EricSivilog opened this issue Apr 17, 2020 · 3 comments
Open

Can we enable LIBCXX_ENABLE_FILESYSTEM in libcxx? #125

EricSivilog opened this issue Apr 17, 2020 · 3 comments

Comments

@EricSivilog
Copy link

Hi there!

I have just recompiled wasi-sdk v10 for a project I am working on and I thought I'd try to enable LIBCXX_ENABLE_FILESYSTEM for libcxx in order to have access to std::filesystem from my WASM code - the custom environment I am using is WASI-capable and works fine with C file I/O and C++ streams, but I hit a problem when trying to use std::filesystem::create_directory (or std::__fs::filesystem::create_directory as it seems to be named here).

My problem is that enabling the flag leads to an include error with a missing <sys/statvfs.h> included in "filesystem_common.h": does anyone know if it is at all possible to get std::filesystem to compile in libcxx for use in WASM?

For a bit of context, I am compiling under Ubuntu 18.04 (through WSL in Windows 10), cloned the wasi-sdk repo and used make. Everything works as expected without the flag.

Thanks a lot for your hard work!!!

@sunfishcode
Copy link
Member

At a quick glance, it looks like the only thing in libcxx that needs <sys/statvfs.h> is the space functions, which you don't need for create_directory or indeed most of the filesystem library.

It would probably be straightforward to get the filesystem library to build if you disabled use of <sys/statvfs.h> and the space functions. If someone wanted to write up a patch that introduced a new CMake variable like LIBCXX_ENABLE_FILESYSTEM_SPACE or so that did that, we may be able to help land that in upstream LLVM and use it in wasi-sdk to allow us to enable the rest of LIBCXX_ENABLE_FILESYSTEM.

We could also talk about adding functionality to WASI to support a subset of <sys/statvfs.h> sufficient to implement the space` function, though that would be more involved.

@EricSivilog
Copy link
Author

EricSivilog commented Apr 19, 2020

Dan,

I've done what you suggested but I then have other issues with functions referenced in "filesystem_common.h" or "operations.cpp" which are not available in WASI such as:

  • ::utimes
  • fchmod
  • realpath
  • getcwd
  • chdir
  • chmod

I'll follow the same idea as for statvfs and see where i get.

Thanks for your help. :-)

@sbc100
Copy link
Member

sbc100 commented Apr 19, 2020

For fchmod/chmod the underlying functions were added to WASI ephemeral here: https://github.com/WebAssembly/WASI/pull/170/files. I imagine that once we make next snapshot and this migrates into wasi-sdk we can them implement fchmod and chmod.

For chdir/getcwd we don't currently implement them in wasi-libc, but I don't see why we couldn't implement this purely in userspace.

realpath looks a bit more tricky. We already support readlink (via __wasi_path_readlink) which might be enough get a useful implementation.

kildom pushed a commit to kildom/clang-wasi-port that referenced this issue Jul 14, 2021
)

POSIX requires `environ` to be a pointer to a NULL-terminated array of
pointers, so it itself can't be NULL.

This fixes a regression in src/functional/env.c in wasi-libc-test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants