Skip to content

Commit

Permalink
Merge pull request #223 from tannergooding/main
Browse files Browse the repository at this point in the history
Updating the repo to target .NET 8
  • Loading branch information
tannergooding authored Apr 29, 2024
2 parents 482af28 + 8dfd177 commit 5562197
Show file tree
Hide file tree
Showing 99 changed files with 1,643 additions and 1,471 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ end_of_line = lf
insert_final_newline = true
indent_style = space
indent_size = 4
spelling_error_severity = information
spelling_exclusion_path = exclusion.dic
spelling_languages = en-us
tab_width = 4
trim_trailing_whitespace = true

Expand Down
40 changes: 10 additions & 30 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,26 +28,6 @@ jobs:
./artifacts/pkg/**/*
./artifacts/tst/**/*
if-no-files-found: error
windows-x86:
runs-on: ${{ matrix.os }}-latest
strategy:
matrix:
architecture: [ x86 ]
configuration: [ debug, release ]
os: [ windows ]
steps:
- uses: actions/checkout@v3
- run: ./scripts/cibuild.cmd -configuration ${{ matrix.configuration }} -architecture ${{ matrix.architecture }} /p:PlatformTarget=${{ matrix.architecture }}
shell: cmd
- uses: actions/upload-artifact@v3
with:
name: ${{ matrix.os }}_${{ matrix.configuration }}_${{ matrix.architecture }}
path: |
./artifacts/bin/**/*
./artifacts/log/**/*
./artifacts/pkg/**/*
./artifacts/tst/**/*
if-no-files-found: error
linux-x64:
runs-on: ${{ matrix.os }}-latest
strategy:
Expand Down Expand Up @@ -120,8 +100,8 @@ jobs:
path: ./artifacts
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
- run: dotnet tool install --tool-path ./artifacts/tools sign --version 0.9.0-beta.23063.3
global-json-file: ./global.json
- run: dotnet tool install --tool-path ./artifacts/tools sign --version 0.9.1-beta.24170.3
- 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 }}"
- uses: actions/upload-artifact@v3
with:
Expand Down Expand Up @@ -161,8 +141,8 @@ jobs:
path: ./artifacts
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
- run: dotnet tool install --tool-path ./artifacts/tools sign --version 0.9.0-beta.23063.3
global-json-file: ./global.json
- run: dotnet tool install --tool-path ./artifacts/tools sign --version 0.9.1-beta.24170.3
- 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 }}"
- uses: actions/upload-artifact@v3
with:
Expand All @@ -173,29 +153,29 @@ jobs:
publish-nightlies-azure:
runs-on: ubuntu-latest
if: ${{ github.event_name == 'push' }}
needs: [ windows-x64, windows-x86, linux-x64, macos-x64, sign-nuget-preview, sign-nuget-release ]
needs: [ windows-x64, linux-x64, macos-x64, sign-nuget-preview, sign-nuget-release ]
steps:
- uses: actions/download-artifact@v3
with:
name: windows_release_x64
path: ./artifacts
- uses: actions/setup-dotnet@v2
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
dotnet-version: '8.0.x'
source-url: https://pkgs.clangsharp.dev/index.json
env:
NUGET_AUTH_TOKEN: ${{ secrets.AZURE_DEVOPS_PAT }}
- run: dotnet nuget push "./artifacts/pkg/Release/*.nupkg" --api-key AzureDevOps --skip-duplicate
publish-nightlies-github:
runs-on: ubuntu-latest
if: false
needs: [ windows-x64, windows-x86, linux-x64, macos-x64, sign-nuget-preview, sign-nuget-release ]
needs: [ windows-x64, linux-x64, macos-x64, sign-nuget-preview, sign-nuget-release ]
steps:
- uses: actions/download-artifact@v3
with:
name: windows_release_x64
path: ./artifacts
- uses: actions/setup-dotnet@v2
- uses: actions/setup-dotnet@v3
with:
dotnet-version: '6.0.x'
dotnet-version: '8.0.x'
- run: dotnet nuget push "./artifacts/pkg/Release/*.nupkg" --source https://nuget.pkg.github.com/dotnet/index.json --api-key ${{ secrets.GITHUB_TOKEN }} --skip-duplicate
4 changes: 3 additions & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<!-- Default settings that explicitly differ from the Sdk.props defaults -->
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<AnalysisLevel>preview</AnalysisLevel>
<AnalysisLevel>latest-all</AnalysisLevel>
<BaseIntermediateOutputPath>$(BaseArtifactsPath)obj/$(BaseArtifactsPathSuffix)/</BaseIntermediateOutputPath>
<DebugType>embedded</DebugType>
<EnableDefaultNoneItems>false</EnableDefaultNoneItems>
Expand All @@ -42,7 +42,9 @@
<BaseOutputPath>$(BaseArtifactsPath)bin/$(BaseArtifactsPathSuffix)/</BaseOutputPath>
<Company>.NET Foundation</Company>
<ContinuousIntegrationBuild Condition="'$(GITHUB_RUN_ID)' != ''">true</ContinuousIntegrationBuild>
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
<PackageOutputPath>$(BaseArtifactsPath)pkg/$(Configuration)/</PackageOutputPath>
<PackageValidationBaselineVersion>16.0.0</PackageValidationBaselineVersion>
<Product>LLVMSharp</Product>
<RootNamespace>LLVMSharp</RootNamespace>
<VersionPrefix>16.0.0</VersionPrefix>
Expand Down
4 changes: 2 additions & 2 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

