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

[NativeAOT] cross-compiling to osx-arm64 from osx-x64 does not work #82542

Closed
jkotas opened this issue Feb 23, 2023 · 18 comments · May be fixed by dotnet/sdk#30818
Closed

[NativeAOT] cross-compiling to osx-arm64 from osx-x64 does not work #82542

jkotas opened this issue Feb 23, 2023 · 18 comments · May be fixed by dotnet/sdk#30818

Comments

@jkotas
Copy link
Member

jkotas commented Feb 23, 2023

Reported by @lemonmojo in #73678 (comment):

I'm also running into the same error using .NET 8 Preview 1.

While cross-compiling to x64 from an M1 machine works fine for me, I can't get the reverse (cross-compiling to ARM64 from an Intel machine) to work.

I'm not using any packages in this project. In fact, the issue is very easy to reproduce:

dotnet new classlib -n "AOTTest"
cd AOTTest
dotnet publish -p "PublishAot=true" -r osx-x64
dotnet publish -p "PublishAot=true" -r osx-arm64

Publishing using dotnet publish -r osx-x64 and dotnet publish -r osx-arm64 works fine from an M1 machine.
While on an Intel machine only the x64 build works and the ARM64 one fails with the error message:

/Users/redacted/.nuget/packages/microsoft.dotnet.ilcompiler/8.0.0-preview.1.23110.8/build/Microsoft.NETCore.Native.Publish.targets(74,5): error : The PrivateSdkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative [/Path/to/Project.csproj].

So here's what works and what doesn't work in my testing:
ARM64 -> x64: OK
ARM64 -> ARM64: OK
x64 -> x64: OK
x64 -> ARM64: Error

@ghost ghost added the untriaged New issue has not been triaged by the area owner label Feb 23, 2023
@jkotas
Copy link
Member Author

jkotas commented Feb 23, 2023

@filipnavara Do you happen to know what the problem is?

@ghost
Copy link

ghost commented Feb 23, 2023

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

Issue Details

Reported by @lemonmojo in #73678 (comment):

I'm also running into the same error using .NET 8 Preview 1.

While cross-compiling to x64 from an M1 machine works fine for me, I can't get the reverse (cross-compiling to ARM64 from an Intel machine) to work.

I'm not using any packages in this project. In fact, the issue is very easy to reproduce:

dotnet new classlib -n "AOTTest"
cd AOTTest
dotnet publish -p "PublishAot=true" -r osx-x64
dotnet publish -p "PublishAot=true" -r osx-arm64

Publishing using dotnet publish -r osx-x64 and dotnet publish -r osx-arm64 works fine from an M1 machine.
While on an Intel machine only the x64 build works and the ARM64 one fails with the error message:

/Users/redacted/.nuget/packages/microsoft.dotnet.ilcompiler/8.0.0-preview.1.23110.8/build/Microsoft.NETCore.Native.Publish.targets(74,5): error : The PrivateSdkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative [/Path/to/Project.csproj].

So here's what works and what doesn't work in my testing:
ARM64 -> x64: OK
ARM64 -> ARM64: OK
x64 -> x64: OK
x64 -> ARM64: Error

Author: jkotas
Assignees: -
Labels:

untriaged, area-NativeAOT-coreclr

Milestone: -

@jkotas jkotas added the os-mac-os-x macOS aka OSX label Feb 23, 2023
@jkotas jkotas added this to the 8.0.0 milestone Feb 23, 2023
@am11
Copy link
Member

am11 commented Feb 23, 2023

While cross-compiling to x64 from an M1 machine works fine for me, I can't get the reverse (cross-compiling to ARM64 from an Intel machine) to work.

FWIW, the CI is cross-compiling for arm64 on osx-x64 machine.

@ghost ghost removed the untriaged New issue has not been triaged by the area owner label Feb 23, 2023
@filipnavara
Copy link
Member

It used to work, and this error is new to me. I'll try to reproduce it on my machine, but just in case that doesn't work, it would be useful to get a MSBuild binlog. It can be produced with a /bl switch on the dotnet publish command line, which will produce a msbuild.binlog file.

@kant2002
Copy link
Contributor

I do have binlog from @lemonmojo and we troubleshoot that issue in #coreclr channel on dotnet evolution.
Issue was that runtime package was not downloaded as part of restore(?) process.
We solve that by manually adding package <PackageReference Include="runtime.osx-arm64.Microsoft.DotNet.ILCompiler" Version="8.0.0-preview.1.23110.8" />.
Discrepancies in differences quite possible was because ARM64 -> x64: OK was first attemp, and ARM64 machine has runtime package in the cache already.

@jkotas
Copy link
Member Author

jkotas commented Feb 23, 2023

If you do not use explicit Microsoft.DotNet.ILCompiler package reference, it should just work.

The explicit runtime.osx-arm64.Microsoft.DotNet.ILCompiler package reference should be only needed if you use explicit Microsoft.DotNet.ILCompiler package reference. This is documented in https://github.com/dotnet/runtime/blob/main/src/coreclr/nativeaot/docs/compiling.md#cross-architecture-compilation.

@filipnavara
Copy link
Member

It reproduces. The RuntimePackagePath property in ImportRuntimeIlcPackageTarget gets set to an empty value.

