-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBuild-Linux.ps1
More file actions
64 lines (55 loc) · 2.5 KB
/
Build-Linux.ps1
File metadata and controls
64 lines (55 loc) · 2.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# Local-developer convenience: builds Linux x64 .so files for both PG extension
# projects by running `dotnet publish` inside the sharppostgres-builder Docker
# container. Outputs land in artifacts/linux-x64/.
#
# In CI on Ubuntu (GitHub Actions), invoke `dotnet publish -c Release -r linux-x64`
# directly per project -- no Docker needed.
#
# Prerequisites:
# 1. Docker Desktop running, Linux containers active.
# 2. The sharppostgres-builder image built once via:
# docker build -t sharppostgres-builder -f Dockerfile.linux-build .
#
# Usage:
# .\Build-Linux.ps1
#
# Outputs:
# .\artifacts\linux-x64\sharppostgres.so (from SharpPostgres.Demos)
# .\artifacts\linux-x64\json_schema_check.so (from SharpPostgres.JsonSchemaCheck)
$ErrorActionPreference = 'Stop'
$repoRoot = $PSScriptRoot
Write-Host "Building both extension .so files via Docker..." -ForegroundColor Cyan
# Wipe obj/ everywhere before invoking Docker. Windows-host NuGet restores
# can leave RID/framework shapes that don't translate to Linux containers
# (and historically also leaked Windows-only fallback-package paths into
# project.assets.json). A clean restore inside the container avoids both.
Write-Host "Cleaning obj/ folders..." -ForegroundColor Cyan
Get-ChildItem -Path $repoRoot -Recurse -Directory -Force `
| Where-Object { $_.Name -eq 'obj' -and $_.FullName -notlike '*\.dotnet-home\*' } `
| ForEach-Object { Remove-Item -Recurse -Force $_.FullName }
$projects = @(
@{ Path = 'SharpPostgres.Demos/SharpPostgres.Demos.csproj'; Output = 'sharppostgres_demos.so' },
@{ Path = 'SharpPostgres.JsonSchemaCheck/SharpPostgres.JsonSchemaCheck.csproj'; Output = 'json_schema_check.so' }
)
foreach ($project in $projects) {
Write-Host ""
Write-Host "=> $($project.Path)" -ForegroundColor Cyan
docker run --rm `
-v "${repoRoot}:/src" `
-w /src `
sharppostgres-builder `
dotnet publish $project.Path `
-c Release -r linux-x64 `
-o /src/artifacts/linux-x64 `
--force
if ($LASTEXITCODE -ne 0) {
throw "Linux build failed for $($project.Path) (exit code $LASTEXITCODE)"
}
$soPath = Join-Path $repoRoot "artifacts\linux-x64\$($project.Output)"
if (-not (Test-Path $soPath)) {
throw "Build reported success but $soPath was not produced"
}
$soInfo = Get-Item $soPath
Write-Host "Built: $($soInfo.FullName)" -ForegroundColor Green
Write-Host "Size: $([math]::Round($soInfo.Length / 1MB, 2)) MB"
}