Skip to content

[build] Copy NDK redistributables when creating runtime packs - #12494

Open
simonrozsival wants to merge 1 commit into
mainfrom
dev/simonrozsival/pack-ndk-redistributables
Open

[build] Copy NDK redistributables when creating runtime packs#12494
simonrozsival wants to merge 1 commit into
mainfrom
dev/simonrozsival/pack-ndk-redistributables

Conversation

@simonrozsival

Copy link
Copy Markdown
Member

Context

make prepare currently copies selected Android NDK files into bin/<Configuration>/lib/runtimes/redist, even though those files are only consumed when producing runtime packs. This creates an approximately 58 MB configuration- and checkout-local staging directory in every prepared worktree.

The NDK itself is already stored in the shared Android toolchain directory, so the intermediate copy is unnecessary.

Changes

  • Remove _CopyNdkRedistributables from Android SDK provisioning.
  • Add the NDK toolchain metadata to AndroidSupportedTargetJitAbi.
  • Expose the selected NDK files through a reusable _AndroidGetNdkRedistributables target.
  • Copy those files directly from $(AndroidNdkDirectory) into local unpacked runtime packs.
  • Use the same direct NDK inputs when creating runtime-pack NuGet packages.
  • Remove the now-unused runtime redist staging property.

Mono runtime packs receive the five Android system-library stubs. CoreCLR and NativeAOT runtime packs additionally receive the CRT objects, libc++, compiler-rt, and libunwind, preserving the existing payload.

Validation

  • make prepare succeeds without creating bin/Debug/lib/runtimes/redist.
  • _AndroidGetNdkRedistributables selects 44 existing files: 11 for each supported RID.
  • make all succeeds.
  • Local runtime packs contain 5 NDK assets for Mono and 11 for CoreCLR/NativeAOT.
  • Representative android-arm64 Mono and CoreCLR NuGet runtime packs build successfully and contain the expected files under runtimes/android-arm64/native.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

Copilot-Session: cbf40b05-e7fb-454f-a214-feb9a301ae95
@simonrozsival
simonrozsival marked this pull request as ready for review August 24, 2026 20:39
Copilot AI lite review requested due to automatic review settings August 24, 2026 20:39

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors how Android NDK redistributable assets are sourced for runtime pack creation, removing the configuration-local “redist” staging directory created during make prepare and instead selecting/copying the needed NDK files directly from $(AndroidNdkDirectory) when producing runtime packs and runtime-pack NuGets.

Changes:

  • Removes _CopyNdkRedistributables from Android SDK provisioning and deletes the unused _RuntimeRedistDirName property.
  • Introduces a reusable _AndroidGetNdkRedistributables target and extends AndroidSupportedTargetJitAbi metadata to support selecting the right NDK files per RID.
  • Updates runtime pack directory population and runtime-pack NuGet packing to consume @(_AndroidNdkRedistributable) directly.
Show a summary per file
File Description
src/native/native.targets Uses _AndroidGetNdkRedistributables and copies NDK redistributables directly into local unpacked runtime packs.
src/androidsdk/androidsdk.targets Stops copying NDK redistributables during SDK install/provisioning (make prepare).
Configuration.props Removes the now-unused _RuntimeRedistDirName property and imports NDK build script definitions.
build-tools/scripts/Ndk.targets Adds _AndroidGetNdkRedistributables to compute the per-RID NDK redistributable file list.
build-tools/scripts/Ndk.projitems Adds NDK toolchain metadata (prefix/arch/unwind dir) to AndroidSupportedTargetJitAbi items.
build-tools/create-packs/Microsoft.Android.Runtime.proj Packs NDK system/toolchain assets directly from @(_AndroidNdkRedistributable) when building runtime-pack NuGets.

Review details

Suppressed comments (1)

src/native/native.targets:379

  • 💡 suggestion performance_CopyToPackDirs performs a large Copy into the local packs directory but still has no Inputs/Outputs, so MSBuild will consider it out-of-date on every build. Since this target is in the Build dependency chain, it can add noticeable overhead even when SkipUnchangedFiles="true". Consider making it incremental (e.g., move input item computation to a helper ...Inputs target and use a stamp file output).
  <Target Name="_CopyToPackDirs"
          DependsOnTargets="_AndroidGetNdkRedistributables">
    <PropertyGroup>
      <_RuntimePackName Condition=" '$(CMakeRuntimeFlavor)' == 'MonoVM' ">Mono</_RuntimePackName>
      <_RuntimePackName Condition=" '$(CMakeRuntimeFlavor)' == 'CoreCLR' ">CoreCLR</_RuntimePackName>
      <_RuntimePackName Condition=" '$(CMakeRuntimeFlavor)' == 'NativeAOT' ">NativeAOT</_RuntimePackName>
    </PropertyGroup>

    <ItemGroup>
      <_RuntimePackFiles Include="$(OutputPath)\%(AndroidSupportedTargetJitAbi.AndroidRID)\*"
                         AndroidRID="%(AndroidSupportedTargetJitAbi.AndroidRID)"
                         AndroidRuntime="$(CMakeRuntimeFlavor)"
                         RuntimePackName="$(_RuntimePackName)" />
      <_RuntimePackFiles Include="@(_AndroidNdkRedistributable)"
                         Condition=" '%(_AndroidNdkRedistributable.Kind)' == 'System' "
                         AndroidRID="%(_AndroidNdkRedistributable.AndroidRID)"
                         AndroidRuntime="$(CMakeRuntimeFlavor)"
                         RuntimePackName="$(_RuntimePackName)" />
    </ItemGroup>

    <ItemGroup Condition=" '$(CMakeRuntimeFlavor)' == 'CoreCLR' Or '$(CMakeRuntimeFlavor)' == 'NativeAOT' ">
      <_RuntimePackFiles Include="@(_AndroidNdkRedistributable)"
                         Condition=" '%(_AndroidNdkRedistributable.Kind)' == 'Toolchain' "
                         AndroidRID="%(_AndroidNdkRedistributable.AndroidRID)"
                         AndroidRuntime="$(CMakeRuntimeFlavor)"
                         RuntimePackName="$(_RuntimePackName)" />
    </ItemGroup>

    <Copy
        SourceFiles="%(_RuntimePackFiles.Identity)"
        DestinationFolder="$(MicrosoftAndroidPacksRootDir)Microsoft.Android.Runtime.%(_RuntimePackFiles.RuntimePackName).$(AndroidApiLevel).%(_RuntimePackFiles.AndroidRID)\$(AndroidPackVersion)\runtimes\%(_RuntimePackFiles.AndroidRID)\native"
        SkipUnchangedFiles="true" />
  </Target>
  • Files reviewed: 6/6 changed files
  • Comments generated: 1
  • Review effort level: Lite

Comment on lines +11 to +21
<PropertyGroup>
<_AndroidNdkToolchainOSTag Condition=" '$(HostOS)' == 'Linux' ">linux-x86_64</_AndroidNdkToolchainOSTag>
<_AndroidNdkToolchainOSTag Condition=" '$(HostOS)' == 'Darwin' ">darwin-x86_64</_AndroidNdkToolchainOSTag>
<_AndroidNdkToolchainOSTag Condition=" '$(HostOS)' == 'Windows' ">windows-x86_64</_AndroidNdkToolchainOSTag>
<_AndroidNdkToolchainRoot>$(AndroidNdkDirectory)\toolchains\llvm\prebuilt\$(_AndroidNdkToolchainOSTag)</_AndroidNdkToolchainRoot>
<_AndroidNdkSysrootLib>$(_AndroidNdkToolchainRoot)\sysroot\usr\lib</_AndroidNdkSysrootLib>
<!-- AndroidVersion.txt starts with the full LLVM version e.g. "19.0.1\n". -->
<_AndroidNdkVersionFileContent>$([System.IO.File]::ReadAllText('$(_AndroidNdkToolchainRoot)\AndroidVersion.txt'))</_AndroidNdkVersionFileContent>
<_AndroidNdkLlvmMajor>$(_AndroidNdkVersionFileContent.Substring(0, $(_AndroidNdkVersionFileContent.IndexOf('.'))))</_AndroidNdkLlvmMajor>
<_AndroidNdkClangLibLinux>$(_AndroidNdkToolchainRoot)\lib\clang\$(_AndroidNdkLlvmMajor)\lib\linux</_AndroidNdkClangLibLinux>
</PropertyGroup>
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.

2 participants