@kant2002
Copy link
Contributor

I ask OP manually add this to download package in the cache. I think after this package in the Nuget cache issue will disappear.

@kant2002
Copy link
Contributor

It obviosly still a bug, but I do not troubleshoot that far and I do not have Mac

@filipnavara
Copy link
Member

filipnavara commented Feb 23, 2023

The problem happens on this line:

<RuntimePackagePath Condition="'@(ResolvedTargetILCompilerPack)' == '$(RuntimeIlcPackageName)'">@(ResolvedTargetILCompilerPack->'%(PackageDirectory)')</RuntimePackagePath>

ResolvedTargetILCompilerPack is set earlier:
image

It matches RuntimeIlcPackageName = runtime.osx-arm64.Microsoft.DotNet.ILCompiler.

However, there's no PackageDirectory property on the ResolvedTargetILCompilerPack item.

osx-arm64 binlog (fail):
msbuild.binlog.zip
osx-x64 binlog (success):
msbuild1.binlog.zip

@kant2002
Copy link
Contributor

It happens because RuntimeIlcPackageName package not in the cache. Without that GetPackageDirectory cannot find path to package(it does not exists locally)

@filipnavara
Copy link
Member

It happens because RuntimeIlcPackageName package not in the cache. Without that GetPackageDirectory cannot find path to package(it does not exists locally)

Yep, I agree with the assessment. It doesn't restore the NuGet of the target runtime package. If it already exists though then the error doesn't happen.

Here's a proof:

filipnavara@Filips-MacBook-Air AOTTest % ~/.dotnet/dotnet publish -p "PublishAot=true" -r osx-arm64 
MSBuild version 17.6.0-preview-23108-10+51df47643 for .NET
  Determining projects to restore...
  Restored /Users/filipnavara/Projects/AOTTest/AOTTest.csproj (in 537 ms).
/Users/filipnavara/.dotnet/sdk/8.0.100-preview.1.23115.2/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(287,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [/Users/filipnavara/Projects/AOTTest/AOTTest.csproj]
  AOTTest -> /Users/filipnavara/Projects/AOTTest/bin/Release/net8.0/osx-arm64/AOTTest.dll
  Generating native code
  AOTTest -> /Users/filipnavara/Projects/AOTTest/bin/Release/net8.0/osx-arm64/publish/
filipnavara@Filips-MacBook-Air AOTTest % rm -fr ~/.nuget
filipnavara@Filips-MacBook-Air AOTTest % ~/.dotnet/dotnet publish -p "PublishAot=true" -r osx-arm64 
MSBuild version 17.6.0-preview-23108-10+51df47643 for .NET
  Determining projects to restore...
  Restored /Users/filipnavara/Projects/AOTTest/AOTTest.csproj (in 1.88 sec).
/Users/filipnavara/.dotnet/sdk/8.0.100-preview.1.23115.2/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.RuntimeIdentifierInference.targets(287,5): message NETSDK1057: You are using a preview version of .NET. See: https://aka.ms/dotnet-support-policy [/Users/filipnavara/Projects/AOTTest/AOTTest.csproj]
  AOTTest -> /Users/filipnavara/Projects/AOTTest/bin/Release/net8.0/osx-arm64/AOTTest.dll
/Users/filipnavara/.nuget/packages/microsoft.dotnet.ilcompiler/8.0.0-preview.1.23110.8/build/Microsoft.NETCore.Native.Publish.targets(74,5): error : The PrivateSdkAssemblies ItemGroup is required for _ComputeAssembliesToCompileToNative [/Users/filipnavara/Projects/AOTTest/AOTTest.csproj]

@jkotas
Copy link
Member Author

jkotas commented Feb 23, 2023

This code should be responsible for downloading both x64 and arm64 packages for cross-compilation:

https://github.com/dotnet/sdk/blob/main/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs#L668-L684

@filipnavara
Copy link
Member

filipnavara commented Feb 23, 2023

https://github.com/dotnet/sdk/blob/main/src/Tasks/Microsoft.NET.Build.Tasks/ProcessFrameworkReferences.cs#L668-L684

The output of the task has only the host targeting pack in the _PackageToDownload output despite the rest of the inputs and outputs being correct.

The branch that should do this actually doesn't have the code to add to the downloads.

@filipnavara
Copy link
Member

filipnavara commented Feb 23, 2023

I suppose the fix would be placing this somewhere around here:

                if (EnableRuntimePackDownload)
                {
                    // We need to download the target runtime pack
                    TaskItem runtimePackToDownload = new TaskItem(targetIlcPackName);
                    runtimePackToDownload.SetMetadata(MetadataKeys.Version, packVersion);
                    packagesToDownload.Add(runtimePackToDownload);
                }

@filipnavara
Copy link
Member

I tested the fix with local build and it works, so I opened a PR.

@jkotas
Copy link
Member Author

jkotas commented Feb 23, 2023

This specific cross-compilation scenario is fixed by #82558.

(If there are other cross-compilation scenarios to improve, we should open specific issues for them.)

@jkotas jkotas closed this as completed Feb 23, 2023
@lemonmojo
Copy link

Thx @jkotas and @filipnavara! I'll test again when the next preview lands. Cheers

@ghost ghost locked as resolved and limited conversation to collaborators Mar 26, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants