Commit 89a3632
XCTestDynamicOverlay: prefer delay loading
* XCTestDynamicOverlay: prefer delay loading `XCTFail`
Similar to the ObjC XCTest, prefer to delay load the XCTest runtime.
This is likely to fail on release distributions as XCTest is a developer
component. However, if it is available in the library search path on
(non-Darwin) Unix or in `Path` on Windows, it will be used.
Windows does not (yet) ship a static XCTest library. On Linux, it is
unclear whether the linkage is dynamic or static, so we perform a little
trick. We pass `RTLD_NOLOAD` to `dlopen` which will get a handle to
`libXCTest.so` if it is currently loaded in the address space but not
load the library if not already there. In such a case, it will return
`NULL`. In such a case, we resort to looking within the main binary
(assuming that XCTest may have been statically linked).
For both platforms, if we do not find the symbol from XCTest, we will
proceed to simply use the fallback path.
Note that both `GetProcAddress` and `dlsym` do not know how to cast the
resulting pointer to indicate the calling convention. As a result, we
rely on the use of `unsafeBitCast` to restore the calling convention to
`swiftcall`. To completely avoid the undefined behaviour here, we would
need to resort to C to perform the cast as these methods return type
erased pointers (i.e. `void *`).
* Update ci.yml
* XCTestDynamicOverlay: add an adjustment for Windows
Add a cast for Windows after the last round of tweaks for Linux.
Additionally, use `LoadLibraryA` instead of `LoadLibraryW` as we know
that the library name is ASCII compliant and the array buffer does not
work with `LoadLibraryW` and would require pulling in Foundation.
---------
Co-authored-by: Stephen Celis <[email protected]>XCTFail (#73)1 parent 6f357ee commit 89a3632
File tree
2 files changed
+64
-12
lines changed- .github/workflows
- Sources/XCTestDynamicOverlay
2 files changed
+64
-12
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
38 | | - | |
| 38 | + | |
39 | 39 | | |
40 | 40 | | |
41 | | - | |
| 41 | + | |
42 | 42 | | |
43 | | - | |
| 43 | + | |
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
69 | | - | |
| 69 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
144 | 144 | | |
145 | 145 | | |
146 | 146 | | |
147 | | - | |
148 | | - | |
149 | | - | |
150 | 147 | | |
151 | | - | |
152 | | - | |
153 | | - | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
| 179 | + | |
| 180 | + | |
| 181 | + | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
154 | 205 | | |
| 206 | + | |
155 | 207 | | |
156 | | - | |
157 | | - | |
| 208 | + | |
| 209 | + | |
158 | 210 | | |
159 | 211 | | |
160 | 212 | | |
| |||
0 commit comments