Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.
/ corefx Public archive

Enable build on hosted arm64 #40453

Merged
merged 1 commit into from
Sep 12, 2019
Merged

Conversation

omajid
Copy link
Member

@omajid omajid commented Aug 20, 2019

This is attempt #2.

Initialize HostArch to the arch-style used in RIDs directly. Unless running in Visual Studio, when it should be forced to x64.

Initialize ArchGroup to HostArch unless overridden.

Use the HostArch for the tool runtime instead of assuming x64.

@omajid
Copy link
Member Author

omajid commented Aug 20, 2019

cc @joperezr @ViktorHofer

@omajid
Copy link
Member Author

omajid commented Aug 20, 2019

I dont have access to VS to verify this change :(

Copy link
Member

@ViktorHofer ViktorHofer left a comment

Choose a reason for hiding this comment

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

What about running VS on an x86 system?

@omajid
Copy link
Member Author

omajid commented Aug 21, 2019

@ViktorHofer Ah, good point. It would get forced to x64 🙁

Then again, it seems to me the current code (without my changes) forces it to x64 too:

    <HostArch>$([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture)</HostArch>
    <ArchGroup Condition="'$(ArchGroup)' == '' AND '$(HostArch)' == 'Arm'">arm</ArchGroup>
    <ArchGroup Condition="'$(ArchGroup)' == '' AND '$(HostArch)' == 'Arm64'">arm64</ArchGroup>
    <ArchGroup Condition="'$(ArchGroup)' == ''">x64</ArchGroup>

HostArch gets set to X86 and ArchGroup gets set to x64.

Do you know if building/testing with VS currently works on x86 systems out of the box?

@ViktorHofer
Copy link
Member

Then again, it seems to me the current code (without my changes) forces it to x64 too

No, see the comment here: https://github.com/dotnet/corefx/blob/master/Directory.Build.props#L57-L63. We set that property based on the configuration string that is supplied by VS.

Directory.Build.props Outdated Show resolved Hide resolved
Copy link
Member

@joperezr joperezr left a comment

Choose a reason for hiding this comment

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

Can you please explain what is blocking the build on a hosted arm64 machine today? Why can't you just call ./build.sh -arch arm64 or whatever arch you want? Building inside a hosted environment is not a common case, so I would try not to optimize for those as long as we have a way of building by passing in an extra arg.

@omajid
Copy link
Member Author

omajid commented Aug 21, 2019

I wrote about this in #40427, copying it here:

When I build a .NET Core component on linux-x64, I just do ./build.sh. I was hoping that things could be just as simple on other platforms. On linux-arm64, I would like to just do ./build.sh and have everything work out of the box without having to worry about runtime ids, architecture names or property names.

Is that an unrealistic goal?

@wfurt agreed:

I agree with @omajid that it would be nice if ./build.sh just work. In ideal case, all scripted cases can be parametrized but defaults for developers should be as simple as possible.

@joperezr
Copy link
Member

On linux-arm64, I would like to just do ./build.sh and have everything work out of the box without having to worry about runtime ids, architecture names or property names.

I see. Why does this not work today though? if you are in linux-arm64 then HostOS should be Arm64 so should archgroup automatically default to arm64 as well?

@omajid
Copy link
Member Author

omajid commented Aug 21, 2019

Out of the box, ./build.sh fails on arm64 with this error:

/home/omajid/.nuget/packages/microsoft.net.sdk.il/5.0.0-alpha1.19413.7/targets/Microsoft.NET.Sdk.IL.targets(135,5): error MSB3073: The command "/home/omajid/corefx/artifacts/toolset/ilasm/ilasm -QUIET -NOLOGO -DLL  -INCLUDE=include/netcoreapp -OUTPUT="/home/omajid/corefx/artifacts/obj/System.Runtime.CompilerServices.Unsafe/netcoreapp-Debug/System.Runtime.CompilerServices.Unsafe.dll" -KEY="/home/omajid/.nuget/packages/microsoft.dotnet.arcade.sdk/1.0.0-beta.19416.16/tools/snk/MSFT.snk" System.Runtime.CompilerServices.Unsafe.il" exited with code 126. [/home/omajid/corefx/src/System.Runtime.CompilerServices.Unsafe/src/System.Runtime.CompilerServices.Unsafe.ilproj]  

it turns out the ilasm executible is bad:

$ file /home/omajid/corefx/artifacts/toolset/ilasm/ilasm
/home/omajid/corefx/artifacts/toolset/ilasm/ilasm: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, for GNU/Linux 2.6.32, BuildID[sha1]=6b99261d576d77b0cb852e8d30e328a3a12f1e80, not stripped

It's incorrectly using the ilasm binary for x64 instead of the binary on arm64.

A hardcoded fix for that is:

-    <ToolRuntimeRID>$(_runtimeOS)-x64</ToolRuntimeRID>
+    <ToolRuntimeRID>$(_runtimeOS)-arm64</ToolRuntimeRID>

But that will only work on arm64. If I generalize this to:

-    <ToolRuntimeRID>$(_runtimeOS)-x64</ToolRuntimeRID>
+    <ToolRuntimeRID>$(_runtimeOS)-$(ArchGroup)</ToolRuntimeRID>

Then that (AFAIK) breaks cross compilation - because we want to use x64 tools when building arm64 on x64.

So we need to use architecture of the platform that is running the build - $(HostArch.ToString.ToLowerInvariant()) - here.

My fix then goes (maybe too far?) and sets ArchGroup (which can take values of x86, x64, arm64 and arm) explicitly based on HostArch.

@tmds suggested offline that maybe we could only set ArchGroup to $(HostArch) on non-Windows platforms? That might take care of the issues with VS architecture?

@omajid
Copy link
Member Author

omajid commented Aug 21, 2019

I am also interested in fixing up how we use the host architecture within our build scripts to handle potential new architectures in the future without further changes.

@joperezr
Copy link
Member

I see, if all that needs in order to unblock your scenario is to change ToolRuntimeRID, then can't we just scope the change to that property? As in, can't we just have something like:

<ToolRuntimeRID>$(_runtimeOS)-$(HostArch.ToString.ToLowerInvariant())</ToolRuntimeRID>

@omajid
Copy link
Member Author

omajid commented Aug 22, 2019

Yeah, that seems like a good idea. Do you know how that would affect VS on x86/x64?

@joperezr
Copy link
Member

Do you know how that would affect VS on x86/x64?

Oh you are right that would probably make VS build not work for that case. Perhaps we could keep the default to x64 and add a condition to set it to the above if BuildingInsideVisualStudio is not set, so basically similar to your current approach except that we would be narrowing down the impact by setting ToolRuntimeRID instead of ArchGroup.

This is attempt dotnet#2. The first attempt was commit
176da26.

Initialize HostArch to the arch-style used in RIDs directly by
converting things to lowercase.

Use the HostArch for the tool runtime instead of assuming x64.
@omajid
Copy link
Member Author

omajid commented Aug 30, 2019

I have verified that the my latest changes build on arm64 as well as x86_64. Any thoughts on it?

@omajid
Copy link
Member Author

omajid commented Sep 5, 2019

@safern, this is the updated version of #40311

@omajid
Copy link
Member Author

omajid commented Sep 11, 2019

Anyone have any thoughts on this?

@joperezr
Copy link
Member

I think I'm fine with the change as it is. We might still be missing a special case where this would break (for example cross builds or similar) but I believe that if we do find such a case we can fix it easily. @ericstj @ViktorHofer @safern any additional thoughts? or is this good to go?

@ViktorHofer
Copy link
Member

I'm ok with the change as well. Thanks for boxing this through.

@ViktorHofer
Copy link
Member

Re-running the CI according to our merge policies.

Copy link
Member

@safern safern left a comment

Choose a reason for hiding this comment

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

Looks good to me.

@ViktorHofer ViktorHofer merged commit be3d4ba into dotnet:master Sep 12, 2019
@ViktorHofer
Copy link
Member

Thanks

@omajid
Copy link
Member Author

omajid commented Sep 12, 2019

Thanks for the review and merging this, folks! Please do comment here (or in another issue and cc me) if this causes any other issues.

omajid added a commit to omajid/dotnet-source-build that referenced this pull request Nov 12, 2019
This chnage allows source-build to be cloned and built on arm64
 machines. I have tested this on RHEL 8 aarch64.

This change includes backports of the following pull-requests
 which have been merged into their respective master branches:

- dotnet/aspnetcore#14790
- dotnet/aspnetcore#15354
- dotnet/installer#4102
- dotnet/core-setup#8468
- dotnet/corefx#40453
omajid added a commit to omajid/dotnet-source-build that referenced this pull request Nov 12, 2019
This chnage allows source-build to be cloned and built on arm64
 machines. I have tested this on RHEL 8 aarch64.

This change includes backports of the following pull-requests
 which have been merged into their respective master branches:

- dotnet/aspnetcore#14790
- dotnet/aspnetcore#15354
- dotnet/installer#4102
- dotnet/core-setup#8468
- dotnet/corefx#40453
omajid added a commit to omajid/dotnet-source-build that referenced this pull request Nov 12, 2019
This chnage allows source-build to be cloned and built on arm64
 machines. I have tested this on RHEL 8 aarch64.

This change includes backports of the following pull-requests
 which have been merged into their respective master branches:

- dotnet/aspnetcore#14790
- dotnet/aspnetcore#15354
- dotnet/installer#4102
- dotnet/core-setup#8468
- dotnet/corefx#40453
omajid added a commit to omajid/dotnet-source-build that referenced this pull request Nov 12, 2019
This chnage allows source-build to be cloned and built on arm64
 machines. I have tested this on RHEL 8 aarch64.

This change includes backports of the following pull-requests
 which have been merged into their respective master branches:

- dotnet/aspnetcore#14790
- dotnet/aspnetcore#15354
- dotnet/installer#4102
- dotnet/core-setup#8468
- dotnet/corefx#40453
omajid added a commit to omajid/dotnet-source-build that referenced this pull request Nov 15, 2019
This chnage allows source-build to be cloned and built on arm64
 machines. I have tested this on RHEL 8 aarch64.

This change includes backports of the following pull-requests
 which have been merged into their respective master branches:

- dotnet/aspnetcore#14790
- dotnet/aspnetcore#15354
- dotnet/installer#4102
- dotnet/core-setup#8468
- dotnet/corefx#40453
omajid added a commit to omajid/dotnet-source-build that referenced this pull request Nov 15, 2019
This chnage allows source-build to be cloned and built on arm64
 machines. I have tested this on RHEL 8 aarch64.

This change includes backports of the following pull-requests
 which have been merged into their respective master branches:

- dotnet/aspnetcore#14790
- dotnet/aspnetcore#15354
- dotnet/installer#4102
- dotnet/core-setup#8468
- dotnet/corefx#40453
omajid added a commit to omajid/dotnet-source-build that referenced this pull request Nov 15, 2019
This chnage allows source-build to be cloned and built on arm64
 machines. I have tested this on RHEL 8 aarch64.

This change includes backports of the following pull-requests
 which have been merged into their respective master branches:

- dotnet/aspnetcore#14790
- dotnet/aspnetcore#15354
- dotnet/installer#4102
- dotnet/core-setup#8468
- dotnet/corefx#40453
omajid added a commit to omajid/dotnet-source-build that referenced this pull request Nov 15, 2019
This chnage allows source-build to be cloned and built on arm64
 machines. I have tested this on RHEL 8 aarch64.

This change includes backports of the following pull-requests
 which have been merged into their respective master branches:

- dotnet/aspnetcore#14790
- dotnet/aspnetcore#15354
- dotnet/installer#4102
- dotnet/core-setup#8468
- dotnet/corefx#40453
omajid added a commit to omajid/dotnet-source-build that referenced this pull request Nov 15, 2019
This chnage allows source-build to be cloned and built on arm64
 machines. I have tested this on RHEL 8 aarch64.

This change includes backports of the following pull-requests
 which have been merged into their respective master branches:

- dotnet/aspnetcore#14790
- dotnet/aspnetcore#15354
- dotnet/installer#4102
- dotnet/core-setup#8468
- dotnet/corefx#40453
omajid added a commit to omajid/dotnet-source-build that referenced this pull request Nov 16, 2019
This chnage allows source-build to be cloned and built on arm64
machines. It shouldn't affect cross compilation at all, however. I have
tested this on RHEL 8 aarch64.

This change includes backports of the following pull-requests which have
been merged into their respective master branches:

- dotnet/aspnetcore#14790
- dotnet/aspnetcore#15354
- dotnet/installer#4102
- dotnet/core-setup#8468
- dotnet/corefx#40453

To support using darc on arm64, this commit removes the customizations
of LD_LIBRARY_PATH and instead forces darc to run again a .NET Core 3.0
runtime. This in-turn makes darc pick up the right libgit2sharp
automatically for the right set of platforms and architectures.

There's a number of existing build configuration that are
conditionalized on arm64, such as setting up a root file system. Those
they are actually only meant to be invoked when cross-compiling for
arm64 (on x86_64). This commit modifies those conditions to not apply
when building on an arm64 machine.
omajid added a commit to omajid/dotnet-source-build that referenced this pull request Nov 20, 2019
This change allows source-build to be cloned and built on arm64
machines. It shouldn't affect cross compilation at all, however. I have
tested this on RHEL 8 aarch64.

This change includes backports of the following pull-requests which have
been merged into their respective master branches:

- dotnet/aspnetcore#14790
- dotnet/aspnetcore#15354
- dotnet/installer#4102
- dotnet/core-setup#8468
- dotnet/corefx#40453

There's a number of existing build configuration that are
conditionalized on arm64, such as setting up a root file system. Those
they are actually only meant to be invoked when cross-compiling for
arm64 (on x86_64). This commit modifies those conditions to not apply
when building on an arm64 machine.
omajid added a commit to omajid/dotnet-source-build that referenced this pull request Nov 21, 2019
This change allows source-build to be cloned and built on arm64
machines. It shouldn't affect cross compilation at all, however. I have
tested this on RHEL 8 aarch64.

This change includes backports of the following pull-requests which have
been merged into their respective master branches:

- dotnet/aspnetcore#14790
- dotnet/aspnetcore#15354
- dotnet/installer#4102
- dotnet/core-setup#8468
- dotnet/corefx#40453

There's a number of existing build configuration that are
conditionalized on arm64, such as setting up a root file system. Those
they are actually only meant to be invoked when cross-compiling for
arm64 (on x86_64). This commit modifies those conditions to not apply
when building on an arm64 machine.
crummel pushed a commit to omajid/dotnet-source-build that referenced this pull request Nov 22, 2019
This change allows source-build to be cloned and built on arm64
machines. It shouldn't affect cross compilation at all, however. I have
tested this on RHEL 8 aarch64.

This change includes backports of the following pull-requests which have
been merged into their respective master branches:

- dotnet/aspnetcore#14790
- dotnet/aspnetcore#15354
- dotnet/installer#4102
- dotnet/core-setup#8468
- dotnet/corefx#40453

There's a number of existing build configuration that are
conditionalized on arm64, such as setting up a root file system. Those
they are actually only meant to be invoked when cross-compiling for
arm64 (on x86_64). This commit modifies those conditions to not apply
when building on an arm64 machine.
crummel pushed a commit to dotnet/source-build that referenced this pull request Nov 24, 2019
* Enable building on arm64

This change allows source-build to be cloned and built on arm64
machines. It shouldn't affect cross compilation at all, however. I have
tested this on RHEL 8 aarch64.

This change includes backports of the following pull-requests which have
been merged into their respective master branches:

- dotnet/aspnetcore#14790
- dotnet/aspnetcore#15354
- dotnet/installer#4102
- dotnet/core-setup#8468
- dotnet/corefx#40453

There's a number of existing build configuration that are
conditionalized on arm64, such as setting up a root file system. Those
they are actually only meant to be invoked when cross-compiling for
arm64 (on x86_64). This commit modifies those conditions to not apply
when building on an arm64 machine.

* Patch fixup.
@karelz karelz added this to the 5.0 milestone Dec 19, 2019
omajid added a commit to omajid/dotnet-runtime that referenced this pull request Jul 17, 2020
crossgen2 (and by extension, runtime) fails to build on an arm64 box.
This is the error I see on Fedora 32 aarch64:

    ./build.sh
    ...
    crossgen2 -> artifacts/bin/coreclr/Linux.arm64.Debug/crossgen2/crossgen2.dll
    src/coreclr/src/tools/aot/crossgen2/crossgen2.csproj(87,5): error MSB3030: Could not copy the file "artifacts/bin/coreclr/Linux.arm64.Debug//x64/libjitinterface.so" because it was not found.

The file is there, just not under the `x64` directory:

    $ find -iname libjitinterface.so
    ./artifacts/bin/coreclr/Linux.arm64.Debug/libjitinterface.so
    ./artifacts/bin/coreclr/Linux.arm64.Debug/crossgen2/libjitinterface.so
    ./artifacts/obj/coreclr/Linux.arm64.Debug/src/tools/aot/jitinterface/libjitinterface.so

The actual bug is that crossgen2 seems to assume that if the build is
for an `arm64` RID, it's a cross-build, not a hosted build. Fix that by
explicitly checking `BuildArchitecture` as well.

Please see dotnet/corefx#40453 and
dotnet/core-setup#8468 for related fixes
enabling building for arm64 on an arm64 machine.

I have *not* verified this change in Visual Studio.
MichaelSimons pushed a commit to dotnet/source-build-externals that referenced this pull request Feb 8, 2022
* Enable building on arm64

This change allows source-build to be cloned and built on arm64
machines. It shouldn't affect cross compilation at all, however. I have
tested this on RHEL 8 aarch64.

This change includes backports of the following pull-requests which have
been merged into their respective master branches:

- dotnet/aspnetcore#14790
- dotnet/aspnetcore#15354
- dotnet/installer#4102
- dotnet/core-setup#8468
- dotnet/corefx#40453

There's a number of existing build configuration that are
conditionalized on arm64, such as setting up a root file system. Those
they are actually only meant to be invoked when cross-compiling for
arm64 (on x86_64). This commit modifies those conditions to not apply
when building on an arm64 machine.

* Patch fixup.
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.

6 participants