Skip to content

Wrong computed RID on Alpine Linux alpha / beta releases #73525

Closed

Description

@ayakael

Description

Runtime does not support RID format for alpha / beta releases of Alpine Linux which uses a VERSION_ID format which goes as such: x.xx_alphayyyymmdd (i.e. alpine.3.17_alpha20220715-x64) During build, even when RID is added to JSON RID graph using source-build's _IsBootstrapping=true flag and eng/native/init-distro-rid.sh logics are modified to not cut what's after alpine.3, fails with MSB4018: System.FormatException: Input string was not in a correct format. in src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(55,5)

Reproduction Steps

  • Run abuild -r using aport as available here in current Alpine Edge environment

Expected behavior

Either GenerateRuntimeGraph should be able to cope with that VERSION_ID format, as it is within spec of /etc/os-release, or [System.Runtime.InteropServices.RuntimeInformation]::RuntimeIdentifier should cut whatever's after _ as irrelevant information, just as it does with subversions. (i.e 3.17.1 becomes 3.17, thus should 3.17_alpha20220715 become 3.17)

Actual behavior

Computed RID through eng/native/init-distro-rid is alpine.3-x64 and through [System.Runtime.InteropServices.RuntimeInformation]::RuntimeIdentifier it is alpine.3.17_alpha20220715-x64

Regression?

No response

Known Workarounds

No response

Configuration

Note that this is done within source-build environment with 6.0.107 release on an Alpine Linux LXC container. Many patches are also applied by Alpine's build system. Patches relevant to runtime are prefixed by runtime_ in aport here

Other information

