Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
XCTestDynamicOverlay: prefer delay loading
XCTFail
(#73)
* 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]>
- Loading branch information