Skip to content
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

Crossplatform ResourceUpdater #89303

Merged
merged 79 commits into from
Aug 8, 2023

Conversation

anatawa12
Copy link
Contributor

@anatawa12 anatawa12 commented Jul 21, 2023

I tried to implement resource updater based on Mono.Cecil.Binary from mono repository System.Reflection.Metadata and Compiler/Win32Resources

Fixes #3828
Fixes #88465

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-HostModel Microsoft.NET.HostModel issues label Jul 21, 2023
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jul 21, 2023
@ghost
Copy link

ghost commented Jul 21, 2023

Tagging subscribers to this area: @vitek-karas, @agocke
See info in area-owners.md if you want to be subscribed.

Issue Details

I tried to implement resource updater based on Mono.Cecil.Binary from mono repository

Fixes #3828

Author: anatawa12
Assignees: -
Labels:

area-HostModel

Milestone: -

@vitek-karas
Copy link
Member

/cc @elinor-fung

@anatawa12 anatawa12 changed the title Crossplatform resource updater Crossplatform ResourceUpdater Jul 21, 2023
@anatawa12
Copy link
Contributor Author

The test failure AppHost.Bundle.Tests_net8.0_arm64.html and HostActivation.Tests_net8.0_arm64.html are failed also on main branch in my environment (08a6e06) so I think those failure is not produced by my changes.

@vitek-karas
Copy link
Member

The test failures are suspect - these tests suites are exactly those which target the functionality around the ResourceUpdater... so we need to figure out what's wrong.

@anatawa12
Copy link
Contributor Author

Sorry I found the failure on main branch is my fault.
I fixed ResourceUpdater and ResourceWriter.

@elinor-fung
Copy link
Member

Thanks a lot for tackling this @anatawa12.

Some high level comments/questions about the implementation:

  1. Microsoft.NET.HostModel already depends on System.Reflection.Metadata. There seems to be quite some overlap between the functionality being pulled into Mono.Cecil.Binary and what is already provided in System.Reflection.PortableExecutable - specifically PEReader.
    • Could this use the reading functionality available in System.Reflection.Metadata instead?
  2. The runtime repo has some code used by other tools to read resource data into a model and update it: https://github.com/dotnet/runtime/tree/main/src/coreclr/tools/Common/Compiler/Win32Resources
    • Could this re-use that resource data model instead?

In general, I'm looking to re-use existing code/functionality and pull in as little new logic as possible that we would have to ship in the SDK and maintain separately from other implementations. I think if the two things above are doable, it would just leave the actual writing/patching as new logic specific to HostModel.

Testing is probably my biggest concern here. This basically affects every build targeting Windows. Unfortunately, even running on Windows, we have a significant test hole around resource updating.

With the exception of those two tests, that were failing and you addressed, the tests in the runtime repo aren't actually using ResourceUpdater (if they were, I expect more tests would have failed). There is one test in dotnet/sdk that explicitly targets resources being copied from the managed dll, but that would only catch failures when we try to integrate runtime into sdk, rather than when the changes are made in runtime.

Ideally, we would have:

  • Unit tests for ResourceUpdater
    • Something basic like updating and reading it back to check that a resource was added
  • Integration tests using HostModel to update an apphost
    • Most tests in this repo don't actually go through HostWriter/ResourceUpdater and the ones that do actually don't pass in a binary from which to copy resources. I'm going to look into this - this was a surprise to me and we need to fix it.
  • E2E tests for cross-building an app on Unix targeting Windows
    • I don't think we really have a good mechanism for doing this in runtime. I believe the sdk repo has some tests that cross-build, so that may be where we add tests like this.

@anatawa12
Copy link
Contributor Author

anatawa12 commented Jul 26, 2023

Could this use the reading functionality available in System.Reflection.Metadata instead?

I think yes. I didn't know about System.Reflection.Metadata. I'm going to rewriting with System.Reflection.Metadata.

Could this re-use that resource data model instead?

I think data model can be reused but I think we need new writing resource logic because it looks current logic is for object file, not suitable for image files. writing logic may also reusable.

Copy link
Member

@elinor-fung elinor-fung left a comment

Choose a reason for hiding this comment

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

Final minor comment. Excited to see this come together - thank you!

@anatawa12
Copy link
Contributor Author

#90136 fixed the CI failure. Thank you.

anatawa12 added a commit to anatawa12/dotnet-sdk that referenced this pull request Aug 8, 2023
ResourceUpdater.IsSupportedOS() will always return true since dotnet/runtime#89303
@elinor-fung elinor-fung merged commit a3e38ff into dotnet:main Aug 8, 2023
131 checks passed
@elinor-fung
Copy link
Member

Thank you, @anatawa12!

@matt-richardson
Copy link

@anatawa12 - you are a legend. Thanks!

@akirayamamoto
Copy link

Thank you @anatawa12, that is awesome!

anatawa12 added a commit to anatawa12/dotnet-sdk that referenced this pull request Aug 10, 2023
ResourceUpdater.IsSupportedOS() will always return true since dotnet/runtime#89303
@agocke
Copy link
Member

agocke commented Aug 14, 2023

@anatawa12 Thanks for your contribution, this is great! Really excellent work.

@vitek-karas
Copy link
Member

Thanks a lot @anatawa12 - this is great.

anatawa12 added a commit to anatawa12/dotnet-sdk that referenced this pull request Aug 15, 2023
ResourceUpdater.IsSupportedOS() will always return true since dotnet/runtime#89303
@ghost ghost locked as resolved and limited conversation to collaborators Sep 14, 2023
@anatawa12 anatawa12 deleted the crossplatform-resource-updater branch February 24, 2024 19:07
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-HostModel Microsoft.NET.HostModel issues community-contribution Indicates that the PR has been added by a community member
Projects
None yet
8 participants