Skip to content

Commit 308fb64

Browse files
[wasm] sync libc module style with c5b7e7f
1 parent 50d8065 commit 308fb64

File tree

3 files changed

+148
-209
lines changed

3 files changed

+148
-209
lines changed

stdlib/public/Platform/CMakeLists.txt

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,11 +103,14 @@ if(WASI IN_LIST SWIFT_SDKS)
103103
set(module_dir_static "${SWIFTSTATICLIB_DIR}/${arch_subdir}")
104104
set(wasi_libc_modulemap_out "${module_dir}/wasi.modulemap")
105105
set(wasi_libc_modulemap_out_static "${module_dir_static}/wasi.modulemap")
106+
set(wasi_libc_modulemap_target_list)
106107
handle_gyb_source_single(wasi_libc_modulemap_target
107108
SOURCE "wasi.modulemap.gyb"
108109
OUTPUT "${wasi_libc_modulemap_out}"
109110
FLAGS "-DLIBC_INCLUDE_PATH=${SWIFT_SDK_WASI_ARCH_wasm32_LIBC_INCLUDE_DIRECTORY}"
110111
"-DLIBC_ARCH_INCLUDE_PATH=${SWIFT_SDK_WASI_ARCH_wasm32_LIBC_ARCHITECTURE_INCLUDE_DIRECTORY}")
112+
list(APPEND wasi_libc_modulemap_target_list ${wasi_libc_modulemap_target})
113+
111114
add_custom_command_target(
112115
copy_wasi_libc_modulemap_static
113116
COMMAND
@@ -119,6 +122,28 @@ if(WASI IN_LIST SWIFT_SDKS)
119122
"${wasi_libc_modulemap_target}"
120123
COMMENT "Copying WASILlibc modulemap to static resources")
121124

125+
list(APPEND wasi_libc_modulemap_target_list ${copy_wasi_libc_modulemap_static})
126+
127+
set(wasi_libc_header_out "${module_dir}/SwiftWASILibc.h")
128+
set(wasi_libc_header_out_static "${module_dir_static}/SwiftWASILibc.h")
129+
handle_gyb_source_single(wasi_libc_header_target
130+
SOURCE "SwiftWASILibc.h.gyb"
131+
OUTPUT "${wasi_libc_header_out}"
132+
FLAGS "-DCMAKE_SDK=${sdk}")
133+
list(APPEND wasi_libc_modulemap_target_list ${wasi_libc_header_target})
134+
135+
add_custom_command_target(
136+
copy_wasi_libc_header_static
137+
COMMAND
138+
"${CMAKE_COMMAND}" "-E" "make_directory" ${module_dir_static}
139+
COMMAND
140+
"${CMAKE_COMMAND}" "-E" "copy" ${wasi_libc_header_out} ${wasi_libc_header_out_static}
141+
OUTPUT ${wasi_libc_header_out_static}
142+
DEPENDS
143+
"${wasi_libc_header_target}"
144+
COMMENT "Copying WASILlibc header to static resources")
145+
list(APPEND wasi_libc_modulemap_target_list ${copy_wasi_libc_header_static})
146+
122147
add_swift_target_library(swiftWASILibc ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
123148
${swift_platform_sources}
124149
POSIXError.swift
@@ -133,7 +158,7 @@ if(WASI IN_LIST SWIFT_SDKS)
133158
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
134159
TARGET_SDKS WASI
135160
INSTALL_IN_COMPONENT sdk-overlay
136-
DEPENDS ${wasi_libc_modulemap_target} ${copy_wasi_libc_modulemap_static})
161+
DEPENDS ${wasi_libc_modulemap_target_list})
137162

138163
swift_install_in_component(FILES "${wasi_libc_modulemap_out}"
139164
DESTINATION "lib/swift/${arch_subdir}"
@@ -143,8 +168,16 @@ if(WASI IN_LIST SWIFT_SDKS)
143168
DESTINATION "lib/swift_static/${arch_subdir}"
144169
COMPONENT sdk-overlay)
145170

