-
Notifications
You must be signed in to change notification settings - Fork 67
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
XCTestDynamicOverlay: prefer delay loading XCTFail
#73
Conversation
@compnerd Thanks for looking into this and for the PR! It does look like Ubuntu and Wasm aren't happy with the changes, though, at the moment. We have a |
Let me see if I can figure out what is going on. |
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 *`).
@compnerd Looks like just one small compiler error in the Windows debug branch. I pushed an update to Wasm's CI to get it building in case you force push again be sure not to lose it 😄 |
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.
@stephencelis - should be good to go now. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, thanks so much!
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
todlopen
which will get a handle tolibXCTest.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 returnNULL
. 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
anddlsym
do not know how to cast the resulting pointer to indicate the calling convention. As a result, we rely on the use ofunsafeBitCast
to restore the calling convention toswiftcall
. 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 *
).