Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@
"format": "prettier --write \"src/**/*.{js,jsx,ts,tsx,css,json}\"",
"format:check": "prettier --check \"src/**/*.{js,jsx,ts,tsx,css,json}\"",
"test:unit": "vitest run",
"test:unit:watch": "vitest watch"
"test:unit:watch": "vitest watch",
"cargo:check": "bash scripts/cargo-with-real-cc.sh check",
"cargo:clippy": "bash scripts/cargo-with-real-cc.sh clippy",
"check:all": "pnpm typecheck && pnpm format:check && pnpm test:unit && pnpm cargo:check && pnpm cargo:clippy"
},
"keywords": [],
"author": "Jason Young",
Expand Down
63 changes: 63 additions & 0 deletions scripts/cargo-with-real-cc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#!/usr/bin/env bash
# pnpm/npm 脚本在非交互 shell 中也可能继承把 `cc` 指到非编译器的环境;
# cc-rs 会调用 `cc`,此处在未显式设置 CC 时强制使用系统 Clang/GCC。
set -euo pipefail
ROOT="$(cd "$(dirname "$0")/.." && pwd)"
cd "${ROOT}/src-tauri"

# 显式 SDK:cc-rs 使用 --target=*-apple-macosx 时必须能解析系统头文件。
# 环境中可能残留指向旧版 Xcode 的 SDKROOT(例如 MacOSX12.3.sdk),会导致 stdlib.h 找不到;
# 此处始终用当前 xcrun 的 macOS SDK,除非显式设置 CC_SWITCH_KEEP_SDKROOT=1。
if [[ "$(uname -s)" == "Darwin" && -z "${CC_SWITCH_KEEP_SDKROOT:-}" ]]; then
_SDK="$(xcrun --sdk macosx --show-sdk-path 2>/dev/null || true)"
if [[ -n "${_SDK}" ]]; then
export SDKROOT="${_SDK}"
# cc-rs 子进程对 SDKROOT 的传递偶有不一致,CFLAGS 更稳妥
if [[ "${CFLAGS:-}" != *"-isysroot"* ]]; then
export CFLAGS="${CFLAGS:+$CFLAGS }-isysroot ${_SDK}"
fi
if [[ "${CXXFLAGS:-}" != *"-isysroot"* ]]; then
export CXXFLAGS="${CXXFLAGS:+$CXXFLAGS }-isysroot ${_SDK}"
fi
fi
fi

if [[ -z "${CC:-}" ]]; then
case "$(uname -s)" in
Darwin)
if [[ -x /usr/bin/clang ]]; then
export CC=/usr/bin/clang
elif command -v clang >/dev/null 2>&1; then
export CC="$(command -v clang)"
fi
;;
*)
if command -v clang >/dev/null 2>&1; then
export CC="$(command -v clang)"
elif command -v gcc >/dev/null 2>&1; then
export CC="$(command -v gcc)"
fi
;;
esac
fi

if [[ -z "${CXX:-}" ]]; then
case "$(uname -s)" in
Darwin)
if [[ -x /usr/bin/clang++ ]]; then
export CXX=/usr/bin/clang++
elif command -v clang++ >/dev/null 2>&1; then
export CXX="$(command -v clang++)"
fi
;;
*)
if command -v clang++ >/dev/null 2>&1; then
export CXX="$(command -v clang++)"
elif command -v g++ >/dev/null 2>&1; then
export CXX="$(command -v g++)"
fi
;;
esac
fi

exec cargo "$@"
1 change: 1 addition & 0 deletions src-tauri/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src-tauri/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ webkit2gtk = { version = "2.0.1", features = ["v2_16"] }

[target.'cfg(target_os = "windows")'.dependencies]
winreg = "0.52"
windows-sys = { version = "0.61", features = ["Win32_Foundation", "Win32_Storage_FileSystem"] }

[target.'cfg(target_os = "macos")'.dependencies]
objc2 = "0.5"
Expand Down
4 changes: 2 additions & 2 deletions src-tauri/src/commands/misc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ pub async fn get_tool_versions(
#[cfg(target_os = "windows")]
{
let _ = (tools, wsl_shell_by_tool);
return Ok(Vec::new());
Ok(Vec::new())
}

#[cfg(not(target_os = "windows"))]
Expand Down Expand Up @@ -879,7 +879,7 @@ fn launch_terminal_with_env(
#[cfg(target_os = "windows")]
{
launch_windows_terminal(&temp_dir, &config_file, cwd)?;
return Ok(());
Ok(())
}

#[cfg(not(any(target_os = "macos", target_os = "linux", target_os = "windows")))]
Expand Down
Loading