Build native code for WebAssembly target - #4624
Conversation
|
@ph1ll, |
|
You only need: libbootstrappercpp.bc, libPortableRuntime.bc and libSystem.Private.CoreLib.Native.bc . The rest are not applicable for the WebAssembly target. |
| elseif(CLR_CMAKE_PLATFORM_ARCH_ARM) | ||
| set(ARCH_SOURCES_DIR arm) | ||
| set(ASM_SUFFIX S) | ||
| elseif(CLR_CMAKE_PLATFORM_ARCH_WASM) |
| SHARED | ||
| ${NATIVE_SOURCES} | ||
| ) | ||
| if(CMAKE_SYSTEM_NAME STREQUAL Emscripten) |
There was a problem hiding this comment.
Exclude jitinterface in src\Native\CMakeLists.txt instead
|
Thanks @jkotas. I have updated the cmake files to conditionally exclude the non-applicable libraries. Should make it a bit easier to focus on getting the rest to compile. |
| #else | ||
| uuid_generate_random(*(uuid_t*)pGuid); | ||
|
|
||
There was a problem hiding this comment.
Nit: Unnecessary white space change
| // Change the byte order of the Data1, 2 and 3, since the uuid_generate_random | ||
| // generates them with big endian while GUIDS need to have them in little endian. | ||
| pGuid->Data1 = SWAP32(pGuid->Data1); |
There was a problem hiding this comment.
I would think this swapping should be done for uuid_generate as well.
| extern "C" void CoreLibNative_CreateGuid(GUID* pGuid) | ||
| { | ||
| #if HAVE_LIBUUID_H | ||
| #ifdef _WASM_ |
There was a problem hiding this comment.
It would be nice to do this using HAVE_XXX autogenerated defines for portability, not hard coding it to WASM.
There was a problem hiding this comment.
Will do.
My only concern here would be that uuid_generate_random will always provide version 4 UUIDs, where as uuid_generate will fall back to version 1 UUIDs, based on current time and MAC address. Where as we know Emscripten implements uuid_generate using version 4 UUIDs, this could result in information leakage on other platforms in the future.
| add_subdirectory(jitinterface) | ||
|
|
||
| # We don't need jitinterface for WASM. | ||
| if(NOT CMAKE_SYSTEM_NAME STREQUAL Emscripten) |
There was a problem hiding this comment.
Should we rather use CLR_CMAKE_PLATFORM_ARCH_WASM for these checks? (It would be self-explanatory at least - no need to have We don't need jitinterface for WASM. comment)
|
|
||
| add_subdirectory(base) | ||
| # We don't need base for WASM. | ||
| if(NOT CMAKE_SYSTEM_NAME STREQUAL Emscripten) |
There was a problem hiding this comment.
Do we have the WASM build variable available here? Based on some of the other comments, it's not clear if emcmake is a long term plan, so it might be better to switch based on the target rather than the cmake name
|
|
||
| if(CMAKE_SYSTEM_NAME STREQUAL Emscripten) | ||
| set(CLR_CMAKE_PLATFORM_UNIX 1) | ||
| set(CLR_CMAKE_PLATFORM_UNIX_TARGET_WASM 1) |
There was a problem hiding this comment.
WebAssembly isn't really UNIX, would it make sense for this variable to just be called CLR_CMAKE_PLATFORM_WASM ?
|
I have rebased this on master so that the build scripts are present. |
|
OSX build failed with: Other failures are infrastructure issues - not related to your change. |
|
I dont have an OS X machine for testing on unfortunately. I have instead switched to a different method of checking for the uuid functions in the |
|
@dotnet-bot build and test Windows_NT Debug and CoreCLR tests please |
|
@ph1ll Looks like you're clean on all OSes now. |
| #include <uuid/uuid.h> | ||
| int main() | ||
| { | ||
| #ifndef uuid_generate_random |
There was a problem hiding this comment.
This hack does not look like improvement. I would rather take the WASM ifdef that you had originally than this.
There was a problem hiding this comment.
Were you happy with the check_function_exists usage as below? This fails on OS X but I should imagine it is case of linking the correct library for the check. I don't have a OS X machine to test with at the moment, but if you bear with me I can try and sort something out.
set(CMAKE_REQUIRED_LIBRARIES uuid)
check_function_exists(uuid_generate_random HAVE_UUID_GENERATE_RANDOM)
check_function_exists(uuid_generate HAVE_UUID_GENERATE)
set(CMAKE_REQUIRED_LIBRARIES)
There was a problem hiding this comment.
Yes, the check_function_exists usage looked much better.
There was a problem hiding this comment.
@ph1ll , if you need to commit and watch the CI results a couple times to figure out OS X, that's totally fine. I'll also try to get a build on a Mac soon, but it's probably easier for you to just iterate with CI.
|
@ph1ll, is there anything you need help with? I'd really love to get the runtime compiling 😄 |
|
@morganbr Sorry I've had a couple of busy weeks with work and haven't had a chance to do anymore yet I am afraid. I have some time next week, but I certainly do not want to hold anything up. I've added you to as a collaborator to my fork, but also feel free to take what is already here if you want to get things moving. At the moment, there is the cmake OSX issue to look at, and about 40 or so initial build errors for libPortableRuntime. Some of the build errors relate to simple defines, but I haven't had a chance to go beyond that at the moment. |
|
I've got libPortableRuntime and libRuntime building using these changes and I can link it to the wasm test program. I had to touch a lot of files in the runtime, so I'll create a separate PR. I only needed a couple tiny changes to your build system changes, so hopefully we can just deal with the merge conflict and UUID issue to merge this change. |
|
The libraries are specified without If it still does not work, I think the following should be good enough: |
|
Changing libc to c didn't work, trying the conditional required libraries check now. |
| if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) | ||
| set(CMAKE_REQUIRED_LIBRARIES uuid) | ||
| endif() | ||
| unset(HAVE_UUID_GENERATE_RANDOM CACHE) |
There was a problem hiding this comment.
These unset commands should not be needed.
This reverts commit 2b50344.
|
Thanks for getting most of this together, @ph1ll! When you're less busy, there's lots more that we'd love your help with if you're interested. |
|
@morganbr I think you did the hard part, sorry again for not being able to get it finished up. Will definitely try and help out where I can. |
This is very much a work in progress, but adding the PR so that changes are visible.
At the moment, the overall wasm build will fail. See #4620 for the related build scripts.
Update cmake files for wasm target.
Build sdk\libbootstrappercpp.bc
Build sdk\libPortableRuntime.bc (Compile Runtime with Emscripten #4505)
Build sdk\libSystem.Private.CoreLib.Native.bc (Compile System.Private.CoreLib.Native for WebAssembly #4507)
* [ ] Build sdk\libbootstrapper.bc* [ ] Build sdk\libRuntime.bc (#4505)* [ ] Build tools\jitinterface.bc