[build] Copy NDK redistributables when creating runtime packs - #12494
Open
simonrozsival wants to merge 1 commit into
Open
[build] Copy NDK redistributables when creating runtime packs#12494simonrozsival wants to merge 1 commit into
simonrozsival wants to merge 1 commit into
Conversation
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Copilot-Session: cbf40b05-e7fb-454f-a214-feb9a301ae95
Contributor
There was a problem hiding this comment.
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
_CopyNdkRedistributablesfrom Android SDK provisioning and deletes the unused_RuntimeRedistDirNameproperty. - Introduces a reusable
_AndroidGetNdkRedistributablestarget and extendsAndroidSupportedTargetJitAbimetadata 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 —
_CopyToPackDirsperforms a largeCopyinto the local packs directory but still has noInputs/Outputs, so MSBuild will consider it out-of-date on every build. Since this target is in theBuilddependency chain, it can add noticeable overhead even whenSkipUnchangedFiles="true". Consider making it incremental (e.g., move input item computation to a helper...Inputstarget 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
make preparecurrently copies selected Android NDK files intobin/<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
_CopyNdkRedistributablesfrom Android SDK provisioning.AndroidSupportedTargetJitAbi._AndroidGetNdkRedistributablestarget.$(AndroidNdkDirectory)into local unpacked runtime packs.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 preparesucceeds without creatingbin/Debug/lib/runtimes/redist._AndroidGetNdkRedistributablesselects 44 existing files: 11 for each supported RID.make allsucceeds.android-arm64Mono and CoreCLR NuGet runtime packs build successfully and contain the expected files underruntimes/android-arm64/native.