Skip to content

Commit 582b40f

Browse files
committed
Updating the repo to target .NET 8
1 parent 482af28 commit 582b40f

File tree

99 files changed

+1641
-1471
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

99 files changed

+1641
-1471
lines changed

.editorconfig

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ end_of_line = lf
2121
insert_final_newline = true
2222
indent_style = space
2323
indent_size = 4
24+
spelling_error_severity = information
25+
spelling_exclusion_path = exclusion.dic
26+
spelling_languages = en-us
2427
tab_width = 4
2528
trim_trailing_whitespace = true
2629

.github/workflows/ci.yml

Lines changed: 10 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -28,26 +28,6 @@ jobs:
2828
./artifacts/pkg/**/*
2929
./artifacts/tst/**/*
3030
if-no-files-found: error
31-
windows-x86:
32-
runs-on: ${{ matrix.os }}-latest
33-
strategy:
34-
matrix:
35-
architecture: [ x86 ]
36-
configuration: [ debug, release ]
37-
os: [ windows ]
38-
steps:
39-
- uses: actions/checkout@v3
40-
- run: ./scripts/cibuild.cmd -configuration ${{ matrix.configuration }} -architecture ${{ matrix.architecture }} /p:PlatformTarget=${{ matrix.architecture }}
41-
shell: cmd
42-
- uses: actions/upload-artifact@v3
43-
with:
44-
name: ${{ matrix.os }}_${{ matrix.configuration }}_${{ matrix.architecture }}
45-
path: |
46-
./artifacts/bin/**/*
47-
./artifacts/log/**/*
48-
./artifacts/pkg/**/*
49-
./artifacts/tst/**/*
50-
if-no-files-found: error
5131
linux-x64:
5232
runs-on: ${{ matrix.os }}-latest
5333
strategy:
@@ -120,8 +100,8 @@ jobs:
120100
path: ./artifacts
121101
- uses: actions/setup-dotnet@v3
122102
with:
123-
dotnet-version: '6.0.x'
124-
- run: dotnet tool install --tool-path ./artifacts/tools sign --version 0.9.0-beta.23063.3
103+
global-json-file: ./global.json
104+
- run: dotnet tool install --tool-path ./artifacts/tools sign --version 0.9.1-beta.24170.3
125105
- run: ./artifacts/tools/sign code azure-key-vault "**/*.nupkg" --timestamp-url "http://timestamp.digicert.com" --base-directory "${{ github.workspace }}/artifacts/pkg" --file-list "${{ github.workspace }}/scripts/SignClientFileList.txt" --publisher-name ".NET Foundation" --description "LLVMSharp" --description-url "https://github.com/dotnet/llvmsharp" --azure-key-vault-certificate "${{ secrets.SC_KEY_VAULT_CERTIFICATE_ID }}" --azure-key-vault-client-id "${{ secrets.SC_AZURE_CLIENT_ID }}" --azure-key-vault-client-secret "${{ secrets.SC_AZURE_CLIENT_SECRET }}" --azure-key-vault-tenant-id "${{ secrets.SC_AZURE_TENANT_ID }}" --azure-key-vault-url "${{ secrets.SC_KEY_VAULT_URL }}"
126106
- uses: actions/upload-artifact@v3
127107
with:
@@ -161,8 +141,8 @@ jobs:
161141
path: ./artifacts
162142
- uses: actions/setup-dotnet@v3
163143
with:
164-
dotnet-version: '6.0.x'
165-
- run: dotnet tool install --tool-path ./artifacts/tools sign --version 0.9.0-beta.23063.3
144+
global-json-file: ./global.json
145+
- run: dotnet tool install --tool-path ./artifacts/tools sign --version 0.9.1-beta.24170.3
166146
- run: ./artifacts/tools/sign code azure-key-vault "**/*.nupkg" --timestamp-url "http://timestamp.digicert.com" --base-directory "${{ github.workspace }}/artifacts/pkg" --file-list "${{ github.workspace }}/scripts/SignClientFileList.txt" --publisher-name ".NET Foundation" --description "LLVMSharp" --description-url "https://github.com/dotnet/llvmsharp" --azure-key-vault-certificate "${{ secrets.SC_KEY_VAULT_CERTIFICATE_ID }}" --azure-key-vault-client-id "${{ secrets.SC_AZURE_CLIENT_ID }}" --azure-key-vault-client-secret "${{ secrets.SC_AZURE_CLIENT_SECRET }}" --azure-key-vault-tenant-id "${{ secrets.SC_AZURE_TENANT_ID }}" --azure-key-vault-url "${{ secrets.SC_KEY_VAULT_URL }}"
167147
- uses: actions/upload-artifact@v3
168148
with:
@@ -173,29 +153,29 @@ jobs:
173153
publish-nightlies-azure:
174154
runs-on: ubuntu-latest
175155
if: ${{ github.event_name == 'push' }}
176-
needs: [ windows-x64, windows-x86, linux-x64, macos-x64, sign-nuget-preview, sign-nuget-release ]
156+
needs: [ windows-x64, linux-x64, macos-x64, sign-nuget-preview, sign-nuget-release ]
177157
steps:
178158
- uses: actions/download-artifact@v3
179159
with:
180160
name: windows_release_x64
181161
path: ./artifacts
182-
- uses: actions/setup-dotnet@v2
162+
- uses: actions/setup-dotnet@v3
183163
with:
184-
dotnet-version: '6.0.x'
164+
dotnet-version: '8.0.x'
185165
source-url: https://pkgs.clangsharp.dev/index.json
186166
env:
187167
NUGET_AUTH_TOKEN: ${{ secrets.AZURE_DEVOPS_PAT }}
188168
- run: dotnet nuget push "./artifacts/pkg/Release/*.nupkg" --api-key AzureDevOps --skip-duplicate
189169
publish-nightlies-github:
190170
runs-on: ubuntu-latest
191171
if: false
192-
needs: [ windows-x64, windows-x86, linux-x64, macos-x64, sign-nuget-preview, sign-nuget-release ]
172+
needs: [ windows-x64, linux-x64, macos-x64, sign-nuget-preview, sign-nuget-release ]
193173
steps:
194174
- uses: actions/download-artifact@v3
195175
with:
196176
name: windows_release_x64
197177
path: ./artifacts
198-
- uses: actions/setup-dotnet@v2
178+
- uses: actions/setup-dotnet@v3
199179
with:
200-
dotnet-version: '6.0.x'
180+
dotnet-version: '8.0.x'
201181
- run: dotnet nuget push "./artifacts/pkg/Release/*.nupkg" --source https://nuget.pkg.github.com/dotnet/index.json --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate

