Skip to content

[CoreCLR] link app native runtime/library statically #9938

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

Merged
merged 73 commits into from
Jul 18, 2025

Conversation

grendello
Copy link
Contributor

@grendello grendello commented Mar 19, 2025

This pull request introduces several enhancements to streamline runtime flavor management, improve native runtime asset handling, and support additional runtime configurations for Android builds. The changes focus on consolidating runtime flavor properties, extending native runtime asset definitions, and refining build processes for CoreCLR and Mono runtimes.

Runtime Flavor Management:

  • Configuration.props: Added _MonoRuntimeFlavorDirName and _CLRRuntimeFlavorDirName properties to centralize runtime flavor strings, reducing duplication across tools.
  • KnownProperties.cs: Introduced constants for _MonoRuntimeFlavorDirName and _CLRRuntimeFlavorDirName to ensure consistent property access. [1] [2]

Native Runtime Asset Handling:

  • Microsoft.Android.Runtime.proj: Updated runtime flavor directory names to use centralized properties and added definitions for multiple native runtime assets, including debug and release variants.
  • Step_Android_SDK_NDK.cs: Added support for copying redistributable files, including CRT files, CPP ABI files, and Clang architecture-specific files, to ensure proper runtime linking. [1] [2]

Build Process Enhancements:

These changes collectively improve runtime management, streamline asset handling, and enhance build configurations for Android applications targeting CoreCLR and Mono runtimes.

@grendello grendello force-pushed the dev/grendel/clr-host-static-link branch 7 times, most recently from e21e634 to 4e02da2 Compare March 27, 2025 11:52
@grendello grendello force-pushed the dev/grendel/clr-host-static-link branch from e15ccf6 to 9026080 Compare March 28, 2025 17:25
@grendello grendello force-pushed the dev/grendel/clr-host-static-link branch 3 times, most recently from 4aff532 to 0b7bb8c Compare April 2, 2025 20:47
@grendello grendello force-pushed the dev/grendel/clr-host-static-link branch 3 times, most recently from 96d8326 to 39031e6 Compare April 14, 2025 07:07
@grendello grendello force-pushed the dev/grendel/clr-host-static-link branch 5 times, most recently from 7cdfb21 to 86691d0 Compare April 28, 2025 07:53
jonpryor pushed a commit that referenced this pull request Apr 29, 2025
Context: #9938

PR #9938 is an attempt to build `libnet-android.Debug.so` and
`libnet-android.Release.so` so that CoreCLR is *statically linked* in
to `libnet-android*.so`.  This reduces the number of native libraries
that must be placed into the `.apk`, and allows the `.apk` to be
smaller, as the native linker can remove unused code.

*Note*: CoreCLR is ***not*** yet statically linked into
`libnet-android*.so`.  This is *preliminary* work to support that.

This iteration of static linking also requires that *all* symbols be
resolvable, by requiring `lld --no-undefined` by default.  This in
turn requires that we ship *copies* of `libc.so` et al, so that *all*
symbols needed by `libnet-android*.so` can be resolved, including
those from the Android NDK.

Update `build-tools/xaprepare` to extract required native libraries
from the NDK, and add those to the .NET for Android Workload packs.

Update `Xamarin.Android.Build.Tasks.dll` to cleanup and refactor
`ld` invocation, so that `libnet-android*.so` is built with
`ld --no-undefined`.  This makes it easier to maintain and update the
linker code in the future, as well as ensures that we use consistent
linking flags across the board.

Updates the LLVM IR code generator bits, also extracted from #9938,
which aren't strictly related to native linking, but they are placed
here in order to make #9938 smaller.
@grendello grendello force-pushed the dev/grendel/clr-host-static-link branch 2 times, most recently from 96649e1 to 75e6902 Compare May 6, 2025 08:49
@grendello grendello force-pushed the dev/grendel/clr-host-static-link branch 3 times, most recently from 29ac51a to bfc4af0 Compare May 16, 2025 10:54
@grendello grendello force-pushed the dev/grendel/clr-host-static-link branch 2 times, most recently from 9327572 to 3ba61c3 Compare May 26, 2025 09:12
@grendello grendello requested a review from Copilot May 26, 2025 12:31
Copilot

This comment was marked as outdated.

grendello and others added 20 commits July 15, 2025 22:20
…veAssemblyGenerator.cs

Co-authored-by: Jonathan Peppers <[email protected]>
…veAssemblyGenerator.cs

Co-authored-by: Jonathan Peppers <[email protected]>
@grendello grendello force-pushed the dev/grendel/clr-host-static-link branch from 7acf14d to 36196cb Compare July 15, 2025 20:20
@grendello
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@jonathanpeppers jonathanpeppers enabled auto-merge (squash) July 16, 2025 20:09
@jonathanpeppers jonathanpeppers merged commit 2adcf2a into main Jul 18, 2025
59 checks passed
@jonathanpeppers jonathanpeppers deleted the dev/grendel/clr-host-static-link branch July 18, 2025 02:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants