-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathbootstrap-macos.sh
More file actions
executable file
·117 lines (97 loc) · 4.01 KB
/
bootstrap-macos.sh
File metadata and controls
executable file
·117 lines (97 loc) · 4.01 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
#!/usr/bin/env bash
# scripts/bootstrap-macos.sh — bootstrap mcpp on macOS via xmake.
#
# Uses xmake (which has mature C++23 module support) to compile mcpp
# from source on macOS. This is the "Plan B" bootstrap: xmake handles
# module dependency scanning and compilation ordering automatically.
#
# Prerequisites:
# - xmake (brew install xmake or https://xmake.io)
# - Clang 20+ (xlings LLVM or Homebrew LLVM)
# - macOS SDK (xcode-select --install)
#
# Usage:
# ./scripts/bootstrap-macos.sh [LLVM_ROOT]
#
# Output:
# target/bootstrap/bin/mcpp
#
set -euo pipefail
PROJROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "$PROJROOT"
# ─── Locate LLVM ────────────────────────────────────────────────────────────
if [ -n "${1:-}" ] && [ -d "$1/bin" ]; then
LLVM_ROOT="$1"
elif [ -n "${LLVM_ROOT:-}" ]; then
: # already set via env
elif [ -d "$HOME/.xlings/data/xpkgs/xim-x-llvm" ]; then
LLVM_ROOT=$(find "$HOME/.xlings/data/xpkgs/xim-x-llvm" -maxdepth 1 -type d | sort -V | tail -1)
elif command -v brew >/dev/null 2>&1 && [ -d "$(brew --prefix llvm)/bin" ]; then
LLVM_ROOT=$(brew --prefix llvm)
else
echo "error: cannot find LLVM. Pass LLVM_ROOT or install via xlings/Homebrew." >&2
exit 1
fi
CXX="$LLVM_ROOT/bin/clang++"
echo ":: LLVM_ROOT = $LLVM_ROOT"
"$CXX" --version | head -1
# ─── Ensure xmake is available ───────────────────────────────────────────────
if ! command -v xmake >/dev/null 2>&1; then
echo ":: Installing xmake via Homebrew..."
brew install xmake
fi
echo ":: xmake $(xmake --version | head -1)"
# ─── Ensure xmake.lua exists ────────────────────────────────────────────────
if [ ! -f "$PROJROOT/xmake.lua" ]; then
echo ":: Generating xmake.lua for bootstrap..."
cat > "$PROJROOT/xmake.lua" << 'XMAKE'
-- Bootstrap xmake.lua for mcpp (macOS)
-- This file is auto-generated by scripts/bootstrap-macos.sh
add_rules("mode.release")
set_languages("c++23")
package("cmdline")
set_homepage("https://github.com/mcpplibs/cmdline")
set_description("Modern C++ command-line parsing library")
set_license("Apache-2.0")
add_urls("https://github.com/mcpplibs/cmdline/archive/refs/tags/$(version).tar.gz")
add_versions("0.0.1", "3fb2f5495c1a144485b3cbb2e43e27059151633460f702af0f3851cbff387ef0")
on_install(function (package)
import("package.tools.xmake").install(package)
end)
package_end()
add_requires("cmdline 0.0.1")
target("mcpp")
set_kind("binary")
add_files("src/main.cpp")
add_files("src/**.cppm")
add_packages("cmdline")
add_includedirs("src/libs/json")
set_policy("build.c++.modules", true)
XMAKE
fi
# ─── Build with xmake ────────────────────────────────────────────────────────
echo
echo ":: Building mcpp with xmake (LLVM/Clang toolchain)..."
echo
# Configure xmake to use the specified LLVM toolchain
xmake f -y -m release \
--toolchain=llvm \
--sdk="$LLVM_ROOT" \
2>&1 | tail -5
# Build
xmake build -y mcpp 2>&1
# ─── Stage output ────────────────────────────────────────────────────────────
echo
echo ":: Staging output..."
OUTDIR="$PROJROOT/target/bootstrap/bin"
mkdir -p "$OUTDIR"
# xmake puts output in build/<platform>/<arch>/release/mcpp
BUILT=$(find "$PROJROOT/build" -name mcpp -type f -perm +111 2>/dev/null | head -1)
if [ -z "$BUILT" ]; then
echo "error: mcpp binary not found in xmake build output" >&2
find "$PROJROOT/build" -type f 2>/dev/null | head -20
exit 1
fi
cp "$BUILT" "$OUTDIR/mcpp"
echo ":: SUCCESS: $OUTDIR/mcpp"
"$OUTDIR/mcpp" --version