Skip to content

[5.9.1] Enable macros for Windows in 5.9.1 #68858

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

Merged
merged 1 commit into from
Oct 3, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 20 additions & 9 deletions cmake/modules/AddPureSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ function(force_target_link_libraries TARGET)
cmake_parse_arguments(ARGS "" "" "PUBLIC" ${ARGN})

foreach(DEPENDENCY ${ARGS_PUBLIC})
target_link_libraries(${TARGET} PRIVATE
${DEPENDENCY}
)
target_link_libraries(${TARGET} PRIVATE ${DEPENDENCY})
add_dependencies(${TARGET} ${DEPENDENCY})

add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
string(REGEX REPLACE [<>:\"/\\|?*] _ sanitized ${DEPENDENCY})
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift
DEPENDS ${DEPENDENCY}
)
target_sources(${TARGET} PRIVATE
${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift
)
endforeach()
endfunction()
Expand Down Expand Up @@ -270,7 +269,8 @@ function(add_pure_swift_host_tool name)

# Option handling
set(options)
set(single_parameter_options)
set(single_parameter_options
SWIFT_COMPONENT)
set(multiple_parameter_options
DEPENDENCIES
SWIFT_DEPENDENCIES)
Expand Down Expand Up @@ -324,6 +324,17 @@ function(add_pure_swift_host_tool name)
target_include_directories(${name} PUBLIC
${SWIFT_HOST_LIBRARIES_DEST_DIR})

# Export this target.
set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name})
if(NOT APSHT_SWIFT_COMPONENT STREQUAL no_component)
add_dependencies(${APSHT_SWIFT_COMPONENT} ${name})
swift_install_in_component(TARGETS ${name}
COMPONENT ${APSHT_SWIFT_COMPONENT}
RUNTIME DESTINATION bin)
swift_is_installing_component(${APSHT_SWIFT_COMPONENT} is_installing)
endif()

if(NOT is_installing)
set_property(GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS ${name})
else()
set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name})
endif()
endfunction()
3 changes: 3 additions & 0 deletions cmake/modules/AddSwift.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,9 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
else()
message(FATAL_ERROR "Unknown BOOTSTRAPPING_MODE '${ASRLF_BOOTSTRAPPING_MODE}'")
endif()
else()
target_link_directories(${target} PRIVATE
${SWIFT_PATH_TO_SWIFT_SDK}/usr/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH})
endif()

if(SWIFT_SWIFT_PARSER)
Expand Down
27 changes: 12 additions & 15 deletions include/swift/AST/CASTBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,9 @@

SWIFT_BEGIN_NULLABILITY_ANNOTATIONS

typedef long SwiftInt;
typedef unsigned long SwiftUInt;

typedef struct {
const void *_Nullable data;
long numElements;
SwiftInt numElements;
} BridgedArrayRef;

