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

[wasm] Grab wasi-libc constants manually #4906

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions CoreFoundation/Base.subproj/ForSwiftFoundationOnly.h
Expand Up @@ -64,6 +64,8 @@
#include <sys/stat.h>
#include <sys/syscall.h>
#include <termios.h>
#elif TARGET_OS_WASI
#include <fcntl.h>
#elif TARGET_OS_LINUX
#include <errno.h>
#include <features.h>
Expand Down Expand Up @@ -712,6 +714,15 @@ typedef struct _REPARSE_DATA_BUFFER {
} REPARSE_DATA_BUFFER;
#endif

#if TARGET_OS_WASI
static inline uint8_t _getConst_DT_DIR(void) { return DT_DIR; }
static inline int32_t _getConst_O_CREAT(void) { return O_CREAT; }
static inline int32_t _getConst_O_DIRECTORY(void) { return O_DIRECTORY; }
static inline int32_t _getConst_O_EXCL(void) { return O_EXCL; }
static inline int32_t _getConst_O_TRUNC(void) { return O_TRUNC; }
static inline int32_t _getConst_O_WRONLY(void) { return O_WRONLY; }
#endif

#if !TARGET_OS_WIN32
typedef void * _CFPosixSpawnFileActionsRef;
typedef void * _CFPosixSpawnAttrRef;
Expand Down
12 changes: 12 additions & 0 deletions Sources/Foundation/FileManager+POSIX.swift
Expand Up @@ -13,6 +13,18 @@ internal func &(left: UInt32, right: mode_t) -> mode_t {
}
#endif

#if os(WASI)
import WASILibc
// wasi-libc defines the following constants in a way that Clang Importer can't
// understand, so we need to grab them manually through ForSwiftFoundationOnly.h
internal var DT_DIR: UInt8 { _getConst_DT_DIR() }
internal var O_CREAT: Int32 { _getConst_O_CREAT() }
internal var O_DIRECTORY: Int32 { _getConst_O_DIRECTORY() }
internal var O_EXCL: Int32 { _getConst_O_EXCL() }
internal var O_TRUNC: Int32 { _getConst_O_TRUNC() }
internal var O_WRONLY: Int32 { _getConst_O_WRONLY() }
#endif

@_implementationOnly import CoreFoundation

extension FileManager {
Expand Down