Skip to content

Commit

Permalink
Merge pull request #202 from glessard/platform-support-1.4.0
Browse files Browse the repository at this point in the history
[1.4.0] cherry-pick platform support changes
  • Loading branch information
glessard authored Oct 17, 2024
2 parents 938fda5 + 209dfea commit 69eee99
Show file tree
Hide file tree
Showing 7 changed files with 186 additions and 19 deletions.
31 changes: 31 additions & 0 deletions Sources/CSystem/include/CSystemWASI.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
This source file is part of the Swift System open source project
Copyright (c) 2024 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception
See https://swift.org/LICENSE.txt for license information
*/

#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/CSystem/include/module.modulemap
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
module CSystem {
header "CSystemLinux.h"
header "CSystemWASI.h"
header "CSystemWindows.h"
export *
}
23 changes: 19 additions & 4 deletions Sources/System/Errno.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift System open source project

Copyright (c) 2020 Apple Inc. and the Swift System project authors
Copyright (c) 2021 - 2024 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
Expand Down Expand Up @@ -226,7 +226,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
@available(*, unavailable, renamed: "badAddress")
public static var EFAULT: Errno { badAddress }

#if !os(Windows)
#if !os(Windows) && !os(WASI)
/// Not a block device.
///
/// You attempted a block device operation on a nonblock device or file.
Expand Down Expand Up @@ -618,6 +618,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
@available(*, unavailable, renamed: "protocolNotSupported")
public static var EPROTONOSUPPORT: Errno { protocolNotSupported }

#if !os(WASI)
/// Socket type not supported.
///
/// Support for the socket type hasn't been configured into the system
Expand All @@ -630,6 +631,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
@_alwaysEmitIntoClient
@available(*, unavailable, renamed: "socketTypeNotSupported")
public static var ESOCKTNOSUPPORT: Errno { socketTypeNotSupported }
#endif

/// Not supported.
///
Expand All @@ -644,6 +646,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
@available(*, unavailable, renamed: "notSupported")
public static var ENOTSUP: Errno { notSupported }

#if !os(WASI)
/// Protocol family not supported.
///
/// The protocol family hasn't been configured into the system
Expand All @@ -656,6 +659,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
@_alwaysEmitIntoClient
@available(*, unavailable, renamed: "protocolFamilyNotSupported")
public static var EPFNOSUPPORT: Errno { protocolFamilyNotSupported }
#endif

/// The address family isn't supported by the protocol family.
///
Expand Down Expand Up @@ -802,6 +806,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
@available(*, unavailable, renamed: "socketNotConnected")
public static var ENOTCONN: Errno { socketNotConnected }

#if !os(WASI)
/// Can't send after socket shutdown.
///
/// A request to send data wasn't permitted
Expand All @@ -815,6 +820,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
@_alwaysEmitIntoClient
@available(*, unavailable, renamed: "socketShutdown")
public static var ESHUTDOWN: Errno { socketShutdown }
#endif

/// Operation timed out.
///
Expand Down Expand Up @@ -871,6 +877,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
@available(*, unavailable, renamed: "fileNameTooLong")
public static var ENAMETOOLONG: Errno { fileNameTooLong }

#if !os(WASI)
/// The host is down.
///
/// A socket operation failed because the destination host was down.
Expand All @@ -882,6 +889,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
@_alwaysEmitIntoClient
@available(*, unavailable, renamed: "hostIsDown")
public static var EHOSTDOWN: Errno { hostIsDown }
#endif

/// No route to host.
///
Expand Down Expand Up @@ -920,6 +928,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
public static var EPROCLIM: Errno { tooManyProcesses }
#endif

#if !os(WASI)
/// Too many users.
///
/// The quota system ran out of table entries.
Expand All @@ -931,6 +940,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
@_alwaysEmitIntoClient
@available(*, unavailable, renamed: "tooManyUsers")
public static var EUSERS: Errno { tooManyUsers }
#endif

/// Disk quota exceeded.
///
Expand Down Expand Up @@ -1284,6 +1294,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
@available(*, unavailable, renamed: "multiHop")
public static var EMULTIHOP: Errno { multiHop }

#if !os(WASI)
/// No message available.
///
/// No message was available to be received by the requested operation.
Expand All @@ -1295,6 +1306,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
@_alwaysEmitIntoClient
@available(*, unavailable, renamed: "noData")
public static var ENODATA: Errno { noData }
#endif

/// Reserved.
///
Expand All @@ -1308,6 +1320,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
@available(*, unavailable, renamed: "noLink")
public static var ENOLINK: Errno { noLink }

#if !os(WASI)
/// Reserved.
///
/// This error is reserved for future use.
Expand All @@ -1331,6 +1344,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
@_alwaysEmitIntoClient
@available(*, unavailable, renamed: "notStream")
public static var ENOSTR: Errno { notStream }
#endif
#endif

/// Protocol error.
Expand All @@ -1347,7 +1361,7 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
@available(*, unavailable, renamed: "protocolError")
public static var EPROTO: Errno { protocolError }

#if !os(OpenBSD)
#if !os(OpenBSD) && !os(WASI)
/// Reserved.
///
/// This error is reserved for future use.
Expand Down Expand Up @@ -1379,7 +1393,6 @@ public struct Errno: RawRepresentable, Error, Hashable, Codable {
// Constants defined in header but not man page
@available(/*System 0.0.1: macOS 11.0, iOS 14.0, watchOS 7.0, tvOS 14.0*/iOS 8, *)
extension Errno {

/// Operation would block.
///
/// The corresponding C error is `EWOULDBLOCK`.
Expand All @@ -1390,6 +1403,7 @@ extension Errno {
@available(*, unavailable, renamed: "wouldBlock")
public static var EWOULDBLOCK: Errno { wouldBlock }

#if !os(WASI)
/// Too many references: can't splice.
///
/// The corresponding C error is `ETOOMANYREFS`.
Expand All @@ -1409,6 +1423,7 @@ extension Errno {
@_alwaysEmitIntoClient
@available(*, unavailable, renamed: "tooManyRemoteLevels")
public static var EREMOTE: Errno { tooManyRemoteLevels }
#endif

#if SYSTEM_PACKAGE_DARWIN
/// No such policy registered.
Expand Down
7 changes: 6 additions & 1 deletion Sources/System/Internals/CInterop.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
This source file is part of the Swift System open source project

Copyright (c) 2020 - 2021 Apple Inc. and the Swift System project authors
Copyright (c) 2020 - 2024 Apple Inc. and the Swift System project authors
Licensed under Apache License v2.0 with Runtime Library Exception

See https://swift.org/LICENSE.txt for license information
Expand All @@ -18,6 +18,11 @@ 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
Loading

0 comments on commit 69eee99

Please sign in to comment.