diff --git a/qt/launcher/mac/build.sh b/qt/launcher/mac/build.sh index 6143451b4..b861bc006 100755 --- a/qt/launcher/mac/build.sh +++ b/qt/launcher/mac/build.sh @@ -30,6 +30,12 @@ lipo -create \ -output "$APP_LAUNCHER/Contents/MacOS/launcher" cp "$OUTPUT_DIR/uv" "$APP_LAUNCHER/Contents/MacOS/" +# Build install_name_tool stub +clang -arch arm64 -o "$OUTPUT_DIR/stub_arm64" stub.c +clang -arch x86_64 -o "$OUTPUT_DIR/stub_x86_64" stub.c +lipo -create "$OUTPUT_DIR/stub_arm64" "$OUTPUT_DIR/stub_x86_64" -output "$APP_LAUNCHER/Contents/MacOS/install_name_tool" +rm "$OUTPUT_DIR/stub_arm64" "$OUTPUT_DIR/stub_x86_64" + # Copy support files ANKI_VERSION=$(cat ../../../.version | tr -d '\n') sed "s/ANKI_VERSION/$ANKI_VERSION/g" Info.plist > "$APP_LAUNCHER/Contents/Info.plist" @@ -40,7 +46,7 @@ cp ../versions.py "$APP_LAUNCHER/Contents/Resources/" # Codesign/bundle if [ -z "$NODMG" ]; then - for i in "$APP_LAUNCHER/Contents/MacOS/uv" "$APP_LAUNCHER/Contents/MacOS/launcher" "$APP_LAUNCHER"; do + for i in "$APP_LAUNCHER/Contents/MacOS/uv" "$APP_LAUNCHER/Contents/MacOS/install_name_tool" "$APP_LAUNCHER/Contents/MacOS/launcher" "$APP_LAUNCHER"; do codesign --force -vvvv -o runtime -s "Developer ID Application:" \ --entitlements entitlements.python.xml \ "$i" diff --git a/qt/launcher/mac/stub.c b/qt/launcher/mac/stub.c new file mode 100644 index 000000000..09f1479a7 --- /dev/null +++ b/qt/launcher/mac/stub.c @@ -0,0 +1,6 @@ +// Copyright: Ankitects Pty Ltd and contributors +// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html + +int main(void) { + return 0; +} \ No newline at end of file diff --git a/qt/launcher/src/main.rs b/qt/launcher/src/main.rs index ccc4022b7..c4aba4509 100644 --- a/qt/launcher/src/main.rs +++ b/qt/launcher/src/main.rs @@ -261,11 +261,6 @@ fn handle_version_install_or_update(state: &State, choice: MainMenuChoice) -> Re None }; - let have_venv = state.venv_folder.exists(); - if cfg!(target_os = "macos") && !have_developer_tools() && !have_venv { - println!("If you see a pop-up about 'install_name_tool', you can cancel it, and ignore the warning below.\n"); - } - // Prepare to sync the venv let mut command = Command::new(&state.uv_path); command.current_dir(&state.uv_install_root); @@ -277,17 +272,29 @@ fn handle_version_install_or_update(state: &State, choice: MainMenuChoice) -> Re } } - // remove CONDA_PREFIX/bin from PATH to avoid conda interference - #[cfg(target_os = "macos")] - if let Ok(conda_prefix) = std::env::var("CONDA_PREFIX") { + if cfg!(target_os = "macos") { + // remove CONDA_PREFIX/bin from PATH to avoid conda interference + if let Ok(conda_prefix) = std::env::var("CONDA_PREFIX") { + if let Ok(current_path) = std::env::var("PATH") { + let conda_bin = format!("{conda_prefix}/bin"); + let filtered_paths: Vec<&str> = current_path + .split(':') + .filter(|&path| path != conda_bin) + .collect(); + let new_path = filtered_paths.join(":"); + command.env("PATH", new_path); + } + } + // put our fake install_name_tool at the top of the path to override + // potential conflicts if let Ok(current_path) = std::env::var("PATH") { - let conda_bin = format!("{conda_prefix}/bin"); - let filtered_paths: Vec<&str> = current_path - .split(':') - .filter(|&path| path != conda_bin) - .collect(); - let new_path = filtered_paths.join(":"); - command.env("PATH", new_path); + let exe_dir = std::env::current_exe() + .ok() + .and_then(|exe| exe.parent().map(|p| p.to_path_buf())); + if let Some(exe_dir) = exe_dir { + let new_path = format!("{}:{}", exe_dir.display(), current_path); + command.env("PATH", new_path); + } } } @@ -930,14 +937,6 @@ fn handle_uninstall(state: &State) -> Result { Ok(true) } -fn have_developer_tools() -> bool { - Command::new("xcode-select") - .args(["-p"]) - .output() - .map(|output| output.status.success()) - .unwrap_or(false) -} - fn build_python_command(state: &State, args: &[String]) -> Result { let python_exe = if cfg!(target_os = "windows") { let show_console = std::env::var("ANKI_CONSOLE").is_ok();