diff --git a/docs/nuget-packaging.md b/docs/nuget-packaging.md new file mode 100644 index 00000000..88eb4a2d --- /dev/null +++ b/docs/nuget-packaging.md @@ -0,0 +1,17 @@ +# NuGet Packaging + +CultLib publishes the managed dependency graph as separate packages. The leaf +package is `GameCult.Mesh`; its NuGet dependencies preserve the CultMesh, +CultNet, and CultCache ownership boundaries. + +```powershell +powershell -ExecutionPolicy Bypass -File .\scripts\pack-nuget.ps1 +``` + +The command creates a local feed under `artifacts/nuget`, verifies that every +internal dependency package exists at the same version, then restores and runs +a clean .NET consumer using only `PackageReference Include="GameCult.Mesh"`. + +The Unity distribution remains `org.gamecult.cultlib`, built by +`scripts/build-unity-package.ps1`, because Unity consumes the managed assembly +closure through UPM rather than NuGet restore. diff --git a/scripts/pack-nuget.ps1 b/scripts/pack-nuget.ps1 new file mode 100644 index 00000000..b027c492 --- /dev/null +++ b/scripts/pack-nuget.ps1 @@ -0,0 +1,93 @@ +param( + [string] $Configuration = "Release", + [string] $OutputDirectory = "artifacts\nuget", + [switch] $SkipConsumerSmoke +) + +$ErrorActionPreference = "Stop" +$repoRoot = Split-Path -Parent $PSScriptRoot +$outputRoot = if ([IO.Path]::IsPathRooted($OutputDirectory)) { + $OutputDirectory +} else { + Join-Path $repoRoot $OutputDirectory +} + +$projects = @( + "src\GameCult.Logging\GameCult.Logging.csproj", + "src\GameCult.Caching\GameCult.Caching.csproj", + "src\GameCult.Caching.MessagePack.Analyzers\GameCult.Caching.MessagePack.Analyzers.csproj", + "src\GameCult.Caching.MessagePack\GameCult.Caching.MessagePack.csproj", + "src\GameCult.Networking\GameCult.Networking.csproj", + "src\GameCult.Mesh\GameCult.Mesh.csproj" +) + +if (Test-Path -LiteralPath $outputRoot) { + Remove-Item -LiteralPath $outputRoot -Recurse -Force +} +New-Item -ItemType Directory -Force -Path $outputRoot | Out-Null + +foreach ($project in $projects) { + dotnet pack (Join-Path $repoRoot $project) -c $Configuration -o $outputRoot + if ($LASTEXITCODE -ne 0) { + throw "NuGet pack failed for $project with exit code $LASTEXITCODE" + } +} + +$meshPackage = Get-ChildItem -LiteralPath $outputRoot -Filter "GameCult.Mesh.*.nupkg" | + Where-Object { $_.Name -notlike "*.snupkg" } | + Select-Object -First 1 +if (-not $meshPackage) { + throw "GameCult.Mesh package was not produced." +} + +$version = [regex]::Match($meshPackage.Name, '^GameCult\.Mesh\.(.+)\.nupkg$').Groups[1].Value +$expectedPackages = @( + "GameCult.Logging.$version.nupkg", + "GameCult.Caching.$version.nupkg", + "GameCult.Caching.MessagePack.Analyzers.$version.nupkg", + "GameCult.Caching.MessagePack.$version.nupkg", + "GameCult.Networking.$version.nupkg", + "GameCult.Mesh.$version.nupkg" +) +foreach ($package in $expectedPackages) { + if (-not (Test-Path -LiteralPath (Join-Path $outputRoot $package))) { + throw "NuGet dependency closure is missing $package" + } +} + +if (-not $SkipConsumerSmoke) { + $smokeRoot = Join-Path $repoRoot "artifacts\nuget-consumer-smoke" + if (Test-Path -LiteralPath $smokeRoot) { + Remove-Item -LiteralPath $smokeRoot -Recurse -Force + } + New-Item -ItemType Directory -Force -Path $smokeRoot | Out-Null + $projectDocument = @" + + + net10.0 + Exe + enable + $outputRoot;https://api.nuget.org/v3/index.json + + + + + +"@ + $program = @" +using GameCult.Mesh; + +var verse = CultMesh.Verse("nuget-smoke", "cultlib.pack"); +Console.WriteLine(verse.Context.VerseId); +"@ + [IO.File]::WriteAllText((Join-Path $smokeRoot "Consumer.csproj"), $projectDocument, [Text.UTF8Encoding]::new($false)) + [IO.File]::WriteAllText((Join-Path $smokeRoot "Program.cs"), $program, [Text.UTF8Encoding]::new($false)) + dotnet run --project (Join-Path $smokeRoot "Consumer.csproj") -c Release + if ($LASTEXITCODE -ne 0) { + throw "GameCult.Mesh NuGet consumer smoke failed with exit code $LASTEXITCODE" + } +} + +Write-Host "CultLib NuGet feed: $outputRoot" +Write-Host "GameCult.Mesh: $version" +Write-Host "Public package closure: $($expectedPackages.Count) packages"