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

Build managed part of crossgen2 as platform independent (AnyCPU) #33041

Merged
merged 1 commit into from
Apr 1, 2020

Conversation

gbalykov
Copy link
Member

@gbalykov gbalykov commented Mar 2, 2020

After this change same crossgen2.dll can be launched on different architectures.

Related issue: #31793

cc @alpencolt @jkotas

@gbalykov gbalykov changed the title Build managed part of crossgen2 as platfrom independent (AnyCPU) Build managed part of crossgen2 as platform independent (AnyCPU) Mar 2, 2020
@jkotas
Copy link
Member

jkotas commented Mar 2, 2020

Why not build everything as AnyCpu? ie delete https://github.com/dotnet/runtime/blob/master/src/coreclr/dir.common.props#L33

@gbalykov
Copy link
Member Author

gbalykov commented Mar 3, 2020

@jkotas this change by itself didn't seem to work, and I was not sure whether that was the correct approach, because for example System.Private.CoreLib build relies on Platform set equal to build arch.

@jkotas
Copy link
Member

jkotas commented Mar 3, 2020

System.Private.CoreLib build relies on Platform set equal to build arch

Set Platform for System.Private.CoreLib, and leave it to default to AnyCPU for everything else?

@@ -7,6 +7,7 @@
<EnableDefaultCompileItems>false</EnableDefaultCompileItems>
<Platforms>x64;x86</Platforms>
Copy link
Member

Choose a reason for hiding this comment

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

None of this should be needed once the default is AnyCPU.

@gbalykov
Copy link
Member Author

gbalykov commented Apr 1, 2020

@jkotas there is a problem with the approach that sets Platform to AnyCPU for everything.

Crossgen2 is built as an app targeting specific RID (e.g. linux-x64 for x64 build), besides as a self-contained application:

/home/z/Dev/runtime/dotnet.sh publish --self-contained -r linux-x64 -c Release -o /home/z/Dev/runtime/artifacts/bin/coreclr/Linux.x64.Release/crossgen2 /home/z/Dev/runtime/src/coreclr/src/tools/crossgen2/crossgen2/crossgen2.csproj /nologo /p:TargetArchitecture=x64

I've done the change that sets Platform to AnyCPU for everything (gbalykov@703ca05), however, this doesn't affect the resulting dlls, because they still target the specific platform. The same effect is from simple build command instead of publish:

/home/z/Dev/runtime/dotnet.sh build -r linux-x64 -c Release -o /home/z/Dev/runtime/artifacts/bin/coreclr/Linux.x64.Release/crossgen2 /home/z/Dev/runtime/src/coreclr/src/tools/crossgen2/crossgen2/crossgen2.csproj /nologo /p:TargetArchitecture=x64

Only if I remove -r option from there, dlls become platform independent. However, as I understand, crossgen2 is planned to be distributed as a self-contained app, so -r is required: #31741.

On the other side, approach with setting PlatformTarget to AnyCPU works even with build for specific rid. What do you think?

@jkotas
Copy link
Member

jkotas commented Apr 1, 2020

Hmmm, I have not realized that dotnet publish sets the Platform based on the RID. The change looks good to me as is. Thanks for looking into this.

Copy link
Member

@jkotas jkotas left a comment

Choose a reason for hiding this comment

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

Ok, I have not realized we can clean this up later if necessary.

@jkotas jkotas merged commit b5d044d into dotnet:master Apr 1, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 10, 2020
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.

3 participants