forked from SkGufranAhmed/Cardinal-Language
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_release.ps1
More file actions
77 lines (67 loc) · 4 KB
/
Copy pathbuild_release.ps1
File metadata and controls
77 lines (67 loc) · 4 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
# build_release.ps1 — builds the standalone G distribution into dist/
# Produces a self-contained `dist/` folder: g.exe + bundled TCC (bin/) + runtime.
# End users need no Rust, no Cargo, and no manually installed C compiler.
$ErrorActionPreference = "Stop"
$root = Split-Path -Parent $MyInvocation.MyCommand.Path
Set-Location $root
Write-Host "Building g (release)..."
# Run cargo via cmd so its stderr progress output never surfaces as PS error
# records (which $ErrorActionPreference = "Stop" would treat as fatal).
cmd /c "cargo build --release 2>&1"
if ($LASTEXITCODE -ne 0) { throw "cargo build --release failed" }
$dist = Join-Path $root "dist"
$bin = Join-Path $dist "bin"
$rt = Join-Path $dist "runtime"
$std = Join-Path $dist "stdlib"
New-Item -ItemType Directory -Force -Path $bin, $rt, $std | Out-Null
Copy-Item -Force (Join-Path $root "target\release\g.exe") (Join-Path $dist "g.exe")
Copy-Item -Force (Join-Path $root "target\release\gufran.exe") (Join-Path $dist "gufran.exe")
# Phase 39: the Language Server Protocol server (stdin/stdout JSON-RPC).
Copy-Item -Force (Join-Path $root "target\release\g-lsp.exe") (Join-Path $dist "g-lsp.exe")
# Phase 36: the Cardinal Package Manager (cpm) and its alias (apm).
Copy-Item -Force (Join-Path $root "target\release\cpm.exe") (Join-Path $dist "cpm.exe")
Copy-Item -Force (Join-Path $root "target\release\apm.exe") (Join-Path $dist "apm.exe")
Copy-Item -Force (Join-Path $root "runtime\g_rt.h") (Join-Path $rt "g_rt.h")
Copy-Item -Force (Join-Path $root "runtime\cli_shim.h") (Join-Path $rt "cli_shim.h")
Copy-Item -Force (Join-Path $root "runtime\fs_shim.h") (Join-Path $rt "fs_shim.h")
Copy-Item -Force (Join-Path $root "runtime\tcp_shim.h") (Join-Path $rt "tcp_shim.h")
# Phase 41: the stdlib/math.g and stdlib/regex.g FFI shims.
Copy-Item -Force (Join-Path $root "runtime\math_shim.h") (Join-Path $rt "math_shim.h")
Copy-Item -Force (Join-Path $root "runtime\regex_shim.h") (Join-Path $rt "regex_shim.h")
# Phase 44: the stdlib/os.g FFI shim (RunCommand / FileSize).
Copy-Item -Force (Join-Path $root "runtime\os_shim.h") (Join-Path $rt "os_shim.h")
Copy-Item -Force (Join-Path $root "runtime\ws2_32.def") (Join-Path $rt "ws2_32.def")
# Phase 31: ship the standard library next to the compiler so
# `Import "stdlib/net.g"` resolves from any working directory.
foreach ($f in @(Get-ChildItem (Join-Path $root "stdlib") -Filter "*.g")) {
Copy-Item -Force $f.FullName (Join-Path $std $f.Name)
}
# TCC: use the local install when present; otherwise (CI / fresh machines)
# download the official win64 binary bundle from Savannah and expand it.
$tccRoot = "C:\Users\Laptop\tcc\tcc"
if (-not (Test-Path (Join-Path $tccRoot "tcc.exe"))) {
$tccZip = Join-Path $env:TEMP "tcc-0.9.27-win64-bin.zip"
if (-not (Test-Path $tccZip)) {
Write-Host "Downloading TCC 0.9.27 (win64)..."
Invoke-WebRequest -UseBasicParsing "https://download.savannah.gnu.org/releases/tinycc/tcc-0.9.27-win64-bin.zip" -OutFile $tccZip
}
$tccExtract = Join-Path $env:TEMP "tcc-0.9.27-win64-bin"
if (-not (Test-Path (Join-Path $tccExtract "tcc.exe"))) {
Remove-Item -Recurse -Force $tccExtract -ErrorAction SilentlyContinue
Expand-Archive -Path $tccZip -DestinationPath $tccExtract
}
$tccRoot = (Get-ChildItem -Recurse -Path $tccExtract -Filter "tcc.exe" | Select-Object -First 1).DirectoryName
}
if (-not (Test-Path (Join-Path $tccRoot "tcc.exe"))) { throw "TCC not found at $tccRoot" }
Copy-Item -Force (Join-Path $tccRoot "tcc.exe") (Join-Path $bin "tcc.exe")
if (Test-Path (Join-Path $tccRoot "libtcc.dll")) {
Copy-Item -Force (Join-Path $tccRoot "libtcc.dll") (Join-Path $bin "libtcc.dll")
}
# Copy-Item -Recurse into an existing directory nests the source folder
# (include\include); remove stale copies first so the script is idempotent.
foreach ($d in @("include", "lib")) {
$dest = Join-Path $bin $d
if (Test-Path $dest) { Remove-Item -Recurse -Force $dest }
Copy-Item -Recurse -Force (Join-Path $tccRoot $d) $dest
}
Write-Host "Standalone G runtime built at dist\g.exe"