Skip to content

Fixing a typo in copying pdb files #71450

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 2 commits into from
Jun 30, 2022
Merged

Conversation

LakshanF
Copy link
Contributor

@am11
Copy link
Member

am11 commented Jun 29, 2022

Ah, NativeBinaryExt is needed on Unix in this context, but not on Windows.

This should fix both:

  <Target Name="CopyNativeBinary" AfterTargets="Publish">
    <!-- replace apphost with binary we generated during native compilation -->
    <Delete Files="$(PublishDir)\$(TargetName)$(NativeBinaryExt)" />
    <Copy SourceFiles="$(NativeOutputPath)$(TargetName)$(NativeBinaryExt)" DestinationFolder="$(PublishDir)" />

    <!-- dotnet CLI produces managed debug symbols, which we will delete and copy native symbols instead -->
    <Delete Files="$(PublishDir)\$(TargetName).pdb" />

    <PropertyGroup>
      <_symbolExt Condition="'$(OS)' == 'Windows_NT'">$(NativeSymbolExt)</_symbolExt>
      <_symbolExt Condition="'$(OS)' != 'Windows_NT'">$(NativeBinaryExt)$(NativeSymbolExt)</_symbolExt>
    </PropertyGroup>

    <!-- replace native symbol file if it exists -->
    <Delete Files="$(PublishDir)\$(TargetName)$(_symbolExt)" />
    <Copy SourceFiles="$(NativeOutputPath)$(TargetName)$(_symbolExt)" DestinationFolder="$(PublishDir)"
      Condition="Exists('$(NativeOutputPath)$(TargetName)$(_symbolExt)')" />
  </Target>

Copy link
Member

@am11 am11 left a comment

Choose a reason for hiding this comment

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

Thank you!

I have tested on linux with classlib and console projects and it works as expected (with -p:StripSymbols=true):

$ dotnet7 --version
7.0.100-preview.7.22324.4

$ dotnet7 new console -n nativeapp1
$ dotnet7 publish -c Release -o nativeapp1/dist --use-current-runtime -p:PublishAot=true -p:StripSymbols=true nativeapp1
$ ls -la nativeapp1/dist
 
total 15224
drwxrwxr-x 2 am11 am11     4096 Jun 30 01:07 .
drwxrwxr-x 5 am11 am11     4096 Jun 30 01:07 ..
-rwxrwxr-x 1 am11 am11  4878176 Jun 30 01:07 nativeapp1
-rwxrwxr-x 1 am11 am11 10701896 Jun 30 01:07 nativeapp1.dbg

$ readelf --string-dump=.gnu_debuglink nativeapp1/dist/nativeapp1

String dump of section '.gnu_debuglink':
  [     0]  nativeapp1.dbg
 
$ dotnet7 new classlib -n nativelib1
$ dotnet7 publish -c Release -o nativelib1/dist --use-current-runtime -p:PublishAot=true -p:StripSymbols=true -p:NativeLib=Shared nativelib1
$ ls -la nativelib1/dist

total 14488
drwxrwxr-x 2 am11 am11     4096 Jun 30 01:08 .
drwxrwxr-x 5 am11 am11     4096 Jun 30 01:08 ..
-rwxrwxr-x 1 am11 am11  4587888 Jun 30 01:08 nativelib1.so
-rwxrwxr-x 1 am11 am11 10233648 Jun 30 01:08 nativelib1.so.dbg

$ readelf --string-dump=.gnu_debuglink nativelib1/dist/nativelib1.so

String dump of section '.gnu_debuglink':
  [     0]  nativelib1.so.dbg

Would be nice to have a unit test in SDK repo which checks the presence of .dbg on Linux, .dwarf on macOS and .pdb on Windows.

@LakshanF LakshanF merged commit 667812e into dotnet:main Jun 30, 2022
@LakshanF LakshanF deleted the FixNativeAotPdb branch June 30, 2022 14:14
@ghost ghost locked as resolved and limited conversation to collaborators Jul 30, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Publishing native aot applications no longer create pdb files
3 participants