Repository navigation
Description
Description
The dotnet/runtime build fails when running on Alpine in source-build mode with a portable configuration:
/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(63,5): error MSB4018: The "GenerateRuntimeGraph" task failed unexpectedly. [TargetFramework=net8.0]
/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(63,5): error MSB4018: System.InvalidOperationException: AdditionalRuntimeIdentifier x64 was specified, which could not be found in any existing RuntimeGroup, and no parent was specified. [TargetFramework=net8.0]
/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(63,5): error MSB4018: at Microsoft.NETCore.Platforms.BuildTasks.RuntimeGroupCollection.AddRuntimeIdentifier(RID rid, String parent) in /runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/RuntimeGroupCollection.cs:line 116 [TargetFramework=net8.0]
/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(63,5): error MSB4018: at Microsoft.NETCore.Platforms.BuildTasks.RuntimeGroupCollection.AddRuntimeIdentifier(RID rid, String parent) in /runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/RuntimeGroupCollection.cs:line 140 [TargetFramework=net8.0]
/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(63,5): error MSB4018: at Microsoft.NETCore.Platforms.BuildTasks.RuntimeGroupCollection.AddRuntimeIdentifier(RID rid, String parent) in /runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/RuntimeGroupCollection.cs:line 140 [TargetFramework=net8.0]
/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(63,5): error MSB4018: at Microsoft.NETCore.Platforms.BuildTasks.RuntimeGroupCollection.AddRuntimeIdentifier(String runtimeIdentifier, String parent) in /runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/RuntimeGroupCollection.cs:line 39 [TargetFramework=net8.0]
/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(63,5): error MSB4018: at Microsoft.NETCore.Platforms.BuildTasks.GenerateRuntimeGraph.AddRuntimeIdentifiers(ICollection`1 runtimeGroups) in /runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/GenerateRuntimeGraph.cs:line 327 [TargetFramework=net8.0]
/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(63,5): error MSB4018: at Microsoft.NETCore.Platforms.BuildTasks.GenerateRuntimeGraph.Execute() in /runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/GenerateRuntimeGraph.cs:line 157 [TargetFramework=net8.0]
/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(63,5): error MSB4018: at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [TargetFramework=net8.0]
/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(63,5): error MSB4018: at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [TargetFramework=net8.0]
The problem is most visible with .NET 6, because dotnet/runtime is built in portable mode as part of the end-to-end source-build process.
With .NET 7 and .NET 8, source-build only builds dotnet/runtime in non-portable mode, so this problem doesn't appear there out of the box. It only appears when building dotnet/runtime by itself, in a configuration that's not used by source-build.
Reproduction Steps
Create an alpine container using a Dockerfile
# Dockerfile suitable for building .NET on Alpine
FROM alpine:3.17
RUN apk update && \
apk add \
bash \
binutils \
clang \
cmake \
git \
gcc \
icu-dev \
krb5-dev \
llvm \
libstdc++ \
linux-headers \
lttng-ust-dev \
make \
musl-dev \
openssl-dev \
python3 \
zlib-dev \Then git clone https://github.com/dotnet/runtime in the container and try and build runtime in source-build mode in the appropriate branch:
main:
./build.sh -p:TargetRid=linux-musl-x64 -c Release --restore --build --pack /p:ArcadeBuildFromSource=true -bl
release/7.0 and release/6.0
./build.sh -c Release --restore --build --pack /p:ArcadeBuildFromSource=true -bl
Expected behavior
Build works
Actual behavior
Build fails
Regression?
No response
Known Workarounds
No response
Configuration
No response
Other information
No response
Metadata
Metadata
Assignees
Labels
Type
Projects
- StatusShow more project fieldsNo status
Activity
omajid commentedon Mar 30, 2023
cc @ayakael @crummel @mthalman @MichaelSimons @tmds
[-]GenerateRuntimeGraph fails when building rutime in source-build on Alpine[/-][+]GenerateRuntimeGraph fails when building runtime in source-build on Alpine[/+][-]GenerateRuntimeGraph fails when building runtime in source-build on Alpine[/-][+]GenerateRuntimeGraph fails when building runtime in source-build mode on Alpine[/+]tmds commentedon Mar 30, 2023
This is probably due to #77508 being merged in 6.0 for runtime, but not the changes in installer: dotnet/installer#14816.
The fix is to revert #77508 and maybe some other PRs that got merged for eliminating the portable build with 6.0.
ayakael commentedon Mar 30, 2023
Reverting this particular one would break a workaround we use for #73525 as TargetRid would never be passed to __DistroRid. I'm looking into this right now to propose a better fix.
tmds commentedon Mar 30, 2023
The fix for this can backported.
ayakael commentedon Mar 30, 2023
Could you point to the fix for this so I can backport?
omajid commentedon Mar 30, 2023
I am not sure I follow. I ran into this issue when building dotnet/runtime standalone. How is dotnet/installer involved?
tmds commentedon Mar 30, 2023
SourceBuild.propsno longer worked standalone with the changes for the non-portable build. That is fixed onmain.If you want to make it work standalone on 6.0 as-is, you can add
/p:BaseOS=.I think that would be #80901 and #81497
ayakael commentedon Mar 30, 2023
Applying the following diff yields the same behaviour, as well:
Thus, this seems to have to do something with how GenerateRuntimeGraph parses AdditionalRuntimeIdentifiers. If it had to do with how OutputRid was set (or not, in the case of lack of the installer backport), this would've fixed the error.
Also, re-reading omajid's tests, they also tested against
main. So, there's someting wrong with the code regardless of the backport.Awesome, thank you for pointing that out :)
tmds commentedon Mar 30, 2023
There were other PRs backported to 6.0 for eliminating portable build, like #77510.
I think we should start by reverting those, and seeing if there is still an issue to be solved.
afaik everything works well on
main.9 remaining items
tmds commentedon Apr 5, 2023
Aha, good you found the root cause!
Looking at the code here:
runtime/src/libraries/Microsoft.NETCore.Platforms/src/RID.cs
Lines 91 to 95 in 042a350
We should add something like the following (at line 93), which causes the first
-oflinux-musl-x64to be considered part of theRIDPart.Base.ayakael commentedon Apr 5, 2023
Nice, that did it! I wish I could read C#! Want me to get a PR going for this?
tmds commentedon Apr 5, 2023
I was going to suggest adding something to the tests, and looking at them I see:
runtime/src/libraries/Microsoft.NETCore.Platforms/tests/RidTests.cs
Lines 22 to 23 in 042a350
So, it's a known ambiguity with the parser.
The parsing takes into account an optional qualifier that may exist at the end of the rid, which is also separated by a
-.A full rid can look like:
[os].[version]-[architecture]-[additional qualifiers].(see https://learn.microsoft.com/en-us/dotnet/core/rid-catalog).
I'm not sure what the desired solution is.
One option would be to make the parser aware of the architectures. We know the dashes before the
architectureshould be considered part of theos.@ericstj @ViktorHofer what do you think?
ericstj commentedon Apr 6, 2023
linux-musl-x64should already be part of the RID graph. It's defined inruntimeGroups:runtime/src/libraries/Microsoft.NETCore.Platforms/src/runtimeGroups.props
Lines 12 to 15 in 58d1ecb
I would expect this to be pre-loaded into the collection:
runtime/src/libraries/Microsoft.NETCore.Platforms/src/GenerateRuntimeGraph.cs
Lines 323 to 328 in 58d1ecb
Later on, I'd expect this fast path to be hit:
runtime/src/libraries/Microsoft.NETCore.Platforms/src/RuntimeGroupCollection.cs
Lines 44 to 48 in 58d1ecb
However it's not hit, since we hit the ambiguous case where
linux-musl-x64was parsed differently, so it's getting a different hashcode even though its string representation is identical.runtime/src/libraries/Microsoft.NETCore.Platforms/src/RID.cs
Lines 190 to 194 in 58d1ecb
One fix would be to use a comparer for this hashset that treated RIDs that were the same string representation as equal. There's really not a case where we'd define structured RIDs from the runtime groups with this ambiguity - it's only comping from string parsing in which case we want to ignore that ambiguity.
That's actually ignoring Qualifier. The same check works for Version because the version delimiter can only occur once. I think one option would be to make the Parse option have a flag to ignore Qualifiers and then plumb this through for AdditionalRuntimeIdentifier. The use of qualifiers was something we did early on (
-aotcould be used to provide a different asset for .NET Native vs CoreCLR) but then later abandoned due to RID graph explosion. I think dropping it from the AdditionalRuntimeIdentifier scenario is reasonable.tmds commentedon Apr 6, 2023
I had come to that conclusion as well.
@ericstj I had also suggested another option:
Any thoughts about that?
Shall I go ahead and implement this?
ericstj commentedon Apr 6, 2023
I'd prefer to not further complicate the parsing algorithm with lookahead searches for known architectures. If anything I'd prefer we simplify it.
My order of preference would be:
tmds commentedon Apr 6, 2023
I assume the path doesn't get hit because the
knownRIDsdidn't get parsed but constructed. So it looks like:BaseRID = "linux-musl", Architecture = "x64", Qualifier = "". And then fails equality againstBaseRID = "linux", Architecture = "musl", Qualifier = "x64".Because we know the additional rids won't have a qualifier, my preferred option would be:
Otherwise we still have issue when an additional runtime identifier has
-in itsosand is not yet known.tmds commentedon Apr 6, 2023
@ayakael because source-build uses a non-portable rid, it won't encounter this parse issue.
To make this command work, you can probably unblock yourself by explicitly adding
/p:AdditionalRuntimeIdentifiers=to it.ericstj commentedon Apr 6, 2023
I'm good with that. I'd even consider deprecating the qualifier completely if we thought we could remove the
-aotRIDs, not sure about that breaking change though.I'd also be OK with doing both 1&2. It's not correct to allow two different RIDs with the same string representation but different meaning into the graph. Things will break later on when writing the graph in this case.
tmds commentedon Apr 6, 2023
The parsing problem is fixed by #84413.
@omajid @ayakael are we good to close this issue?
ayakael commentedon Apr 6, 2023
Yes, I'd like to backport this to
release/6.0to unblock the testing CI if that's okay.tmds commentedon Apr 6, 2023
I think the most important CI, is the one for
main.I'm not sure the 6.0 will catch many issues at this point. Or if it will catch them in time, so you can act on them before the release date.
You can make the request on the PR. The maintainers will decide.