From 62c23fe237717e88f8fde75c556b2218e771c680 Mon Sep 17 00:00:00 2001 From: Adeel <3840695+am11@users.noreply.github.com> Date: Tue, 2 Jul 2024 14:09:28 +0300 Subject: [PATCH] Add option to install dotnet at .dotnet/$rid --- .devcontainer/android/devcontainer.json | 2 +- .devcontainer/devcontainer.json | 2 +- .devcontainer/libraries/devcontainer.json | 2 +- .../wasm-multiThreaded/devcontainer.json | 2 +- .devcontainer/wasm/devcontainer.json | 2 +- dotnet.cmd | 4 ++-- dotnet.sh | 4 ++-- eng/common/tools.ps1 | 17 +++++++++++++++++ eng/common/tools.sh | 5 +++++ .../libraries/fuzzing/deploy-to-onefuzz.yml | 2 +- .../crossboundarylayout/buildcrossgen2image.cmd | 10 +++++----- 11 files changed, 37 insertions(+), 15 deletions(-) diff --git a/.devcontainer/android/devcontainer.json b/.devcontainer/android/devcontainer.json index 9bfc25bd6cf54f..b48a78a0ef0ca9 100644 --- a/.devcontainer/android/devcontainer.json +++ b/.devcontainer/android/devcontainer.json @@ -54,7 +54,7 @@ // This allows developers to just use 'dotnet build' on the command-line, and the local dotnet version will be used. // Add the Android SDK tooling and emulator to the path. "remoteEnv": { - "PATH": "${containerWorkspaceFolder}/.dotnet:${containerEnv:ANDROID_SDK_ROOT}/cmdline-tools/cmdline-tools/bin:${containerEnv:ANDROID_SDK_ROOT}/emulator:${containerEnv:ANDROID_SDK_ROOT}/platform-tools:${containerEnv:PATH}", + "PATH": "${containerWorkspaceFolder}/.dotnet/linux-x64:${containerEnv:ANDROID_SDK_ROOT}/cmdline-tools/cmdline-tools/bin:${containerEnv:ANDROID_SDK_ROOT}/emulator:${containerEnv:ANDROID_SDK_ROOT}/platform-tools:${containerEnv:PATH}", "DOTNET_MULTILEVEL_LOOKUP": "0" }, diff --git a/.devcontainer/devcontainer.json b/.devcontainer/devcontainer.json index ed9d1f78e2f502..f836694086ee86 100644 --- a/.devcontainer/devcontainer.json +++ b/.devcontainer/devcontainer.json @@ -39,7 +39,7 @@ // Add the locally installed dotnet to the path to ensure that it is activated // This allows developers to just use 'dotnet build' on the command-line, and the local dotnet version will be used. "remoteEnv": { - "PATH": "${containerWorkspaceFolder}/.dotnet:${containerEnv:PATH}", + "PATH": "${containerWorkspaceFolder}/.dotnet/linux-x64:${containerEnv:PATH}", "DOTNET_MULTILEVEL_LOOKUP": "0" }, diff --git a/.devcontainer/libraries/devcontainer.json b/.devcontainer/libraries/devcontainer.json index 1cb53754298ab2..a445922831f214 100644 --- a/.devcontainer/libraries/devcontainer.json +++ b/.devcontainer/libraries/devcontainer.json @@ -45,7 +45,7 @@ // Add the locally installed dotnet to the path to ensure that it is activated // This allows developers to just use 'dotnet build' on the command-line, and the local dotnet version will be used. "remoteEnv": { - "PATH": "${containerWorkspaceFolder}/.dotnet:${containerEnv:PATH}", + "PATH": "${containerWorkspaceFolder}/.dotnet/linux-x64:${containerEnv:PATH}", "DOTNET_MULTILEVEL_LOOKUP": "0" }, diff --git a/.devcontainer/wasm-multiThreaded/devcontainer.json b/.devcontainer/wasm-multiThreaded/devcontainer.json index 62786b8319c3a6..c10c672c6dc122 100644 --- a/.devcontainer/wasm-multiThreaded/devcontainer.json +++ b/.devcontainer/wasm-multiThreaded/devcontainer.json @@ -47,7 +47,7 @@ // This allows developers to just use 'dotnet build' on the command-line, and the local dotnet version will be used. // Add the global tools dir to the PATH so that globally installed tools will work "remoteEnv": { - "PATH": "${containerWorkspaceFolder}/.dotnet:${containerWorkspaceFolder}/.dotnet-tools-global:${containerEnv:PATH}", + "PATH": "${containerWorkspaceFolder}/.dotnet/linux-x64:${containerWorkspaceFolder}/.dotnet-tools-global:${containerEnv:PATH}", "DOTNET_MULTILEVEL_LOOKUP": "0", }, diff --git a/.devcontainer/wasm/devcontainer.json b/.devcontainer/wasm/devcontainer.json index 0f9d19e8cdacc3..667317b83705cd 100644 --- a/.devcontainer/wasm/devcontainer.json +++ b/.devcontainer/wasm/devcontainer.json @@ -47,7 +47,7 @@ // This allows developers to just use 'dotnet build' on the command-line, and the local dotnet version will be used. // Add the global tools dir to the PATH so that globally installed tools will work "remoteEnv": { - "PATH": "${containerWorkspaceFolder}/.dotnet:${containerWorkspaceFolder}/.dotnet-tools-global:${containerEnv:PATH}", + "PATH": "${containerWorkspaceFolder}/.dotnet/linux-x64:${containerWorkspaceFolder}/.dotnet-tools-global:${containerEnv:PATH}", "DOTNET_MULTILEVEL_LOOKUP": "0", }, diff --git a/dotnet.cmd b/dotnet.cmd index b3cf59daa28baf..564f0730d86710 100644 --- a/dotnet.cmd +++ b/dotnet.cmd @@ -16,7 +16,7 @@ set Platform= :: Don't resolve runtime, shared framework, or SDK from other locations to ensure build determinism set DOTNET_MULTILEVEL_LOOKUP=0 -:: Disable first run since we want to control all package sources -set DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +:: Install at .dotent/${RID} +set DOTNET_USE_ARCH_IN_INSTALL_PATH=1 call "%dotnetPath%\dotnet.exe" %* diff --git a/dotnet.sh b/dotnet.sh index a612ebac1ce1e4..67cd5b5e8f8116 100755 --- a/dotnet.sh +++ b/dotnet.sh @@ -15,8 +15,8 @@ scriptroot="$( cd -P "$( dirname "$source" )" && pwd )" # Don't resolve runtime, shared framework, or SDK from other locations to ensure build determinism export DOTNET_MULTILEVEL_LOOKUP=0 -# Disable first run since we want to control all package sources -export DOTNET_SKIP_FIRST_TIME_EXPERIENCE=1 +# Install at .dotent/${RID} +export DOTNET_USE_ARCH_IN_INSTALL_PATH=1 source $scriptroot/eng/common/tools.sh diff --git a/eng/common/tools.ps1 b/eng/common/tools.ps1 index 9574f4eb9df09c..28187de99a1b07 100644 --- a/eng/common/tools.ps1 +++ b/eng/common/tools.ps1 @@ -188,6 +188,23 @@ function InitializeDotNetCli([bool]$install, [bool]$createSdkLocationFile) { $dotnetRoot = $env:DOTNET_INSTALL_DIR } else { $dotnetRoot = Join-Path $RepoRoot '.dotnet' + if ($env:DOTNET_USE_ARCH_IN_INSTALL_PATH -eq "1") { + $osArchitecture = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture + if ($osArchitecture) { + $rid = "win-$osArchitecture".ToLowerInvariant() + } else { + # netfx / desktop + $osArchitecture = (Get-CimInstance -ClassName Win32_OperatingSystem).OSArchitecture + switch -Wildcard ($osArchitecture) { + "*ARM 64-bit*" { $rid = "win-arm64"; break } + "*ARM*" { $rid = "win-arm"; break } + "*32-bit*" { $rid = "win-x86"; break } + "*64-bit*" { $rid = "win-x64"; break } + } + } + + $dotnetRoot = Join-Path $dotnetRoot $rid + } if (-not (Test-Path(Join-Path $dotnetRoot "sdk\$dotnetSdkVersion"))) { if ($install) { diff --git a/eng/common/tools.sh b/eng/common/tools.sh index 00473c9f918d47..7de532773efb9b 100755 --- a/eng/common/tools.sh +++ b/eng/common/tools.sh @@ -145,6 +145,11 @@ function InitializeDotNetCli { dotnet_root="$DOTNET_INSTALL_DIR" else dotnet_root="${repo_root}.dotnet" + if [[ "${DOTNET_USE_ARCH_IN_INSTALL_PATH:-}" == "1" ]]; then + . "$_script_dir/native/init-os-and-arch.sh" + if (ldd --version 2>&1 || true) | grep -q musl; then os="${os}-musl"; fi + dotnet_root="${dotnet_root}/${os}-${arch}" + fi export DOTNET_INSTALL_DIR="$dotnet_root" diff --git a/eng/pipelines/libraries/fuzzing/deploy-to-onefuzz.yml b/eng/pipelines/libraries/fuzzing/deploy-to-onefuzz.yml index 276cc50f97de31..13f543ea9fb5c7 100644 --- a/eng/pipelines/libraries/fuzzing/deploy-to-onefuzz.yml +++ b/eng/pipelines/libraries/fuzzing/deploy-to-onefuzz.yml @@ -12,7 +12,7 @@ variables: - name: fuzzerProject value: $(Build.SourcesDirectory)/src/libraries/Fuzzing/DotnetFuzzing - name: dotnetPath - value: $(Build.SourcesDirectory)/.dotnet/dotnet + value: $(Build.SourcesDirectory)/dotnet.cmd extends: template: /eng/pipelines/common/templates/pipeline-with-resources.yml diff --git a/src/tests/readytorun/crossboundarylayout/buildcrossgen2image.cmd b/src/tests/readytorun/crossboundarylayout/buildcrossgen2image.cmd index e75f4808a4d9e1..70a4836ebb2d89 100644 --- a/src/tests/readytorun/crossboundarylayout/buildcrossgen2image.cmd +++ b/src/tests/readytorun/crossboundarylayout/buildcrossgen2image.cmd @@ -48,7 +48,7 @@ goto Loop if "%COMPOSITENAME%"=="" goto done -set BUILDCMD=%TESTBATCHROOT%\..\..\..\..\..\..\.dotnet\dotnet %CORE_ROOT%\crossgen2\crossgen2.dll -r %CORE_ROOT%\* -r %TESTINITIALBINPATH%\*.dll -o %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%Composite.dll --composite %COMPILEARG% +set BUILDCMD=%TESTBATCHROOT%\..\..\..\..\..\..\dotnet.cmd %CORE_ROOT%\crossgen2\crossgen2.dll -r %CORE_ROOT%\* -r %TESTINITIALBINPATH%\*.dll -o %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%Composite.dll --composite %COMPILEARG% echo %BUILDCMD% > %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%Composite.dll.log call %BUILDCMD% >> %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%Composite.dll.log 2>&1 if NOT EXIST %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%Composite.dll del %TESTINITIALBINPATH%\%TESTTARGET_DIR%\a.dll @@ -56,28 +56,28 @@ goto done :CG2Single del %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll -set BUILDCMD=%TESTBATCHROOT%\..\..\..\..\..\..\.dotnet\dotnet %CORE_ROOT%\crossgen2\crossgen2.dll -r %CORE_ROOT%\* -r %TESTINITIALBINPATH%\*.dll -o %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll %TESTINITIALBINPATH%\%COMPOSITENAME%.dll +set BUILDCMD=%TESTBATCHROOT%\..\..\..\..\..\..\dotnet.cmd %CORE_ROOT%\crossgen2\crossgen2.dll -r %CORE_ROOT%\* -r %TESTINITIALBINPATH%\*.dll -o %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll %TESTINITIALBINPATH%\%COMPOSITENAME%.dll echo %BUILDCMD% > %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll.log call %BUILDCMD% >> %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll.log 2>&1 goto done :CG2NoMethods del %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll -set BUILDCMD=%TESTBATCHROOT%\..\..\..\..\..\..\.dotnet\dotnet %CORE_ROOT%\crossgen2\crossgen2.dll --compile-no-methods -r %CORE_ROOT%\* -r %TESTINITIALBINPATH%\*.dll -o %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll %TESTINITIALBINPATH%\%COMPOSITENAME%.dll +set BUILDCMD=%TESTBATCHROOT%\..\..\..\..\..\..\dotnet.cmd %CORE_ROOT%\crossgen2\crossgen2.dll --compile-no-methods -r %CORE_ROOT%\* -r %TESTINITIALBINPATH%\*.dll -o %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll %TESTINITIALBINPATH%\%COMPOSITENAME%.dll echo %BUILDCMD% > %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll.log call %BUILDCMD% >> %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll.log 2>&1 goto done :CG2SingleInputBubble del %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll -set BUILDCMD=%TESTBATCHROOT%\..\..\..\..\..\..\.dotnet\dotnet %CORE_ROOT%\crossgen2\crossgen2.dll -r %CORE_ROOT%\* -r %TESTINITIALBINPATH%\*.dll -o %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll --inputbubble %TESTINITIALBINPATH%\%COMPOSITENAME%.dll +set BUILDCMD=%TESTBATCHROOT%\..\..\..\..\..\..\dotnet.cmd %CORE_ROOT%\crossgen2\crossgen2.dll -r %CORE_ROOT%\* -r %TESTINITIALBINPATH%\*.dll -o %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll --inputbubble %TESTINITIALBINPATH%\%COMPOSITENAME%.dll echo %BUILDCMD% > %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll.log call %BUILDCMD% >> %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll.log 2>&1 goto done :CG2SingleBubbleADOnly del %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll -set BUILDCMD=%TESTBATCHROOT%\..\..\..\..\..\..\.dotnet\dotnet %CORE_ROOT%\crossgen2\crossgen2.dll -r %CORE_ROOT%\* -r %TESTINITIALBINPATH%\d.dll -o %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll --inputbubble %TESTINITIALBINPATH%\%COMPOSITENAME%.dll +set BUILDCMD=%TESTBATCHROOT%\..\..\..\..\..\..\dotnet.cmd %CORE_ROOT%\crossgen2\crossgen2.dll -r %CORE_ROOT%\* -r %TESTINITIALBINPATH%\d.dll -o %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll --inputbubble %TESTINITIALBINPATH%\%COMPOSITENAME%.dll echo %BUILDCMD% > %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll.log call %BUILDCMD% >> %TESTINITIALBINPATH%\%TESTTARGET_DIR%\%COMPOSITENAME%.dll.log 2>&1 goto done