Skip to content

Commit 28f2f86

Browse files
authored
RID work for macOS 12 (#59066)
1 parent d500e00 commit 28f2f86

4 files changed

Lines changed: 101 additions & 35 deletions

File tree

src/libraries/Microsoft.NETCore.Platforms/src/runtime.compatibility.json

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5229,6 +5229,73 @@
52295229
"any",
52305230
"base"
52315231
],
5232+
"osx.12": [
5233+
"osx.12",
5234+
"osx.11.0",
5235+
"osx.10.16",
5236+
"osx.10.15",
5237+
"osx.10.14",
5238+
"osx.10.13",
5239+
"osx.10.12",
5240+
"osx.10.11",
5241+
"osx.10.10",
5242+
"osx",
5243+
"unix",
5244+
"any",
5245+
"base"
5246+
],
5247+
"osx.12-arm64": [
5248+
"osx.12-arm64",
5249+
"osx.12",
5250+
"osx.11.0-arm64",
5251+
"osx.11.0",
5252+
"osx.10.16-arm64",
5253+
"osx.10.16",
5254+
"osx.10.15-arm64",
5255+
"osx.10.15",
5256+
"osx.10.14-arm64",
5257+
"osx.10.14",
5258+
"osx.10.13-arm64",
5259+
"osx.10.13",
5260+
"osx.10.12-arm64",
5261+
"osx.10.12",
5262+
"osx.10.11-arm64",
5263+
"osx.10.11",
5264+
"osx.10.10-arm64",
5265+
"osx.10.10",
5266+
"osx-arm64",
5267+
"osx",
5268+
"unix-arm64",
5269+
"unix",
5270+
"any",
5271+
"base"
5272+
],
5273+
"osx.12-x64": [
5274+
"osx.12-x64",
5275+
"osx.12",
5276+
"osx.11.0-x64",
5277+
"osx.11.0",
5278+
"osx.10.16-x64",
5279+
"osx.10.16",
5280+
"osx.10.15-x64",
5281+
"osx.10.15",
5282+
"osx.10.14-x64",
5283+
"osx.10.14",
5284+
"osx.10.13-x64",
5285+
"osx.10.13",
5286+
"osx.10.12-x64",
5287+
"osx.10.12",
5288+
"osx.10.11-x64",
5289+
"osx.10.11",
5290+
"osx.10.10-x64",
5291+
"osx.10.10",
5292+
"osx-x64",
5293+
"osx",
5294+
"unix-x64",
5295+
"unix",
5296+
"any",
5297+
"base"
5298+
],
52325299
"rhel": [
52335300
"rhel",
52345301
"linux",

src/libraries/Microsoft.NETCore.Platforms/src/runtime.json

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2133,6 +2133,23 @@
21332133
"osx.10.16-x64"
21342134
]
21352135
},
2136+
"osx.12": {
2137+
"#import": [
2138+
"osx.11.0"
2139+
]
2140+
},
2141+
"osx.12-arm64": {
2142+
"#import": [
2143+
"osx.12",
2144+
"osx.11.0-arm64"
2145+
]
2146+
},
2147+
"osx.12-x64": {
2148+
"#import": [
2149+
"osx.12",
2150+
"osx.11.0-x64"
2151+
]
2152+
},
21362153
"rhel": {
21372154
"#import": [
21382155
"linux"

src/libraries/Microsoft.NETCore.Platforms/src/runtimeGroups.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@
156156
<RuntimeGroup Include="osx">
157157
<Parent>unix</Parent>
158158
<Architectures>x64;arm64</Architectures>
159-
<Versions>10.10;10.11;10.12;10.13;10.14;10.15;10.16;11.0</Versions>
159+
<Versions>10.10;10.11;10.12;10.13;10.14;10.15;10.16;11.0;12</Versions>
160160
</RuntimeGroup>
161161

162162
<RuntimeGroup Include="freebsd">

src/native/corehost/hostmisc/pal.unix.cpp

Lines changed: 16 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -568,48 +568,30 @@ pal::string_t pal::get_current_os_rid_platform()
568568
pal::string_t ridOS;
569569

570570
char str[256];
571-
572-
// There is no good way to get the visible version of OSX (i.e. something like 10.x.y) as
573-
// certain APIs work till 10.9 and have been deprecated and others require linking against
574-
// UI frameworks to get the data.
575-
//
576-
// We will, instead, use kern.osrelease and use its major version number
577-
// as a means to formulate the OSX 10.X RID.
578-
//
579571
size_t size = sizeof(str);
580-
int ret = sysctlbyname("kern.osrelease", str, &size, nullptr, 0);
572+
573+
// returns something like 10.5.2
574+
int ret = sysctlbyname("kern.osproductversion", str, &size, nullptr, 0);
581575
if (ret == 0)
582576
{
583-
std::string release(str, size);
584-
size_t pos = release.find('.');
585-
if (pos != std::string::npos)
577+
// the value _should_ be null terminated but let's make sure
578+
str[size - 1] = 0;
579+
char* pos = strchr(str, '.');
580+
if (pos != NULL)
586581
{
587-
int majorVersion = stoi(release.substr(0, pos));
588-
// compat path with 10.x
589-
if (majorVersion < 20)
590-
{
591-
// Extract the major version and subtract 4 from it
592-
// to get the Minor version used in OSX versioning scheme.
593-
// That is, given a version 10.X.Y, we will get X below.
594-
//
595-
// macOS Cataline 10.15.5 has kernel 19.5.0
596-
int minorVersion = majorVersion - 4;
597-
if (minorVersion < 10)
598-
{
599-
// On OSX, our minimum supported RID is 10.12.
600-
minorVersion = 12;
601-
}
582+
pos = strchr(pos + 1, '.');
602583

603-
ridOS.append(_X("osx.10."));
604-
ridOS.append(pal::to_string(minorVersion));
605-
}
606-
else
584+
if (pos != NULL)
607585
{
608-
// 11.0 shipped with kernel 20.0
609-
ridOS.append(_X("osx.11."));
610-
ridOS.append(pal::to_string(majorVersion - 20));
586+
// strip anything after second dot and return something like 10.5
587+
*pos = 0;
588+
size = pos - str;
611589
}
612590
}
591+
592+
std::string release(str, size);
593+
ridOS.append(_X("osx."));
594+
ridOS.append(release);
613595
}
614596

615597
return ridOS;

0 commit comments

Comments
 (0)