feat: add bundled WireGuard tools support for macOS desktop client with fallback path resolution
Add wg and wg-quick bundling to build-tunnel-helper.sh for aarch64-apple-darwin target. Check for wireguard-tools installation and copy binaries to output directory with execute permissions. Implement find_wg_quick helper with bundled tool detection and standard path fallbacks. Add bundled_macos_tool to check for tools in current executable directory. Update connect_direct and disconnect_direct to use explicit
This commit is contained in:
@@ -76,4 +76,21 @@ else
|
|||||||
cargo build --manifest-path "${HELPER_DIR}/Cargo.toml" --release --target "${TARGET}"
|
cargo build --manifest-path "${HELPER_DIR}/Cargo.toml" --release --target "${TARGET}"
|
||||||
fi
|
fi
|
||||||
cp "${HELPER_DIR}/target/${TARGET}/release/${OUTPUT_NAME}" "${OUTPUT_DIR}/${OUTPUT_NAME}"
|
cp "${HELPER_DIR}/target/${TARGET}/release/${OUTPUT_NAME}" "${OUTPUT_DIR}/${OUTPUT_NAME}"
|
||||||
|
|
||||||
|
if [ "${TARGET}" = "aarch64-apple-darwin" ]; then
|
||||||
|
WG_BIN="$(command -v wg || true)"
|
||||||
|
WG_QUICK_BIN="$(command -v wg-quick || true)"
|
||||||
|
|
||||||
|
if [ -z "${WG_BIN}" ] || [ -z "${WG_QUICK_BIN}" ]; then
|
||||||
|
echo "macOS bundle requires wg and wg-quick to be installed on the build machine."
|
||||||
|
echo "Install them with:"
|
||||||
|
echo " brew install wireguard-tools"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
cp "${WG_BIN}" "${OUTPUT_DIR}/wg"
|
||||||
|
cp "${WG_QUICK_BIN}" "${OUTPUT_DIR}/wg-quick"
|
||||||
|
chmod +x "${OUTPUT_DIR}/wg" "${OUTPUT_DIR}/wg-quick"
|
||||||
|
fi
|
||||||
|
|
||||||
echo "Bundled ${OUTPUT_NAME} into ${OUTPUT_DIR}"
|
echo "Bundled ${OUTPUT_NAME} into ${OUTPUT_DIR}"
|
||||||
|
|||||||
@@ -529,7 +529,9 @@ fn connect_direct(profile: &Path) -> Result<(), String> {
|
|||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
let command = format!("wg-quick up '{}'", profile.display());
|
let wg_quick = find_wg_quick()?;
|
||||||
|
let path_prefix = macos_command_path_prefix(&wg_quick);
|
||||||
|
let command = format!("PATH='{}:$PATH' '{}' up '{}'", path_prefix, wg_quick.display(), profile.display());
|
||||||
let status = Command::new("osascript")
|
let status = Command::new("osascript")
|
||||||
.arg("-e")
|
.arg("-e")
|
||||||
.arg(format!("do shell script \"{}\" with administrator privileges", command))
|
.arg(format!("do shell script \"{}\" with administrator privileges", command))
|
||||||
@@ -567,7 +569,9 @@ fn disconnect_direct(profile: &Path) -> Result<(), String> {
|
|||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
{
|
{
|
||||||
let command = format!("wg-quick down '{}'", profile.display());
|
let wg_quick = find_wg_quick()?;
|
||||||
|
let path_prefix = macos_command_path_prefix(&wg_quick);
|
||||||
|
let command = format!("PATH='{}:$PATH' '{}' down '{}'", path_prefix, wg_quick.display(), profile.display());
|
||||||
let status = Command::new("osascript")
|
let status = Command::new("osascript")
|
||||||
.arg("-e")
|
.arg("-e")
|
||||||
.arg(format!("do shell script \"{}\" with administrator privileges", command))
|
.arg(format!("do shell script \"{}\" with administrator privileges", command))
|
||||||
@@ -808,9 +812,59 @@ fn find_wg_cli() -> Result<PathBuf, String> {
|
|||||||
|
|
||||||
#[cfg(target_os = "macos")]
|
#[cfg(target_os = "macos")]
|
||||||
fn find_wg_cli() -> Result<PathBuf, String> {
|
fn find_wg_cli() -> Result<PathBuf, String> {
|
||||||
|
if let Some(path) = bundled_macos_tool("wg") {
|
||||||
|
return Ok(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
let candidates = [
|
||||||
|
PathBuf::from("/opt/homebrew/bin/wg"),
|
||||||
|
PathBuf::from("/usr/local/bin/wg"),
|
||||||
|
PathBuf::from("/usr/bin/wg"),
|
||||||
|
];
|
||||||
|
|
||||||
|
if let Some(path) = candidates.into_iter().find(|path| path.exists()) {
|
||||||
|
return Ok(path);
|
||||||
|
}
|
||||||
|
|
||||||
Ok(PathBuf::from("wg"))
|
Ok(PathBuf::from("wg"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
fn find_wg_quick() -> Result<PathBuf, String> {
|
||||||
|
if let Some(path) = bundled_macos_tool("wg-quick") {
|
||||||
|
return Ok(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
let candidates = [
|
||||||
|
PathBuf::from("/opt/homebrew/bin/wg-quick"),
|
||||||
|
PathBuf::from("/usr/local/bin/wg-quick"),
|
||||||
|
PathBuf::from("/usr/bin/wg-quick"),
|
||||||
|
];
|
||||||
|
|
||||||
|
candidates
|
||||||
|
.into_iter()
|
||||||
|
.find(|path| path.exists())
|
||||||
|
.or_else(|| Some(PathBuf::from("wg-quick")))
|
||||||
|
.ok_or_else(|| "required macOS tunnel runtime is not available".to_string())
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
fn bundled_macos_tool(name: &str) -> Option<PathBuf> {
|
||||||
|
let current_exe = std::env::current_exe().ok()?;
|
||||||
|
let dir = current_exe.parent()?;
|
||||||
|
let path = dir.join(name);
|
||||||
|
path.exists().then_some(path)
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
fn macos_command_path_prefix(tool_path: &Path) -> String {
|
||||||
|
let parent = tool_path
|
||||||
|
.parent()
|
||||||
|
.map(|path| path.display().to_string())
|
||||||
|
.unwrap_or_else(|| "/opt/homebrew/bin".to_string());
|
||||||
|
format!("{parent}:/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin")
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(target_os = "windows")]
|
#[cfg(target_os = "windows")]
|
||||||
fn find_windows_wireguard() -> Result<PathBuf, String> {
|
fn find_windows_wireguard() -> Result<PathBuf, String> {
|
||||||
let candidates = [
|
let candidates = [
|
||||||
|
|||||||
Reference in New Issue
Block a user