Skip to content

Commit 70e1072

Browse files
Thefrankam11MichalStrehovskyjkotasSuchiman
authored
NativeAOT for FreeBSD (#80323)
* add inotify for FreeBSD during linking * remove FreeBSD for now * netstandard does not understand FreeBSD * add FreeBSD platform to HostModel Tests * add inotify for FreeBSD during linking * remove FreeBSD for now * netstandard does not understand FreeBSD * add FreeBSD platform to HostModel Tests * Use Clang12, update LinkerArg * WIP FreeBSD NativeAOT * add inotify for FreeBSD during linking * remove FreeBSD for now * netstandard does not understand FreeBSD * add FreeBSD platform to HostModel Tests * WIP FreeBSD NativeAOT * remove FreeBSD for now * add FreeBSD platform to HostModel Tests * Use Clang12, update LinkerArg * Update JITTools and ObjWriter for FreeBSD-x64 * fixes for tests * fixes for tests * add TargetTriple for FreeBSD * Some changes from feedback, remove out of scope * HostModel back to netstandard2.0 * Update src/coreclr/CMakeLists.txt * Publish crossgen2 as single-file on cross-os * pass NativeAotSupported to MSBuild crossgen2 tasks * Can't use NativeAOT in source build yet Co-authored-by: Adeel Mujahid <[email protected]> * Update private string HostFxr and HostPolicy * Fix private string HostPolicy * Apply suggestions from code review Co-authored-by: Adeel Mujahid <[email protected]> Co-authored-by: Michal Strehovský <[email protected]> Co-authored-by: Jan Kotas <[email protected]> Co-authored-by: Robin Sue <[email protected]>
1 parent ad9efe8 commit 70e1072

File tree

12 files changed

+32
-16
lines changed

12 files changed

+32
-16
lines changed

eng/Subsets.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@
103103

104104
<PropertyGroup>
105105
<!-- CLR NativeAot only builds in a subset of the matrix -->
106-
<NativeAotSupported Condition="('$(TargetOS)' == 'windows' or '$(TargetOS)' == 'linux' or '$(TargetOS)' == 'osx') and ('$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'arm64')">true</NativeAotSupported>
106+
<NativeAotSupported Condition="('$(TargetOS)' == 'windows' or '$(TargetOS)' == 'linux' or '$(TargetOS)' == 'osx' or '$(TargetOS)' == 'freebsd') and ('$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'arm64')">true</NativeAotSupported>
107107

108108
<!-- If we're building clr.nativeaotlibs and not building the CLR runtime, compile libraries against NativeAOT CoreLib -->
109109
<UseNativeAotCoreLib Condition="$(_subset.Contains('+clr.nativeaotlibs+')) and !$(_subset.Contains('+clr.native+')) and !$(_subset.Contains('+clr.runtime+'))">true</UseNativeAotCoreLib>

eng/Versions.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@
111111
<runtimewinx64MicrosoftNETCoreRuntimeObjWriterVersion>1.0.0-alpha.1.23059.1</runtimewinx64MicrosoftNETCoreRuntimeObjWriterVersion>
112112
<runtimeosx110arm64MicrosoftNETCoreRuntimeObjWriterVersion>1.0.0-alpha.1.23059.1</runtimeosx110arm64MicrosoftNETCoreRuntimeObjWriterVersion>
113113
<runtimeosx1012x64MicrosoftNETCoreRuntimeObjWriterVersion>1.0.0-alpha.1.23059.1</runtimeosx1012x64MicrosoftNETCoreRuntimeObjWriterVersion>
114+
<runtimefreebsdx64MicrosoftNETCoreRuntimeObjWriterVersion>1.0.0-alpha.1.23059.1</runtimefreebsdx64MicrosoftNETCoreRuntimeObjWriterVersion>
114115
<!-- Libraries dependencies -->
115116
<MicrosoftBclAsyncInterfacesVersion>6.0.0</MicrosoftBclAsyncInterfacesVersion>
116117
<MicrosoftBclHashCodeVersion>1.1.1</MicrosoftBclHashCodeVersion>
@@ -248,5 +249,6 @@
248249
<runtimewinx64MicrosoftNETCoreRuntimeJITToolsVersion>1.0.0-alpha.1.23059.1</runtimewinx64MicrosoftNETCoreRuntimeJITToolsVersion>
249250
<runtimeosx110arm64MicrosoftNETCoreRuntimeJITToolsVersion>1.0.0-alpha.1.23059.1</runtimeosx110arm64MicrosoftNETCoreRuntimeJITToolsVersion>
250251
<runtimeosx1012x64MicrosoftNETCoreRuntimeJITToolsVersion>1.0.0-alpha.1.23059.1</runtimeosx1012x64MicrosoftNETCoreRuntimeJITToolsVersion>
252+
<runtimefreebsdx64MicrosoftNETCoreRuntimeJITToolsVersion>1.0.0-alpha.1.23059.1</runtimefreebsdx64MicrosoftNETCoreRuntimeJITToolsVersion>
251253
</PropertyGroup>
252254
</Project>

src/coreclr/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ add_subdirectory(tools/aot/jitinterface)
139139

140140
if(NOT CLR_CROSS_COMPONENTS_BUILD)
141141
# NativeAOT only buildable for a subset of CoreCLR-supported configurations
142-
if((CLR_CMAKE_HOST_LINUX OR CLR_CMAKE_HOST_OSX OR CLR_CMAKE_HOST_WIN32) AND (CLR_CMAKE_HOST_ARCH_ARM64 OR CLR_CMAKE_HOST_ARCH_AMD64))
142+
if(CLR_CMAKE_HOST_ARCH_ARM64 OR CLR_CMAKE_HOST_ARCH_AMD64)
143143
add_subdirectory(nativeaot)
144144
endif()
145145
endif(NOT CLR_CROSS_COMPONENTS_BUILD)

src/coreclr/nativeaot/BuildIntegration/Microsoft.DotNet.ILCompiler.SingleEntry.targets

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<!-- Define the name of the runtime specific compiler package to import -->
55
<OSIdentifier Condition="$(RuntimeIdentifier.StartsWith('win'))">win</OSIdentifier>
66
<OSIdentifier Condition="$(RuntimeIdentifier.StartsWith('osx'))">osx</OSIdentifier>
7+
<OSIdentifier Condition="$(RuntimeIdentifier.StartsWith('freebsd'))">freebsd</OSIdentifier>
78
<OSIdentifier Condition="$(RuntimeIdentifier.StartsWith('linux-musl')) OR $(RuntimeIdentifier.StartsWith('alpine'))">linux-musl</OSIdentifier>
89
<OSIdentifier Condition="'$(OSIdentifier)' == ''">linux</OSIdentifier>
910

src/coreclr/nativeaot/BuildIntegration/Microsoft.NETCore.Native.Unix.targets

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ The .NET Foundation licenses this file to you under the MIT license.
3939
<TargetTriple />
4040
<TargetTriple Condition="'$(CrossCompileArch)' != ''">$(CrossCompileArch)-linux-gnu</TargetTriple>
4141
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('linux-musl')) or $(CrossCompileRid.StartsWith('alpine')))">$(CrossCompileArch)-alpine-linux-musl</TargetTriple>
42+
<TargetTriple Condition="'$(CrossCompileArch)' != '' and ($(CrossCompileRid.StartsWith('freebsd')))">$(CrossCompileArch)-unknown-freebsd12</TargetTriple>
4243