<!-- Settings that append the existing setting value -->
<PropertyGroup>
<NoWarn>$(NoWarn);AD0001</NoWarn>
<NoWarn>$(NoWarn)</NoWarn>
</PropertyGroup>

<!-- Settings that are only set for CI builds -->
Expand All @@ -26,7 +26,7 @@
</PropertyGroup>

<!-- Settings that are only set for libraries -->
<PropertyGroup Condition="'$(OutputType)' == 'Library'">
<PropertyGroup Condition="'$(OutputType)' == 'Library' AND '$(TargetFrameworkIdentifier)' == '.NETCoreApp'">
<EnableTrimAnalyzer>true</EnableTrimAnalyzer>
<IsTrimmable>true</IsTrimmable>
</PropertyGroup>
Expand Down
2 changes: 2 additions & 0 deletions LLVMSharp.sln
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Directory.Build.props = Directory.Build.props
Directory.Build.targets = Directory.Build.targets
Directory.Packages.props = Directory.Packages.props
exclusion.dic = exclusion.dic
global.json = global.json
LICENSE.md = LICENSE.md
NOTICE.md = NOTICE.md
NuGet.config = NuGet.config
Expand Down
15 changes: 15 additions & 0 deletions exclusion.dic
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
addr
aliasee
alloca
attrs
bitcode
dest
funclet
greaterthan
instr
interp
lshift
netscripten
trunc
vals
xchg
7 changes: 7 additions & 0 deletions global.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"sdk": {
"version": "8.0.100",
"allowPrerelease": true,
"rollForward": "latestFeature"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>
</Project>
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net6.0;net7.0</TargetFrameworks>
<TargetFrameworks>net8.0</TargetFrameworks>
</PropertyGroup>

<ItemGroup>
Expand Down
3 changes: 1 addition & 2 deletions scripts/build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,7 @@ try {
$DotNetInstallDirectory = Join-Path -Path $ArtifactsDir -ChildPath "dotnet"
Create-Directory -Path $DotNetInstallDirectory

& $DotNetInstallScript -Channel 6.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture
& $DotNetInstallScript -Channel 7.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture
& $DotNetInstallScript -Channel 8.0 -Version latest -InstallDir $DotNetInstallDirectory -Architecture $architecture

$env:PATH="$DotNetInstallDirectory;$env:PATH"
}
Expand Down
3 changes: 1 addition & 2 deletions scripts/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ if [[ ! -z "$architecture" ]]; then
DotNetInstallDirectory="$ArtifactsDir/dotnet"
CreateDirectory "$DotNetInstallDirectory"

. "$DotNetInstallScript" --channel 6.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture"
. "$DotNetInstallScript" --channel 7.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture"
. "$DotNetInstallScript" --channel 8.0 --version latest --install-dir "$DotNetInstallDirectory" --architecture "$architecture"

PATH="$DotNetInstallDirectory:$PATH:"
fi
Expand Down
5 changes: 1 addition & 4 deletions sources/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

<PropertyGroup>
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<EnablePackageValidation>false</EnablePackageValidation>
<LLVMSharpProjectCategory>sources</LLVMSharpProjectCategory>
</PropertyGroup>

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

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" PrivateAssets="all" />
</ItemGroup>

</Project>
33 changes: 33 additions & 0 deletions sources/LLVMSharp.Interop/Configuration.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// 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.

using System;
using System.Runtime.InteropServices;

[assembly: DefaultDllImportSearchPaths(DllImportSearchPath.SafeDirectories)]

namespace LLVMSharp.Interop;

internal static class Configuration
{
private static readonly bool s_disableResolveLibraryHook = GetAppContextData("LLVMSharp.Interop.DisableResolveLibraryHook", defaultValue: false);

public static bool DisableResolveLibraryHook => s_disableResolveLibraryHook;

private static bool GetAppContextData(string name, bool defaultValue)
{
object? data = AppContext.GetData(name);

if (data is bool value)
{
return value;
}
else if ((data is string s) && bool.TryParse(s, out bool result))
{
return result;
}
else
{
return defaultValue;
}
}
}
48 changes: 34 additions & 14 deletions sources/LLVMSharp.Interop/Extensions/LLVM.ResolveLibrary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@
using System;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

[assembly: DisableRuntimeMarshalling]

namespace LLVMSharp.Interop;

public static unsafe partial class LLVM
Expand All @@ -13,36 +16,53 @@ public static unsafe partial class LLVM

static LLVM()
{
NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), OnDllImport);
if (!Configuration.DisableResolveLibraryHook)
{
NativeLibrary.SetDllImportResolver(Assembly.GetExecutingAssembly(), OnDllImport);
}
}

