Skip to content

Commit 5998bbd

Browse files
Use apinote's SwiftPrivate instead of patching header file
1 parent 808e9d6 commit 5998bbd

3 files changed

+135
-106
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
From 90799cfdf73e69147baab6f92f934c3a74235c5e Mon Sep 17 00:00:00 2001
2+
From: Yuta Saito <[email protected]>
3+
Date: Sat, 10 Aug 2024 13:29:48 +0000
4+
Subject: [PATCH] Revert "[wasm] Fix ambiguous `errno` error when importing
5+
WASILibc module"
6+
7+
This reverts commit 164ec0adaa80e7a29d2a10fb31ee72baddeda6b2.
8+
---
9+
stdlib/public/Platform/Platform.swift | 6 ------
10+
1 file changed, 6 deletions(-)
11+
12+
diff --git a/stdlib/public/Platform/Platform.swift b/stdlib/public/Platform/Platform.swift
13+
index ca7417c5357..0c2d63a0cff 100644
14+
--- a/stdlib/public/Platform/Platform.swift
15+
+++ b/stdlib/public/Platform/Platform.swift
16+
@@ -84,11 +84,6 @@ func _convertDarwinBooleanToBool(_ x: DarwinBoolean) -> Bool {
17+
18+
#endif
19+
20+
-// wasi-libc defines `errno` in a way ClangImporter can understand, so we don't
21+
-// need to define shims for it. On the contrary, if we define the shim, we will
22+
-// get an ambiguity error when importing WASILibc module and SwiftWASILibc Clang
23+
-// module (or a Clang module that re-exports SwiftWASILibc).
24+
-#if !os(WASI)
25+
//===----------------------------------------------------------------------===//
26+
// sys/errno.h
27+
//===----------------------------------------------------------------------===//
28+
@@ -101,7 +96,6 @@ public var errno : Int32 {
29+
return _swift_stdlib_setErrno(val)
30+
}
31+
}
32+
-#endif
33+
34+
35+
//===----------------------------------------------------------------------===//
36+
--
37+
2.43.2
38+

schemes/main/swift/0001-wasm-Mark-errno-as-nonisolated-unsafe-in-wasi-libc.patch