4344
<IlcRPath Condition="'$(IlcRPath)' == '' and '$(TargetOS)' != 'osx'">$ORIGIN</IlcRPath>
4445
<IlcRPath Condition="'$(IlcRPath)' == '' and '$(TargetOS)' == 'osx'">@executable_path</IlcRPath>
@@ -141,8 +142,12 @@ The .NET Foundation licenses this file to you under the MIT license.
141142
<LinkerArg Include="-Wl,-z,relro" Condition="'$(TargetOS)' != 'osx'" />
142143
<!-- binskim warning BA3011 The BIND_NOW flag is missing -->
143144
<LinkerArg Include="-Wl,-z,now" Condition="'$(TargetOS)' != 'osx'" />
144-
<LinkerArg Include="-Wl,-u,_NativeAOT_StaticInitialization" Condition="'$(TargetOS)' == 'osx' and '$(NativeLib)' == 'Shared'" />
145-
<LinkerArg Include="-Wl,--require-defined,NativeAOT_StaticInitialization" Condition="'$(TargetOS)' != 'osx' and '$(NativeLib)' == 'Shared'" />
145+
<LinkerArg Include="-Wl,-u,_NativeAOT_StaticInitialization" Condition="('$(TargetOS)' == 'osx' or '$(TargetOS)' == 'freebsd') and '$(NativeLib)' == 'Shared'" />
146+
<LinkerArg Include="-Wl,--require-defined,NativeAOT_StaticInitialization" Condition="('$(TargetOS)' == 'linux') and '$(NativeLib)' == 'Shared'" />
147+
<!-- FreeBSD has two versions of the GSSAPI it can use, but we only use the ports version (MIT version) here -->
148+
<LinkerArg Include="-L/usr/local/lib -lgssapi_krb5" Condition="'$(TargetOS)' == 'freebsd'" />
149+
<!-- FreeBSD's inotify is an installed package and not found in default libraries -->
150+
<LinkerArg Include="-L/usr/local/lib -linotify" Condition="'$(TargetOS)' == 'freebsd'" />
146151

