⌜ ᐸ ᐊ ᐯ Ⲷ Ⲡ ⌟
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

migrate to sh entirely for building

yzzxyz 74365963 e8b3833b

+199 -298
+8 -35
build-mac-cpu-mesh-llm.sh mesh-build-scripts/build-mac-cpu-mesh-llm.sh
··· 91 91 92 92 configure_compiler_cache 93 93 94 + echo cpu 95 + 94 96 cmake_flags=( 95 97 -B "$BUILD_DIR" 96 98 -S "$LLAMA_DIR" 97 99 -DGGML_RPC=ON 98 100 -DBUILD_SHARED_LIBS=OFF 99 101 -DLLAMA_OPENSSL=OFF 100 - ) 101 - 102 - if [[ "$BACKEND" == "cpu" ]]; then 103 - echo cpu 104 - cmake_flags+=( 105 - -DGGML_VULKAN=OFF 106 - -DGGML_METAL=OFF 107 - ) 108 - elif [[ "$BACKEND" == "vulkan" ]]; then 109 - echo vulkan 110 - cmake_flags+=( 111 - -DGGML_VULKAN=ON 112 - -DGGML_METAL=OFF 102 + -DGGML_VULKAN=OFF 103 + -DGGML_METAL=OFF 113 104 ) 114 - else 115 - echo metal 116 - cmake_flags+=( 117 - -DGGML_VULKAN=OFF 118 - -DGGML_METAL=ON 119 - ) 120 - fi 105 + 106 + 121 107 if (( ${+commands[ninja]} )); then 122 108 cmake_flags=(-G Ninja "${cmake_flags[@]}") 123 109 fi ··· 134 120 if [[ -d "$MESH_DIR" ]]; then 135 121 echo "Building mesh-llm..." 136 122 if [[ -d "$UI_DIR" ]]; then 137 - "$SCRIPT_DIR/build-ui.sh" "$UI_DIR" 123 + "$SCRIPT_DIR/scripts/build-ui.sh" "$UI_DIR" 138 124 fi 139 125 140 126 if [[ -n "$rustc_wrapper" ]]; then ··· 149 135 ) 150 136 fi 151 137 152 - if [[ "$BACKEND" == "cpu" ]]; then 153 - ( 154 - stage_dev_runtime_binaries "cpu" "target/release" 155 - ) 156 - elif [[ "$BACKEND" == "vulkan" ]]; then 157 - ( 158 - stage_dev_runtime_binaries "vulkan" "$REPO_ROOT/target/release" 159 - ) 160 - else 161 - ( 162 - stage_dev_runtime_binaries "metal" "$REPO_ROOT/target/release" 163 - 164 - ) 165 - fi 138 + stage_dev_runtime_binaries "cpu" "target/release" 166 139 echo "Mesh binary: target/release/mesh-llm" 167 140 fi
install_prereq.sh mesh-build-scripts/install_prereq.sh
+191
mesh-build-scripts/setup.sh
··· 1 + #!/usr/bin/env bash 2 + set -euo pipefail 3 + 4 + NAME="Clone mesh-llm, detect GPU card version, then invoke build backend" 5 + 6 + REPO_URL="https://github.com/Mesh-LLM/mesh-llm" 7 + CLOPE_DIR=".deps/mesh-llm" 8 + 9 + die() { 10 + echo "ERROR: $1" >&2 11 + exit 1 12 + } 13 + 14 + has_cmd() { 15 + command -v "$1" > /dev/null 16 + } 17 + 18 + platform() { 19 + case "$(uname_s)" in 20 + Darwin) echo "Darwin" ;; 21 + Linux) echo "Linux" ;; 22 + CYGWIN*|MSYS*) echo "Windows" ;; 23 + *) echo "Unknown" ;; 24 + esac 25 + } 26 + 27 + detect_backend() { 28 + local out 29 + 30 + if has_cmd nvidia-smi; then 31 + echo -n "Checking CUDA ... " 32 + echo "found" 33 + echo -n "Running detect-cuda-arch.sh ... " 34 + 35 + if [[ ! -f "scripts/detect-cuda-arch.sh" ]]; then 36 + die "detect-cuda-arch.sh not found — clone may be corrupted" 37 + fi 38 + 39 + if out=$(bash scripts/detect-cuda-arch.sh); then 40 + if [[ -n "$out" && "$out" != "" ]]; then 41 + echo "SM values detected: $out" 42 + echo "cuda" 43 + return 44 + fi 45 + fi 46 + echo "script failed or returned empty — falling back" 47 + else 48 + echo "nvidia-smi not in PATH" 49 + fi 50 + 51 + if has_cmd reem-smi || has_cmd rocminfo; then 52 + echo -n "Checking ROCm ... " 53 + echo "found" 54 + echo -n "Running detect-rocm-arch.sh ... " 55 + 56 + if [[ ! -f "scripts/detect-rocm-arch.sh" ]]; then 57 + die "detect-rocm-arch.sh not found — clone may be corrupted" 58 + fi 59 + 60 + if out=$(bash scripts/detect-rocm-arch.sh); then 61 + if [[ -n "$out" && "$out" != "" ]]; then 62 + echo "gfx values detected: $out" 63 + echo "rocm" 64 + return 65 + fi 66 + fi 67 + echo "script failed or returned empty — falling back" 68 + else 69 + echo "ROCm tools not found" 70 + fi 71 + 72 + local arch="" 73 + if [[ "$(platform)" == "Darwin" ]]; then 74 + arch=$(uname -m) || true 75 + if [[ "$arch" == "arm" ]]; then 76 + echo "Apple Silicon Mac detected (backing with Metal)" 77 + echo "metal" 78 + return 79 + fi 80 + fi 81 + 82 + echo -n "Checking Vulkan ... " 83 + if check_vulkan; then 84 + echo "vulkan present" 85 + 86 + if has_cmd vulkaninfo; then 87 + echo -n "Running vulkaninfo --summary ... " 88 + 89 + if out=$(vulkaninfo --summary 2>&1); then 90 + if [[ -n "$out" && "$out" != "" ]]; then 91 + echo "GPU: $(parse_gpu_name_from_vulkaninfo_output "$out")" 92 + echo "vulkan" 93 + return 94 + fi 95 + fi 96 + echo "could not detect GPU model — falling through" 97 + else 98 + echo "no vulkaninfo binary, but SDK present — using vulkan backend" 99 + echo "vulkan" 100 + return 101 + fi 102 + else 103 + echo "Vulkan SDK / vulkaninfo not found" 104 + fi 105 + 106 + echo "No GPU acceleration available — using cpu backend" 107 + echo "cpu" 108 + } 109 + 110 + check_vulkan() { 111 + if has_cmd vulkaninfo; then 112 + return 0 113 + fi 114 + 115 + local header_paths=( 116 + "/usr/include/vulkan/vulkan.h", 117 + "/usr/local/include/vulkan/vulkan.h", 118 + "/opt/homebrew/Cellar/vulkan-loader/2024.12.18/include/vulkan/vulkan.h" 119 + ) 120 + 121 + for p in "${header_paths[@]}"; do 122 + if [[ -f "$p" ]]; then 123 + return 0 124 + fi 125 + done 126 + 127 + return 1 128 + } 129 + 130 + parse_gpu_name_from_vulkaninfo_output() { 131 + local out="$1" 132 + 133 + while IFS= read -r line; do 134 + if [[ "$line" == *"GPU #"* ]] || [[ "$line" == *": Device"* ]] || [[ "$line" == *": GPU"* ]]; then 135 + if [[ "$line" == *":"* ]]; then 136 + local after_colon="${line#*:}" 137 + after_colon="${after_colon#"${after_colon%%[^ ]*}"}" 138 + after_colon="${after_colon#"${after_colon##[![:space:]]}"}" 139 + after_colon="$(echo "$after_colon" | xargs)" 140 + 141 + if [[ -n "$after_colon" && "$after_colon" != "{"* ]]; then 142 + echo "$after_colon" 143 + return 144 + fi 145 + fi 146 + fi 147 + done <<< "$out" 148 + 149 + echo "unknown device" 150 + } 151 + 152 + clone_repo() { 153 + if [[ ! -d "$CLOPE_DIR" ]]; then 154 + echo -n "Cloning $REPO_URL ... " 155 + 156 + mkdir -p .deps 157 + 158 + if git clone --quiet "$REPO_URL" "$CLOPE_DIR"; then 159 + echo "done" 160 + else 161 + die "git clone failed with exit code $?" 162 + fi 163 + else 164 + echo "Clone already exists at $CLOPE_DIR, using it." 165 + fi 166 + } 167 + 168 + execute_just_build() { 169 + local backend="$1" 170 + 171 + echo "Running \`just build backend=\"$backend\"\` ..." 172 + 173 + if ! just "build backend=$backend"; then 174 + die "\`just build\` exited with non-zero status (hint: make sure \`just\` is installed and in PATH)" 175 + fi 176 + 177 + echo "Build succeeded" 178 + } 179 + 180 + main() { 181 + clone_repo 182 + 183 + cd "$CLOPE_DIR" || die "failed to cd into $CLOPE_DIR" 184 + 185 + local backend 186 + backend=$(detect_backend) || die "detection failed" 187 + 188 + execute_just_build "$backend" 189 + } 190 + 191 + main "$@"
-263
setup.rs
··· 1 - //! Clone mesh-llm, detect GPU card version, then invoke `just build backend`. 2 - 3 - use std::io::Write; 4 - use std::path::Path; 5 - use std::process::{Command, Stdio}; 6 - 7 - const REPO_URL: &str = "https://github.com/Mesh-LLM/mesh-llm"; 8 - const CLOPE_DIR: &str = ".deps/mesh-llm"; 9 - 10 - fn die(msg: &str) { 11 - eprintln!("ERROR: {}", msg); 12 - std::process::exit(1); 13 - } 14 - 15 - fn main() { 16 - if let Err(e) = run() { 17 - eprintln!("ERROR: {}", e); 18 - std::process::exit(1); 19 - } 20 - } 21 - 22 - fn run() -> Result<(), Box<dyn std::error::Error>> { 23 - clone_repo()?; 24 - cd_to_clone(); 25 - println!("Detecting GPU back-end ..."); 26 - let backend = detect_backend()?; 27 - execute_just_build(&backend)?; 28 - Ok(()) 29 - } 30 - 31 - fn clone_repo() -> Result<(), Box<dyn std::error::Error>> { 32 - let path = Path::new(CLOPE_DIR); 33 - 34 - if !path.exists() { 35 - print!("Cloning {} ... ", REPO_URL); 36 - std::io::stdout().flush(); 37 - 38 - std::fs::create_dir_all(".deps")?; 39 - 40 - let status = Command::new("git") 41 - .args(["clone", "--quiet", REPO_URL, CLOPE_DIR]) 42 - .current_dir(Path::new(".deps")) 43 - .stdout(Stdio::null()) 44 - .stderr(Stdio::null()) 45 - .status(); 46 - 47 - match status { 48 - Ok(s) if s.success() => { 49 - println!(" done"); 50 - } 51 - _ => { 52 - let code = match status { 53 - Ok(s) => format!("{:?}", s.code()), 54 - Err(_) => "signal".to_string(), 55 - }; 56 - return Err(format!("git clone failed with exit code {}", code).into()); 57 - } 58 - } 59 - } else { 60 - println!("Clone already exists at {}, using it.", CLOPE_DIR); 61 - } 62 - 63 - Ok(()) 64 - } 65 - 66 - fn cd_to_clone() -> Result<(), Box<dyn std::error::Error>> { 67 - std::env::set_current_dir(std::path::Path::new(CLOPE_DIR))?; 68 - Ok(()) 69 - } 70 - 71 - fn run_bash(script: &str) -> Result<String, Box<dyn std::error::Error>> { 72 - let out = Command::new("/bin/bash") 73 - .arg("--noconf") 74 - .arg("-c") 75 - .arg(script) 76 - .stdout(Stdio::piped()) 77 - .output(); 78 - 79 - match out { 80 - Ok(o) => { 81 - if o.status.success() { 82 - Ok(String::from_utf8_lossy(&o.stdout).trim().to_string()) 83 - } else { 84 - Ok("".to_string()) 85 - } 86 - } 87 - Err(e) => Err(Box::new(e)), 88 - } 89 - } 90 - 91 - fn has_command(name: &str) -> bool { 92 - matches!( 93 - Command::new("command").args(["-v", name]).status(), 94 - Ok(s) if s.success(), 95 - ) 96 - } 97 - 98 - fn detect_backend() -> Result<String, Box<dyn std::error::Error>> { 99 - // ── 1. Try nvidia-smi + detect-cuda-arch.sh 100 - print!("Checking CUDA ... "); 101 - std::io::stdout().flush(); 102 - 103 - if has_command("nvidia-smi") { 104 - println!("found"); 105 - print!("Running detect-cuda-arch.sh ... "); 106 - std::io::stdout().flush(); 107 - 108 - let sm_list = run_bash("scripts/detect-cuda-arch.sh"); 109 - 110 - match sm_list { 111 - Ok(list) if !list.is_empty() && list != "" => { 112 - println!("SM values detected: {}", list); 113 - return Ok("cuda".to_string()); 114 - } 115 - _ => { 116 - println!("script failed or returned empty — falling back"); 117 - } 118 - } 119 - } else { 120 - println!("nvidia-smi not in PATH"); 121 - } 122 - 123 - // ── 2. Try reem-smi / rocminfo + detect-rocm-arch.sh 124 - print!("Checking ROCm ... "); 125 - std::io::stdout().flush(); 126 - 127 - if has_command("reem-smi") || has_command("rocminfo") { 128 - println!("found"); 129 - print!("Running detect-rocm-arch.sh ... "); 130 - std::io::stdout().flush(); 131 - 132 - let gfx_list = run_bash("scripts/detect-rocm-arch.sh"); 133 - 134 - match gfx_list { 135 - Ok(list) if !list.is_empty() && list != "" => { 136 - println!("gfx values detected: {}", list); 137 - return Ok("rocm".to_string()); 138 - } 139 - _ => { 140 - println!("script failed or returned empty — falling back"); 141 - } 142 - } 143 - } else { 144 - println!("ROCm tools not found"); 145 - } 146 - 147 - // ── 3. Apple Silicon on macOS (Metal backend) 148 - #[cfg(target_os = "macos")] 149 - { 150 - let output = Command::new("uname").arg("-m").output().ok(); 151 - if let Some(o) = output { 152 - let arch = String::from_utf8_lossy(&o.stdout).trim().to_string(); 153 - if arch == "arm" { 154 - println!("Apple Silicon Mac detected (backing with Metal)"); 155 - return Ok("metal".to_string()); 156 - } 157 - } 158 - } 159 - 160 - // ── 4. Vulkan via vulkaninfo or SDK headers 161 - print!("Checking Vulkan ... "); 162 - std::io::stdout().flush(); 163 - 164 - if check_vulkan() { 165 - println!("vulkan present"); 166 - 167 - if has_command("vulkaninfo") { 168 - print!("Running vulkaninfo --summary ... "); 169 - std::io::stdout().flush(); 170 - 171 - match run_bash("vulkaninfo --summary") { 172 - Ok(info) if !info.is_empty() && info != "" => { 173 - println!("GPU: {}", parse_gpu_name_from_vulkaninfo_output(&info)); 174 - return Ok("vulkan".to_string()); 175 - } 176 - _ => { 177 - println!("could not detect GPU model — falling through"); 178 - } 179 - } 180 - } else { 181 - println!("no vulkaninfo binary, but SDK present — using vulkan backend"); 182 - return Ok("vulkan".to_string()); 183 - } 184 - } else { 185 - println!("Vulkan SDK / vulkaninfo not found") 186 - } 187 - 188 - // ── 5. Fall back to CPU only 189 - println!("No GPU acceleration available — using cpu backend"); 190 - Ok("cpu".to_string()) 191 - } 192 - 193 - fn execute_just_build(backend: &str) -> Result<(), Box<dyn std::error::Error>> { 194 - println!("Running `just build backend=\"{}\"` ...", backend); 195 - std::io::stdout().flush(); 196 - 197 - let out = Command::new("just") 198 - .arg(format!("build backend={}", backend)) 199 - .current_dir(std::path::Path::new(".")) 200 - .stderr(Stdio::piped()) 201 - .output(); 202 - 203 - match out { 204 - Ok(o) => { 205 - if o.status.success() { 206 - println!("Build succeeded with exit code {:?}", o.status.code()); 207 - Ok(()) 208 - } else { 209 - let exit_code = o.status.code(); 210 - let code_str = match exit_code.map(|c| c.to_string()) { 211 - Some(s) => s, 212 - None => "signal".to_string(), 213 - }; 214 - let msg = format!("`just build` exited with code {}", code_str); 215 - return Err(msg.into()); 216 - } 217 - } 218 - Err(e) => { 219 - let msg = format!( 220 - "failed to run `just`: {} (hint: make sure `just` is installed and in PATH; see README.md).", 221 - e, 222 - ); 223 - return Err(msg.into()); 224 - } 225 - } 226 - } 227 - 228 - fn check_vulkan() -> bool { 229 - if has_command("vulkaninfo") { 230 - return true; 231 - } 232 - 233 - const VULKAN_HEADER_PATHS: [&str; 3] = [ 234 - "/usr/include/vulkan/vulkan.h", 235 - "/usr/local/include/vulkan/vulkan.h", 236 - "/opt/homebrew/Cellar/vulkan-loader/2024.12.18/include/vulkan/vulkan.h", 237 - ]; 238 - 239 - for p in VULKAN_HEADER_PATHS.iter() { 240 - if std::path::PathBuf::from(*p).exists() { 241 - return true; 242 - } 243 - } 244 - 245 - false 246 - } 247 - 248 - fn parse_gpu_name_from_vulkaninfo_output(output: &str) -> String { 249 - let lines: Vec<&str> = output.lines().collect(); 250 - 251 - for line in lines.iter().take(20) { 252 - if line.starts_with("GPU #") || line.contains(": Device") || line.contains(": GPU") { 253 - if let Some(pos) = line.find(':') { 254 - let after_colon = line[pos + 1..].trim(); 255 - if !after_colon.is_empty() && !after_colon.starts_with("{") { 256 - return after_colon.to_string(); 257 - } 258 - } 259 - } 260 - } 261 - 262 - "unknown device".to_string() 263 - }