Skip to content

Commit c5b7e7f

Browse files
martinboehmezoecarverhlopko
authored
Fix two issues with the SwiftGlibc module map (#32404)
* Fix two issues with the SwiftGlibc module map. The issues are: - Today, some submodules in `SwiftGlibc` fail to provide definitions that they should contain. As a consequence, Swift fails to import some code that compiles correctly with standalone Clang. As just one example, including `signal.h` should make the type `pid_t` available, but it currently does not. - `SwiftGlibc` is not compatible with the libc++ module map. Trying to include libc++ headers in a C++ module imported into Swift results in an error message about cyclic dependencies. This change fixes both of these issues by making it so that `SwiftGlibc` no actually longer defines a module map for the glibc headers but merely makes all of the symbols from those headers available in a module that can be imported into Swift. C / Objective-C / C++ code, on the other hand, will now include the glibc headers texually. For more context on the two issues and this fix, see this forum discussion: https://forums.swift.org/t/problems-with-swiftglibc-and-proposed-fix/37594 This change only modifies `glibc.modulemap.gyb` for the time being but leaves `bionic.modulemap.gyb` and `libc-openbsd.modulemap.gyb` unchanged. The intent is to fix these in the same way, but it will be easier to do this in separate PRs that can be tested individually. Co-authored-by: zoecarver <[email protected]> Co-authored-by: Marcel Hlopko <[email protected]>
1 parent f052313 commit c5b7e7f

File tree

7 files changed

+184
-500
lines changed

7 files changed

+184
-500
lines changed

stdlib/public/Platform/CMakeLists.txt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,13 @@ foreach(sdk ${SWIFT_SDKS})
119119
list(APPEND glibc_modulemap_target_list ${copy_glibc_modulemap_static})
120120
endif()
121121

122+
set(glibc_header_out "${module_dir}/SwiftGlibc.h")
123+
handle_gyb_source_single(glibc_header_target
124+
SOURCE "SwiftGlibc.h.gyb"
125+
OUTPUT "${glibc_header_out}"
126+
FLAGS "-DCMAKE_SDK=${sdk}")
127+
list(APPEND glibc_modulemap_target_list ${glibc_header_target})
128+
122129
# If this SDK is a target for a non-native host, except if it's for Android
123130
# with its own native sysroot, create a native modulemap without a sysroot
124131
# prefix. This is the one we'll install instead.
@@ -150,11 +157,17 @@ foreach(sdk ${SWIFT_SDKS})
150157
swift_install_in_component(FILES "${glibc_modulemap_out}"
151158
DESTINATION "lib/swift/${arch_subdir}"
152159
COMPONENT sdk-overlay)
160+
swift_install_in_component(FILES "${glibc_header_out}"
161+
DESTINATION "lib/swift/${arch_subdir}"
162+
COMPONENT sdk-overlay)
153163

154164
if(SWIFT_BUILD_STATIC_STDLIB)
155165
swift_install_in_component(FILES "${glibc_modulemap_out}"
156166
DESTINATION "lib/swift_static/${arch_subdir}"
157167
COMPONENT sdk-overlay)
168+
swift_install_in_component(FILES "${glibc_header_out}"
169+
DESTINATION "lib/swift_static/${arch_subdir}"
170+
COMPONENT sdk-overlay)
158171
endif()
159172
endforeach()
160173
endforeach()
Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
%{
2+
headers = [
3+
'stdc-predef.h',
4+
'features.h',
5+
6+
# C standard library
7+
'complex.h',
8+
'ctype.h',
9+
'errno.h',
10+
'fenv.h',
11+
'float.h',
12+
'inttypes.h',
13+
'iso646.h',
14+
'libutil.h',
15+
'limits.h',
16+
'locale.h',
17+
'math.h',
18+
'pty.h',
19+
'setjmp.h',
20+
'signal.h',
21+
'stdarg.h',
22+
'stdbool.h',
23+
'stddef.h',
24+
'stdint.h',
25+
'stdio.h',
26+
'stdlib.h',
27+
'string.h',
28+
'tgmath.h',
29+
'time.h',
30+
'utmp.h',
31+
'utmpx.h',
32+
33+
# POSIX
34+
'aio.h',
35+
'arpa/inet.h',
36+
'bsd/ifaddrs.h',
37+
'bsd/pty.h',
38+
'cpio.h',
39+
'dirent.h',
40+
'dlfcn.h',
41+
'fcntl.h',
42+
'fmtmsg.h',
43+
'fnmatch.h',
44+
'ftw.h',
45+
'glob.h',
46+
'grp.h',
47+
'iconv.h',
48+
'ifaddrs.h',
49+
'langinfo.h',
50+
'libgen.h',
51+
'link.h',
52+
'monetary.h',
53+
'net/if.h',
54+
'netdb.h',
55+
'netinet/in.h',
56+
'netinet/tcp.h',
57+
'nl_types.h',
58+
'poll.h',
59+
'pthread.h',
60+
'pwd.h',
61+
'regex.h',
62+
'sched.h',
63+
'search.h',
64+
'semaphore.h',
65+
'spawn.h',
66+
'strings.h',
67+
'sys/event.h',
68+
'sys/file.h',
69+
'sys/inotify.h',
70+
'sys/ioctl.h',
71+
'sys/ipc.h',
72+
'sys/mman.h',
73+
'sys/msg.h',
74+
'sys/resource.h',
75+
'sys/select.h',
76+
'sys/sem.h',
77+
'sys/sendfile.h',
78+
'sys/shm.h',
79+
'sys/socket.h',
80+
'sys/stat.h',
81+
'sys/statvfs.h',
82+
'sys/time.h',
83+
'sys/times.h',
84+
'sys/types.h',
85+
'sys/uio.h',
86+
'sys/un.h',
87+
'sys/user.h',
88+
'sys/utsname.h',
89+
'sys/wait.h',
90+
'sysexits.h',
91+
'syslog.h',
92+
'tar.h',
93+
'termios.h',
94+
'ulimit.h',
95+
'unistd.h',
96+
'utime.h',
97+
'utmpx.h',
98+
'wait.h',
99+
'wordexp.h',
100+
]
101+
}%
102+
103+
% for header in headers:
104+
#if __has_include(<${header}>)
105+
#include <${header}>
106+
#endif
107+
% end

0 commit comments

Comments
 (0)