forked from ziglang/zig
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbootstrap.ps1
More file actions
90 lines (70 loc) · 3.31 KB
/
bootstrap.ps1
File metadata and controls
90 lines (70 loc) · 3.31 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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# bootstrap.ps1 — Build the Sig build runner from source on Windows.
#
# This script compiles tools/sig_build/main.sig into a standalone executable
# using a direct compiler invocation. Once built, `sig build` can rebuild
# itself (self-hosting).
#
# Usage:
# .\bootstrap.ps1
#
# Environment variables:
# SIG_COMPILER — Path to the sig compiler binary (default: auto-detect)
# SIG_OUT_DIR — Output directory for the binary (default: sig-out\bin)
$ErrorActionPreference = 'Stop'
# ── Configuration ────────────────────────────────────────────────────────────
$SOURCE = "tools/sig_build/main.sig"
$MOD_PATH = "lib/sig/sig.zig"
$OUT_DIR = if ($env:SIG_OUT_DIR) { $env:SIG_OUT_DIR } else { "sig-out\bin" }
$OUT_NAME = "sig-build"
$OUT_PATH = "$OUT_DIR\$OUT_NAME.exe"
# ── Locate the sig compiler ─────────────────────────────────────────────────
$SIG = $null
if ($env:SIG_COMPILER) {
$SIG = $env:SIG_COMPILER
} elseif (Get-Command "sig" -ErrorAction SilentlyContinue) {
$SIG = "sig"
} else {
# Check known local dev path
$LOCAL_SIG = "C:\Just-Things\Projects\Lib\sig-bin\sig.exe"
if (Test-Path $LOCAL_SIG) {
$SIG = $LOCAL_SIG
}
}
if (-not $SIG) {
Write-Error @"
error: sig compiler not found
The sig compiler is required to bootstrap the build runner.
Install sig and ensure it is on your PATH, or set the SIG_COMPILER
environment variable to the full path of the sig binary.
`$env:SIG_COMPILER = "C:\path\to\sig.exe"
.\bootstrap.ps1
"@
exit 1
}
# ── Verify source files exist ────────────────────────────────────────────────
if (-not (Test-Path $SOURCE)) {
Write-Error "error: source file not found: $SOURCE`nRun this script from the repository root."
exit 1
}
if (-not (Test-Path $MOD_PATH)) {
Write-Error "error: sig module not found: $MOD_PATH`nRun this script from the repository root."
exit 1
}
# ── Create output directory ──────────────────────────────────────────────────
if (-not (Test-Path $OUT_DIR)) {
New-Item -ItemType Directory -Path $OUT_DIR -Force | Out-Null
}
# ── Compile the build runner ─────────────────────────────────────────────────
Write-Host "Bootstrapping sig build runner..."
Write-Host " compiler: $SIG"
Write-Host " source: $SOURCE"
Write-Host " output: $OUT_PATH"
& $SIG build-exe $SOURCE --mod "sig:$MOD_PATH" --name $OUT_NAME -femit-bin=$OUT_PATH
if ($LASTEXITCODE -ne 0) {
Write-Error "`nerror: compilation failed`nCheck the compiler output above for details."
exit 1
}
# ── Done ─────────────────────────────────────────────────────────────────────
Write-Host ""
Write-Host "Bootstrap complete: $OUT_PATH"
Write-Host "You can now use 'sig build' via: $OUT_PATH"