typedef struct {
Expand All @@ -65,7 +62,7 @@ typedef struct {
void *_Nullable TrailingCommaLoc;
} BridgedTupleTypeElement;

typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedRequirementReprKind : long {
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedRequirementReprKind : SwiftInt {
/// A type bound T : P, where T is a type that depends on a generic
/// parameter and P is some type that should bound T, either as a concrete
/// supertype or a protocol to which T must conform.
Expand All @@ -92,7 +89,7 @@ typedef struct {
} BridgedRequirementRepr;

/// Diagnostic severity when reporting diagnostics.
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : long {
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : SwiftInt {
BridgedFatalError,
BridgedError,
BridgedWarning,
Expand All @@ -102,7 +99,7 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : long {

typedef void* BridgedDiagnostic;

typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedMacroDefinitionKind : long {
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedMacroDefinitionKind : SwiftInt {
/// An expanded macro.
BridgedExpandedMacro = 0,
/// An external macro, spelled with either the old spelling (Module.Type)
Expand Down Expand Up @@ -130,7 +127,7 @@ BridgedDiagnostic SwiftDiagnostic_create(void *diagnosticEngine,
BridgedDiagnosticSeverity severity,
const void *_Nullable sourceLoc,
const unsigned char *_Nullable text,
long textLen);
SwiftInt textLen);

/// Highlight a source range as part of the diagnostic.
void SwiftDiagnostic_highlight(
Expand All @@ -141,14 +138,14 @@ void SwiftDiagnostic_fixItReplace(BridgedDiagnostic diag,
const void *_Nullable replaceStartLoc,
const void *_Nullable replaceEndLoc,
const unsigned char *_Nullable newText,
long newTextLen);
SwiftInt newTextLen);

/// Finish the given diagnostic and emit it.
void SwiftDiagnostic_finish(BridgedDiagnostic diag);

BridgedIdentifier
SwiftASTContext_getIdentifier(void *ctx, const unsigned char *_Nullable str,
long len);
SwiftInt len);

void *SwiftImportDecl_create(void *, void *, void *, char, void *,
BridgedArrayRef, BridgedArrayRef);
Expand All @@ -173,11 +170,11 @@ void *SwiftIdentifierExpr_create(void *ctx, BridgedIdentifier base, void *loc);

void *SwiftStringLiteralExpr_create(void *ctx,
const unsigned char *_Nullable string,
long len, void *TokenLoc);
SwiftInt len, void *TokenLoc);

void *SwiftIntegerLiteralExpr_create(void *ctx,
const unsigned char *_Nullable string,
long len, void *TokenLoc);
SwiftInt len, void *TokenLoc);

void *SwiftBooleanLiteralExpr_create(void *ctx, _Bool value, void *TokenLoc);

Expand All @@ -194,7 +191,7 @@ void *SingleValueStmtExpr_createWithWrappedBranches(void *ctx, void *S,
void *IfStmt_create(void *ctx, void *ifLoc, void *cond, void *_Nullable then,
void *_Nullable elseLoc, void *_Nullable elseStmt);

typedef enum ENUM_EXTENSIBILITY_ATTR(open) ASTNodeKind : long {
typedef enum ENUM_EXTENSIBILITY_ATTR(open) ASTNodeKind : SwiftInt {
ASTNodeKindExpr,
ASTNodeKindStmt,
ASTNodeKindDecl
Expand All @@ -208,7 +205,7 @@ struct ASTNodeBridged {
void *BraceStmt_create(void *ctx, void *lbloc, BridgedArrayRef elements,
void *rbloc);

void *BridgedSourceLoc_advanced(void *loc, long len);
void *BridgedSourceLoc_advanced(void *loc, SwiftInt len);

void *ParamDecl_create(void *ctx, void *loc, void *_Nullable argLoc,
void *_Nullable argName, void *_Nullable paramLoc,
Expand Down Expand Up @@ -282,7 +279,7 @@ void *GenericParamList_create(void *ctx, void *lAngleLoc,
BridgedArrayRef reqs, void *rAngleLoc);
void *GenericTypeParamDecl_create(void *ctx, void *declContext,
BridgedIdentifier name, void *nameLoc,
void *_Nullable eachLoc, long index,
void *_Nullable eachLoc, SwiftInt index,
_Bool isParameterPack);
void GenericTypeParamDecl_setInheritedType(void *ctx, void *Param, void *ty);

Expand Down
14 changes: 7 additions & 7 deletions include/swift/AST/PluginRegistry.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,14 +52,13 @@ class LoadedExecutablePlugin {

/// Represents the current process of the executable plugin.
struct PluginProcess {
const llvm::sys::procid_t pid;
const int inputFileDescriptor;
const int outputFileDescriptor;
const llvm::sys::ProcessInfo process;
const int input;
const int output;
bool isStale = false;

PluginProcess(llvm::sys::procid_t pid, int inputFileDescriptor,
int outputFileDescriptor);

PluginProcess(llvm::sys::ProcessInfo process, int input, int output)
: process(process), input(input), output(output) {}
~PluginProcess();

ssize_t write(const void *buf, size_t nbyte) const;
Expand Down Expand Up @@ -138,7 +137,8 @@ class LoadedExecutablePlugin {
llvm::erase_value(onReconnect, fn);
}

llvm::sys::procid_t getPid() { return Process->pid; }
llvm::sys::procid_t getPid() { return Process->process.Pid; }
llvm::sys::process_t getProcess() { return Process->process.Process; }

NullTerminatedStringRef getExecutablePath() {
return {ExecutablePath.c_str(), ExecutablePath.size()};
Expand Down
65 changes: 64 additions & 1 deletion include/swift/Basic/CBasicBridging.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,69 @@
// it causes importing the "Darwin"/"Glibc" overlay module. That violates
// layering. i.e. Darwin overlay is created by Swift compiler.

// NOTE: Partially ported from SwiftShim's SwiftStdint.h. We cannot include
// that header here because it belongs to the runtime, but we need the same
// logic for interoperability with Swift code in the compiler itself.
// stdint.h is provided by Clang, but it dispatches to libc's stdint.h. As a
// result, using stdint.h here would pull in Darwin module (which includes
// libc). This creates a dependency cycle, so we can't use stdint.h in
// SwiftShims.
// On Linux, the story is different. We get the error message
// "/usr/include/x86_64-linux-gnu/sys/types.h:146:10: error: 'stddef.h' file not
// found"
// This is a known Clang/Ubuntu bug.

// Clang has been defining __INTxx_TYPE__ macros for a long time.
// __UINTxx_TYPE__ are defined only since Clang 3.5.
#if defined(_MSC_VER) && !defined(__clang__)
typedef __int64 __swiftc_int64_t;
typedef unsigned __int64 __swiftc_uint64_t;
typedef int __swiftc_int32_t;
typedef unsigned int __swiftc_uint32_t;
#elif !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__wasi__)
#include <stdint.h>
typedef int64_t __swiftc_int64_t;
typedef uint64_t __swiftc_uint64_t;
typedef int32_t __swiftc_int32_t;
typedef uint32_t __swiftc_uint32_t;
typedef intptr_t __swiftc_intptr_t;
typedef uintptr_t __swiftc_uintptr_t;
#else
typedef __INT64_TYPE__ __swiftc_int64_t;
#ifdef __UINT64_TYPE__
typedef __UINT64_TYPE__ __swiftc_uint64_t;
#else
typedef unsigned __INT64_TYPE__ __swiftc_uint64_t;
#endif

typedef __INT32_TYPE__ __swiftc_int32_t;
#ifdef __UINT32_TYPE__
typedef __UINT32_TYPE__ __swiftc_uint32_t;
#else
typedef unsigned __INT32_TYPE__ __swiftc_uint32_t;
#endif
#endif

#define __swiftc_join3(a,b,c) a ## b ## c

#define __swiftc_intn_t(n) __swiftc_join3(__swiftc_int, n, _t)
#define __swiftc_uintn_t(n) __swiftc_join3(__swiftc_uint, n, _t)

#if defined(_MSC_VER) && !defined(__clang__)
#if defined(_WIN64)
typedef __swiftc_int64_t SwiftInt;
typedef __swiftc_uint64_t SwiftUInt;
#elif defined(_WIN32)
typedef __swiftc_int32_t SwiftInt;
typedef __swiftc_uint32_t SwiftUInt;
#else
#error unknown windows pointer width
#endif
#else
typedef __swiftc_intn_t(__INTPTR_WIDTH__) SwiftInt;
typedef __swiftc_uintn_t(__INTPTR_WIDTH__) SwiftUInt;
#endif

#if __clang__
// Provide macros to temporarily suppress warning about the use of
// _Nullable and _Nonnull.
Expand Down Expand Up @@ -48,7 +111,7 @@ extern "C" {

typedef struct BridgedData {
const char *_Nullable baseAddress;
unsigned long size;
SwiftUInt size;
} BridgedData;

void BridgedData_free(BridgedData data);
Expand Down
12 changes: 5 additions & 7 deletions include/swift/Basic/Program.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,12 @@ int ExecuteInPlace(const char *Program, const char **args,
const char **env = nullptr);

struct ChildProcessInfo {
llvm::sys::procid_t Pid;
int WriteFileDescriptor;
int ReadFileDescriptor;
llvm::sys::ProcessInfo ProcessInfo;
int Write;
int Read;

ChildProcessInfo(llvm::sys::procid_t Pid, int WriteFileDescriptor,
int ReadFileDescriptor)
: Pid(Pid), WriteFileDescriptor(WriteFileDescriptor),
ReadFileDescriptor(ReadFileDescriptor) {}
ChildProcessInfo(llvm::sys::ProcessInfo ProcessInfo, int Write, int Read)
: ProcessInfo(ProcessInfo), Write(Write), Read(Read) {}
};

/// This function executes the program using the argument provided.
Expand Down
5 changes: 4 additions & 1 deletion include/swift/Driver/ToolChain.h
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,10 @@ class ToolChain {
void addLinkRuntimeLib(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &Arguments,
StringRef LibName) const;


virtual void addPluginArguments(const llvm::opt::ArgList &Args,
llvm::opt::ArgStringList &Arguments) const {}

/// Validates arguments passed to the toolchain.
///
/// An override point for platform-specific subclasses to customize the
Expand Down
Loading