Skip to content

Commit eba2a02

Browse files
compnerdbnbarham
authored andcommitted
Enable macros for Windows in 5.9.1
Squashed cherry-pick of #68334 and #68743.
1 parent b96b2d9 commit eba2a02

File tree

74 files changed

+897
-384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+897
-384
lines changed

cmake/modules/AddPureSwift.cmake

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,16 @@ function(force_target_link_libraries TARGET)
55
cmake_parse_arguments(ARGS "" "" "PUBLIC" ${ARGN})
66

77
foreach(DEPENDENCY ${ARGS_PUBLIC})
8-
target_link_libraries(${TARGET} PRIVATE
9-
${DEPENDENCY}
10-
)
8+
target_link_libraries(${TARGET} PRIVATE ${DEPENDENCY})
119
add_dependencies(${TARGET} ${DEPENDENCY})
1210

13-
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
14-
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
11+
string(REGEX REPLACE [<>:\"/\\|?*] _ sanitized ${DEPENDENCY})
12+
add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift
13+
COMMAND ${CMAKE_COMMAND} -E touch ${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift
1514
DEPENDS ${DEPENDENCY}
1615
)
1716
target_sources(${TARGET} PRIVATE
18-
${CMAKE_CURRENT_BINARY_DIR}/forced-${DEPENDENCY}-dep.swift
17+
${CMAKE_CURRENT_BINARY_DIR}/forced-${sanitized}-dep.swift
1918
)
2019
endforeach()
2120
endfunction()
@@ -270,7 +269,8 @@ function(add_pure_swift_host_tool name)
270269

271270
# Option handling
272271
set(options)
273-
set(single_parameter_options)
272+
set(single_parameter_options
273+
SWIFT_COMPONENT)
274274
set(multiple_parameter_options
275275
DEPENDENCIES
276276
SWIFT_DEPENDENCIES)
@@ -324,6 +324,17 @@ function(add_pure_swift_host_tool name)
324324
target_include_directories(${name} PUBLIC
325325
${SWIFT_HOST_LIBRARIES_DEST_DIR})
326326

327-
# Export this target.
328-
set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name})
327+
if(NOT APSHT_SWIFT_COMPONENT STREQUAL no_component)
328+
add_dependencies(${APSHT_SWIFT_COMPONENT} ${name})
329+
swift_install_in_component(TARGETS ${name}
330+
COMPONENT ${APSHT_SWIFT_COMPONENT}
331+
RUNTIME DESTINATION bin)
332+
swift_is_installing_component(${APSHT_SWIFT_COMPONENT} is_installing)
333+
endif()
334+
335+
if(NOT is_installing)
336+
set_property(GLOBAL APPEND PROPERTY SWIFT_BUILDTREE_EXPORTS ${name})
337+
else()
338+
set_property(GLOBAL APPEND PROPERTY SWIFT_EXPORTS ${name})
339+
endif()
329340
endfunction()

cmake/modules/AddSwift.cmake

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -570,6 +570,9 @@ function(_add_swift_runtime_link_flags target relpath_to_lib_dir bootstrapping)
570570
else()
571571
message(FATAL_ERROR "Unknown BOOTSTRAPPING_MODE '${ASRLF_BOOTSTRAPPING_MODE}'")
572572
endif()
573+
else()
574+
target_link_directories(${target} PRIVATE
575+
${SWIFT_PATH_TO_SWIFT_SDK}/usr/lib/swift/${SWIFT_SDK_${SWIFT_HOST_VARIANT_SDK}_LIB_SUBDIR}/${SWIFT_HOST_VARIANT_ARCH})
573576
endif()
574577

575578
if(SWIFT_SWIFT_PARSER)

include/swift/AST/CASTBridging.h

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,9 @@
3939

4040
SWIFT_BEGIN_NULLABILITY_ANNOTATIONS
4141

42-
typedef long SwiftInt;
43-
typedef unsigned long SwiftUInt;
44-
4542
typedef struct {
4643
const void *_Nullable data;
47-
long numElements;
44+
SwiftInt numElements;
4845
} BridgedArrayRef;
4946