Full error is as follows:

  /var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(55,5): error MSB4018: The "GenerateRuntimeGraph" task failed unexpectedly.
  /var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(55,5): error MSB4018: System.FormatException: Input string was not in a correct format.
  /var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(55,5): error MSB4018:    at System.Number.ThrowOverflowOrFormatException(ParsingStatus status, TypeCode type)
  /var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(55,5): error MSB4018:    at System.Version.TryParseComponent(ReadOnlySpan`1 component, String componentName, Boolean throwOnFailure, Int32& parsedComponent)
  /var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(55,5): error MSB4018:    at System.Version.ParseVersion(ReadOnlySpan`1 input, Boolean throwOnFailure)
  /var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(55,5): error MSB4018:    at System.Version.Parse(String input)
  /var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(55,5): error MSB4018:    at Microsoft.NETCore.Platforms.BuildTasks.RuntimeVersion..ctor(String versionString) in /var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/RuntimeVersion.cs:line 37
  /var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(55,5): error MSB4018:    at Microsoft.NETCore.Platforms.BuildTasks.RID.Parse(String runtimeIdentifier) in /var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/RID.cs:line 152
  /var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(55,5): error MSB4018:    at Microsoft.NETCore.Platforms.BuildTasks.GenerateRuntimeGraph.AddRuntimeIdentifiers(ICollection`1 runtimeGroups) in /var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/GenerateRuntimeGraph.cs:line 325
  /var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(55,5): error MSB4018:    at Microsoft.NETCore.Platforms.BuildTasks.GenerateRuntimeGraph.Execute() in /var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/GenerateRuntimeGraph.cs:line 157
  /var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(55,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute()
  /var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/src/libraries/Microsoft.NETCore.Platforms/src/Microsoft.NETCore.Platforms.csproj(55,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask)
      478 Warning(s)
      1 Error(s)
  
  Time Elapsed 00:10:20.07
  Build failed with exit code 1. Check errors above.
/var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/Tools/source-built/Microsoft.DotNet.Arcade.Sdk/tools/SourceBuild/SourceBuildArcadeBuild.targets(194,5): error MSB3073: The command "./build.sh  --arch x64 --configuration Release --allconfigurations --verbosity minimal --nodereuse false --warnAsError false /p:MicrosoftNetFrameworkReferenceAssembliesVersion=1.0.2 /p:PackageRid=alpine.3.17_alpha20220715-x64 /p:NoPgoOptimize=true /p:KeepNativeSymbols=true /p:RuntimeOS=alpine.3.17_alpha20220715 /p:PortableBuild=false /p:BuildDebPackage=false --cmakeargs -DCLR_CMAKE_USE_SYSTEM_LIBUNWIND=TRUE /p:ArcadeInnerBuildFromSource=true /p:DotNetBuildFromSource=true /p:RepoRoot=/var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/ /p:ArtifactsDir=/var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/artifacts/ /bl:/var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/self/src/artifacts/sourcebuild.binlog /p:ContinuousIntegrationBuild=true /p:SourceBuildOutputDir=/var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/src/runtime/artifacts/source-build/ /p:SourceBuiltBlobFeedDir= /p:EnableSourceControlManagerQueries=false /p:EnableSourceLink=false /p:DeterministicSourcePaths=false /p:DotNetBuildOffline=true /p:DotNetPackageVersionPropsPath=/var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/artifacts/obj/x64/Release/PackageVersions.props" exited with code 1. [/var/build/dotnet6-fix-rid/community/dotnet6-stage0/src/source-build-tarball-6.0.107/Tools/source-built/Microsoft.DotNet.Arcade.Sdk/tools/Build.proj]

Full log of build here

Activity

  1. ghost added
    untriaged
    on Aug 7, 2022
  2. added
    source-build
    on Aug 7, 2022
  3. ayakael commented on Aug 8, 2022

    @ayakael
    ContributorAuthor

    The following bit of code is relevant to this issue:

    pal::string_t normalize_linux_rid(pal::string_t rid)
    {
    pal::string_t rhelPrefix(_X("rhel."));
    pal::string_t alpinePrefix(_X("alpine."));
    pal::string_t rockyPrefix(_X("rocky."));
    size_t lastVersionSeparatorIndex = std::string::npos;
    if (rid.compare(0, rhelPrefix.length(), rhelPrefix) == 0)
    {
    lastVersionSeparatorIndex = rid.find(_X("."), rhelPrefix.length());
    }
    else if (rid.compare(0, alpinePrefix.length(), alpinePrefix) == 0)
    {
    size_t secondVersionSeparatorIndex = rid.find(_X("."), alpinePrefix.length());
    if (secondVersionSeparatorIndex != std::string::npos)
    {
    lastVersionSeparatorIndex = rid.find(_X("."), secondVersionSeparatorIndex + 1);
    }
    }
    else if (rid.compare(0, rockyPrefix.length(), rockyPrefix) == 0)
    {
    lastVersionSeparatorIndex = rid.find(_X("."), rockyPrefix.length());
    }
    if (lastVersionSeparatorIndex != std::string::npos)
    {
    rid.erase(lastVersionSeparatorIndex, rid.length() - lastVersionSeparatorIndex);
    }
    return rid;
    }

    I think it'd be easy to fix if there was some logic put in place to strip any information following a '_' character, similar to how minor version numbers are stripped.

  4. ayakael commented on Aug 15, 2022

    @ayakael
    ContributorAuthor

    I've mitigated this issue by doing two things:

    1. Build runtime with p:TargetRid=alpine.3.17-x64
    2. Patched eng/native/init-distro-rid.sh to cut out _* from `alpine.3.17_alpha20220715```
    From 389814c78216f8f969f99bd87d58d7f386e0301a Mon Sep 17 00:00:00 2001
    From: Antoine Martin (ayakael) <[email protected]>
    Date: Fri, 5 Aug 2022 15:05:30 +0000
    Subject: [PATCH 1/1] improved VERSION_ID parsing
    
    Runtime doesn't generate a proper distro-rid for Alpine, leaving the
    last version digit. Patch fixes this by adding new VERSION_ID parsing
    logics.
    
    ---
     eng/native/init-distro-rid.sh | 15 ++++++++++-----
     1 file changed, 10 insertions(+), 5 deletions(-)
    
    diff --git a/eng/native/init-distro-rid.sh b/eng/native/init-distro-rid.sh
    index f71aa8640b1..fce4092a43d 100644
    --- a/eng/native/init-distro-rid.sh
    +++ b/eng/native/init-distro-rid.sh
    @@ -41,16 +41,21 @@ initNonPortableDistroRid()
                 # We have forced __PortableBuild=0. This is because -portablebuld
                 # has been passed as false.
                 if (( isPortable == 0 )); then
    -                if [ "${ID}" = "rhel" ]; then
    -                    # remove the last version digit
    -                    VERSION_ID="${VERSION_ID%.*}"
    -                fi
    -
                     if [ -z "${VERSION_ID+x}" ]; then
                             # Rolling release distros do not set VERSION_ID, so omit
                             # it here to be consistent with everything else.
                             nonPortableBuildID="${ID}-${buildArch}"
                     else
    +                        local VERSION_ID_DOT="${VERSION_ID//[^.]}"
    +                        while [[ ${#VERSION_ID_DOT} -gt 1 ]]; do
    +                                VERSION_ID="${VERSION_ID%.*}"
    +                                local VERSION_ID_DOT="${VERSION_ID//[^.]}"
    +                        done
    +                       local VERSION_ID_DASH="${VERSION_ID//[^_]}"
    +                        while [[ ${#VERSION_ID_DASH} -ge 1 ]]; do
    +                                VERSION_ID="${VERSION_ID%_*}"
    +                                local VERSION_ID_DASH="${VERSION_ID//[^_]}"
    +                        done
                             nonPortableBuildID="${ID}.${VERSION_ID}-${buildArch}"
                     fi
                 fi
    -- 
    2.37.1

    As you see above, I removed the distro-specific VERSION_ID normalization logics in favor of distro-agnostic logics. I do not know if this would break build on other platforms, but it would probably be worthwhile to explore other ways to normalize this variable.

  5. added this to the 8.0.0 milestone on Aug 16, 2022
  6. ghost removed
    untriaged
    on Aug 16, 2022
  7. LakshanF commented on Aug 16, 2022

    @LakshanF
    Contributor

    Moving to 8.0 since there is a mitigation

  8. ayakael commented on Nov 21, 2022

    @ayakael
    ContributorAuthor

    Of note, with #74504 changing init-distro-rid.sh is not necessary as TargetRid is now used to define __DistroRid when in source-build. [System.Runtime.InteropServices.RuntimeInformation]::RuntimeIdentifier should be changed as to parse all VERSION_ID variables that respects the specification so that TargetRid is well defined.

  9. ayakael commented on Nov 23, 2022

    @ayakael
    ContributorAuthor

    To add to the above, this means the following manipulations should be supported on Alpine:
    alpine.3.17.0-$arch -» alpine.3.17-$arch
    alpine.3.17-$arch -» alpine.3.17-$arch
    alpine.3.17_alpha-$arch -» alpine.3.17-$arch
    alpine.3.17.0_rc1 -» alpine.3.17-$arch

    My knowledge of c++ is non-existent, so I've been working on pal.unix.cpp to, just like cut anything after _, and then cut after ..

  10. soutieslak commented on Feb 16, 2023

    @soutieslak

    Hi all, I think I've run into the same issue as described above.

    I am using the official ASP.NET Core runtime image as my base image i.e. "mcr.microsoft.com/dotnet/aspnet:7.0.2-alpine3.17-amd64".

    When I want to populate my image with my application, I follow these 4 basic steps:
    dotnet restore
    dotnet build
    dotnet publish
    copy the published app to the container

    So in other words, I am publishing my application for all RIDs, but then when I run my container, I get a segmentation fault -> This is where I assumed its selecting the wrong RID.

    I then tried a different approach, and instead of publishing my application for all RIDs, I targeted a specific RID i.e. 'linux-musl-x64'. This results in a single RID variant of my application. If I then copy this published app to the container, it works as expected.

    As @ayakael mentioned, I think this is because I am using the 'alpine3.17-amd64' base image i.e. 'alpine.3.17-$arch' which seems like a manipulation that is not yet supported on Alpine. Is that right?

  11. ayakael commented on Mar 30, 2023

    @ayakael
    ContributorAuthor

    Hi all, I think I've run into the same issue as described above.

    I am using the official ASP.NET Core runtime image as my base image i.e. "mcr.microsoft.com/dotnet/aspnet:7.0.2-alpine3.17-amd64".

    When I want to populate my image with my application, I follow these 4 basic steps: dotnet restore dotnet build dotnet publish copy the published app to the container

    So in other words, I am publishing my application for all RIDs, but then when I run my container, I get a segmentation fault -> This is where I assumed its selecting the wrong RID.

    I then tried a different approach, and instead of publishing my application for all RIDs, I targeted a specific RID i.e. 'linux-musl-x64'. This results in a single RID variant of my application. If I then copy this published app to the container, it works as expected.

    As @ayakael mentioned, I think this is because I am using the 'alpine3.17-amd64' base image i.e. 'alpine.3.17-$arch' which seems like a manipulation that is not yet supported on Alpine. Is that right?

    Sorry for the late reply! Your application should be supported. This issue occurs when running dotnet on edge, thus you should not get a segmentation fault. Have you tried using the aspnetcore package that Alpine provides?

  12. ghost locked as resolved and limited conversation to collaborators on Jul 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-Hostsource-build

    Type

    No type

    Projects

    • Status
      No status

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions