Skip to content

Commit

Permalink
Get the project to compile after updating to .NET 7
Browse files Browse the repository at this point in the history
  • Loading branch information
Thealexbarney committed Nov 23, 2022
1 parent fe8699e commit ffc9a76
Show file tree
Hide file tree
Showing 95 changed files with 409 additions and 253 deletions.
2 changes: 1 addition & 1 deletion DotnetCliVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
6.0.403
7.0.100
8 changes: 4 additions & 4 deletions build/Build.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ partial class Build : NukeBuild
AbsolutePath ArtifactsDirectory => RootDirectory / "artifacts";
AbsolutePath SignedArtifactsDirectory => ArtifactsDirectory / "signed";
AbsolutePath TempDirectory => RootDirectory / ".nuke" / "temp";
AbsolutePath CliCoreDir => TempDirectory / "hactoolnet_net6.0";
AbsolutePath CliCoreDir => TempDirectory / "hactoolnet_net7.0";
AbsolutePath CliNativeDir => TempDirectory / $"hactoolnet_{HostOsName}";
AbsolutePath CliNativeExe => CliNativeDir / $"hactoolnet{NativeProgramExtension}";
AbsolutePath CliCoreZip => ArtifactsDirectory / $"hactoolnet-{VersionString}-netcore.zip";
Expand Down Expand Up @@ -229,7 +229,7 @@ public Build()

DotNetPublish(s => publishSettings
.SetProject(HactoolnetProject)
.SetFramework("net6.0")
.SetFramework("net7.0")
.SetOutput(CliCoreDir)
.SetNoBuild(true)
.SetProperties(VersionProps));
Expand Down Expand Up @@ -279,7 +279,7 @@ public Build()
.EnableNoBuild()
.SetConfiguration(Configuration);

if (EnvironmentInfo.IsUnix) settings = settings.SetProperty("TargetFramework", "net6.0");
if (EnvironmentInfo.IsUnix) settings = settings.SetProperty("TargetFramework", "net7.0");

DotNetTest(s => settings);
});
Expand Down Expand Up @@ -596,7 +596,7 @@ public void SignAndReZip(string password)
SignAssemblies(password, toSign.Select(x => x.ToString()).ToArray());

// Avoid having multiple signed versions of the same file
File.Copy(nupkgDir / "lib" / "net6.0" / "LibHac.dll", coreFxDir / "LibHac.dll", true);
File.Copy(nupkgDir / "lib" / "net7.0" / "LibHac.dll", coreFxDir / "LibHac.dll", true);

ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(nupkgFile), nupkgDir, pkgFileList, CommitTime);
ZipDirectory(SignedArtifactsDirectory / Path.GetFileName(CliCoreZip), coreFxDir, CommitTime);
Expand Down
1 change: 0 additions & 1 deletion build/CodeGen/Common.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System.Linq;
using System.Reflection;
using System.Text;
using Nuke.Common;

namespace LibHacBuild.CodeGen;

Expand Down
2 changes: 1 addition & 1 deletion build/CodeGen/_buildCodeGen.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<RootNamespace>LibHacBuild.CodeGen</RootNamespace>
<IsPackable>False</IsPackable>
Expand Down
2 changes: 1 addition & 1 deletion build/_build.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<TargetFramework>net7.0</TargetFramework>
<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<RootNamespace>LibHacBuild</RootNamespace>
<IsPackable>False</IsPackable>
Expand Down
1 change: 0 additions & 1 deletion nuget.config
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,5 @@
<configuration>
<packageSources>
<add key="dotnet-core" value="https://dotnetfeed.blob.core.windows.net/dotnet-core/index.json" />
<add key="dotnet-experimental" value="https://pkgs.dev.azure.com/dnceng/public/_packaging/dotnet-experimental/nuget/v3/index.json" />
</packageSources>
</configuration>
2 changes: 2 additions & 0 deletions src/LibHac/Account/Uid.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using LibHac.Common;

Expand Down Expand Up @@ -43,6 +44,7 @@ public int CompareTo(object obj)

public void ToBytes(Span<byte> output) => Id.ToBytes(output);

[UnscopedRef]
public ReadOnlySpan<byte> AsBytes()
{
return SpanHelpers.AsByteSpan(ref this);
Expand Down
9 changes: 5 additions & 4 deletions src/LibHac/Boot/KeyBlob.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using LibHac.Common;
using LibHac.Common.FixedArrays;
Expand All @@ -13,8 +14,8 @@ public struct EncryptedKeyBlob
public AesIv Counter;
public Array144<byte> Payload;

public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
public readonly ReadOnlySpan<byte> BytesRo => SpanHelpers.AsReadOnlyByteSpan(in this);
[UnscopedRef] public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
[UnscopedRef] public readonly ReadOnlySpan<byte> BytesRo => SpanHelpers.AsReadOnlyByteSpan(in this);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool IsZeros()
Expand All @@ -41,8 +42,8 @@ public struct KeyBlob
public Array112<byte> Unused;
public AesKey Package1Key;

public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
public readonly ReadOnlySpan<byte> BytesRo => SpanHelpers.AsReadOnlyByteSpan(in this);
[UnscopedRef] public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
[UnscopedRef] public readonly ReadOnlySpan<byte> BytesRo => SpanHelpers.AsReadOnlyByteSpan(in this);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly bool IsZeros()
Expand Down
5 changes: 3 additions & 2 deletions src/LibHac/Boot/Package1.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using LibHac.Common;
Expand Down Expand Up @@ -35,8 +36,8 @@ public struct Package1MetaData
public byte KeyGeneration;
public byte Version;

public U8Span BuildDate => new U8Span(_buildDate);
public ReadOnlySpan<byte> Iv => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_buildDate.Items), 0x10);
[UnscopedRef] public U8Span BuildDate => new U8Span(_buildDate);
[UnscopedRef] public ReadOnlySpan<byte> Iv => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_buildDate.Items), 0x10);
}

public struct Package1Stage1Footer
Expand Down
17 changes: 9 additions & 8 deletions src/LibHac/Common/Buffer.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using LibHac.Util;
Expand All @@ -22,7 +23,7 @@ public byte this[int i]
set => Bytes[i] = value;
}

public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
[UnscopedRef] public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);

// Prevent a defensive copy by changing the read-only in reference to a reference with Unsafe.AsRef()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand All @@ -37,7 +38,7 @@ public static implicit operator ReadOnlySpan<byte>(in Buffer16 value)
return SpanHelpers.AsReadOnlyByteSpan(in value);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref T As<T>() where T : unmanaged
{
if (Unsafe.SizeOf<T>() > (uint)Unsafe.SizeOf<Buffer16>())
Expand All @@ -48,13 +49,13 @@ public ref T As<T>() where T : unmanaged
return ref MemoryMarshal.GetReference(AsSpan<T>());
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<T> AsSpan<T>() where T : unmanaged
{
return SpanHelpers.AsSpan<Buffer16, T>(ref this);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ReadOnlySpan<T> AsReadOnlySpan<T>() where T : unmanaged
{
return SpanHelpers.AsReadOnlySpan<Buffer16, T>(in this);
Expand All @@ -80,7 +81,7 @@ public byte this[int i]
set => Bytes[i] = value;
}

public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);
[UnscopedRef] public Span<byte> Bytes => SpanHelpers.AsByteSpan(ref this);

// Prevent a defensive copy by changing the read-only in reference to a reference with Unsafe.AsRef()
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand All @@ -95,7 +96,7 @@ public static implicit operator ReadOnlySpan<byte>(in Buffer32 value)
return SpanHelpers.AsReadOnlyByteSpan(in value);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)]
public ref T As<T>() where T : unmanaged
{
if (Unsafe.SizeOf<T>() > (uint)Unsafe.SizeOf<Buffer32>())
Expand All @@ -106,13 +107,13 @@ public ref T As<T>() where T : unmanaged
return ref MemoryMarshal.GetReference(AsSpan<T>());
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)]
public Span<T> AsSpan<T>() where T : unmanaged
{
return SpanHelpers.AsSpan<Buffer32, T>(ref this);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
[UnscopedRef, MethodImpl(MethodImplOptions.AggressiveInlining)]
public readonly ReadOnlySpan<T> AsReadOnlySpan<T>() where T : unmanaged
{
return SpanHelpers.AsReadOnlySpan<Buffer32, T>(in this);
Expand Down
7 changes: 4 additions & 3 deletions src/LibHac/Common/FixedArrays/Array1.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace LibHac.Common.FixedArrays;
Expand All @@ -10,10 +11,10 @@ public struct Array1<T>

private T _0;

public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];

public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[UnscopedRef] public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
[UnscopedRef] public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ReadOnlySpan<T>(in Array1<T> value) => value.ItemsRo;
Expand Down
5 changes: 4 additions & 1 deletion src/LibHac/Common/FixedArrays/Array1024.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

Expand All @@ -12,14 +13,16 @@ public struct Array1024<T>
private Array512<T> _0;
private Array512<T> _512;

public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];

