|
| 1 | +#!/usr/bin/env bash |
| 2 | +# 40_llvm_bmi_cache.sh — Clang BMI cache reuse for dependency packages. |
| 3 | +set -e |
| 4 | + |
| 5 | +LLVM_ROOT="${HOME}/.mcpp/registry/data/xpkgs/xim-x-llvm/20.1.7" |
| 6 | +if [[ ! -x "$LLVM_ROOT/bin/clang++" ]]; then |
| 7 | + echo "SKIP: xlings llvm@20.1.7 is not installed" |
| 8 | + exit 0 |
| 9 | +fi |
| 10 | +if [[ ! -f "$LLVM_ROOT/share/libc++/v1/std.cppm" ]]; then |
| 11 | + echo "SKIP: xlings llvm@20.1.7 has no libc++ std.cppm" |
| 12 | + exit 0 |
| 13 | +fi |
| 14 | + |
| 15 | +TMP=$(mktemp -d) |
| 16 | +trap "rm -rf $TMP" EXIT |
| 17 | +export MCPP_HOME="$TMP/mcpp-home" |
| 18 | +source "$(dirname "$0")/_inherit_toolchain.sh" |
| 19 | + |
| 20 | +# mcpplibs packages live in a separate registry namespace; inherit it so the |
| 21 | +# index lookup for mcpplibs.cmdline succeeds in the isolated MCPP_HOME. |
| 22 | +USER_MCPP="${HOME}/.mcpp" |
| 23 | +if [[ -d "$USER_MCPP/registry/data/mcpplibs" ]]; then |
| 24 | + mkdir -p "$MCPP_HOME/registry/data" |
| 25 | + [[ -e "$MCPP_HOME/registry/data/mcpplibs" ]] \ |
| 26 | + || ln -sf "$USER_MCPP/registry/data/mcpplibs" "$MCPP_HOME/registry/data/mcpplibs" |
| 27 | +fi |
| 28 | + |
| 29 | +mkdir -p "$TMP/proj/src" |
| 30 | +cd "$TMP/proj" |
| 31 | + |
| 32 | +cat > mcpp.toml <<'EOF' |
| 33 | +[package] |
| 34 | +name = "llvm_cache" |
| 35 | +version = "0.1.0" |
| 36 | +[toolchain] |
| 37 | +linux = "llvm@20.1.7" |
| 38 | +[dependencies] |
| 39 | +"mcpplibs.cmdline" = "0.0.1" |
| 40 | +EOF |
| 41 | + |
| 42 | +cat > src/main.cpp <<'EOF' |
| 43 | +import std; |
| 44 | +import mcpplibs.cmdline; |
| 45 | +int main() { |
| 46 | + std::println("cache test ok"); |
| 47 | + return 0; |
| 48 | +} |
| 49 | +EOF |
| 50 | + |
| 51 | +# First build — should compile the dependency |
| 52 | +out1=$("$MCPP" build --no-cache 2>&1) |
| 53 | +echo "$out1" | grep -q "Compiling.*mcpplibs.cmdline" || { |
| 54 | + # It's OK if it says "Cached" because global cache may exist |
| 55 | + echo "$out1" | grep -q "Cached.*mcpplibs.cmdline" || { |
| 56 | + echo "FAIL: mcpplibs.cmdline not mentioned in first build: $out1" |
| 57 | + exit 1 |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +# Second build (clean target, keep BMI cache) — dependency should be cached |
| 62 | +rm -rf target |
| 63 | +out2=$("$MCPP" build 2>&1) |
| 64 | +echo "$out2" | grep -q "Cached.*mcpplibs.cmdline" || { |
| 65 | + echo "FAIL: mcpplibs.cmdline not cached on second build: $out2" |
| 66 | + exit 1 |
| 67 | +} |
| 68 | + |
| 69 | +echo "OK" |
0 commit comments