Skip to content

Commit 4c730f1

Browse files
committed
Revert "Define _GNU_SOURCE and _DEFAULT_SOURCE in the package manifest and cmakefile"
This reverts commit 4801296.
1 parent 4801296 commit 4c730f1

File tree

6 files changed

+67
-26
lines changed

6 files changed

+67
-26
lines changed

Package.swift

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,6 @@ extension Array where Element == PackageDescription.CXXSetting {
162162
static var packageSettings: Self {
163163
var result = Self()
164164

165-
// On platforms that use glibc, define some additional macros to expose some
166-
// useful (but non-standard) interfaces.
167-
result += [
168-
.define("_DEFAULT_SOURCE", to: "1", .when(platforms: [.linux, .custom("FreeBSD"), .android])),
169-
.define("_GNU_SOURCE", to: "1", .when(platforms: [.linux, .custom("FreeBSD"), .android])),
170-
]
171-
172165
// Capture the testing library's version as a C++ string constant.
173166
if let git = Context.gitInformation {
174167
let testingLibraryVersion = if let tag = git.currentTag {

Sources/Testing/ExitTests/ExitTest.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public struct ExitTest: Sendable {
5656
// will often be disabled by default.) If a particular Linux distro performs
5757
// additional crash diagnostics, we may want to special-case them as well if we can.
5858
var rl = rlimit(rlim_cur: 0, rlim_max: 0)
59-
_ = setrlimit(RLIMIT_CORE, &rl)
59+
_ = setrlimit(CInt(RLIMIT_CORE.rawValue), &rl)
6060
#elseif os(Windows)
6161
// On Windows, similarly disable Windows Error Reporting and the Windows
6262
// Error Reporting UI. Note we expect to be the first component to call

Sources/Testing/ExitTests/WaitFor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ private let _createWaitThreadImpl: Void = {
109109
#if SWT_TARGET_OS_APPLE
110110
_ = pthread_setname_np("Swift Testing exit test monitor")
111111
#elseif os(Linux)
112-
_ = pthread_setname_np(pthread_self(), "SWT ExT monitor")
112+
_ = swt_pthread_setname_np(pthread_self(), "SWT ExT monitor")
113113
#elseif os(FreeBSD)
114114
_ = pthread_set_name_np(pthread_self(), "SWT ex test monitor")
115115
#else

Sources/_TestingInternals/Stubs.cpp

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
//
2+
// This source file is part of the Swift.org open source project
3+
//
4+
// Copyright (c) 2024 Apple Inc. and the Swift project authors
5+
// Licensed under Apache License v2.0 with Runtime Library Exception
6+
//
7+
// See https://swift.org/LICENSE.txt for license information
8+
// See https://swift.org/CONTRIBUTORS.txt for Swift project authors
9+
//
10+
11+
/// This source file includes implementations of functions that _should_ simply
12+
/// be `static` stubs in Stubs.h, but which for technical reasons cannot be
13+
/// imported into Swift when defined in a header.
14+
///
15+
/// Do not, as a rule, add function implementations in this file. Prefer to add
16+
/// them to Stubs.h so that they can be inlined at compile- or link-time. Only
17+
/// include functions here if Swift cannot successfully import and call them
18+
/// otherwise.
19+
20+
#if defined(__linux__) || defined(__FreeBSD__)
21+
#undef _DEFAULT_SOURCE
22+
#define _DEFAULT_SOURCE 1
23+
#undef _GNU_SOURCE
24+
#define _GNU_SOURCE 1
25+
#endif
26+
27+
#include "Stubs.h"
28+
29+
#include <features.h>
30+
31+
#if defined(__linux__) || defined(__FreeBSD__)
32+
#endif
33+
34+
#if defined(__linux__)
35+
int swt_pthread_setname_np(pthread_t thread, const char *name) {
36+
return pthread_setname_np(thread, name);
37+
}
38+
#endif
39+
40+
#if defined(__linux__) || defined(__FreeBSD__)
41+
int swt_posix_spawn_file_actions_addclosefrom_np(posix_spawn_file_actions_t *fileActions, int from) {
42+
int result = 0;
43+
44+
#if defined(__GLIBC_PREREQ)
45+
#if __GLIBC_PREREQ(2, 34)
46+
result = posix_spawn_file_actions_addclosefrom_np(fileActions, from);
47+
#endif
48+
#endif
49+
50+
return result;
51+
}
52+
#endif

Sources/_TestingInternals/include/Stubs.h

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -109,22 +109,23 @@ static char *_Nullable *_Null_unspecified swt_environ(void) {
109109
}
110110
#endif
111111

112+
#if defined(__linux__)
113+
/// Set the name of the current thread.
114+
///
115+
/// This function declaration is provided because `pthread_setname_np()` is
116+
/// only declared if `_GNU_SOURCE` is set, but setting it causes build errors
117+
/// due to conflicts with Swift's Glibc module.
118+
SWT_EXTERN int swt_pthread_setname_np(pthread_t thread, const char *name);
119+
#endif
120+
112121
#if defined(__linux__) || defined(__FreeBSD__)
113122
/// Close file descriptors above a given value when spawing a new process.
114123
///
115124
/// This symbol is provided because the underlying function was added to glibc
116-
/// relatively recently and may not be available on all targets.
117-
static int swt_posix_spawn_file_actions_addclosefrom_np(posix_spawn_file_actions_t *fileActions, int from) {
118-
int result = 0;
119-
120-
#if defined(__GLIBC_PREREQ)
121-
#if __GLIBC_PREREQ(2, 34)
122-
result = posix_spawn_file_actions_addclosefrom_np(fileActions, from);
123-
#endif
124-
#endif
125-
126-
return result;
127-
}
125+
/// relatively recently and may not be available on all targets. Checking
126+
/// `__GLIBC_PREREQ()` is insufficient because `_DEFAULT_SOURCE` may not be
127+
/// defined at the point spawn.h is first included.
128+
SWT_EXTERN int swt_posix_spawn_file_actions_addclosefrom_np(posix_spawn_file_actions_t *fileActions, int from);
128129
#endif
129130

130131
#if !defined(__ANDROID__)

cmake/modules/shared/CompilerSettings.cmake

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,6 @@ add_compile_options(
1616
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-upcoming-feature -Xfrontend ExistentialAny>"
1717
"SHELL:$<$<COMPILE_LANGUAGE:Swift>:-Xfrontend -enable-upcoming-feature -Xfrontend InternalImportsByDefault>")
1818

19-
set(SWT_GLIBC "Linux" "FreeBSD" "Android")
20-
if(CMAKE_SYSTEM_NAME IN_LIST SWT_GLIBC)
21-
add_compile_definitions("_DEFAULT_SOURCE" "_GNU_SOURCE")
22-
endif()
23-
2419
# Platform-specific definitions.
2520
if(APPLE)
2621
add_compile_definitions("SWT_TARGET_OS_APPLE")

0 commit comments

Comments
 (0)