Directory.Build.props

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
<!-- Default settings that explicitly differ from the Sdk.props defaults -->
2121
<PropertyGroup>
2222
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
23-
<AnalysisLevel>preview</AnalysisLevel>
23+
<AnalysisLevel>latest-all</AnalysisLevel>
2424
<BaseIntermediateOutputPath>$(BaseArtifactsPath)obj/$(BaseArtifactsPathSuffix)/</BaseIntermediateOutputPath>
2525
<DebugType>embedded</DebugType>
2626
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
@@ -42,7 +42,9 @@
4242
<BaseOutputPath>$(BaseArtifactsPath)bin/$(BaseArtifactsPathSuffix)/</BaseOutputPath>
4343
<Company>.NET Foundation</Company>
4444
<ContinuousIntegrationBuild Condition="'$(GITHUB_RUN_ID)' != ''">true</ContinuousIntegrationBuild>
45+
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
4546
<PackageOutputPath>$(BaseArtifactsPath)pkg/$(Configuration)/</PackageOutputPath>
47+
<PackageValidationBaselineVersion>16.0.0</PackageValidationBaselineVersion>
4648
<Product>LLVMSharp</Product>
4749
<RootNamespace>LLVMSharp</RootNamespace>
4850
<VersionPrefix>16.0.0</VersionPrefix>

Directory.Build.targets

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
<!-- Settings that append the existing setting value -->
1414
<PropertyGroup>
15-
<NoWarn>$(NoWarn);AD0001</NoWarn>
15+
<NoWarn>$(NoWarn)</NoWarn>
1616
</PropertyGroup>
1717

1818
<!-- Settings that are only set for CI builds -->
@@ -26,7 +26,7 @@
2626
</PropertyGroup>
2727

2828
<!-- Settings that are only set for libraries -->
29-
<PropertyGroup Condition="'$(OutputType)' == 'Library'">
29+
<PropertyGroup Condition="'$(OutputType)' == 'Library' AND '$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
3030
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
3131
<IsTrimmable>true</IsTrimmable>
3232
</PropertyGroup>

LLVMSharp.sln

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
1414
Directory.Build.props = Directory.Build.props
1515
Directory.Build.targets = Directory.Build.targets
1616
Directory.Packages.props = Directory.Packages.props
17+
exclusion.dic = exclusion.dic
18+
global.json = global.json
1719
LICENSE.md = LICENSE.md
1820
NOTICE.md = NOTICE.md
1921
NuGet.config = NuGet.config

exclusion.dic

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
addr
2+
aliasee
3+
alloca
4+
attrs
5+
bitcode
6+
dest
7+
funclet
8+
greaterthan
9+
instr
10+
interp
11+
lshift
12+
netscripten
13+
trunc
14+
vals
15+
xchg

