@@ -140,20 +140,72 @@ to load that information:
140
140
+ UseResFile(refNum);
141
141
+ Handle handle = Get1NamedResource('swft', "\p__swift5_types");
142
142
+ if (handle && *handle) {
143
- + size_t size = GetHandleSize(handle);
144
- + body(*handle, size);
143
+ + auto imageAddress = reinterpret_cast<const void *>(static_cast<uintptr_t>(refNum));
144
+ + SWTSectionBounds sb = { imageAddress, *handle, GetHandleSize(handle) };
145
+ + bool stop = false;
146
+ + body(sb, &stop);
147
+ + if (stop) {
148
+ + break;
149
+ + }
145
150
+ }
146
151
+ } while (noErr == GetNextResourceFile(refNum, &refNum));
147
152
+ UseResFile(oldRefNum);
148
153
+ }
149
154
+ }
150
155
#else
151
- #warning Platform-specific implementation missing: Runtime test discovery unavailable
156
+ #warning Platform-specific implementation missing: Runtime test discovery unavailable (dynamic)
152
157
template <typename SectionEnumerator>
153
158
static void enumerateTypeMetadataSections(const SectionEnumerator& body) {}
154
159
#endif
155
160
```
156
161
162
+ ## Runtime test discovery with static linkage
163
+
164
+ If your platform does not support dynamic linking and loading, you will need to
165
+ use static linkage instead. Define the ` "SWT_NO_DYNAMIC_LINKING" ` compiler
166
+ conditional for your platform in both Package.swift and CompilerSettings.cmake,
167
+ then define the ` sectionBegin ` and ` sectionEnd ` symbols in Discovery.cpp:
168
+
169
+ ``` diff
170
+ diff --git a/Sources/_TestingInternals/Discovery.cpp b/Sources/_TestingInternals/Discovery.cpp
171
+ // ...
172
+ + #elif defined(macintosh)
173
+ + extern "C" const char sectionBegin __asm__("...");
174
+ + extern "C" const char sectionEnd __asm__("...");
175
+ #else
176
+ #warning Platform-specific implementation missing: Runtime test discovery unavailable (static)
177
+ static const char sectionBegin = 0;
178
+ static const char& sectionEnd = sectionBegin;
179
+ #endif
180
+ ```
181
+
182
+ These symbols must have unique addresses corresponding to the first byte of the
183
+ test content section and the first byte _ after_ the test content section,
184
+ respectively. Their linker-level names will be platform-dependent: refer to the
185
+ linker documentation for your platform to determine what names to place in the
186
+ ` __asm__ ` attribute applied to each.
187
+
188
+ If you can't use ` __asm__ ` on your platform, you can declare these symbols as
189
+ C++ references to linker-defined symbols:
190
+
191
+ ``` diff
192
+ diff --git a/Sources/_TestingInternals/Discovery.cpp b/Sources/_TestingInternals/Discovery.cpp
193
+ // ...
194
+ + #elif defined(macintosh)
195
+ + extern "C" const char __linker_defined_begin_symbol;
196
+ + extern "C" const char __linker_defined_end_symbol;
197
+ + static const auto& sectionBegin = __linker_defined_begin_symbol;
198
+ + static const auto& sectionEnd = __linker_defined_end_symbol;
199
+ #else
200
+ #warning Platform-specific implementation missing: Runtime test discovery unavailable (static)
201
+ static const char sectionBegin = 0;
202
+ static const char& sectionEnd = sectionBegin;
203
+ #endif
204
+ ```
205
+
206
+ The names of ` __linker_defined_begin_symbol ` and ` __linker_defined_end_symbol `
207
+ in this example are, as with the shorter implementation, platform-dependent.
208
+
157
209
## C++ stub implementations
158
210
159
211
Some symbols defined in C and C++ headers, especially "complex" macros, cannot
0 commit comments