Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions .github/workflows/build-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
- name: Install Prerequisites
run: |
brew update
brew install icu4c libdeflate argon2
brew install icu4c argon2
- name: Set Library Path
run: echo "DYLD_LIBRARY_PATH=/opt/homebrew/lib:$DYLD_LIBRARY_PATH" >> $GITHUB_ENV
- name: Build
Expand Down Expand Up @@ -129,13 +129,13 @@ jobs:
# unversioned .so symlink and mask the very thing the binding packages now probe for, so a
# regression in versioned-SONAME resolution would sail through CI.
- name: Install Prerequisites using dnf
run: dnf makecache --refresh && dnf install -y findutils libicu libdeflate libargon2 tzdata
run: dnf makecache --refresh && dnf install -y findutils libicu isa-l libargon2 tzdata
if: ${{ matrix.packageManager == 'dnf' }}
# ICU's runtime package carries the ABI version in its name (libicu70 on jammy, libicu76 on
# trixie) and has no stable alias, so match it by pattern. libicu-dev was the old way to stay
# version-independent, but it drags in the unversioned symlink and defeats the check below.
- name: Install Prerequisites using apt
run: apt-get update -y && apt-get install -y curl '^libicu[0-9]+$' libdeflate0 libargon2-1 tzdata
run: apt-get update -y && apt-get install -y curl '^libicu[0-9]+$' libisal2 libargon2-1 tzdata
if: ${{ matrix.packageManager == 'apt' }}
# Versioned-SONAME resolution is only under test while the unversioned symlink is absent. If a
# base image or a package ever starts shipping it, every probe would succeed on the first try
Expand All @@ -144,7 +144,7 @@ jobs:
- name: Assert the unversioned .so symlinks are absent
run: |
found=""
for lib in libicuuc libicui18n libdeflate libargon2; do
for lib in libicuuc libicui18n libisal libargon2; do
hit=$(ls /usr/lib/*/"$lib".so /usr/lib64/"$lib".so 2>/dev/null || true)
if [ -n "$hit" ]; then
found="$found $hit"
Expand Down
30 changes: 17 additions & 13 deletions Projects/BuildTool/Prerequisites/NativeLibraryChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@ public static (string Description, string[] InstallCommands) GetRequirementsForT
"macOS",
[
".NET 11 Runtime — https://dotnet.microsoft.com/download/dotnet/11.0",
"brew install icu4c libdeflate zstd argon2"
"brew install icu4c argon2",
"Intel Macs also: brew install isa-l (Apple Silicon uses the copy bundled with IGzip.Bindings)"
]
),
"linux" => (
"Linux",
[
".NET 11 Runtime — https://dotnet.microsoft.com/download/dotnet/11.0",
"Debian/Ubuntu: sudo apt-get install -y libdeflate0 libargon2-1 libicuNN tzdata",
"Debian/Ubuntu: sudo apt-get install -y libisal2 libargon2-1 libicuNN tzdata",
" (libicuNN varies by release, e.g. libicu76 — run build-tool --check-prereqs there for the exact name)",
" (add tzdata-legacy if the shard is configured with an alias such as US/Eastern)",
"Fedora/RHEL: sudo dnf install -y libdeflate libargon2 libicu tzdata",
"Fedora/RHEL: sudo dnf install -y isa-l libargon2 libicu tzdata",
"CentOS: Also requires epel-release and CRB enabled"
]
),
Expand Down Expand Up @@ -136,7 +137,10 @@ private static List<PrerequisiteResult> CheckMacOS()
}

// Check required Homebrew formulae
var formulae = new[] { "icu4c", "libdeflate", "zstd", "argon2" };
// IGzip.Bindings bundles libisal for osx-arm64 only; Intel Macs need Homebrew's.
var formulae = RuntimeInformation.OSArchitecture == Architecture.Arm64
? new[] { "icu4c", "argon2" }
: new[] { "icu4c", "isa-l", "argon2" };
var listResult = ProcessRunner.RunCaptured("brew", "list --formula");
var installedFormulae = listResult.Success
? new HashSet<string>(
Expand Down Expand Up @@ -187,7 +191,7 @@ private static readonly (string Name, int MinSoVersion, int MaxSoVersion)[] _lin
[
("libicuuc", 60, 120),
("libicui18n", 60, 120),
("libdeflate", 0, 9),
("libisal", 0, 9),
("libargon2", 0, 9)
];

Expand Down Expand Up @@ -319,10 +323,10 @@ private static string BuildInstallCommand(PlatformInfo platform, List<string> mi
var packages = missing.Select(
library => library switch
{
"libdeflate" => "libdeflate0",
"libargon2" => "libargon2-1",
"tzdata" => "tzdata",
_ => _aptIcuPackage ??= ResolveAptIcuPackage()
"libisal" => "libisal2",
"libargon2" => "libargon2-1",
"tzdata" => "tzdata",
_ => _aptIcuPackage ??= ResolveAptIcuPackage()
}
).Distinct();

Expand All @@ -333,10 +337,10 @@ private static string BuildInstallCommand(PlatformInfo platform, List<string> mi
var packages = missing.Select(
library => library switch
{
"libdeflate" => "libdeflate",
"libargon2" => "libargon2",
"tzdata" => "tzdata",
_ => "libicu"
"libisal" => "isa-l",
"libargon2" => "libargon2",
"tzdata" => "tzdata",
_ => "libicu"
}
).Distinct();

Expand Down
2 changes: 1 addition & 1 deletion Projects/Server.Tests/Server.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<RootNamespace>Server.Tests</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.SkippableFact" Version="1.5.85" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.1">
Expand Down
2 changes: 1 addition & 1 deletion Projects/Server/Client/MultiData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private static void LoadUOP(string path)
}

var decompressedSize = entry.Size;
if (Deflate.Standard.Unpack(compressionBuffer, buffer, out var bytesDecompressed) != LibDeflateResult.Success
if (Deflate.Standard.Unpack(compressionBuffer, buffer, out var bytesDecompressed) != IGzipResult.Success
|| decompressedSize != bytesDecompressed)
{
throw new FileLoadException($"Error loading file {stream.Name}. Failed to unpack entry {i}.");
Expand Down
10 changes: 2 additions & 8 deletions Projects/Server/Compression/Deflate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,9 @@ namespace Server.Compression;
public static class Deflate
{
[ThreadStatic]
private static LibDeflateBinding _standard;
private static IGzipBinding _standard;

[ThreadStatic]
private static LibDeflateBinding _maximum;

public static LibDeflateBinding Standard => _standard ??= new LibDeflateBinding();

// Best-ratio compressor, cached per thread like Standard (construction allocates native state).
public static LibDeflateBinding Maximum => _maximum ??= new LibDeflateBinding(LibDeflateCompressionLevel.VeryHigh);
public static IGzipBinding Standard => _standard ??= new IGzipBinding();

/// <summary>
/// Frees the calling thread's <see cref="Standard"/> instance. Cleared too, so a later use on this
Expand Down
2 changes: 1 addition & 1 deletion Projects/Server/Main.cs
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ You should have received a copy of the GNU General Public License
logger.Information("Headless mode detected (stdin is not a TTY); interactive console input is disabled.");
}

// LibDeflate is not thread safe, so each thread gets its own instance; this is the loop's.
// IGZip is not thread safe, so each thread gets its own instance; this is the loop's.
_ = Deflate.Standard;

ServerConfiguration.Load();
Expand Down
8 changes: 4 additions & 4 deletions Projects/Server/Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@
<Delete Files="..\..\Distribution\Serilog.dll" ContinueOnError="true" />
<Delete Files="..\..\Distribution\Serilog.Sinks.Async.dll" ContinueOnError="true" />
<Delete Files="..\..\Distribution\Serilog.Sinks.Console.dll" ContinueOnError="true" />
<Delete Files="..\..\Distribution\LibDeflate.Bindings.dll" ContinueOnError="true" />
<Delete Files="..\..\Distribution\libdeflate.dll" ContinueOnError="true" />
<Delete Files="..\..\Distribution\libdeflate.dylib" ContinueOnError="true" />
<Delete Files="..\..\Distribution\IGzip.Bindings.dll" ContinueOnError="true" />
<Delete Files="..\..\Distribution\isa-l.dll" ContinueOnError="true" />
<Delete Files="..\..\Distribution\libisal.dylib" ContinueOnError="true" />
<Delete Files="..\..\Distribution\System.IO.Hashing.dll" ContinueOnError="true" />
</Target>
<ItemGroup>
<ProjectReference Include="..\Logger\Logger.csproj" />
<PackageReference Include="IGzip.Bindings" Version="1.0.0" />
<PackageReference Include="IORingGroup" Version="1.2.0" />
<PackageReference Include="CommunityToolkit.HighPerformance" Version="8.4.2" />
<PackageReference Include="LibDeflate.Bindings" Version="1.1.0" />
<PackageReference Include="System.IO.Hashing" Version="11.0.0" />

<PackageReference Include="ModernUO.Serialization.Annotations" Version="4.4.0" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Server.Tests.Pathfinding;
/// asserted byte-identical after a round trip:
///
/// predictive-Z — a directional-Z array that matches its prediction is omitted entirely,
/// compression — each record deflates independently, or stores raw when that doesn't shrink it,
/// compression — each record is its own zstd frame, or stored raw when that doesn't shrink it,
/// compact index — the trailer carries no file offsets; the reader sums record lengths instead.
///
/// Several tests assert on file size, because a round trip alone cannot tell you a transform ran:
Expand Down Expand Up @@ -352,6 +352,43 @@ public void MultipleChunks_ResolveIndividually_FromDerivedOffsets()
}
}

[Fact]
public void LargeChunkSet_TrainsADictionary_AndRoundTrips()
{
// Big enough that the writer's sample clears the training threshold, so every record here
// is compressed against the embedded dictionary — the path a real map bake takes.
var chunks = new (int cx, int cy, StepChunk c)[1024];
for (var i = 0; i < chunks.Length; i++)
{
chunks[i] = (i & 31, i >> 5, VariedChunk(seed: i * 13));
}

var path = Write(chunks);
try
{
using (var fs = File.OpenRead(path))
{
Span<byte> header = stackalloc byte[44];
fs.ReadExactly(header);
Assert.True(BitConverter.ToUInt32(header[40..]) > 0, "no dictionary was trained");
}

using var reader = StepCacheFile.OpenForLazy(path);
Assert.NotNull(reader);

foreach (var (cx, cy, src) in chunks)
{
var rt = reader!.TryReadChunk(cx, cy);
Assert.NotNull(rt);
AssertIdentical(src, rt!);
}
}
finally
{
File.Delete(path);
}
}

[Fact]
public void EmptyChunkSet_WritesAReadableFile()
{
Expand All @@ -375,6 +412,7 @@ public void EmptyChunkSet_WritesAReadableFile()
[InlineData(0u)]
[InlineData(5u)]
[InlineData(8u)]
[InlineData(9u)]
[InlineData(StepCacheFile.FormatVersion + 1)]
public void UnsupportedVersion_IsRejected(uint version)
{
Expand Down
29 changes: 0 additions & 29 deletions Projects/UOContent.Tests/Tests/Items/Clothing/ClothingRaceTests.cs

This file was deleted.

2 changes: 1 addition & 1 deletion Projects/UOContent.Tests/UOContent.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<Configurations>Debug;Release;Analyze</Configurations>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.11.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="18.12.0" />
<PackageReference Include="xunit" Version="2.9.3" />
<PackageReference Include="xunit.runner.visualstudio" Version="4.0.1">
<PrivateAssets>all</PrivateAssets>
Expand Down
13 changes: 6 additions & 7 deletions Projects/UOContent/Compression/ManagedArchive.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,12 @@
using System.IO;
using System.IO.Compression;
using Server.Logging;
using ZstdNet;

namespace Server.Compression;

/// <summary>
/// Cross-platform archive creation and extraction using System.Formats.Tar + ZstdNet (native libzstd).
/// Single-pass streaming: TarWriter → CompressionStream → FileStream.
/// Cross-platform archive creation and extraction using System.Formats.Tar + System.IO.Compression's zstd.
/// Single-pass streaming: TarWriter → ZstandardStream → FileStream.
/// </summary>
public static class ManagedArchive
{
Expand Down Expand Up @@ -60,8 +59,8 @@ public static int CreateTarZstd(
bufferSize: 81920
);

using var compressionOptions = new CompressionOptions(compressionLevel);
using var zstdStream = new CompressionStream(fileStream, compressionOptions);
var compressionOptions = new ZstandardCompressionOptions { Quality = compressionLevel };
using var zstdStream = new ZstandardStream(fileStream, compressionOptions, leaveOpen: true);
using var tarWriter = new TarWriter(zstdStream, TarEntryFormat.Pax, leaveOpen: true);

var entryCount = 0;
Expand Down Expand Up @@ -157,7 +156,7 @@ public static bool ExtractTarZstd(string archiveFile, string outputDirectory)
bufferSize: 81920
);

using var zstdStream = new DecompressionStream(fileStream);
using var zstdStream = new ZstandardStream(fileStream, CompressionMode.Decompress);
return ExtractTarFromStream(zstdStream, outputDirectory);
}
catch (Exception ex)
Expand Down Expand Up @@ -267,7 +266,7 @@ public static int CountEntries(string archiveFile)
bufferSize: 81920
);

using var zstdStream = new DecompressionStream(fileStream);
using var zstdStream = new ZstandardStream(fileStream, CompressionMode.Decompress);
using var tarReader = new TarReader(zstdStream);

var count = 0;
Expand Down
Loading
Loading