147152
<LinkerArg Include="@(NativeFramework->'-framework %(Identity)')" Condition="'$(TargetOS)' == 'osx'" />
148153
</ItemGroup>

src/coreclr/tools/aot/ILCompiler/ILCompiler.props

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
<ObjWriterRidWithoutPlatform>$(RuntimeIdentifier.Substring(0, $(_objWriterRidPlatformIndex)))</ObjWriterRidWithoutPlatform>
2929
<ObjWriterRidPlatform>$(RuntimeIdentifier.Substring($(_objWriterRidPlatformIndex)).TrimStart('-'))</ObjWriterRidPlatform>
3030

31-
<!-- If it's not win/osx/linux-musl, it's a non-portable Linux. Treat as Linux. -->
32-
<ObjWriterRidWithoutPlatform Condition="'$(ObjWriterRidWithoutPlatform)' != 'win' and '$(ObjWriterRidWithoutPlatform)' != 'osx' and '$(ObjWriterRidWithoutPlatform)' != 'linux-musl'">linux</ObjWriterRidWithoutPlatform>
31+
<!-- If it's not win/osx/freebsd/linux-musl, it's a non-portable Linux. Treat as Linux. -->
32+
<ObjWriterRidWithoutPlatform Condition="'$(ObjWriterRidWithoutPlatform)' != 'win' and '$(ObjWriterRidWithoutPlatform)' != 'osx' and '$(ObjWriterRidWithoutPlatform)' != 'linux-musl' and '$(ObjWriterRidWithoutPlatform)' != 'freebsd'">linux</ObjWriterRidWithoutPlatform>
3333

3434
<!-- OSX builds have a version -->
3535
<ObjWriterRidWithoutPlatform Condition="'$(ObjWriterRidWithoutPlatform)' == 'osx' and '$(ObjWriterRidPlatform)' == 'x64'">osx.10.12</ObjWriterRidWithoutPlatform>
@@ -45,6 +45,7 @@
4545
<ObjWriterVersion Condition="'$(ObjWriterVersion)' == '' and '$(ObjWriterRid)' == 'win-x64'">$(runtimewinx64MicrosoftNETCoreRuntimeObjWriterVersion)</ObjWriterVersion>
4646
<ObjWriterVersion Condition="'$(ObjWriterVersion)' == '' and '$(ObjWriterRid)' == 'osx.11.0-arm64'">$(runtimeosx110arm64MicrosoftNETCoreRuntimeObjWriterVersion)</ObjWriterVersion>
4747
<ObjWriterVersion Condition="'$(ObjWriterVersion)' == '' and '$(ObjWriterRid)' == 'osx.10.12-x64'">$(runtimeosx1012x64MicrosoftNETCoreRuntimeObjWriterVersion)</ObjWriterVersion>
48+
<ObjWriterVersion Condition="'$(ObjWriterVersion)' == '' and '$(ObjWriterRid)' == 'freebsd-x64'">$(runtimefreebsdx64MicrosoftNETCoreRuntimeObjWriterVersion)</ObjWriterVersion>
4849