global.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"sdk": {
3+
"version": "8.0.100",
4+
"allowPrerelease": true,
5+
"rollForward": "latestFeature"
6+
}
7+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0</TargetFrameworks>
55
</PropertyGroup>
66
</Project>

samples/KaleidoscopeTutorial/Chapter3/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0</TargetFrameworks>
55
</PropertyGroup>
66

77
<ItemGroup>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0</TargetFrameworks>
55
</PropertyGroup>
66
</Project>

samples/KaleidoscopeTutorial/Chapter4/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0</TargetFrameworks>
55
</PropertyGroup>
66

77
<ItemGroup>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0</TargetFrameworks>
55
</PropertyGroup>
66
</Project>

samples/KaleidoscopeTutorial/Chapter5/KaleidoscopeLLVM/KaleidoscopeLLVM.csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<Project Sdk="Microsoft.NET.Sdk">
33
<PropertyGroup>
4-
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
4+
<TargetFrameworks>net8.0</TargetFrameworks>
55
</PropertyGroup>
66

77
<ItemGroup>

scripts/build.ps1

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ try {
123123
$DotNetInstallDirectory = Join-Path -Path $ArtifactsDir -ChildPath "dotnet"
124124
Create-Directory -Path $DotNetInstallDirectory
125125

126-
& $DotNetInstallScript -Channel 6.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture
127-
& $DotNetInstallScript -Channel 7.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture
126+
& $DotNetInstallScript -Channel 8.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture
128127

129128
$env:PATH="$DotNetInstallDirectory;$env:PATH"
130129
}

scripts/build.sh

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -204,8 +204,7 @@ if [[ ! -z "$architecture" ]]; then
204204
DotNetInstallDirectory="$ArtifactsDir/dotnet"
205205
CreateDirectory "$DotNetInstallDirectory"
206206

207-
. "$DotNetInstallScript" --channel 6.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture"
208-
. "$DotNetInstallScript" --channel 7.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture"
207+
. "$DotNetInstallScript" --channel 8.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture"
209208

210209
PATH="$DotNetInstallDirectory:$PATH:"
211210
fi

sources/Directory.Build.props

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
<PropertyGroup>
1414
<EmbedUntrackedSources>true</EmbedUntrackedSources>
15+
<EnablePackageValidation>false</EnablePackageValidation>
1516
<LLVMSharpProjectCategory>sources</LLVMSharpProjectCategory>
1617
</PropertyGroup>
1718

@@ -21,8 +22,4 @@
2122
<InternalsVisibleTo Include="$(MSBuildProjectName).UnitTests" Key="$(AssemblyOriginatorPublicKey)" />
2223
</ItemGroup>
2324

24-
<ItemGroup>
25-
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="all" />
26-
</ItemGroup>
27-
2825
</Project>
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
// Copyright (c) .NET Foundation and Contributors. All Rights Reserved. Licensed under the MIT License (MIT). See License.md in the repository root for more information.
2+
3+
using System;
4+
using System.Runtime.InteropServices;
5+
6+
[assembly: DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]
7+
8+
namespace LLVMSharp.Interop;
9+
10+
internal static class Configuration
11+
{
12+
private static readonly bool s_disableResolveLibraryHook = GetAppContextData("LLVMSharp.Interop.DisableResolveLibraryHook", defaultValue: false);
13+
14+
public static bool DisableResolveLibraryHook => s_disableResolveLibraryHook;
15+
16+
private static bool GetAppContextData(string name, bool defaultValue)
17+
{
18+
object? data = AppContext.GetData(name);
19+
20+
if (data is bool value)
21+
{
22+
return value;
23+
}
24+
else if ((data is string s) && bool.TryParse(s, out bool result))
25+
{
26+
return result;
27+
}
28+
else
29+
{
30+
return defaultValue;
31+
}
32+
}
33+
}

sources/LLVMSharp.Interop/Extensions/LLVM.ResolveLibrary.cs

Lines changed: 34 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,11 @@
33
using System;
44
using System.Linq;
55
using System.Reflection;
6+
using System.Runtime.CompilerServices;
67
using System.Runtime.InteropServices;
78

9+
[assembly: DisableRuntimeMarshalling]
10+
811
namespace LLVMSharp.Interop;
912

1013
public static unsafe partial class LLVM
@@ -13,36 +16,53 @@ public static unsafe partial class LLVM
1316

1417
static LLVM()
1518
{
16-
NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), OnDllImport);
19+
if (!Configuration.DisableResolveLibraryHook)
20+
{
21+
NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), OnDllImport);
22+
}
1723
}
1824

