From f48b1b0b3bec6a2a85c7dac67a128fa578f7ee15 Mon Sep 17 00:00:00 2001 From: Amr Bashir Date: Thu, 9 Jun 2022 21:16:33 +0200 Subject: [PATCH] feat(bundler): cache bundling tools in a common dir for all projects (#4305) * feat(bundler): cache bundling tools in a common dir for all projects * fix changefile * fix linux * linux again * again * again * omg I could've reboot into my linux system * I rebooted into my linux * fix linux one more time * finally * -nc * cleanup gitignores * Revert "-nc" This reverts commit 8d821c6c372f3840e75c7421166f604479febfbf. * use -N on appimage's wget calls Co-authored-by: Lucas Nogueira --- .changes/bundler-cache-bundle-tools.md | 5 +++++ core/tests/app-updater/.gitignore | 1 - examples/api/src-tauri/.gitignore | 1 - examples/resources/src-tauri/.gitignore | 1 - examples/sidecar/src-tauri/.gitignore | 1 - examples/tauri-dynamic-lib/src-app1/.gitignore | 1 - examples/tauri-dynamic-lib/src-tauri/.gitignore | 1 - examples/updater/src-tauri/.gitignore | 1 - .../bench/tests/cpu_intensive/src-tauri/.gitignore | 1 - .../tests/files_transfer/src-tauri/.gitignore | 1 - .../bench/tests/helloworld/src-tauri/.gitignore | 1 - tooling/bundler/Cargo.toml | 2 +- tooling/bundler/src/bundle/linux/appimage.rs | 10 ++++++++++ .../bundler/src/bundle/linux/templates/appimage | 14 +++++++------- tooling/bundler/src/bundle/windows/msi.rs | 3 ++- tooling/cli/tauri-dev-watcher.gitignore | 3 +-- tooling/cli/tauri.gitignore | 1 - tooling/cli/templates/app/src-tauri/.gitignore | 1 - .../backend/examples/vanilla/src-tauri/.gitignore | 1 - .../examples/svelte-app/src-tauri/.gitignore | 1 - 20 files changed, 26 insertions(+), 25 deletions(-) create mode 100644 .changes/bundler-cache-bundle-tools.md diff --git a/.changes/bundler-cache-bundle-tools.md b/.changes/bundler-cache-bundle-tools.md new file mode 100644 index 000000000..5544e8eb1 --- /dev/null +++ b/.changes/bundler-cache-bundle-tools.md @@ -0,0 +1,5 @@ +--- +"tauri-bundler": patch +--- + +Cache bundling tools in a directory shared by all tauri projects. Usually in `$XDG_HOME/.cache/tauri` on Linux and `$HOME\AppData\Local\tauri` on Windows. diff --git a/core/tests/app-updater/.gitignore b/core/tests/app-updater/.gitignore index 815ea8b94..e69de29bb 100644 --- a/core/tests/app-updater/.gitignore +++ b/core/tests/app-updater/.gitignore @@ -1 +0,0 @@ -WixTools/ diff --git a/examples/api/src-tauri/.gitignore b/examples/api/src-tauri/.gitignore index c12370459..aba21e242 100644 --- a/examples/api/src-tauri/.gitignore +++ b/examples/api/src-tauri/.gitignore @@ -1,4 +1,3 @@ # Generated by Cargo # will have compiled files and executables /target/ -WixTools diff --git a/examples/resources/src-tauri/.gitignore b/examples/resources/src-tauri/.gitignore index c12370459..aba21e242 100644 --- a/examples/resources/src-tauri/.gitignore +++ b/examples/resources/src-tauri/.gitignore @@ -1,4 +1,3 @@ # Generated by Cargo # will have compiled files and executables /target/ -WixTools diff --git a/examples/sidecar/src-tauri/.gitignore b/examples/sidecar/src-tauri/.gitignore index 3bbdbf4b4..72198553f 100644 --- a/examples/sidecar/src-tauri/.gitignore +++ b/examples/sidecar/src-tauri/.gitignore @@ -2,4 +2,3 @@ # will have compiled files and executables /target/ binaries/ -WixTools diff --git a/examples/tauri-dynamic-lib/src-app1/.gitignore b/examples/tauri-dynamic-lib/src-app1/.gitignore index 270a92d27..86473b14e 100644 --- a/examples/tauri-dynamic-lib/src-app1/.gitignore +++ b/examples/tauri-dynamic-lib/src-app1/.gitignore @@ -1,7 +1,6 @@ # Generated by Cargo # will have compiled files and executables /target/ -WixTools # These are backup files generated by rustfmt **/*.rs.bk diff --git a/examples/tauri-dynamic-lib/src-tauri/.gitignore b/examples/tauri-dynamic-lib/src-tauri/.gitignore index 270a92d27..86473b14e 100644 --- a/examples/tauri-dynamic-lib/src-tauri/.gitignore +++ b/examples/tauri-dynamic-lib/src-tauri/.gitignore @@ -1,7 +1,6 @@ # Generated by Cargo # will have compiled files and executables /target/ -WixTools # These are backup files generated by rustfmt **/*.rs.bk diff --git a/examples/updater/src-tauri/.gitignore b/examples/updater/src-tauri/.gitignore index c12370459..aba21e242 100644 --- a/examples/updater/src-tauri/.gitignore +++ b/examples/updater/src-tauri/.gitignore @@ -1,4 +1,3 @@ # Generated by Cargo # will have compiled files and executables /target/ -WixTools diff --git a/tooling/bench/tests/cpu_intensive/src-tauri/.gitignore b/tooling/bench/tests/cpu_intensive/src-tauri/.gitignore index c12370459..aba21e242 100644 --- a/tooling/bench/tests/cpu_intensive/src-tauri/.gitignore +++ b/tooling/bench/tests/cpu_intensive/src-tauri/.gitignore @@ -1,4 +1,3 @@ # Generated by Cargo # will have compiled files and executables /target/ -WixTools diff --git a/tooling/bench/tests/files_transfer/src-tauri/.gitignore b/tooling/bench/tests/files_transfer/src-tauri/.gitignore index c12370459..aba21e242 100644 --- a/tooling/bench/tests/files_transfer/src-tauri/.gitignore +++ b/tooling/bench/tests/files_transfer/src-tauri/.gitignore @@ -1,4 +1,3 @@ # Generated by Cargo # will have compiled files and executables /target/ -WixTools diff --git a/tooling/bench/tests/helloworld/src-tauri/.gitignore b/tooling/bench/tests/helloworld/src-tauri/.gitignore index c12370459..aba21e242 100644 --- a/tooling/bench/tests/helloworld/src-tauri/.gitignore +++ b/tooling/bench/tests/helloworld/src-tauri/.gitignore @@ -1,4 +1,3 @@ # Generated by Cargo # will have compiled files and executables /target/ -WixTools diff --git a/tooling/bundler/Cargo.toml b/tooling/bundler/Cargo.toml index e1569db55..7555d222c 100644 --- a/tooling/bundler/Cargo.toml +++ b/tooling/bundler/Cargo.toml @@ -37,6 +37,7 @@ walkdir = "2" handlebars = "4.3" tempfile = "3.3.0" log = { version = "0.4.17", features = [ "kv_unstable" ] } +dirs-next = "2.0" [target."cfg(target_os = \"windows\")".dependencies] attohttpc = "0.19" @@ -50,7 +51,6 @@ zip = "0.6" [target."cfg(target_os = \"macos\")".dependencies] time = { version = "0.3", features = [ "formatting" ] } -dirs-next = "2.0" [target."cfg(any(target_os = \"macos\", target_os = \"windows\"))".dependencies] regex = "1" diff --git a/tooling/bundler/src/bundle/linux/appimage.rs b/tooling/bundler/src/bundle/linux/appimage.rs index 0bc4488e1..62c79a7db 100644 --- a/tooling/bundler/src/bundle/linux/appimage.rs +++ b/tooling/bundler/src/bundle/linux/appimage.rs @@ -55,6 +55,16 @@ pub fn bundle_project(settings: &Settings) -> crate::Result> { sh_map.insert("app_name", settings.main_binary_name()); sh_map.insert("app_name_uppercase", &upcase_app_name); sh_map.insert("appimage_filename", &appimage_filename); + let tauri_tools_path = dirs_next::cache_dir().map_or_else( + || output_path.to_path_buf(), + |mut p| { + p.push("tauri"); + p + }, + ); + std::fs::create_dir_all(&tauri_tools_path)?; + let tauri_tools_path_str = tauri_tools_path.to_string_lossy(); + sh_map.insert("tauri_tools_path", &tauri_tools_path_str); let larger_icon = icons .iter() .filter(|i| i.width == i.height) diff --git a/tooling/bundler/src/bundle/linux/templates/appimage b/tooling/bundler/src/bundle/linux/templates/appimage index 9c12dca10..d890bdabe 100644 --- a/tooling/bundler/src/bundle/linux/templates/appimage +++ b/tooling/bundler/src/bundle/linux/templates/appimage @@ -35,8 +35,8 @@ find /usr/lib* -name WebKitNetworkProcess -exec mkdir -p "$(dirname '{}')" \; -e find /usr/lib* -name WebKitWebProcess -exec mkdir -p "$(dirname '{}')" \; -exec cp --parents '{}' "." \; || true find /usr/lib* -name libwebkit2gtkinjectedbundle.so -exec mkdir -p "$(dirname '{}')" \; -exec cp --parents '{}' "." \; || true -wget -q -4 -O AppRun https://github.com/AppImage/AppImageKit/releases/download/continuous/AppRun-${ARCH} || wget -q -4 -O AppRun https://github.com/AppImage/AppImageKit/releases/download/12/AppRun-${ARCH} -chmod +x AppRun +wget -q -4 -N -O "{{tauri_tools_path}}/AppRun" https://github.com/AppImage/AppImageKit/releases/download/continuous/AppRun-${ARCH} || wget -q -4 -N -O "{{tauri_tools_path}}/AppRun" https://github.com/AppImage/AppImageKit/releases/download/12/AppRun-${ARCH} +chmod +x "{{tauri_tools_path}}/AppRun" cp "{{icon_path}}" .DirIcon ln -s "{{icon_path}}" "{{app_name}}.png" @@ -45,10 +45,10 @@ ln -s "usr/share/applications/{{app_name}}.desktop" "{{app_name}}.desktop" cd .. -wget -q -4 -O linuxdeploy-plugin-gtk.sh "https://raw.githubusercontent.com/tauri-apps/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh" -wget -q -4 -O linuxdeploy-${ARCH}.AppImage https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-${linuxdeploy_arch}.AppImage +wget -q -4 -N -O "{{tauri_tools_path}}/linuxdeploy-plugin-gtk.sh" "https://raw.githubusercontent.com/tauri-apps/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh" +wget -q -4 -N -O "{{tauri_tools_path}}/linuxdeploy-${ARCH}.AppImage" https://github.com/linuxdeploy/linuxdeploy/releases/download/continuous/linuxdeploy-${linuxdeploy_arch}.AppImage -chmod +x linuxdeploy-plugin-gtk.sh -chmod +x linuxdeploy-${ARCH}.AppImage +chmod +x "{{tauri_tools_path}}/linuxdeploy-plugin-gtk.sh" +chmod +x "{{tauri_tools_path}}/linuxdeploy-${ARCH}.AppImage" -OUTPUT="{{appimage_filename}}" ./linuxdeploy-${ARCH}.AppImage --appimage-extract-and-run --appdir "{{app_name}}.AppDir" --plugin gtk --output appimage +OUTPUT="{{appimage_filename}}" "{{tauri_tools_path}}/linuxdeploy-${ARCH}.AppImage" --appimage-extract-and-run --appdir "{{app_name}}.AppDir" --plugin gtk --output appimage diff --git a/tooling/bundler/src/bundle/windows/msi.rs b/tooling/bundler/src/bundle/windows/msi.rs index 96a302b0c..5acc6d17f 100644 --- a/tooling/bundler/src/bundle/windows/msi.rs +++ b/tooling/bundler/src/bundle/windows/msi.rs @@ -11,7 +11,8 @@ use std::{self, path::PathBuf}; /// Runs all of the commands to build the MSI installer. /// Returns a vector of PathBuf that shows where the MSI was created. pub fn bundle_project(settings: &Settings) -> crate::Result> { - let wix_path = PathBuf::from("./WixTools"); + let mut wix_path = dirs_next::cache_dir().unwrap(); + wix_path.push("tauri/WixTools"); if !wix_path.exists() { wix::get_and_extract_wix(&wix_path)?; diff --git a/tooling/cli/tauri-dev-watcher.gitignore b/tooling/cli/tauri-dev-watcher.gitignore index decb5b866..130e8431e 100644 --- a/tooling/cli/tauri-dev-watcher.gitignore +++ b/tooling/cli/tauri-dev-watcher.gitignore @@ -1,4 +1,3 @@ node_modules/ target/ -WixTools -Cargo.lock \ No newline at end of file +Cargo.lock diff --git a/tooling/cli/tauri.gitignore b/tooling/cli/tauri.gitignore index 9ffb3bcdc..aa8afe611 100644 --- a/tooling/cli/tauri.gitignore +++ b/tooling/cli/tauri.gitignore @@ -1,3 +1,2 @@ node_modules/ target/ -WixTools \ No newline at end of file diff --git a/tooling/cli/templates/app/src-tauri/.gitignore b/tooling/cli/templates/app/src-tauri/.gitignore index c12370459..aba21e242 100755 --- a/tooling/cli/templates/app/src-tauri/.gitignore +++ b/tooling/cli/templates/app/src-tauri/.gitignore @@ -1,4 +1,3 @@ # Generated by Cargo # will have compiled files and executables /target/ -WixTools diff --git a/tooling/cli/templates/plugin/backend/examples/vanilla/src-tauri/.gitignore b/tooling/cli/templates/plugin/backend/examples/vanilla/src-tauri/.gitignore index c12370459..aba21e242 100644 --- a/tooling/cli/templates/plugin/backend/examples/vanilla/src-tauri/.gitignore +++ b/tooling/cli/templates/plugin/backend/examples/vanilla/src-tauri/.gitignore @@ -1,4 +1,3 @@ # Generated by Cargo # will have compiled files and executables /target/ -WixTools diff --git a/tooling/cli/templates/plugin/with-api/examples/svelte-app/src-tauri/.gitignore b/tooling/cli/templates/plugin/with-api/examples/svelte-app/src-tauri/.gitignore index c12370459..aba21e242 100644 --- a/tooling/cli/templates/plugin/with-api/examples/svelte-app/src-tauri/.gitignore +++ b/tooling/cli/templates/plugin/with-api/examples/svelte-app/src-tauri/.gitignore @@ -1,4 +1,3 @@ # Generated by Cargo # will have compiled files and executables /target/ -WixTools