4950
<!-- CoreDisTools are used in debugging visualizers. -->
5051
<IncludeCoreDisTools Condition="'$(Configuration)' != 'Release' and '$(CrossHostArch)' == ''">true</IncludeCoreDisTools>

src/coreclr/tools/aot/ILCompiler/ILCompilerRootCommand.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ public static IEnumerable<Action<HelpContext>> GetExtendedHelp(HelpContext _)
306306
"considered to be input files. If no input files begin with '--' then this option is not necessary.\n");
307307

308308
string[] ValidArchitectures = new string[] { "arm", "arm64", "x86", "x64" };
309-
string[] ValidOS = new string[] { "windows", "linux", "osx" };
309+
string[] ValidOS = new string[] { "windows", "linux", "osx", "freebsd" };
310310

311311
Console.WriteLine("Valid switches for {0} are: '{1}'. The default value is '{2}'\n", "--targetos", string.Join("', '", ValidOS), Helpers.GetTargetOS(null).ToString().ToLowerInvariant());
312312

src/coreclr/tools/aot/ILCompiler/repro/repro.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<PlatformTarget>AnyCPU</PlatformTarget>
77
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
88
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
9-
<RuntimeIdentifiers>linux-x64;win-x64;osx-x64</RuntimeIdentifiers>
9+
<RuntimeIdentifiers>linux-x64;win-x64;osx-x64;freebsd-x64</RuntimeIdentifiers>
1010
<Configurations>Debug;Release;Checked</Configurations>
1111
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
1212
<TreatWarningsAsErrors>false</TreatWarningsAsErrors>

