|
| 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