NativeAOT: Use lib prefix by default on Unix for native library outputs#124611
NativeAOT: Use lib prefix by default on Unix for native library outputs#124611
lib prefix by default on Unix for native library outputs#124611Conversation
…ibPrefix opt-out Co-authored-by: sbomer <787361+sbomer@users.noreply.github.com>
lib prefix by default on Unix for native library outputs
Remove $(LibPrefix) from mscordaccore_universal AssemblyName and let NativeBinaryPrefix handle the prefix consistently, avoiding the double-prefix (liblibmscordaccore_universal.so) that broke bootstrapped CI builds. Add $(NativeBinaryPrefix) to all path constructions in native-library.targets, Microsoft.NETCore.Native.Publish.targets, and Microsoft.NETCore.Native.Unix.targets so strip/copy/install steps use the correct prefixed filename. Opt out of UseNativeLibPrefix in SharedLibrary and CustomMainWithStubExe tests whose C++ drivers derive the library path from argv[0] via dlopen.
# Conflicts: # src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets
|
Added When you commit this breaking change:
Tagging @dotnet/compat for awareness of the breaking change. |
src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets
Outdated
Show resolved
Hide resolved
Remove the explicit UseNativeLibPrefix default property and instead check != 'false' on the NativeBinaryPrefix condition. The _targetOS != 'win' guard on NativeBinaryPrefix already prevents the prefix on Windows, making the separate default-setting line redundant.
|
/azp run runtime-extra-platforms |
|
Azure Pipelines successfully started running 1 pipeline(s). |
There was a problem hiding this comment.
Pull request overview
This PR makes the lib prefix the default for non-executable NativeAOT library outputs on Unix platforms, aligning with standard Unix naming conventions (libfoo.so, libfoo.dylib, libfoo.a). Previously this required explicitly setting the internal _UseNativeLibPrefix property.
Changes:
- Default
NativeBinaryPrefixtolibon non-Windows for non-executable outputs, with a publicUseNativeLibPrefixproperty to opt out. - Update all file path references in
native-library.targetsandMicrosoft.NETCore.Native.Unix.targetsto include$(NativeBinaryPrefix). - Opt out existing tests and projects (SharedLibrary, CustomMainWithStubExe, mscordaccore_universal) that expect no prefix, and remove the now-redundant Android-specific
_UseNativeLibPrefixsetting.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
Microsoft.NETCore.Native.targets |
Change condition from _UseNativeLibPrefix == 'true' to UseNativeLibPrefix != 'false' (default on) |
Microsoft.NETCore.Native.Unix.targets |
Add $(NativeBinaryPrefix) to SharedLibraryInstallName |
native-library.targets |
Add $(NativeBinaryPrefix) to all native output file path references |
tests.android.targets |
Remove redundant _UseNativeLibPrefix setting |
SharedLibrary.csproj |
Opt out of new default with UseNativeLibPrefix=false |
CustomMainWithStubExe.csproj |
Opt out of new default with UseNativeLibPrefix=false |
mscordaccore_universal.csproj |
Opt out to avoid double-prefix (AssemblyName already includes LibPrefix) |
| <CopyFinalFiles Include="$(NativeOutputPath)$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)" /> | ||
| <CopyFinalFilesPDB Include="$(NativeOutputPath)$(NativeBinaryPrefix)$(TargetName).pdb" /> |
There was a problem hiding this comment.
Nit: These two lines are inside a Condition="'$(TargetsWindows)' == 'true'" block, where NativeBinaryPrefix will always be empty. Adding $(NativeBinaryPrefix) here is harmless but unnecessary and could confuse future readers into thinking the prefix might apply on Windows.
| <CopyFinalFiles Include="$(NativeOutputPath)$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)" /> | |
| <CopyFinalFilesPDB Include="$(NativeOutputPath)$(NativeBinaryPrefix)$(TargetName).pdb" /> | |
| <CopyFinalFiles Include="$(NativeOutputPath)$(TargetName)$(NativeBinaryExt)" /> | |
| <CopyFinalFilesPDB Include="$(NativeOutputPath)$(TargetName).pdb" /> |
|
@copilot do we miss taking |
…FilesToPublish Co-authored-by: MichalStrehovsky <13110571+MichalStrehovsky@users.noreply.github.com>
Yes, good catch! All the symbol-related paths in |
Description
On Unix, the
libprefix (e.g.,libfoo.so,libfoo.dylib,libfoo.a) is the standard convention for shared and static libraries. Previously, NativeAOT only applied this prefix when the internal_UseNativeLibPrefixproperty was explicitly set — Android tests required it, but other Unix targets didn't get it by default.This change makes the
libprefix the default for non-executable NativeAOT outputs on all non-Windows targets, and introduces a publicUseNativeLibPrefixproperty for opting out.Changes
Microsoft.NETCore.Native.targets: Replace the private_UseNativeLibPrefixcheck with a new publicUseNativeLibPrefixproperty. The condition uses!= 'false'so the prefix is on by default for non-Windows non-executable outputs without requiring an explicit opt-in.Microsoft.NETCore.Native.Publish.targets: FixComputeLinkedFilesToPublishto include$(NativeBinaryPrefix)in all symbol file paths — source path, target path, recursive glob, and bothRelativePathmetadata values (flat.dbgand dSYM bundle cases).Microsoft.NETCore.Native.Unix.targets: Include$(NativeBinaryPrefix)in theSharedLibraryInstallName(@rpath/...) for Apple platforms.native-library.targets: Include$(NativeBinaryPrefix)in strip source/destination paths and theStripLibraryLikeCoreCLRBuildinputs/outputs.eng/testing/tests.android.targets: Remove the now-redundant<_UseNativeLibPrefix>true</_UseNativeLibPrefix>— the default behavior covers this.Opt-out
Projects that need to suppress the prefix can set:
Changes to public API surface
None — MSBuild property changes only.
UseNativeLibPrefixis the new public opt-out property.Testing
Existing Android NativeAOT test infra validates the
lib-prefixed output; no behavior change there. The main impact is that Unix NativeAOT library outputs now follow the platform convention by default, including correct propagation of the prefix into symbol file paths during publish.Original prompt
🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.