Przeglądaj źródła

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 <lucas@tauri.studio>
Amr Bashir 3 lat temu
rodzic
commit
f48b1b0b3b

+ 5 - 0
.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.

+ 0 - 1
core/tests/app-updater/.gitignore

@@ -1 +0,0 @@
-WixTools/

+ 0 - 1
examples/api/src-tauri/.gitignore

@@ -1,4 +1,3 @@
 # Generated by Cargo
 # will have compiled files and executables
 /target/
-WixTools

+ 0 - 1
examples/resources/src-tauri/.gitignore

@@ -1,4 +1,3 @@
 # Generated by Cargo
 # will have compiled files and executables
 /target/
-WixTools

+ 0 - 1
examples/sidecar/src-tauri/.gitignore

@@ -2,4 +2,3 @@
 # will have compiled files and executables
 /target/
 binaries/
-WixTools

+ 0 - 1
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

+ 0 - 1
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

+ 0 - 1
examples/updater/src-tauri/.gitignore

@@ -1,4 +1,3 @@
 # Generated by Cargo
 # will have compiled files and executables
 /target/
-WixTools

+ 0 - 1
tooling/bench/tests/cpu_intensive/src-tauri/.gitignore

@@ -1,4 +1,3 @@
 # Generated by Cargo
 # will have compiled files and executables
 /target/
-WixTools

+ 0 - 1
tooling/bench/tests/files_transfer/src-tauri/.gitignore

@@ -1,4 +1,3 @@
 # Generated by Cargo
 # will have compiled files and executables
 /target/
-WixTools

+ 0 - 1
tooling/bench/tests/helloworld/src-tauri/.gitignore

@@ -1,4 +1,3 @@
 # Generated by Cargo
 # will have compiled files and executables
 /target/
-WixTools

+ 1 - 1
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"

+ 10 - 0
tooling/bundler/src/bundle/linux/appimage.rs

@@ -55,6 +55,16 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
   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)

+ 7 - 7
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

+ 2 - 1
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<Vec<PathBuf>> {
-  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)?;

+ 1 - 2
tooling/cli/tauri-dev-watcher.gitignore

@@ -1,4 +1,3 @@
 node_modules/
 target/
-WixTools
-Cargo.lock
+Cargo.lock

+ 0 - 1
tooling/cli/tauri.gitignore

@@ -1,3 +1,2 @@
 node_modules/
 target/
-WixTools

+ 0 - 1
tooling/cli/templates/app/src-tauri/.gitignore

@@ -1,4 +1,3 @@
 # Generated by Cargo
 # will have compiled files and executables
 /target/
-WixTools

+ 0 - 1
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

+ 0 - 1
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