Skip to content

Commit 4d88f86

Browse files
guuswLastique
authored andcommitted
Fix standalone wasm define. Rename define.
- Add cmake option to turn WASI API on/off - Rename BOOST_STANDALONE_WASM => BOOST_FILESYSTEM_STANDALONE_WASM
1 parent ef54f76 commit 4d88f86

File tree

2 files changed

+14
-9
lines changed

2 files changed

+14
-9
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +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")
2223

2324
# Note: We can't use the Boost::library targets in the configure checks as they may not yet be included
2425
# by the superproject when this CMakeLists.txt is included. We also don't want to hardcode include paths
@@ -131,6 +132,9 @@ endif()
131132
if(BOOST_FILESYSTEM_DISABLE_BCRYPT)
132133
target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_DISABLE_BCRYPT)
133134
endif()
135+
if(BOOST_FILESYSTEM_DISABLE_EMSCRIPTEN_WASI)
136+
target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_DISABLE_EMSCRIPTEN_WASI)
137+
endif()
134138

135139
if(BOOST_FILESYSTEM_HAS_STAT_ST_BLKSIZE)
136140
target_compile_definitions(boost_filesystem PRIVATE BOOST_FILESYSTEM_HAS_STAT_ST_BLKSIZE)

src/operations.cpp

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

41-
#if defined(__wasm) && (defined(EMSCRIPTEN_STANDALONE_WASM) || !defined(__EMSCRIPTEN__))
42-
#define BOOST_STANDALONE_WASM 1
41+
// Use WASI when not building with emscripten or when BOOST_FILESYSTEM_DISABLE_EMSCRIPTEN_WASI is set
42+
#if defined(__wasm) && (!defined(__EMSCRIPTEN__) || !defined(BOOST_FILESYSTEM_DISABLE_EMSCRIPTEN_WASI))
43+
#define BOOST_FILESYSTEM_STANDALONE_WASM
4344
#endif
4445

4546
#ifdef BOOST_POSIX_API
4647

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

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

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

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

3356-
#if defined(BOOST_STANDALONE_WASM)
3357+
#if defined(BOOST_FILESYSTEM_STANDALONE_WASM)
33573358
emit_error(BOOST_ERROR_NOT_SUPPORTED, p, ec, "boost::filesystem::permissions");
33583359
#elif defined(BOOST_POSIX_API)
33593360
error_code local_ec;
@@ -3617,7 +3618,7 @@ space_info space(path const& p, error_code* ec)
36173618
if (ec)
36183619
ec->clear();
36193620

3620-
#if defined(BOOST_STANDALONE_WASM)
3621+
#if defined(BOOST_FILESYSTEM_STANDALONE_WASM)
36213622

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

0 commit comments

Comments
 (0)