Skip to content

Commit 11b28f0

Browse files
guuswLastique
authored andcommitted
Flip default Emscripten default usage of WASI
When using Emscripten filesystem now links against the POSIX functions
1 parent c33862d commit 11b28f0

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ set(BOOST_FILESYSTEM_DISABLE_STATX OFF CACHE BOOL "Disable usage of statx API in
1919
set(BOOST_FILESYSTEM_DISABLE_GETRANDOM OFF CACHE BOOL "Disable usage of getrandom API in Boost.Filesystem")
2020
set(BOOST_FILESYSTEM_DISABLE_ARC4RANDOM OFF CACHE BOOL "Disable usage of arc4random API in Boost.Filesystem")
2121
set(BOOST_FILESYSTEM_DISABLE_BCRYPT OFF CACHE BOOL "Disable usage of BCrypt API in Boost.Filesystem")
22-
set(BOOST_FILESYSTEM_DISABLE_EMSCRIPTEN_WASI OFF CACHE BOOL "Disable usage of WASI API under emscripten and instead use the JavaScript API in Boost.Filesystem")
22+
set(BOOST_FILESYSTEM_EMSCRIPTEN_USE_WASI OFF CACHE BOOL "Use WASI under emscripten in Boost.Filesystem")
2323

2424
# Note: We can't use the Boost::library targets in the configure checks as they may not yet be included
2525
# by the superproject when this CMakeLists.txt is included. We also don't want to hardcode include paths

src/operations.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,18 @@
3838
#endif
3939
#include <cerrno>
4040

41-
// Use WASI when not building with emscripten or when BOOST_FILESYSTEM_DISABLE_EMSCRIPTEN_WASI is not set
42-
#if defined(__wasm) && (!defined(__EMSCRIPTEN__) || !defined(BOOST_FILESYSTEM_DISABLE_EMSCRIPTEN_WASI))
43-
#define BOOST_FILESYSTEM_STANDALONE_WASM
41+
// Default to POSIX under Emscripten
42+
// If BOOST_FILESYSTEM_EMSCRIPTEN_USE_WASI is set, use WASI instead
43+
#if defined(__wasm) && (!defined(__EMSCRIPTEN__) || defined(BOOST_FILESYSTEM_EMSCRIPTEN_USE_WASI))
44+
#define BOOST_FILESYSTEM_USE_WASI
4445
#endif
4546

4647
#ifdef BOOST_POSIX_API
4748

4849
#include <sys/types.h>
4950
#include <sys/stat.h>
5051

51-
#if defined(BOOST_FILESYSTEM_STANDALONE_WASM)
52+
#if defined(BOOST_FILESYSTEM_USE_WASI)
5253
// WASI does not have statfs or statvfs.
5354
#elif !defined(__APPLE__) && \
5455
(!defined(__OpenBSD__) || BOOST_OS_BSD_OPEN >= BOOST_VERSION_NUMBER(4, 4, 0)) && \
@@ -2225,7 +2226,7 @@ bool copy_file(path const& from, path const& to, unsigned int options, error_cod
22252226
}
22262227

22272228
mode_t to_mode = from_mode;
2228-
#if !defined(BOOST_FILESYSTEM_STANDALONE_WASM)
2229+
#if !defined(BOOST_FILESYSTEM_USE_WASI)
22292230
// Enable writing for the newly created files. Having write permission set is important e.g. for NFS,
22302231
// which checks the file permission on the server, even if the client's file descriptor supports writing.
22312232
to_mode |= S_IWUSR;
@@ -2344,7 +2345,7 @@ bool copy_file(path const& from, path const& to, unsigned int options, error_cod
23442345
if (BOOST_UNLIKELY(err != 0))
23452346
goto fail; // err already contains the error code
23462347

2347-
#if !defined(BOOST_FILESYSTEM_STANDALONE_WASM)
2348+
#if !defined(BOOST_FILESYSTEM_USE_WASI)
23482349
// If we created a new file with an explicitly added S_IWUSR permission,
23492350
// we may need to update its mode bits to match the source file.
23502351
if (to_mode != from_mode)
@@ -2780,7 +2781,7 @@ void create_symlink(path const& to, path const& from, error_code* ec)
27802781
BOOST_FILESYSTEM_DECL
27812782
path current_path(error_code* ec)
27822783
{
2783-
#if defined(UNDER_CE) || defined(BOOST_FILESYSTEM_STANDALONE_WASM)
2784+
#if defined(UNDER_CE) || defined(BOOST_FILESYSTEM_USE_WASI)
27842785
// Windows CE has no current directory, so everything's relative to the root of the directory tree.
27852786
// WASI also does not support current path.
27862787
emit_error(BOOST_ERROR_NOT_SUPPORTED, ec, "boost::filesystem::current_path");
@@ -2850,7 +2851,7 @@ path current_path(error_code* ec)
28502851
BOOST_FILESYSTEM_DECL
28512852
void current_path(path const& p, system::error_code* ec)
28522853
{
2853-
#if defined(UNDER_CE) || defined(BOOST_FILESYSTEM_STANDALONE_WASM)
2854+
#if defined(UNDER_CE) || defined(BOOST_FILESYSTEM_USE_WASI)
28542855
emit_error(BOOST_ERROR_NOT_SUPPORTED, p, ec, "boost::filesystem::current_path");
28552856
#else
28562857
error(!BOOST_SET_CURRENT_DIRECTORY(p.c_str()) ? BOOST_ERRNO : 0, p, ec, "boost::filesystem::current_path");
@@ -3354,7 +3355,7 @@ void permissions(path const& p, perms prms, system::error_code* ec)
33543355
if ((prms & add_perms) && (prms & remove_perms)) // precondition failed
33553356
return;
33563357

3357-
#if defined(BOOST_FILESYSTEM_STANDALONE_WASM)
3358+
#if defined(BOOST_FILESYSTEM_USE_WASI)
33583359
emit_error(BOOST_ERROR_NOT_SUPPORTED, p, ec, "boost::filesystem::permissions");
33593360
#elif defined(BOOST_POSIX_API)
33603361
error_code local_ec;
@@ -3618,7 +3619,7 @@ space_info space(path const& p, error_code* ec)
36183619
if (ec)
36193620
ec->clear();
36203621

3621-
#if defined(BOOST_FILESYSTEM_STANDALONE_WASM)
3622+
#if defined(BOOST_FILESYSTEM_USE_WASI)
36223623

36233624
emit_error(BOOST_ERROR_NOT_SUPPORTED, p, ec, "boost::filesystem::space");
36243625

0 commit comments

Comments
 (0)