Lines changed: 0 additions & 106 deletions
This file was deleted.
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
From be08ebb12a99636832f055e94956cb500af1a86d Mon Sep 17 00:00:00 2001
2+
From: Yuta Saito <[email protected]>
3+
Date: Sat, 10 Aug 2024 13:50:57 +0000
4+
Subject: [PATCH] [wasm] Annotate errno as SwiftPrivate by apinotes
5+
6+
This patch adds an apinotes file for SwiftWASILibc clang module to mark
7+
`errno` macro hidden from Swift code. This resolves ambiguity between
8+
the C macro definition and the Swift wrapper in WASILibc overlay module.
9+
10+
This change installs the apinotes file to the resource directories for
11+
both lib/swift/apinotes and lib/swift_static/apinotes.
12+
---
13+
stdlib/public/Platform/CMakeLists.txt | 28 +++++++++++++++++++
14+
stdlib/public/Platform/SwiftWASILibc.apinotes | 5 ++++
15+
test/stdlib/WASILibcAPI.swift | 19 +++++++++++++
16+
3 files changed, 52 insertions(+)
17+
create mode 100644 stdlib/public/Platform/SwiftWASILibc.apinotes
18+
create mode 100644 test/stdlib/WASILibcAPI.swift
19+
20+
diff --git a/stdlib/public/Platform/CMakeLists.txt b/stdlib/public/Platform/CMakeLists.txt
21+
index 928b5d9cb63..7a7cab3da6d 100644
22+
--- a/stdlib/public/Platform/CMakeLists.txt
23+
+++ b/stdlib/public/Platform/CMakeLists.txt
24+
@@ -527,6 +527,34 @@ if("WASI" IN_LIST SWIFT_SDKS)
25+
DESTINATION "lib/swift_static/${arch_subdir}"
26+
COMPONENT sdk-overlay)
27+
endif()
28+
+
29+
+ set(wasilibc_apinotes_source "SwiftWASILibc.apinotes")
30+
+ add_custom_command_target(
31+
+ copy_wasilibc_apinotes_resource
32+
+ COMMAND
33+
+ "${CMAKE_COMMAND}" "-E" "make_directory" ${SWIFTLIB_DIR}/apinotes ${SWIFTSTATICLIB_DIR}/apinotes
34+
+ COMMAND
35+
+ "${CMAKE_COMMAND}" "-E" "copy_if_different"
36+
+ "${CMAKE_CURRENT_SOURCE_DIR}/${wasilibc_apinotes_source}" ${SWIFTLIB_DIR}/apinotes
37+
+ COMMAND
38+
+ "${CMAKE_COMMAND}" "-E" "copy_if_different"
39+
+ "${CMAKE_CURRENT_SOURCE_DIR}/${wasilibc_apinotes_source}" ${SWIFTSTATICLIB_DIR}/apinotes
40+
+ OUTPUT
41+
+ ${SWIFTLIB_DIR}/apinotes/${wasilibc_apinotes_source}
42+
+ ${SWIFTSTATICLIB_DIR}/apinotes/${wasilibc_apinotes_source}
43+
+ COMMENT "Copying WASILibc API notes to resource directories")
44+
+
45+
+ list(APPEND wasilibc_modulemap_target_list ${copy_wasilibc_apinotes_resource})
46+
+ add_dependencies(sdk-overlay ${copy_wasilibc_apinotes_resource})
47+
+ swift_install_in_component(FILES "${wasilibc_apinotes_source}"
48+
+ DESTINATION "lib/swift/apinotes"
49+
+ COMPONENT sdk-overlay)
50+
+ if(SWIFT_BUILD_STATIC_STDLIB)
51+
+ swift_install_in_component(FILES "${wasilibc_apinotes_source}"
52+
+ DESTINATION "lib/swift_static/apinotes"
53+
+ COMPONENT sdk-overlay)
54+
+ endif()
55+
+
56+
endforeach()
57+
endif()
58+
add_custom_target(wasilibc_modulemap DEPENDS ${wasilibc_modulemap_target_list})
59+
diff --git a/stdlib/public/Platform/SwiftWASILibc.apinotes b/stdlib/public/Platform/SwiftWASILibc.apinotes
60+
new file mode 100644
61+
index 00000000000..001acc7ebb5
62+
--- /dev/null
63+
+++ b/stdlib/public/Platform/SwiftWASILibc.apinotes
64+
@@ -0,0 +1,5 @@
65+
+Name: SwiftWASILibc
66+
+Globals:
67+
+ # errno macro is importable but we provide explicit Swift wrapper
68+
+ - Name: errno
69+
+ SwiftPrivate: true
70+
diff --git a/test/stdlib/WASILibcAPI.swift b/test/stdlib/WASILibcAPI.swift
71+
new file mode 100644
72+
index 00000000000..fe599bb9f38
73+
--- /dev/null
74+
+++ b/test/stdlib/WASILibcAPI.swift
75+
@@ -0,0 +1,19 @@
76+
+// RUN: %target-swift-frontend -typecheck -swift-version 6 %s -verify
77+
+// REQUIRES: executable_test
78+
+// REQUIRES: OS=wasi
79+
+
80+
+import WASILibc
81+
+
82+
+// errno is a global thread-local variable, so it should be accessible
83+
+// from any context.
84+
+
85+
+enum TestErrno {
86+
+ static func testSyncContext() {
87+
+ _ = errno
88+
+ errno = 0
89+
+ }
90+
+ static func testAsyncContext() async {
91+
+ _ = errno
92+
+ errno = 0
93+
+ }
94+
+}
95+
--
96+
2.43.2
97+

0 commit comments

Comments
 (0)