171+
swift_install_in_component(FILES "${wasi_libc_header_out}"
172+
DESTINATION "lib/swift/${arch_subdir}"
173+
COMPONENT sdk-overlay)
174+
175+
swift_install_in_component(FILES "${wasi_libc_header_out}"
176+
DESTINATION "lib/swift_static/${arch_subdir}"
177+
COMPONENT sdk-overlay)
178+
146179
add_custom_target(wasi_libc_modulemap
147-
DEPENDS ${wasi_libc_modulemap_target} ${copy_wasi_libc_modulemap_static})
180+
DEPENDS ${wasi_libc_modulemap_target_list})
148181
set_property(TARGET wasi_libc_modulemap PROPERTY FOLDER "Miscellaneous")
149182
add_dependencies(sdk-overlay wasi_libc_modulemap)
150183
endif()
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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+
'util.h',
31+
'utmp.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/mount.h',
74+
'sys/msg.h',
75+
'sys/resource.h',
76+
'sys/select.h',
77+
'sys/sem.h',
78+
'sys/sendfile.h',
79+
'sys/shm.h',
80+
'sys/socket.h',
81+
'sys/stat.h',
82+
'sys/statvfs.h',
83+
'sys/time.h',
84+
'sys/times.h',
85+
'sys/types.h',
86+
'sys/uio.h',
87+
'sys/un.h',
88+
'sys/user.h',
89+
'sys/utsname.h',
90+
'sys/wait.h',
91+
'sysexits.h',
92+
'syslog.h',
93+
'tar.h',
94+
'termios.h',
95+
'ulimit.h',
96+
'unistd.h',
97+
'utime.h',
98+
'utmpx.h',
99+
'wait.h',
100+
'wordexp.h',
101+
102+
# WASI specific
103+
'wasi/api.h',
104+
]
105+
}%
106+
107+
% for header in headers:
108+
#if __has_include(<${header}>)
109+
#include <${header}>
110+
#endif
111+
% end

stdlib/public/Platform/wasi.modulemap.gyb