1925
private static IntPtr OnDllImport(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
2026
{
21-
return TryResolveLibrary(libraryName, assembly, searchPath, out var nativeLibrary)
22-
? nativeLibrary
23-
: libraryName.Equals("libLLVM") && TryResolveLLVM(assembly, searchPath, out nativeLibrary)
24-
? nativeLibrary
25-
: IntPtr.Zero;
27+
if (TryResolveLibrary(libraryName, assembly, searchPath, out var nativeLibrary))
28+
{
29+
return nativeLibrary;
30+
}
31+
32+
if (libraryName.Equals("libLLVM", StringComparison.Ordinal) && TryResolveLLVM(assembly, searchPath, out nativeLibrary))
33+
{
34+
return nativeLibrary;
35+
}
36+
37+
return IntPtr.Zero;
2638
}
2739

2840
private static bool TryResolveLLVM(Assembly assembly, DllImportSearchPath? searchPath, out IntPtr nativeLibrary)
2941
{
30-
return (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && NativeLibrary.TryLoad("libLLVM.so.14", assembly, searchPath, out nativeLibrary))
31-
|| (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && NativeLibrary.TryLoad("libLLVM-14", assembly, searchPath, out nativeLibrary))
32-
|| (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && NativeLibrary.TryLoad("libLLVM.so.1", assembly, searchPath, out nativeLibrary))
33-
|| (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && NativeLibrary.TryLoad("LLVM-C.dll", assembly, searchPath, out nativeLibrary))
34-
|| NativeLibrary.TryLoad("libLLVM", assembly, searchPath, out nativeLibrary);
42+
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
43+
{
44+
return NativeLibrary.TryLoad("libLLVM.so.16", assembly, searchPath, out nativeLibrary)
45+
|| NativeLibrary.TryLoad("libLLVM-16", assembly, searchPath, out nativeLibrary)
46+
|| NativeLibrary.TryLoad("libLLVM.so.1", assembly, searchPath, out nativeLibrary);
47+
}
48+
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
49+
{
50+
return NativeLibrary.TryLoad("LLVM-C.dll", assembly, searchPath, out nativeLibrary);
51+
}
52+
53+
nativeLibrary = IntPtr.Zero;
54+
return false;
3555
}
3656

3757
private static bool TryResolveLibrary(string libraryName, Assembly assembly, DllImportSearchPath? searchPath, out IntPtr nativeLibrary)
3858
{
3959
var resolveLibrary = ResolveLibrary;
4060

41-
if (resolveLibrary != null)
61+
if (resolveLibrary is not null)
4262
{
43-
var resolvers = resolveLibrary.GetInvocationList();
63+
var resolvers = resolveLibrary.GetInvocationList().Cast<DllImportResolver>();
4464

45-
foreach (DllImportResolver resolver in resolvers.Cast<DllImportResolver>())
65+
foreach (DllImportResolver resolver in resolvers)
4666
{
4767
nativeLibrary = resolver(libraryName, assembly, searchPath);
4868

sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,9 @@
44

55
namespace LLVMSharp.Interop;
66

7-
public unsafe partial struct LLVMAttributeRef : IEquatable<LLVMAttributeRef>
7+
public unsafe partial struct LLVMAttributeRef(IntPtr handle) : IEquatable<LLVMAttributeRef>
88
{
9-
public IntPtr Handle;
10-
11-
public LLVMAttributeRef(IntPtr handle)
12-
{
13-
Handle = handle;
14-
}
9+
public IntPtr Handle = handle;
1510

1611
public readonly uint Kind => LLVM.GetEnumAttributeKind(this);
1712

@@ -25,11 +20,11 @@ public LLVMAttributeRef(IntPtr handle)
2520

2621
public static bool operator !=(LLVMAttributeRef left, LLVMAttributeRef right) => !(left == right);
2722

28-
public override bool Equals(object? obj) => (obj is LLVMAttributeRef other) && Equals(other);
23+
public override readonly bool Equals(object? obj) => (obj is LLVMAttributeRef other) && Equals(other);
2924

30-
public bool Equals(LLVMAttributeRef other) => this == other;
25+
public readonly bool Equals(LLVMAttributeRef other) => this == other;
3126

32-
public override int GetHashCode() => Handle.GetHashCode();
27+
public override readonly int GetHashCode() => Handle.GetHashCode();
3328

34-
public override string ToString() => $"{nameof(LLVMAttributeRef)}: {Handle:X}";
29+
public override readonly string ToString() => $"{nameof(LLVMAttributeRef)}: {Handle:X}";
3530
}

0 commit comments

Comments
 (0)