Skip to content

Commit 865d02e

Browse files
authored
Stop using computed RID for RUNTIME_IDENTIFIER property (#89598)
Update the property to use the host RID instead of the computed current RID. This is in line with the .NET 8 change for selecting RID-specific assets using the host RID instead of a computed RID. This also moves updates the shared helper to stop using the computed RID as the current RID - that is moved into the deps resolving, which needs it. Other places use the build-time RID. This means that `RuntimeInformation.RuntimeIdentifier` (populated by the `RUNTIME_IDENTIFIER` property) will return the RID of platform for which the runtime is built, rather than a RID that is computed at runtime (or a fallback if it could not be computed). For example, for a portable build, on Windows 11, it will be win-x64 instead of win10-x64 or on Ubuntu 20.04 linux-x64 instead of ubuntu.20.04-x64.
1 parent 602b88d commit 865d02e

File tree

8 files changed

+36
-45
lines changed

8 files changed

+36
-45
lines changed

src/installer/tests/HostActivation.Tests/NativeHostApis.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -486,12 +486,13 @@ public void HostRuntimeContract_get_runtime_property()
486486
{
487487
var fixture = sharedTestState.HostApiInvokerAppFixture;
488488

489-
fixture.BuiltDotnet.Exec(fixture.TestProject.AppDll, "host_runtime_contract.get_runtime_property", "APP_CONTEXT_BASE_DIRECTORY", "DOES_NOT_EXIST", "ENTRY_ASSEMBLY_NAME")
489+
fixture.BuiltDotnet.Exec(fixture.TestProject.AppDll, "host_runtime_contract.get_runtime_property", "APP_CONTEXT_BASE_DIRECTORY", "RUNTIME_IDENTIFIER", "DOES_NOT_EXIST", "ENTRY_ASSEMBLY_NAME")
490490
.CaptureStdOut()
491491
.CaptureStdErr()
492492
.Execute()
493493
.Should().Pass()
494494
.And.HaveStdOutContaining($"APP_CONTEXT_BASE_DIRECTORY = {Path.GetDirectoryName(fixture.TestProject.AppDll)}")
495+
.And.HaveStdOutContaining($"RUNTIME_IDENTIFIER = {RepoDirectoriesProvider.Default.BuildRID}")
495496
.And.HaveStdOutContaining($"DOES_NOT_EXIST = <none>")
496497
.And.HaveStdOutContaining($"ENTRY_ASSEMBLY_NAME = {fixture.TestProject.AssemblyName}");
497498
}

src/libraries/System.Runtime.Extensions/tests/System/EnvironmentTests.cs

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -185,15 +185,6 @@ public void OSVersion_ParseVersion(string input, int major, int minor, int build
185185
public void OSVersion_ValidVersion_OSX()
186186
{
187187
Version version = Environment.OSVersion.Version;
188-
189-
// NativeAOT hard-codes the runtime identifier at build time
190-
if (!PlatformDetection.IsNativeAot)
191-
{
192-
// verify that the Environment.OSVersion.Version matches the current RID
193-
// As of 12.0, only major version numbers are included in the RID
194-
Assert.Contains(version.ToString(1), RuntimeInformation.RuntimeIdentifier);
195-
}
196-
197188
Assert.True(version.Minor >= 0, "OSVersion Minor should be non-negative");
198189
Assert.True(version.Build >= 0, "OSVersion Build should be non-negative");
199190
Assert.Equal(-1, version.Revision); // Revision is never set on OSX

src/libraries/System.Runtime.InteropServices.RuntimeInformation/tests/RuntimeIdentifierTests.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,9 @@ public void VerifyLinuxRid()
7474
.Substring("ID=".Length)
7575
.Trim('\"', '\'');
7676

77-
// This gets burned in at publish time on NativeAOT
78-
if (PlatformDetection.IsNativeAot)
79-
expectedOSName = "linux";
80-
81-
Assert.StartsWith(expectedOSName, RuntimeInformation.RuntimeIdentifier, StringComparison.OrdinalIgnoreCase);
77+
// Should either start with linux (portable builds or NativeAOT) or the OS name (source builds)
78+
Assert.True(RuntimeInformation.RuntimeIdentifier.StartsWith("linux", StringComparison.OrdinalIgnoreCase)
79+
|| RuntimeInformation.RuntimeIdentifier.StartsWith(expectedOSName, StringComparison.OrdinalIgnoreCase));
8280
}
8381

8482
[Fact, PlatformSpecific(TestPlatforms.FreeBSD)]

src/native/corehost/fxr/command_line.cpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,17 +282,15 @@ int command_line::parse_args_for_sdk_command(
282282

283283
void command_line::print_muxer_info(const pal::string_t &dotnet_root, const pal::string_t &global_json_path)
284284
{
285-
const pal::char_t* arch = get_current_arch_name();
286285
pal::string_t commit = _STRINGIFY(REPO_COMMIT_HASH);
287286
trace::println(_X("\n")
288287
_X("Host:\n")
289288
_X(" Version: ") _STRINGIFY(HOST_FXR_PKG_VER) _X("\n")
290-
_X(" Architecture: %s\n")
289+
_X(" Architecture: ") _STRINGIFY(CURRENT_ARCH_NAME) _X("\n")
291290
_X(" Commit: %s\n")
292-
_X(" RID: ") _STRINGIFY(HOST_RID_PLATFORM) _X("-%s"),
293-
arch,
291+
_X(" RID: %s"),
294292
commit.substr(0, 10).c_str(),
295-
arch);
293+
get_runtime_id().c_str());
296294

297295
trace::println(_X("\n")
298296
_X(".NET SDKs installed:"));

src/native/corehost/hostmisc/utils.cpp

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -249,23 +249,13 @@ const pal::char_t* get_current_arch_name()
249249
return _STRINGIFY(CURRENT_ARCH_NAME);
250250
}
251251

252-
pal::string_t get_current_runtime_id(bool use_fallback)
252+
pal::string_t get_runtime_id()
253253
{
254254
pal::string_t rid;
255255
if (try_get_runtime_id_from_env(rid))
256256
return rid;
257257

258-
rid = pal::get_current_os_rid_platform();
259-
if (rid.empty() && use_fallback)
260-
rid = pal::get_current_os_fallback_rid();
261-
262-
if (!rid.empty())
263-
{
264-
rid.append(_X("-"));
265-
rid.append(get_current_arch_name());
266-
}
267-
268-
return rid;
258+
return _STRINGIFY(HOST_RID_PLATFORM) _X("-") _STRINGIFY(CURRENT_ARCH_NAME);
269259
}
270260

271261
bool try_get_runtime_id_from_env(pal::string_t& out_rid)
@@ -468,8 +458,8 @@ pal::string_t get_download_url(const pal::char_t* framework_name, const pal::cha
468458
const pal::char_t* arch = get_current_arch_name();
469459
url.append(_X("&arch="));
470460
url.append(arch);
471-
url.append(_X("&rid=") _STRINGIFY(HOST_RID_PLATFORM) _X("-"));
472-
url.append(arch);
461+
url.append(_X("&rid="));
462+
url.append(get_runtime_id());
473463

474464
pal::string_t os = pal::get_current_os_rid_platform();
475465
if (os.empty())

src/native/corehost/hostmisc/utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ pal::architecture get_current_arch();
9090
const pal::char_t* get_arch_name(pal::architecture arch);
9191
const pal::char_t* get_current_arch_name();
9292

93-
pal::string_t get_current_runtime_id(bool use_fallback);
93+
pal::string_t get_runtime_id();
9494
bool try_get_runtime_id_from_env(pal::string_t& out_rid);
9595

9696
bool multilevel_lookup_enabled();

src/native/corehost/hostpolicy/deps_format.cpp

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,26 +213,39 @@ namespace
213213
_X("any"),
214214
};
215215

216-
// Returns the RID determined (computed or fallback) for the platform the host is running on.
217-
pal::string_t get_current_rid(const deps_json_t::rid_fallback_graph_t* rid_fallback_graph)
216+
// Returns the RID determined (computed or fallback) for the machine the host is running on.
217+
// This RID is discoved at run-time from OS APIs and/or files. It may be distro-specific and/or
218+
// version-specific. This usage of the machine RID is for a backwards-compat option that relies
219+
// on the computed RID. All other parts of the host use the compile-time RID corresponding to the
220+
// platform for which the runtime was built.
221+
pal::string_t get_current_machine_rid(const deps_json_t::rid_fallback_graph_t* rid_fallback_graph)
218222
{
219-
pal::string_t currentRid = get_current_runtime_id(false /*use_fallback*/);
223+
pal::string_t current_rid;
224+
if (!try_get_runtime_id_from_env(current_rid))
225+
{
226+
current_rid = pal::get_current_os_rid_platform();
227+
if (!current_rid.empty())
228+
{
229+
current_rid.append(_X("-"));
230+
current_rid.append(get_current_arch_name());
231+
}
232+
}
220233

221-
trace::info(_X("HostRID is %s"), currentRid.empty() ? _X("not available") : currentRid.c_str());
234+
trace::info(_X("HostRID is %s"), current_rid.empty() ? _X("not available") : current_rid.c_str());
222235

223236
// If the current RID is not present in the RID fallback graph, then the platform
224237
// is unknown to us. At this point, we will fallback to using the base RIDs and attempt
225238
// asset lookup using them.
226239
//
227240
// We do the same even when the RID is empty.
228-
if (currentRid.empty() || (rid_fallback_graph != nullptr && rid_fallback_graph->count(currentRid) == 0))
241+
if (current_rid.empty() || (rid_fallback_graph != nullptr && rid_fallback_graph->count(current_rid) == 0))
229242
{
230-
currentRid = pal::get_current_os_fallback_rid() + pal::string_t(_X("-")) + get_current_arch_name();
243+
current_rid = pal::get_current_os_fallback_rid() + pal::string_t(_X("-")) + get_current_arch_name();
231244

232-
trace::info(_X("Falling back to base HostRID: %s"), currentRid.c_str());
245+
trace::info(_X("Falling back to base HostRID: %s"), current_rid.c_str());
233246
}
234247

235-
return currentRid;
248+
return current_rid;
236249
}
237250

238251
void print_host_rid_list()
@@ -322,7 +335,7 @@ void deps_json_t::perform_rid_fallback(rid_specific_assets_t* portable_assets)
322335
pal::string_t host_rid;
323336
if (m_rid_resolution_options.use_fallback_graph)
324337
{
325-
host_rid = get_current_rid(m_rid_resolution_options.rid_fallback_graph);
338+
host_rid = get_current_machine_rid(m_rid_resolution_options.rid_fallback_graph);
326339
}
327340
else
328341
{

src/native/corehost/hostpolicy/hostpolicy_context.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ int hostpolicy_context_t::initialize(const hostpolicy_init_t &hostpolicy_init, c
280280
coreclr_properties.add(common_property::AppContextDepsFiles, app_context_deps_str.c_str());
281281
coreclr_properties.add(common_property::FxDepsFile, fx_deps_str.c_str());
282282
coreclr_properties.add(common_property::ProbingDirectories, resolver.get_lookup_probe_directories().c_str());
283-
coreclr_properties.add(common_property::RuntimeIdentifier, get_current_runtime_id(true /*use_fallback*/).c_str());
283+
coreclr_properties.add(common_property::RuntimeIdentifier, get_runtime_id().c_str());
284284

285285
bool set_app_paths = false;
286286

0 commit comments

Comments
 (0)