Lines changed: 2 additions & 207 deletions
Original file line numberDiff line numberDiff line change
@@ -20,212 +20,7 @@
2020
/// future official WASI modulemap.
2121
module SwiftWASILibc [system] {
2222
// C standard library
23-
module C {
24-
module ctype {
25-
header "${LIBC_INCLUDE_PATH}/ctype.h"
26-
export *
27-
}
28-
module errno {
29-
header "${LIBC_INCLUDE_PATH}/errno.h"
30-
export *
31-
}
23+
header "SwiftWASILibc.h"
3224

33-
module fenv {
34-
header "${LIBC_INCLUDE_PATH}/fenv.h"
35-
export *
36-
}
37-
38-
// note: supplied by compiler
39-
// module float {
40-
// header "${LIBC_INCLUDE_PATH}/float.h"
41-
// export *
42-
// }
43-
44-
module inttypes {
45-
header "${LIBC_INCLUDE_PATH}/inttypes.h"
46-
export *
47-
}
48-
49-
// note: potentially supplied by compiler
50-
// module iso646 {
51-
// header "${LIBC_INCLUDE_PATH}/iso646.h"
52-
// export *
53-
// }
54-
// module limits {
55-
// header "${LIBC_INCLUDE_PATH}/limits.h"
56-
// export *
57-
// }
58-
59-
module locale {
60-
header "${LIBC_INCLUDE_PATH}/locale.h"
61-
export *
62-
}
63-
module math {
64-
header "${LIBC_INCLUDE_PATH}/math.h"
65-
export *
66-
}
67-
module signal {
68-
header "${LIBC_INCLUDE_PATH}/signal.h"
69-
export *
70-
}
71-
72-
// note: supplied by the compiler
73-
// module stdarg {
74-
// header "${LIBC_INCLUDE_PATH}/stdarg.h"
75-
// export *
76-
// }
77-
// module stdbool {
78-
// header "${LIBC_INCLUDE_PATH}/stdbool.h"
79-
// export *
80-
// }
81-
// module stddef {
82-
// header "${LIBC_INCLUDE_PATH}/stddef.h"
83-
// export *
84-
// }
85-
// module stdint {
86-
// header "${LIBC_INCLUDE_PATH}/stdint.h"
87-
// export *
88-
// }
89-
90-
module stdio {
91-
header "${LIBC_INCLUDE_PATH}/stdio.h"
92-
export *
93-
}
94-
module stdlib {
95-
header "${LIBC_INCLUDE_PATH}/stdlib.h"
96-
export *
97-
export stddef
98-
}
99-
module string {
100-
header "${LIBC_INCLUDE_PATH}/string.h"
101-
export *
102-
}
103-
104-
// note: supplied by the compiler
105-
// explicit module tgmath {
106-
// header "${LIBC_INCLUDE_PATH}/tgmath.h"
107-
// export *
108-
// }
109-
110-
module time {
111-
header "${LIBC_INCLUDE_PATH}/time.h"
112-
export *
113-
}
114-
}
115-
116-
// POSIX
117-
module POSIX {
118-
module arpa {
119-
module inet {
120-
header "${LIBC_INCLUDE_PATH}/arpa/inet.h"
121-
export *
122-
}
123-
export *
124-
}
125-
module dirent {
126-
header "${LIBC_INCLUDE_PATH}/dirent.h"
127-
export *
128-
}
129-
module fcntl {
130-
header "${LIBC_INCLUDE_PATH}/fcntl.h"
131-
export *
132-
}
133-
module fnmatch {
134-
header "${LIBC_INCLUDE_PATH}/fnmatch.h"
135-
export *
136-
}
137-
module ioctl {
138-
header "${LIBC_ARCH_INCLUDE_PATH}/sys/ioctl.h"
139-
export *
140-
}
141-
module libgen {
142-
header "${LIBC_INCLUDE_PATH}/libgen.h"
143-
export *
144-
}
145-
module netinet {
146-
module in {
147-
header "${LIBC_INCLUDE_PATH}/netinet/in.h"
148-
export *
149-
150-
exclude header "${LIBC_INCLUDE_PATH}/netinet6/in6.h"
151-
}
152-
module tcp {
153-
header "${LIBC_INCLUDE_PATH}/netinet/tcp.h"
154-
export *
155-
}
156-
}
157-
module poll {
158-
header "${LIBC_INCLUDE_PATH}/poll.h"
159-
export *
160-
}
161-
module regex {
162-
header "${LIBC_INCLUDE_PATH}/regex.h"
163-
export *
164-
}
165-
module sched {
166-
header "${LIBC_INCLUDE_PATH}/sched.h"
167-
export *
168-
}
169-
module semaphore {
170-
header "${LIBC_INCLUDE_PATH}/semaphore.h"
171-
export *
172-
}
173-
module strings {
174-
header "${LIBC_INCLUDE_PATH}/strings.h"
175-
export *
176-
}
177-
178-
module sys {
179-
export *
180-
181-
module mman {
182-
header "${LIBC_ARCH_INCLUDE_PATH}/sys/mman.h"
183-
export *
184-
}
185-
module resource {
186-
header "${LIBC_ARCH_INCLUDE_PATH}/sys/resource.h"
187-
export *
188-
}
189-
module select {
190-
header "${LIBC_ARCH_INCLUDE_PATH}/sys/select.h"
191-
export *
192-
}
193-
module socket {
194-
header "${LIBC_ARCH_INCLUDE_PATH}/sys/socket.h"
195-
export *
196-
}
197-
module stat {
198-
header "${LIBC_ARCH_INCLUDE_PATH}/sys/stat.h"
199-
export *
200-
}
201-
module time {
202-
header "${LIBC_ARCH_INCLUDE_PATH}/sys/time.h"
203-
export *
204-
}
205-
module times {
206-
header "${LIBC_ARCH_INCLUDE_PATH}/sys/times.h"
207-
export *
208-
}
209-
module types {
210-
header "${LIBC_ARCH_INCLUDE_PATH}/sys/types.h"
211-
export *
212-
}
213-
module uio {
214-
header "${LIBC_ARCH_INCLUDE_PATH}/sys/uio.h"
215-
export *
216-
}
217-
module un {
218-
header "${LIBC_ARCH_INCLUDE_PATH}/sys/un.h"
219-
export *
220-
}
221-
module utsname {
222-
header "${LIBC_ARCH_INCLUDE_PATH}/sys/utsname.h"
223-
export *
224-
}
225-
}
226-
module unistd {
227-
header "${LIBC_INCLUDE_PATH}/unistd.h"
228-
export *
229-
}
230-
}
25+
export *
23126
}

0 commit comments

Comments
 (0)