Skip to content

Commit

Permalink
Fix WASM support
Browse files Browse the repository at this point in the history
  • Loading branch information
colemancda committed Nov 14, 2024
1 parent 3ca3d15 commit 37624b6
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 6 deletions.
23 changes: 23 additions & 0 deletions Sources/CSocket/include/CSystemWASI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@

#pragma once

#if __wasi__

#include <errno.h>
#include <fcntl.h>

// wasi-libc defines the following constants in a way that Clang Importer can't
// understand, so we need to expose them manually.
static inline int32_t _getConst_O_ACCMODE(void) { return O_ACCMODE; }
static inline int32_t _getConst_O_APPEND(void) { return O_APPEND; }
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_NONBLOCK(void) { return O_NONBLOCK; }
static inline int32_t _getConst_O_TRUNC(void) { return O_TRUNC; }
static inline int32_t _getConst_O_WRONLY(void) { return O_WRONLY; }

static inline int32_t _getConst_EWOULDBLOCK(void) { return EWOULDBLOCK; }
static inline int32_t _getConst_EOPNOTSUPP(void) { return EOPNOTSUPP; }

#endif
1 change: 1 addition & 0 deletions Sources/CSocket/include/module.modulemap
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module CSocket {
header "CSystemLinux.h"
header "CSystemWASI.h"
header "CSystemWindows.h"
export *
}
15 changes: 12 additions & 3 deletions Sources/Socket/System/CInterop.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ import SystemPackage

#if canImport(Darwin)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
import Glibc
#elseif os(Windows)
import CSocket
import CSystem
import ucrt
#elseif canImport(Glibc)
@_implementationOnly import CSystem
import Glibc
#elseif canImport(Musl)
@_implementationOnly import CSystem
import Musl
#elseif canImport(WASILibc)
import WASILibc
#elseif canImport(Bionic)
@_implementationOnly import CSystem
import Bionic
#else
#error("Unsupported Platform")
#endif
Expand Down
15 changes: 12 additions & 3 deletions Sources/Socket/System/Constants.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,20 @@ import SystemPackage

#if canImport(Darwin)
import Darwin
#elseif os(Linux) || os(FreeBSD) || os(Android)
import Glibc
#elseif os(Windows)
import CSocket
import CSystem
import ucrt
#elseif canImport(Glibc)
@_implementationOnly import CSystem
import Glibc
#elseif canImport(Musl)
@_implementationOnly import CSystem
import Musl
#elseif canImport(WASILibc)
import WASILibc
#elseif canImport(Bionic)
@_implementationOnly import CSystem
import Bionic
#else
#error("Unsupported Platform")
#endif
Expand Down

0 comments on commit 37624b6

Please sign in to comment.