src/installer/managed/Microsoft.NET.HostModel/Bundle/TargetInfo.cs

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,6 @@ public TargetInfo(OSPlatform? os, Architecture? arch, Version targetFrameworkVer
3535
Arch = arch ?? RuntimeInformation.OSArchitecture;
3636
FrameworkVersion = targetFrameworkVersion ?? Environment.Version;
3737

38-
Debug.Assert(IsLinux || IsOSX || IsWindows);
39-
4038
if (FrameworkVersion.Major >= 6)
4139
{
4240
BundleMajorVersion = 6u;
@@ -79,7 +77,7 @@ public TargetInfo(OSPlatform? os, Architecture? arch, Version targetFrameworkVer
7977

8078
public bool IsNativeBinary(string filePath)
8179
{
82-
return IsLinux ? ElfUtils.IsElfImage(filePath) : IsOSX ? MachOUtils.IsMachOImage(filePath) : PEUtils.IsPEImage(filePath);
80+
return IsWindows ? PEUtils.IsPEImage(filePath) : IsOSX ? MachOUtils.IsMachOImage(filePath) : ElfUtils.IsElfImage(filePath);
8381
}
8482

8583
public string GetAssemblyName(string hostName)
@@ -91,15 +89,16 @@ public string GetAssemblyName(string hostName)
9189

9290
public override string ToString()
9391
{
94-
string os = IsWindows ? "win" : IsLinux ? "linux" : "osx";
92+
string os = IsWindows ? "win" : OS.ToString().ToLowerInvariant();
9593
string arch = Arch.ToString().ToLowerInvariant();
9694
return $"OS: {os} Arch: {arch} FrameworkVersion: {FrameworkVersion}";
9795
}
9896

97+
private static readonly OSPlatform s_freebsdOSPlatform = OSPlatform.Create("FREEBSD");
98+
9999
private static OSPlatform HostOS => RuntimeInformation.IsOSPlatform(OSPlatform.Linux) ? OSPlatform.Linux :
100-
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? OSPlatform.OSX : OSPlatform.Windows;
100+
RuntimeInformation.IsOSPlatform(OSPlatform.OSX) ? OSPlatform.OSX : RuntimeInformation.IsOSPlatform(s_freebsdOSPlatform) ? s_freebsdOSPlatform : OSPlatform.Windows;
101101

102-
public bool IsLinux => OS.Equals(OSPlatform.Linux);
103102
public bool IsOSX => OS.Equals(OSPlatform.OSX);
104103
public bool IsWindows => OS.Equals(OSPlatform.Windows);
105104

@@ -116,7 +115,7 @@ public override string ToString()
116115
public bool ShouldExclude(string relativePath) =>
117116
(FrameworkVersion.Major != 3) && (relativePath.Equals(HostFxr) || relativePath.Equals(HostPolicy));
118117

119-
private string HostFxr => IsWindows ? "hostfxr.dll" : IsLinux ? "libhostfxr.so" : "libhostfxr.dylib";
120-
private string HostPolicy => IsWindows ? "hostpolicy.dll" : IsLinux ? "libhostpolicy.so" : "libhostpolicy.dylib";
118+
private string HostFxr => IsWindows ? "hostfxr.dll" : IsOSX ? "libhostfxr.dylib" : "libhostfxr.so";
119+
private string HostPolicy => IsWindows ? "hostpolicy.dll" : IsOSX ? "libhostpolicy.dylib" : "libhostpolicy.so";
121120
}
122121
}

src/installer/pkg/projects/Microsoft.DotNet.ILCompiler/ILCompilerRIDs.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
<OfficialBuildRID Include="osx-x64" Platform="x64" />
1010
<OfficialBuildRID Include="win-arm64" Platform="arm64" />
1111
<OfficialBuildRID Include="win-x64" Platform="x64" />
12+
<OfficialBUildRID Include="freebsd-x64" Platform="x64" />
1213
</ItemGroup>
1314
</Project>

src/installer/pkg/sfx/Microsoft.NETCore.App/Microsoft.NETCore.App.Crossgen2.sfxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,10 @@
1818
<PermitDllAndExeFilesLackingFileVersion>true</PermitDllAndExeFilesLackingFileVersion>
1919
<!-- Publishing as single-file or NativeAOT means we can't examine the interior DLLs -->
2020
<ShouldVerifyClosure>false</ShouldVerifyClosure>
21+
<!-- Publish crossgen2 as a single-file app on cross-OS builds. Cross-OS NativeAOT compilation is not supported yet -->
22+
<NativeAotSupported Condition="'$(CrossBuild)' == 'true' and '$(TargetOS)' != '$(HostOS)'">false</NativeAotSupported>
23+
<!-- Can't use NativeAOT in source build yet https://github.com/dotnet/runtime/issues/66859 -->
24+
<NativeAotSupported Condition="'$(DotNetBuildFromSource)' == 'true'">false</NativeAotSupported>
2125
</PropertyGroup>
2226

2327
<Target Name="PublishCrossgen"
@@ -34,13 +38,15 @@
3438
Properties="MSBuildRestoreSessionId=$([System.Guid]::NewGuid())
3539
;_IsPublishing=true
3640
;RuntimeIdentifier=$(PackageRID)
41+
;NativeAotSupported=$(NativeAotSupported)
3742
;CoreCLRArtifactsPath=$(CoreCLRArtifactsPath)
3843
;R2ROverridePath=$(MSBuildThisFileDirectory)ReadyToRun.targets" />
3944

4045
<MSBuild Projects="$(RepoRoot)src/coreclr/tools/aot/crossgen2/crossgen2.csproj"
4146
Targets="Publish;PublishItemsOutputGroup"
4247
Properties="_IsPublishing=true
4348
;RuntimeIdentifier=$(PackageRID)
49+
;NativeAotSupported=$(NativeAotSupported)
4450
;CoreCLRArtifactsPath=$(CoreCLRArtifactsPath)
4551
;R2ROverridePath=$(MSBuildThisFileDirectory)ReadyToRun.targets">
4652
<Output TaskParameter="TargetOutputs"

src/installer/tests/Microsoft.NET.HostModel.Tests/Helpers/BundleHelper.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,7 @@ public static OSPlatform GetTargetOS(string runtimeIdentifier)
129129
"win" => OSPlatform.Windows,
130130
"osx" => OSPlatform.OSX,
131131
"linux" => OSPlatform.Linux,
132+
"freebsd" => OSPlatform.FreeBSD,
132133
_ => throw new ArgumentException(nameof(runtimeIdentifier))
133134
};
134135
}

0 commit comments

Comments
 (0)