Skip to content

Commit d2d41a6

Browse files
authored
Add _UseNativeLibPrefix option for publishing a NativeAOT shared library on Unix (#118299)
Most Unix systems expect the library filename to be libMyLibrary.so / libMyLibrary.dylib. On Java on android, libraries will not be found unless they follow this naming format. Tring to work around this by renaming the TargetName or AssemblyName can cause rd.xml files to fail to resolve the assembly in ilc, and it doesn't feel right to . This PR adds a _UseNativeLibPrefix option to add the "lib" prefix to the output library when it's a shared library published for a non-windows OS. It's opt-in-only to avoid breaking existing setups, but it might be worth considering as a default in future releases to match the rest of the unix ecosystem.
1 parent ee4be3d commit d2d41a6

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Publish.targets

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,8 @@
2828
</ItemGroup>
2929

3030
<ItemGroup>
31-
<_NativeIntermediateAssembly Include="@(IntermediateAssembly->'$(NativeOutputPath)%(Filename)$(NativeBinaryExt)')" />
3231
<IntermediateAssembly Remove="@(IntermediateAssembly)" />
33-
<IntermediateAssembly Include="@(_NativeIntermediateAssembly)" />
32+
<IntermediateAssembly Include="$(NativeBinary)" />
3433
</ItemGroup>
3534
</Target>
3635

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.targets

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ The .NET Foundation licenses this file to you under the MIT license.
7171
<NativeBinaryExt Condition="'$(IsNativeExecutable)' != 'true' and '$(_targetOS)' == 'win' and '$(NativeLib)' == 'Static'">.lib</NativeBinaryExt>
7272
<NativeBinaryExt Condition="'$(IsNativeExecutable)' != 'true' and '$(_targetOS)' != 'win' and '$(NativeLib)' == 'Static'">.a</NativeBinaryExt>
7373

74+
<NativeBinaryPrefix Condition="'$(_UseNativeLibPrefix)' == 'true' and '$(IsNativeExecutable)' != 'true' and '$(_targetOS)' != 'win'">lib</NativeBinaryPrefix>
75+
7476
<NativeSymbolExt Condition="'$(NativeSymbolExt)' == '' and '$(_IsApplePlatform)' == 'true'">.dSYM</NativeSymbolExt>
7577
<NativeSymbolExt Condition="'$(NativeSymbolExt)' == '' and '$(_targetOS)' == 'win'">.pdb</NativeSymbolExt>
7678
<NativeSymbolExt Condition="'$(NativeSymbolExt)' == ''">.dbg</NativeSymbolExt>
@@ -79,7 +81,7 @@ The .NET Foundation licenses this file to you under the MIT license.
7981
<ExportsFileExt Condition="'$(_targetOS)' != 'win'">.exports</ExportsFileExt>
8082

8183
<NativeObject>$(NativeIntermediateOutputPath)$(TargetName)$(NativeObjectExt)</NativeObject>
82-
<NativeBinary>$(NativeOutputPath)$(TargetName)$(NativeBinaryExt)</NativeBinary>
84+
<NativeBinary>$(NativeOutputPath)$(NativeBinaryPrefix)$(TargetName)$(NativeBinaryExt)</NativeBinary>
8385
<IlcExportUnmanagedEntrypoints Condition="'$(IlcExportUnmanagedEntrypoints)' == '' and '$(NativeLib)' == 'Shared'">true</IlcExportUnmanagedEntrypoints>
8486
<ExportsFile Condition="$(ExportsFile) == '' and '$(BuildingFrameworkLibrary)' != 'true'">$(NativeIntermediateOutputPath)$(TargetName)$(ExportsFileExt)</ExportsFile>
8587

0 commit comments

Comments
 (0)