-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild.sh
More file actions
executable file
·311 lines (284 loc) · 12.7 KB
/
Copy pathbuild.sh
File metadata and controls
executable file
·311 lines (284 loc) · 12.7 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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
#!/usr/bin/env bash
#
# build.sh — build every artifact a working codegraph install needs.
#
# TypeScript : pnpm -r build -> packages/*/dist (incl. the viz bundle
# `codegraph city --serve` looks for) and
# extractors/typescript/dist/cli.js (bin/codegraph-typescript)
# Java : ./mvnw package -> extractors/java/target/codegraph-java.jar
# --native -> extractors/java/dist/<rid>/codegraph-java
# (GraalVM native image; HOST platform only —
# native-image drives the host linker and
# cannot cross-compile, so the per-OS matrix
# is one CI job per runner, not one job)
# C# : dotnet publish -> extractors/csharp/dist/<rid>/codegraph-csharp
# (self-contained single file; --publish-all
# builds the five-RID matrix from this host)
# Elixir mix escript.build -> extractors/elixir/dist/codegraph-elixir
# (an escript: Elixir embedded, needs Erlang/OTP
# on the machine that runs it — bin/codegraph-elixir)
# SEA : --sea -> packages/cli/dist-sea/<rid>/codegraph
# (the CLI + daemon + both frontends as ONE
# Node single-executable — the desktop app's
# backend, PLAN.md §15.3; HOST platform only,
# the image IS the Node that builds it)
#
# Wraps both with the toolchain checks that a bare `pnpm`/`mvnw` invocation
# skips: Node's floor, the pinned pnpm, and a JDK that non-interactive shells
# cannot see because they never source sdkman.
#
# Tests are NOT run here — that is test.sh. `--skip-tests` on the Maven side is
# therefore deliberate, not a shortcut.
SCRIPT_NAME="build.sh"
source "$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/scripts/lib.sh"
trap on_error ERR
CLEAN="no"
NATIVE="no"
SEA="no"
PUBLISH_ALL="no"
PUBLISH_RID=""
usage() {
cat <<'USAGE'
Usage: ./build.sh [options]
Builds the TypeScript workspace and the Java extractor.
Options:
--ts, --ts-only only packages/* (pnpm -r build)
--java, --java-only only extractors/java (./mvnw package)
--csharp, --csharp-only
only extractors/csharp (dotnet publish, host RID)
--elixir, --elixir-only
only extractors/elixir (mix escript.build)
--native Java: also build the GraalVM native binary for THIS
platform (extractors/java/dist/<rid>/codegraph-java);
Elixir: also build the Burrito binary for THIS platform
(extractors/elixir/dist/<rid>/codegraph-elixir, needs Zig 0.16)
platform (extractors/java/dist/<rid>/codegraph-java)
--sea TypeScript: also build the single-executable codegraph
image for THIS platform (packages/cli/dist-sea/<rid>/codegraph)
--publish-all C#: publish linux-x64, linux-arm64, osx-x64, osx-arm64, win-x64
--rid <rid> C#: publish exactly this RID (what the CI matrix calls, one per job)
--all everything (default)
--clean discard previous output first (dist/, target/)
--skip-install do not run pnpm install (requires an existing node_modules)
--no-frozen allow pnpm install to update pnpm-lock.yaml
--no-auto-install never provision pnpm via corepack; fail with instructions
-h, --help this text
Examples:
./build.sh # everything, lockfile frozen
./build.sh --ts --skip-install
./build.sh --java --clean
./build.sh --java --native # jar + the native binary for this OS/arch
USAGE
}
while [ $# -gt 0 ]; do
if parse_common_flag "$1"; then shift; continue; fi
case "$1" in
--clean) CLEAN="yes" ;;
--native) NATIVE="yes" ;;
--sea) SEA="yes" ;;
--publish-all) PUBLISH_ALL="yes" ;;
--rid)
[ $# -ge 2 ] || usage_error "--rid needs a value"
PUBLISH_RID="$2"; shift ;;
-h|--help) usage; exit 0 ;;
*) usage_error "unknown option: $1" ;;
esac
shift
done
printf '%scodegraph build%s %s(%s)%s\n' "$C_BOLD" "$C_RESET" "$C_DIM" "$ROOT" "$C_RESET"
# ---------------------------------------------------------------- checks ----
step "toolchain"
if wants_ts; then check_node; ensure_pnpm; fi
SKIP_JAVA="no"; SKIP_CSHARP="no"; SKIP_ELIXIR="no"
if wants_java; then
if have_java_extractor; then
ensure_jdk; ensure_mvnw
if [ "$NATIVE" = "yes" ]; then ensure_native_image; fi
else warn "no extractors/java in this checkout — skipping the Java build"; SKIP_JAVA="yes"; fi
fi
if wants_csharp; then
if have_csharp_extractor; then ensure_dotnet
else warn "no extractors/csharp in this checkout — skipping the C# build"; SKIP_CSHARP="yes"; fi
fi
if wants_elixir; then
if have_elixir_extractor; then ensure_erlang
else warn "no extractors/elixir in this checkout — skipping the Elixir build"; SKIP_ELIXIR="yes"; fi
fi
step_done
# ------------------------------------------------------------ typescript ----
if wants_ts; then
pnpm_install
if [ "$CLEAN" = "yes" ]; then
step "clean (typescript)"
run rm -rf "$ROOT"/packages/*/dist
step_done
fi
# The website is a Hugo site with its own CI job, not a TypeScript artifact;
# a machine whose hugo cannot read its config must not fail THIS build.
step "build typescript (pnpm -r build)"
run pnpm --dir "$ROOT" -r --filter '!@codegraph/website' build
step_done
# ONE Node single-executable: the CJS bundle tsup already wrote
# (packages/cli/dist-sea/codegraph.cjs) folded into a copy of this very Node
# with both frontends and package.json as assets. No cross-compilation — the
# image is the runtime that builds it — so CI runs this once per runner.
if [ "$SEA" = "yes" ]; then
step "build codegraph single-executable ($(host_rid))"
run node "$ROOT/packages/cli/scripts/sea-build.mjs" --rid "$(host_rid)"
step_done
fi
fi
# ------------------------------------------------------------------ java ----
if wants_java && [ "$SKIP_JAVA" = "no" ]; then
if [ "$CLEAN" = "yes" ] && [ "$NATIVE" = "yes" ]; then
step "clean (java native)"
run rm -rf "$JAVA_DIR/dist"
step_done
fi
step "build java extractor (./mvnw package)"
# -B: batch mode, no ANSI progress spam in logs. Tests belong to test.sh.
( cd "$JAVA_DIR" && run ./mvnw -B -DskipTests package )
step_done
# One native executable for the HOST platform, ahead-of-time compiled from the
# shaded jar — which is deliberately the same artifact `java -jar` runs, so the
# two cannot drift apart. Reachability metadata travels inside that jar
# (META-INF/native-image/…), as does the embedded Java API reference the image
# resolves java.* against, since a native image has no JVM to borrow one from.
#
# --no-fallback refuse to emit an image that secretly needs a JVM;
# a missing reflection entry must fail the BUILD
# -march=compatibility target the baseline ISA, not this builder's CPU —
# a released binary must run on the machine that
# downloads it, not only on the one that built it
if [ "$NATIVE" = "yes" ]; then
rid="$(host_rid)"
step "build java native image ($rid)"
run mkdir -p "$JAVA_DIR/dist/$rid"
( cd "$JAVA_DIR" && run "$NATIVE_IMAGE" \
-jar target/codegraph-java.jar \
-o "dist/$rid/codegraph-java" \
--no-fallback \
-march=compatibility )
step_done
fi
fi
# ---------------------------------------------------------------- csharp ----
# One self-contained single-file binary per RID (PLAN.md §13.7): the runtime,
# Roslyn and the embedded BCL reference pack travel inside it, so the machine
# that runs it needs no SDK. ReadyToRun for startup; never trimmed (Roslyn is
# not trim-clean). Every RID cross-publishes from any host.
publish_csharp() {
local rid="$1"
( cd "$CSHARP_DIR" && run dotnet publish src/Codegraph.CSharp -c Release -r "$rid" --self-contained \
-p:PublishSingleFile=true -p:EnableCompressionInSingleFile=true -p:PublishReadyToRun=true \
-p:IncludeNativeLibrariesForSelfExtract=true -p:DebugType=none \
-o "dist/$rid" --nologo -v quiet )
}
if wants_csharp && [ "$SKIP_CSHARP" = "no" ]; then
if [ "$CLEAN" = "yes" ]; then
step "clean (csharp)"
run rm -rf "$CSHARP_DIR/dist" "$CSHARP_DIR"/src/*/bin "$CSHARP_DIR"/src/*/obj "$CSHARP_DIR"/tests/*/bin "$CSHARP_DIR"/tests/*/obj
step_done
fi
if [ -n "$PUBLISH_RID" ]; then
step "publish csharp extractor ($PUBLISH_RID)"
publish_csharp "$PUBLISH_RID"
step_done
elif [ "$PUBLISH_ALL" = "yes" ]; then
for rid in linux-x64 linux-arm64 osx-x64 osx-arm64 win-x64; do
step "publish csharp extractor ($rid)"
publish_csharp "$rid"
step_done
done
else
step "publish csharp extractor ($(host_rid))"
publish_csharp "$(host_rid)"
step_done
fi
fi
# ---------------------------------------------------------------- elixir ----
if wants_elixir && [ "$SKIP_ELIXIR" = "no" ]; then
if [ "$CLEAN" = "yes" ]; then
step "clean (elixir)"
run rm -rf "$ELIXIR_DIR/dist" "$ELIXIR_DIR/_build"
step_done
fi
step "build elixir extractor (mix escript.build)"
( cd "$ELIXIR_DIR" && run mix local.hex --force --if-missing >/dev/null && run mix escript.build )
step_done
# The Burrito binary for THIS host (PLAN.md §16.7): a prod release wrapped
# with its ERTS, nothing to install on the machine that runs it. Other
# targets need their ERTS downloaded and, for Windows, 7z: CI's job.
if [ "$NATIVE" = "yes" ]; then
step "build elixir native binary (burrito, $(host_rid))"
ensure_zig
( cd "$ELIXIR_DIR" && MIX_ENV=prod run mix deps.get >/dev/null && \
MIX_ENV=prod BURRITO_TARGET="$(burrito_target "$(host_rid)")" run mix release codegraph_elixir --overwrite )
run mkdir -p "$ELIXIR_DIR/dist/$(host_rid)"
case "$(host_rid)" in
win-*) run cp "$ELIXIR_DIR/burrito_out/codegraph_elixir_$(burrito_target "$(host_rid)").exe" "$ELIXIR_DIR/dist/$(host_rid)/codegraph-elixir.exe" ;;
*) run cp "$ELIXIR_DIR/burrito_out/codegraph_elixir_$(burrito_target "$(host_rid)")" "$ELIXIR_DIR/dist/$(host_rid)/codegraph-elixir" ;;
esac
step_done
fi
fi
# -------------------------------------------------------------- artifacts ---
step "artifacts"
missing=0
report() {
if [ -e "$1" ]; then
printf ' %s✓%s %-46s %s\n' "$C_GREEN" "$C_RESET" "${1#$ROOT/}" "$(du -h "$1" | cut -f1)"
else
printf ' %s✗%s %-46s %smissing%s\n' "$C_RED" "$C_RESET" "${1#$ROOT/}" "$C_RED" "$C_RESET"
missing=$(( missing + 1 ))
fi
}
if wants_ts; then
for pkg in core analyzer city navigator cli; do report "$ROOT/packages/$pkg/dist/index.js"; done
# viz and navigator-ui ship Vite apps, not modules: their entry point is the
# HTML the CLI serves. Their absence is what breaks `--serve`, so name them.
report "$ROOT/packages/viz/dist/index.html"
report "$ROOT/packages/navigator-ui/dist/index.html"
# The TypeScript extractor is a workspace package: built by the same pnpm -r build.
report "$ROOT/extractors/typescript/dist/cli.js"
if [ "$SEA" = "yes" ]; then
case "$(host_rid)" in
win-*) report "$ROOT/packages/cli/dist-sea/$(host_rid)/codegraph.exe" ;;
*) report "$ROOT/packages/cli/dist-sea/$(host_rid)/codegraph" ;;
esac
fi
fi
if wants_java && [ "$SKIP_JAVA" = "no" ]; then
report "$JAVA_DIR/target/codegraph-java.jar"
if [ "$NATIVE" = "yes" ]; then
case "$(host_rid)" in
win-*) report "$JAVA_DIR/dist/$(host_rid)/codegraph-java.exe" ;;
*) report "$JAVA_DIR/dist/$(host_rid)/codegraph-java" ;;
esac
fi
fi
report_rid() {
case "$1" in
win-*) report "$CSHARP_DIR/dist/$1/codegraph-csharp.exe" ;;
*) report "$CSHARP_DIR/dist/$1/codegraph-csharp" ;;
esac
}
if wants_csharp && [ "$SKIP_CSHARP" = "no" ]; then
if [ -n "$PUBLISH_RID" ]; then report_rid "$PUBLISH_RID"
elif [ "$PUBLISH_ALL" = "yes" ]; then
for rid in linux-x64 linux-arm64 osx-x64 osx-arm64 win-x64; do report_rid "$rid"; done
else report_rid "$(host_rid)"; fi
fi
if wants_elixir && [ "$SKIP_ELIXIR" = "no" ]; then
report "$ELIXIR_DIR/dist/codegraph-elixir"
if [ "$NATIVE" = "yes" ]; then
case "$(host_rid)" in
win-*) report "$ELIXIR_DIR/dist/$(host_rid)/codegraph-elixir.exe" ;;
*) report "$ELIXIR_DIR/dist/$(host_rid)/codegraph-elixir" ;;
esac
fi
fi
[ "$missing" -eq 0 ] || die "$missing expected artifact(s) missing — the build did not produce a usable tree"
step_done
summary
printf '\nRun it: %s./bin/codegraph --version%s\n' "$C_BOLD" "$C_RESET"