diff --git a/stdlib/public/Platform/WASILibc.swift.gyb b/stdlib/public/Platform/WASILibc.swift.gyb index a4379816ad69d..bd6e03ed3c4af 100644 --- a/stdlib/public/Platform/WASILibc.swift.gyb +++ b/stdlib/public/Platform/WASILibc.swift.gyb @@ -64,35 +64,98 @@ public let ${prefix}_TRUE_MIN = ${type}.leastNonzeroMagnitude public let MAP_FAILED: UnsafeMutableRawPointer! = UnsafeMutableRawPointer(bitPattern: -1) -// wasi-libc's error.h uses a macro that Swift can't import. -@available(*, deprecated, message: "Please use 'POSIXErrorCode.EACCES'.") -public let EACCES: Int32 = 2 -@available(*, deprecated, message: "Please use 'POSIXErrorCode.EDQUOT'.") -public let EDQUOT: Int32 = 19 -@available(*, deprecated, message: "Please use 'POSIXErrorCode.EEXIST'.") -public let EEXIST: Int32 = 20 -@available(*, deprecated, message: "Please use 'POSIXErrorCode.EFBIG'.") -public let EFBIG: Int32 = 22 -@available(*, deprecated, message: "Please use 'POSIXErrorCode.EINTR'.") -public let EINTR: Int32 = 27 -@available(*, deprecated, message: "Please use 'POSIXErrorCode.EINVAL'.") -public let EINVAL: Int32 = 28 -@available(*, deprecated, message: "Please use 'POSIXErrorCode.ENAMETOOLONG'.") -public let ENAMETOOLONG: Int32 = 37 -@available(*, deprecated, message: "Please use 'POSIXErrorCode.ENOENT'.") -public let ENOENT: Int32 = 44 -@available(*, deprecated, message: "Please use 'POSIXErrorCode.ENOSPC'.") -public let ENOSPC: Int32 = 51 -@available(*, deprecated, message: "Please use 'POSIXErrorCode.EPERM'.") -public let EPERM: Int32 = 63 -@available(*, deprecated, message: "Please use 'POSIXErrorCode.EROFS'.") -public let EROFS: Int32 = 69 - - -// wasi-libc's _seek.h uses a macro that Swift can't import. -// https://developer.apple.com/documentation/swift/using-imported-c-macros-in-swift -// https://github.com/apple/swift/blob/c55b9cc87925c5d63a21d383ad23dff056d36607/lib/ClangImporter/ImportName.cpp#L2115-L2117 -// https://github.com/WebAssembly/wasi-libc/pull/148 +// TODO: wasi-libc's error.h defines these macros as function-like macros, which +// Swift can't import for now. +%{ +posix_error_codes = [ + "E2BIG", + "EACCES", + "EADDRINUSE", + "EADDRNOTAVAIL", + "EAFNOSUPPORT", + "EAGAIN", + "EALREADY", + "EBADF", + "EBADMSG", + "EBUSY", + "ECANCELED", + "ECHILD", + "ECONNABORTED", + "ECONNREFUSED", + "ECONNRESET", + "EDEADLK", + "EDESTADDRREQ", + "EDOM", + "EDQUOT", + "EEXIST", + "EFAULT", + "EFBIG", + "EHOSTUNREACH", + "EIDRM", + "EILSEQ", + "EINPROGRESS", + "EINTR", + "EINVAL", + "EIO", + "EISCONN", + "EISDIR", + "ELOOP", + "EMFILE", + "EMLINK", + "EMSGSIZE", + "EMULTIHOP", + "ENAMETOOLONG", + "ENETDOWN", + "ENETRESET", + "ENETUNREACH", + "ENFILE", + "ENOBUFS", + "ENODEV", + "ENOENT", + "ENOEXEC", + "ENOLCK", + "ENOLINK", + "ENOMEM", + "ENOMSG", + "ENOPROTOOPT", + "ENOSPC", + "ENOSYS", + "ENOTCONN", + "ENOTDIR", + "ENOTEMPTY", + "ENOTRECOVERABLE", + "ENOTSOCK", + "ENOTSUP", + "ENOTTY", + "ENXIO", + "EOVERFLOW", + "EOWNERDEAD", + "EPERM", + "EPIPE", + "EPROTO", + "EPROTONOSUPPORT", + "EPROTOTYPE", + "ERANGE", + "EROFS", + "ESPIPE", + "ESRCH", + "ESTALE", + "ETIMEDOUT", + "ETXTBSY", + "EXDEV", + "ENOTCAPABLE", +] +}% + +%for ecode in posix_error_codes: + +@available(*, deprecated, message: "Please use 'POSIXErrorCode.${ecode}'.") +public let ${ecode} = POSIXErrorCode.${ecode}.rawValue + +%end + +// TODO: wasi-libc's _seek.h defines these macros as function-like macros, which +// Swift can't import for now. public let SEEK_SET: Int32 = 0 public let SEEK_CUR: Int32 = 1 public let SEEK_END: Int32 = 2