wasmtime icon indicating copy to clipboard operation
wasmtime copied to clipboard

Android support

Open TheGreatRambler opened this issue 1 year ago • 6 comments

This PR adds CMake compilation support (c-api) for Android. From my tests it does function correctly, no unexpected crashes, so no code modifications were made. It uses the ANDROID CMake variable to transparently detect when Android compilation is being done and sets flags and some other environment variables accordingly. The environment variables are necessary for some crates (as far as I could tell). BUILD_SHARED_LIBS might have to be off.

Some relevant issues are #3867, #3877, #3921.

TheGreatRambler avatar Aug 04 '22 06:08 TheGreatRambler

I should note BUILD_BYPRODUCTS ${WASMTIME_BUILD_PRODUCT} was required to add support for ninja, ninja ignores ExternalProject_Add if no external product is specified. A little additional code was required to set that variable.

TheGreatRambler avatar Aug 04 '22 06:08 TheGreatRambler

Subscribe to Label Action

cc @peterhuene

This issue or pull request has been labeled: "wasmtime:c-api"

Thus the following users have been cc'd because of the following labels:

  • peterhuene: wasmtime:c-api

To subscribe or unsubscribe from this label, edit the .github/subscribe-to-label.json configuration file.

Learn more.

github-actions[bot] avatar Aug 04 '22 06:08 github-actions[bot]

I only sort of barely understand cmake, but is this sort of configuration standard? I would expect all this toolchain configuration to be configured by whomever is building wasmtime-c-api rather than hardcoded into cmake files. I feel like this sort of configuration is also necessary for cross-compiled builds and I don't think we'd want to hardcode everything for that per se?

This is all sort of on the side and fine to add but I'm not sure if you have a particular end goal for the cmake support in mind or how many other platforms might be added.

alexcrichton avatar Aug 04 '22 15:08 alexcrichton

I suppose the reason it's so excessive here is that rust doesn't fit nicely into the CMake ecosystem so I have to manually pass it the compiler, archiver and locations of some required shared libs, especially because as noted in the comments rust incorrectly handles some shared libraries for later versions of the NDK. This process would be a lot cleaner if the calling CMake project could modify the compiler and libraries used by wasmtime but with ExternalProject you can't do that.

TheGreatRambler avatar Aug 05 '22 06:08 TheGreatRambler

Could this perhaps be generalized to avoid duplication? Could --target always be passed perhaps? Or could RUSTFLAGS-the-env var be set to avoid duplicating the build command?

alexcrichton avatar Aug 08 '22 15:08 alexcrichton

My PC won't have internet access for a couple of days but I'll see about that change. I do think this effortlessly pulls wasmtime into Android projects that don't understand rust but if it's messy I understand

TheGreatRambler avatar Aug 10 '22 06:08 TheGreatRambler

Made a slight change to deduplicate ExternalProject_Add and make the CMakeLists.txt cleaner.

TheGreatRambler avatar Aug 23 '22 07:08 TheGreatRambler

Cool, thank you!

TheGreatRambler avatar Aug 30 '22 14:08 TheGreatRambler