[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}

[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
7 changes: 4 additions & 3 deletions src/LibHac/Common/FixedArrays/Array11.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace LibHac.Common.FixedArrays;
Expand All @@ -20,10 +21,10 @@ public struct Array11<T>
private T _9;
private T _10;

public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];

public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[UnscopedRef] public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
[UnscopedRef] public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ReadOnlySpan<T>(in Array11<T> value) => value.ItemsRo;
Expand Down
5 changes: 4 additions & 1 deletion src/LibHac/Common/FixedArrays/Array112.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

Expand All @@ -12,14 +13,16 @@ public struct Array112<T>
private Array80<T> _0;
private Array32<T> _80;

public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];

[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}

[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
7 changes: 4 additions & 3 deletions src/LibHac/Common/FixedArrays/Array12.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;

namespace LibHac.Common.FixedArrays;
Expand All @@ -21,10 +22,10 @@ public struct Array12<T>
private T _10;
private T _11;

public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];

public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);
[UnscopedRef] public Span<T> Items => SpanHelpers.CreateSpan(ref _0, Length);
[UnscopedRef] public readonly ReadOnlySpan<T> ItemsRo => SpanHelpers.CreateReadOnlySpan(in _0, Length);

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static implicit operator ReadOnlySpan<T>(in Array12<T> value) => value.ItemsRo;
Expand Down
5 changes: 4 additions & 1 deletion src/LibHac/Common/FixedArrays/Array128.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

Expand All @@ -12,14 +13,16 @@ public struct Array128<T>
private Array64<T> _0;
private Array64<T> _64;

public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];

[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}

[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
5 changes: 4 additions & 1 deletion src/LibHac/Common/FixedArrays/Array14.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

Expand All @@ -12,14 +13,16 @@ public struct Array14<T>
private Array8<T> _0;
private Array6<T> _8;

public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];

[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}

[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
5 changes: 4 additions & 1 deletion src/LibHac/Common/FixedArrays/Array144.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma warning disable CS0169, CS0649, IDE0051 // Field is never used, Field is never assigned to, Remove unused private members
using System;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

Expand All @@ -12,14 +13,16 @@ public struct Array144<T>
private Array128<T> _0;
private Array16<T> _128;

public ref T this[int i] => ref Items[i];
[UnscopedRef] public ref T this[int i] => ref Items[i];

[UnscopedRef]
public Span<T> Items
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
get => SpanHelpers.CreateSpan(ref MemoryMarshal.GetReference(_0.Items), Length);
}

[UnscopedRef]
public readonly ReadOnlySpan<T> ItemsRo
{
[MethodImpl(MethodImplOptions.AggressiveInlining)]
Expand Down
Loading

0 comments on commit ffc9a76

Please sign in to comment.