Files
dotnet-runtime/docs/workflow/building/coreclr/android.md
T
4682098d3a Move optdata and version file generation up to MSBuild from build-runtime (#58674)
* Move optdata and version file generation from the native build scripts up into the managed scripts. The native build scripts will now by default copy a fallback version file in place if the version files do not exist and will disable PGO if no pgo file path is passed in to the build-runtime scripts.

This removes all cases of build-runtime calling into MSBuild.

* Update CI to use the new prereqs model.

* Remove some old MSBuild arg pass-through that's no longer needed as build-runtime no longer calls into any MSBuild processes.

* Apply suggestions from code review

Co-authored-by: Viktor Hofer <[email protected]>
Co-authored-by: Jan Kotas <[email protected]>

* Move some targets around based on feedback.

* Output version files in the artifacts/obj dir so they can be easily shared.

* Move native pgo into a targets file instead of being a separate project to be more static-graph friendly.

* Fix subsets.

* Share version file path by default

* Fix VER_FILEDESCRIPTION_STR

* Fix version fallback copies.

* Fix include path for the version headers.

* Update src/coreclr/dlls/mscordac/CMakeLists.txt

Co-authored-by: Juan Hoyos <[email protected]>

* Enable easily sharing the fallback version files between all components of the repo.

* Remove some now-unused command-line options from our build scripts.

* Bump importance output to pass the pgo path between steps.

* Add eval statement to run copy_version_files script

* Rename some files and and standardize on a _version.c file name for Linux.

* Remove temp proj ref.

* Fix permissions

* Reference targets to produce version file in libraries native build.

* Fix CoreCLR build breaks

* Generate the version files for Mono

* include configurepaths.cmake on the Windows CoreFX build.

* Restore mono.proj when building it through monoaotcross.proj.

* Update copy script to work on macos.

* Make sure mono pulls in the shared version files.

* Add artifcats/obj dir as include dir for CoreCLR diagonstic components included in Mono

* Add artifacts/obj include for the whole mono build.

* Update CMakeLists.txt

* Fix NativeVersion.rc path on Windows.

* Fix linux version parsing to point at the right file.

* Fix mono version parsing (apparently the quotes make a difference here)

* Update src/coreclr/build-runtime.sh

Co-authored-by: Adeel Mujahid <[email protected]>

* Update eng/native/version/copy_version_files.sh

Co-authored-by: Adeel Mujahid <[email protected]>

* Update copy_version_files.sh to insert the current commit hash into _version.c.

* Apply suggestions from code review

Co-authored-by: Adeel Mujahid <[email protected]>

* Update the _version.c writing script to only update the placeholder version file if it actually is a placeholder (not a real generated file).

* Generate the version files for wasm/browser as well.

* Fix Mono WASM cross build.

* Update eng/nativepgo.targets

Co-authored-by: Juan Hoyos <[email protected]>

* Fix comparison for NativeOptimizationDataSupported.

Co-authored-by: Viktor Hofer <[email protected]>
Co-authored-by: Jan Kotas <[email protected]>
Co-authored-by: Juan Hoyos <[email protected]>
Co-authored-by: Adeel Mujahid <[email protected]>
2021-10-27 10:03:34 -07:00

3.2 KiB

Cross Compilation for Android on Linux

Through cross compilation, on Linux it is possible to build CoreCLR for arm64 Android.

Requirements

You'll need to generate a toolchain and a sysroot for Android. There's a script which takes care of the required steps.

Generating the rootfs

To generate the rootfs, run the following command in the coreclr folder:

cross/init-android-rootfs.sh

This will download the NDK and any packages required to compile Android on your system. It's over 1 GB of data, so it may take a while.

Cross compiling CoreCLR

Once the rootfs has been generated, it will be possible to cross compile CoreCLR.

When cross compiling, you need to set both the CONFIG_DIR and ROOTFS_DIR variables.

To compile for arm64, run:

CONFIG_DIR=`realpath cross/android/arm64` ROOTFS_DIR=`realpath cross/android-rootfs/toolchain/arm64/sysroot` ./build.sh cross arm64 cmakeargs -DENABLE_LLDBPLUGIN=0

The resulting binaries will be found in artifacts/bin/coreclr/Linux.BuildArch.BuildType/

Running the PAL tests on Android

You can run the PAL tests on an Android device. To run the tests, you first copy the PAL tests to your Android phone using adb, and then run them in an interactive Android shell using adb shell:

To copy the PAL tests over to an Android phone:

adb push artifacts/obj/coreclr/Linux.arm64.Debug/src/pal/tests/palsuite/ /data/local/tmp/coreclr/pal/tests/palsuite
adb push cross/android/toolchain/arm64/sysroot/usr/lib/libandroid-support.so /data/local/tmp/coreclr/lib/
adb push cross/android/toolchain/arm64/sysroot/usr/lib/libandroid-glob.so /data/local/tmp/coreclr/lib/
adb push src/pal/tests/palsuite/paltestlist.txt /data/local/tmp/coreclr
adb push src/pal/tests/palsuite/runpaltests.sh /data/local/tmp/coreclr/

Then, use adb shell to launch a shell on Android. Inside that shell, you can launch the PAL tests:

LD_LIBRARY_PATH=/data/local/tmp/coreclr/lib ./runpaltests.sh /data/local/tmp/coreclr/

Debugging coreclr on Android

You can debug coreclr on Android using a remote lldb server which you run on your Android device.

First, push the lldb server to Android:

adb push cross/android/lldb/2.2/android/arm64-v8a/lldb-server /data/local/tmp/

Then, launch the lldb server on the Android device. Open a shell using adb shell and run:

adb shell
cd /data/local/tmp
./lldb-server platform --listen *:1234

After that, you'll need to forward port 1234 from your Android device to your PC:

adb forward tcp:1234 tcp:1234

Finally, install lldb on your PC and connect to the debug server running on your Android device:

lldb-3.9
(lldb) platform select remote-android
  Platform: remote-android
 Connected: no
(lldb) platform connect connect://localhost:1234
  Platform: remote-android
    Triple: aarch64-*-linux-android
OS Version: 23.0.0 (3.10.84-perf-gf38969a)
    Kernel: #1 SMP PREEMPT Fri Sep 16 11:29:29 2016
  Hostname: localhost
 Connected: yes
WorkingDir: /data/local/tmp

(lldb) target create coreclr/pal/tests/palsuite/file_io/CopyFileA/test4/paltest_copyfilea_test4
(lldb) env LD_LIBRARY_PATH=/data/local/tmp/coreclr/lib
(lldb) run