forked from SkGufranAhmed/Cardinal-Language
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_release.sh
More file actions
61 lines (51 loc) · 2.18 KB
/
Copy pathbuild_release.sh
File metadata and controls
61 lines (51 loc) · 2.18 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
#!/usr/bin/env bash
# build_release.sh — builds the standalone G distribution into dist/ (Linux/macOS)
# Mirrors build_release.ps1: runs `cargo build --release`, then assembles dist/:
# the five binaries (g, gufran, cpm, apm, g-lsp), a TCC built from source in bin/,
# the runtime shims, and the standard library. End users need no Rust, no Cargo,
# and no manually installed C compiler.
set -euo pipefail
root="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$root"
echo "Building g (release)..."
cargo build --release
dist="$root/dist"
bin="$dist/bin"
rt="$dist/runtime"
std="$dist/stdlib"
mkdir -p "$bin" "$rt" "$std"
for exe in g gufran g-lsp cpm apm; do
cp -f "target/release/$exe" "$dist/$exe"
done
cp -f runtime/g_rt.h runtime/cli_shim.h runtime/fs_shim.h runtime/tcp_shim.h \
runtime/math_shim.h runtime/regex_shim.h runtime/os_shim.h \
runtime/ws2_32.def "$rt/"
cp -f stdlib/*.g "$std/"
# --- TCC from source (Linux x86-64/arm64, macOS x86-64) -----------------------
# TCC 0.9.27 supports macOS x86-64 but NOT Apple Silicon (arm64): the build
# fails there and 'g --run' falls back to tcc/gcc/clang on PATH (macOS ships
# clang). Every other runner gets a fully bundled TCC.
tcc_version="0.9.27"
tcc_url="https://download.savannah.gnu.org/releases/tinycc/tcc-$tcc_version.tar.bz2"
tmp="$(mktemp -d)"
trap 'rm -rf "$tmp"' EXIT
echo "Downloading TCC $tcc_version..."
if command -v wget >/dev/null 2>&1; then
wget -q -O "$tmp/tcc.tar.bz2" "$tcc_url"
else
curl -fsSL -o "$tmp/tcc.tar.bz2" "$tcc_url"
fi
tar xjf "$tmp/tcc.tar.bz2" -C "$tmp"
echo "Building TCC from source..."
if (cd "$tmp/tcc-$tcc_version" && ./configure >/dev/null && make -j"$(getconf _NPROCESSORS_ONLN 2>/dev/null || echo 2)" >/dev/null); then
rm -rf "$bin/include" "$bin/lib"
cp -f "$tmp/tcc-$tcc_version/tcc" "$bin/tcc"
cp -r "$tmp/tcc-$tcc_version/include" "$bin/include"
cp -r "$tmp/tcc-$tcc_version/lib" "$bin/lib"
chmod +x "$bin/tcc"
echo "Bundled TCC $tcc_version built from source"
else
echo "WARNING: TCC $tcc_version failed to build on $(uname -s)/$(uname -m);" >&2
echo " dist/bin/tcc is absent. 'g --run' will fall back to tcc/gcc/clang on PATH." >&2
fi
echo "Standalone G runtime built at dist/"