Skip to content

Commit 7b2eb1f

Browse files
authored
Merge pull request #39987 from Catfish-Man/printf-in-this-economy
2 parents 14d8c19 + fc3e718 commit 7b2eb1f

File tree

14 files changed

+956
-0
lines changed

14 files changed

+956
-0
lines changed

CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ option(SWIFT_BUILD_DYNAMIC_STDLIB
9393
option(SWIFT_BUILD_STATIC_STDLIB
9494
"Build static variants of the Swift standard library"
9595
FALSE)
96+
97+
option(SWIFT_STDLIB_STATIC_PRINT
98+
"Build compile-time evaluated vprintf()"
99+
FALSE)
96100

97101
option(SWIFT_BUILD_DYNAMIC_SDK_OVERLAY
98102
"Build dynamic variants of the Swift SDK overlay"

stdlib/cmake/modules/SwiftSource.cmake

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,6 +292,10 @@ function(_add_target_variant_swift_compile_flags
292292
if(SWIFT_STDLIB_OS_VERSIONING)
293293
list(APPEND result "-D" "SWIFT_RUNTIME_OS_VERSIONING")
294294
endif()
295+
296+
if(SWIFT_STDLIB_STATIC_PRINT)
297+
list(APPEND result "-D" "SWIFT_STDLIB_STATIC_PRINT")
298+
endif()
295299

296300
if(SWIFT_STDLIB_HAS_COMMANDLINE)
297301
list(APPEND result "-D" "SWIFT_STDLIB_HAS_COMMANDLINE")

stdlib/public/SwiftShims/LibcShims.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,19 @@ static inline int _swift_stdlib_memcmp(const void *s1, const void *s2,
8585
#define CONST_CAST(type, value) (type)value
8686
#endif
8787

88+
#ifndef _VA_LIST
89+
typedef __builtin_va_list va_list;
90+
#define _VA_LIST
91+
#endif
92+
93+
static inline int _swift_stdlib_vprintf(const char * __restrict fmt, va_list args) {
94+
extern int vprintf(const char * __restrict, va_list);
95+
#pragma clang diagnostic push
96+
#pragma clang diagnostic ignored "-Wformat-nonliteral"
97+
return vprintf(fmt, args);
98+
#pragma clang diagnostic pop
99+
}
100+
88101
// Non-standard extensions
89102
#if defined(__APPLE__)
90103
#define HAS_MALLOC_SIZE 1

stdlib/public/core/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,7 @@ set(SWIFTLIB_ESSENTIAL
141141
SmallString.swift
142142
Sort.swift
143143
StaticString.swift
144+
StaticPrint.swift
144145
Stride.swift
145146
StringHashable.swift # ORDER DEPENDENCY: Must precede String.swift
146147
String.swift

stdlib/public/core/GroupInfo.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@
221221
"Runtime.swift",
222222
"RuntimeFunctionCounters.swift",
223223
"Shims.swift",
224+
"StaticPrint.swift",
224225
"ThreadLocalStorage.swift",
225226
"Unmanaged.swift",
226227
"Availability.swift",

0 commit comments

Comments
 (0)