5047
typedef struct {
@@ -65,7 +62,7 @@ typedef struct {
6562
void *_Nullable TrailingCommaLoc;
6663
} BridgedTupleTypeElement;
6764

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

9491
/// Diagnostic severity when reporting diagnostics.
95-
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : long {
92+
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : SwiftInt {
9693
BridgedFatalError,
9794
BridgedError,
9895
BridgedWarning,
@@ -102,7 +99,7 @@ typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedDiagnosticSeverity : long {
10299

103100
typedef void* BridgedDiagnostic;
104101

105-
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedMacroDefinitionKind : long {
102+
typedef enum ENUM_EXTENSIBILITY_ATTR(open) BridgedMacroDefinitionKind : SwiftInt {
106103
/// An expanded macro.
107104
BridgedExpandedMacro = 0,
108105
/// An external macro, spelled with either the old spelling (Module.Type)
@@ -130,7 +127,7 @@ BridgedDiagnostic SwiftDiagnostic_create(void *diagnosticEngine,
130127
BridgedDiagnosticSeverity severity,
131128
const void *_Nullable sourceLoc,
132129
const unsigned char *_Nullable text,
133-
long textLen);
130+
SwiftInt textLen);
134131

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

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

149146
BridgedIdentifier
150147
SwiftASTContext_getIdentifier(void *ctx, const unsigned char *_Nullable str,
151-
long len);
148+
SwiftInt len);
152149

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

174171
void *SwiftStringLiteralExpr_create(void *ctx,
175172
const unsigned char *_Nullable string,
176-
long len, void *TokenLoc);
173+
SwiftInt len, void *TokenLoc);
177174

178175
void *SwiftIntegerLiteralExpr_create(void *ctx,
179176
const unsigned char *_Nullable string,
180-
long len, void *TokenLoc);
177+
SwiftInt len, void *TokenLoc);
181178

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

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

197-
typedef enum ENUM_EXTENSIBILITY_ATTR(open) ASTNodeKind : long {
194+
typedef enum ENUM_EXTENSIBILITY_ATTR(open) ASTNodeKind : SwiftInt {
198195
ASTNodeKindExpr,
199196
ASTNodeKindStmt,
200197
ASTNodeKindDecl
@@ -208,7 +205,7 @@ struct ASTNodeBridged {
208205
void *BraceStmt_create(void *ctx, void *lbloc, BridgedArrayRef elements,
209206
void *rbloc);
210207

211-
void *BridgedSourceLoc_advanced(void *loc, long len);
208+
void *BridgedSourceLoc_advanced(void *loc, SwiftInt len);
212209

213210
void *ParamDecl_create(void *ctx, void *loc, void *_Nullable argLoc,
214211
void *_Nullable argName, void *_Nullable paramLoc,
@@ -282,7 +279,7 @@ void *GenericParamList_create(void *ctx, void *lAngleLoc,
282279
BridgedArrayRef reqs, void *rAngleLoc);
283280
void *GenericTypeParamDecl_create(void *ctx, void *declContext,
284281
BridgedIdentifier name, void *nameLoc,
285-
void *_Nullable eachLoc, long index,
282+
void *_Nullable eachLoc, SwiftInt index,
286283
_Bool isParameterPack);
287284
void GenericTypeParamDecl_setInheritedType(void *ctx, void *Param, void *ty);
288285

include/swift/AST/PluginRegistry.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,13 @@ class LoadedExecutablePlugin {
5252

5353
/// Represents the current process of the executable plugin.
5454
struct PluginProcess {
55-
const llvm::sys::procid_t pid;
56-
const int inputFileDescriptor;
57-
const int outputFileDescriptor;
55+
const llvm::sys::ProcessInfo process;
56+
const int input;
57+
const int output;
5858
bool isStale = false;
5959

60-
PluginProcess(llvm::sys::procid_t pid, int inputFileDescriptor,
61-
int outputFileDescriptor);
62-
60+
PluginProcess(llvm::sys::ProcessInfo process, int input, int output)
61+
: process(process), input(input), output(output) {}
6362
~PluginProcess();
6463

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

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

143143
NullTerminatedStringRef getExecutablePath() {
144144
return {ExecutablePath.c_str(), ExecutablePath.size()};

include/swift/Basic/CBasicBridging.h

Lines changed: 64 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,69 @@
2020
// it causes importing the "Darwin"/"Glibc" overlay module. That violates
2121
// layering. i.e. Darwin overlay is created by Swift compiler.
2222

23+
// NOTE: Partially ported from SwiftShim's SwiftStdint.h. We cannot include
24+
// that header here because it belongs to the runtime, but we need the same
25+
// logic for interoperability with Swift code in the compiler itself.
26+
// stdint.h is provided by Clang, but it dispatches to libc's stdint.h. As a
27+
// result, using stdint.h here would pull in Darwin module (which includes
28+
// libc). This creates a dependency cycle, so we can't use stdint.h in
29+
// SwiftShims.
30+
// On Linux, the story is different. We get the error message
31+
// "/usr/include/x86_64-linux-gnu/sys/types.h:146:10: error: 'stddef.h' file not
32+
// found"
33+
// This is a known Clang/Ubuntu bug.
34+
35+
// Clang has been defining __INTxx_TYPE__ macros for a long time.
36+
// __UINTxx_TYPE__ are defined only since Clang 3.5.
37+
#if defined(_MSC_VER) && !defined(__clang__)
38+
typedef __int64 __swiftc_int64_t;
39+
typedef unsigned __int64 __swiftc_uint64_t;
40+
typedef int __swiftc_int32_t;
41+
typedef unsigned int __swiftc_uint32_t;
42+
#elif !defined(__APPLE__) && !defined(__linux__) && !defined(__OpenBSD__) && !defined(__wasi__)
43+
#include <stdint.h>
44+
typedef int64_t __swiftc_int64_t;
45+
typedef uint64_t __swiftc_uint64_t;
46+
typedef int32_t __swiftc_int32_t;
47+
typedef uint32_t __swiftc_uint32_t;
48+
typedef intptr_t __swiftc_intptr_t;
49+
typedef uintptr_t __swiftc_uintptr_t;
50+
#else
51+
typedef __INT64_TYPE__ __swiftc_int64_t;
52+
#ifdef __UINT64_TYPE__
53+
typedef __UINT64_TYPE__ __swiftc_uint64_t;
54+
#else
55+
typedef unsigned __INT64_TYPE__ __swiftc_uint64_t;
56+
#endif
57+
58+
typedef __INT32_TYPE__ __swiftc_int32_t;
59+
#ifdef __UINT32_TYPE__
60+
typedef __UINT32_TYPE__ __swiftc_uint32_t;
61+
#else
62+
typedef unsigned __INT32_TYPE__ __swiftc_uint32_t;
63+
#endif
64+
#endif
65+
66+
#define __swiftc_join3(a,b,c) a ## b ## c
67+
68+
#define __swiftc_intn_t(n) __swiftc_join3(__swiftc_int, n, _t)
69+
#define __swiftc_uintn_t(n) __swiftc_join3(__swiftc_uint, n, _t)
70+
71+
#if defined(_MSC_VER) && !defined(__clang__)
72+
#if defined(_WIN64)
73+
typedef __swiftc_int64_t SwiftInt;
74+
typedef __swiftc_uint64_t SwiftUInt;
75+
#elif defined(_WIN32)
76+
typedef __swiftc_int32_t SwiftInt;
77+
typedef __swiftc_uint32_t SwiftUInt;
78+
#else
79+
#error unknown windows pointer width
80+
#endif
81+
#else
82+
typedef __swiftc_intn_t(__INTPTR_WIDTH__) SwiftInt;
83+
typedef __swiftc_uintn_t(__INTPTR_WIDTH__) SwiftUInt;
84+
#endif
85+
2386
#if __clang__
2487
// Provide macros to temporarily suppress warning about the use of
2588
// _Nullable and _Nonnull.
@@ -48,7 +111,7 @@ extern "C" {
48111

49112
typedef struct BridgedData {
50113
const char *_Nullable baseAddress;
51-
unsigned long size;
114+
SwiftUInt size;
52115
} BridgedData;
53116

54117
void BridgedData_free(BridgedData data);

include/swift/Basic/Program.h

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,12 @@ int ExecuteInPlace(const char *Program, const char **args,
4040
const char **env = nullptr);
4141

4242
struct ChildProcessInfo {
43-
llvm::sys::procid_t Pid;
44-
int WriteFileDescriptor;
45-
int ReadFileDescriptor;
43+
llvm::sys::ProcessInfo ProcessInfo;
44+
int Write;
45+
int Read;
4646

47-
ChildProcessInfo(llvm::sys::procid_t Pid, int WriteFileDescriptor,
48-
int ReadFileDescriptor)
49-
: Pid(Pid), WriteFileDescriptor(WriteFileDescriptor),
50-
ReadFileDescriptor(ReadFileDescriptor) {}
47+
ChildProcessInfo(llvm::sys::ProcessInfo ProcessInfo, int Write, int Read)
48+
: ProcessInfo(ProcessInfo), Write(Write), Read(Read) {}
5149
};
5250

5351
/// This function executes the program using the argument provided.

include/swift/Driver/ToolChain.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,10 @@ class ToolChain {
340340
void addLinkRuntimeLib(const llvm::opt::ArgList &Args,
341341
llvm::opt::ArgStringList &Arguments,
342342
StringRef LibName) const;
343-
343+
344+
virtual void addPluginArguments(const llvm::opt::ArgList &Args,
345+
llvm::opt::ArgStringList &Arguments) const {}
346+
344347
/// Validates arguments passed to the toolchain.
345348
///
346349
/// An override point for platform-specific subclasses to customize the

0 commit comments

Comments
 (0)