private static IntPtr OnDllImport(string libraryName, Assembly assembly, DllImportSearchPath? searchPath)
{
return TryResolveLibrary(libraryName, assembly, searchPath, out var nativeLibrary)
? nativeLibrary
: libraryName.Equals("libLLVM") && TryResolveLLVM(assembly, searchPath, out nativeLibrary)
? nativeLibrary
: IntPtr.Zero;
if (TryResolveLibrary(libraryName, assembly, searchPath, out var nativeLibrary))
{
return nativeLibrary;
}

if (libraryName.Equals("libLLVM", StringComparison.Ordinal) && TryResolveLLVM(assembly, searchPath, out nativeLibrary))
{
return nativeLibrary;
}

return IntPtr.Zero;
}

private static bool TryResolveLLVM(Assembly assembly, DllImportSearchPath? searchPath, out IntPtr nativeLibrary)
{
return (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && NativeLibrary.TryLoad("libLLVM.so.14", assembly, searchPath, out nativeLibrary))
|| (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && NativeLibrary.TryLoad("libLLVM-14", assembly, searchPath, out nativeLibrary))
|| (RuntimeInformation.IsOSPlatform(OSPlatform.Linux) && NativeLibrary.TryLoad("libLLVM.so.1", assembly, searchPath, out nativeLibrary))
|| (RuntimeInformation.IsOSPlatform(OSPlatform.Windows) && NativeLibrary.TryLoad("LLVM-C.dll", assembly, searchPath, out nativeLibrary))
|| NativeLibrary.TryLoad("libLLVM", assembly, searchPath, out nativeLibrary);
if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return NativeLibrary.TryLoad("libLLVM.so.16", assembly, searchPath, out nativeLibrary)
|| NativeLibrary.TryLoad("libLLVM-16", assembly, searchPath, out nativeLibrary)
|| NativeLibrary.TryLoad("libLLVM.so.1", assembly, searchPath, out nativeLibrary);
}
else if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux))
{
return NativeLibrary.TryLoad("LLVM-C.dll", assembly, searchPath, out nativeLibrary);
}

nativeLibrary = IntPtr.Zero;
return false;
}

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

if (resolveLibrary != null)
if (resolveLibrary is not null)
{
var resolvers = resolveLibrary.GetInvocationList();
var resolvers = resolveLibrary.GetInvocationList().Cast<DllImportResolver>();

foreach (DllImportResolver resolver in resolvers.Cast<DllImportResolver>())
foreach (DllImportResolver resolver in resolvers)
{
nativeLibrary = resolver(libraryName, assembly, searchPath);

Expand Down
17 changes: 6 additions & 11 deletions sources/LLVMSharp.Interop/Extensions/LLVMAttributeRef.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,9 @@

namespace LLVMSharp.Interop;

public unsafe partial struct LLVMAttributeRef : IEquatable<LLVMAttributeRef>
public unsafe partial struct LLVMAttributeRef(IntPtr handle) : IEquatable<LLVMAttributeRef>
{
public IntPtr Handle;

public LLVMAttributeRef(IntPtr handle)
{
Handle = handle;
}
public IntPtr Handle = handle;

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

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

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

public override bool Equals(object? obj) => (obj is LLVMAttributeRef other) && Equals(other);
public override readonly bool Equals(object? obj) => (obj is LLVMAttributeRef other) && Equals(other);

public bool Equals(LLVMAttributeRef other) => this == other;
public readonly bool Equals(LLVMAttributeRef other) => this == other;

public override int GetHashCode() => Handle.GetHashCode();
public override readonly int GetHashCode() => Handle.GetHashCode();

public override string ToString() => $"{nameof(LLVMAttributeRef)}: {Handle:X}";
public override readonly string ToString() => $"{nameof(LLVMAttributeRef)}: {Handle:X}";
}
Loading

0 comments on commit 5562197

Please sign in to comment.