瀏覽代碼

feat(bundler): bundle additional gstreamer files, closes #4092 (#4271)

Co-authored-by: Lucas Nogueira <lucas@tauri.studio>
Fabian-Lars 3 年之前
父節點
當前提交
d335fae92c

+ 5 - 0
.changes/appimage-bundle-gstreamer.md

@@ -0,0 +1,5 @@
+---
+"tauri-bundler": patch
+---
+
+Bundle additional gstreamer files needed for audio and video playback if the `APPIMAGE_BUNDLE_GSTREAMER` environment variable is set.

+ 5 - 0
.changes/bundle-media-framework-config.md

@@ -0,0 +1,5 @@
+---
+"tauri-utils": patch
+---
+
+Added a config flag to bundle the media framework used by webkit2gtk `tauri.conf.json > tauri > bundle > appimage > bundleMediaFramework`.

+ 6 - 0
.changes/cli-bundle-gstreamer.md

@@ -0,0 +1,6 @@
+---
+"cli.rs": patch
+"cli.js": patch
+---
+
+Set the `APPIMAGE_BUNDLE_GSTREAMER` environment variable to make the bundler copy additional gstreamer files to the AppImage.

+ 17 - 0
core/tauri-utils/src/config.rs

@@ -87,6 +87,17 @@ impl BundleTarget {
   }
 }
 
+/// Configuration for AppImage bundles.
+#[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
+#[cfg_attr(feature = "schema", derive(JsonSchema))]
+#[serde(rename_all = "camelCase", deny_unknown_fields)]
+pub struct AppImageConfig {
+  /// Include additional gstreamer dependencies needed for audio and video playback.
+  /// This increases the bundle size by ~15-35MB depending on your build system.
+  #[serde(default)]
+  pub bundle_media_framework: bool,
+}
+
 /// Configuration for Debian (.deb) bundles.
 #[skip_serializing_none]
 #[derive(Debug, Default, PartialEq, Eq, Clone, Deserialize, Serialize)]
@@ -322,6 +333,9 @@ pub struct BundleConfig {
   pub short_description: Option<String>,
   /// A longer, multi-line description of the application.
   pub long_description: Option<String>,
+  /// Configuration for the AppImage bundle.
+  #[serde(default)]
+  pub appimage: AppImageConfig,
   /// Configuration for the Debian bundle.
   #[serde(default)]
   pub deb: DebConfig,
@@ -2728,6 +2742,7 @@ mod build {
       let category = quote!(None);
       let short_description = quote!(None);
       let long_description = quote!(None);
+      let appimage = quote!(Default::default());
       let deb = quote!(Default::default());
       let macos = quote!(Default::default());
       let external_bin = opt_vec_str_lit(self.external_bin.as_ref());
@@ -2745,6 +2760,7 @@ mod build {
         category,
         short_description,
         long_description,
+        appimage,
         deb,
         macos,
         external_bin,
@@ -3147,6 +3163,7 @@ mod test {
         category: None,
         short_description: None,
         long_description: None,
+        appimage: Default::default(),
         deb: Default::default(),
         macos: Default::default(),
         external_bin: None,

+ 11 - 2
tooling/bundler/src/bundle/linux/templates/appimage

@@ -7,6 +7,7 @@ set -euxo pipefail
 
 export ARCH={{arch}}
 APPIMAGE_BUNDLE_XDG_OPEN=${APPIMAGE_BUNDLE_XDG_OPEN-0}
+APPIMAGE_BUNDLE_GSTREAMER=${APPIMAGE_BUNDLE_GSTREAMER-0}
 TRAY_LIBRARY_PATH=${TRAY_LIBRARY_PATH-0}
 
 if [ "$ARCH" == "i686" ]; then
@@ -51,12 +52,20 @@ ln -s "usr/share/applications/{{app_name}}.desktop" "{{app_name}}.desktop"
 
 cd ..
 
-wget -q -4 -N -O linuxdeploy-plugin-gtk.sh "https://raw.githubusercontent.com/tauri-apps/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh"
+if [[ "$APPIMAGE_BUNDLE_GSTREAMER" != "0" ]]; then
+  gst_plugin="--plugin gstreamer"
+  wget -q -4 -N -O linuxdeploy-plugin-gstreamer.sh "https://raw.githubusercontent.com/tauri-apps/linuxdeploy-plugin-gstreamer/master/linuxdeploy-plugin-gstreamer.sh"
+  chmod +x linuxdeploy-plugin-gstreamer.sh
+else
+  gst_plugin=""
+fi
+
+wget -q -4 -N -O linuxdeploy-plugin-gtk.sh https://raw.githubusercontent.com/tauri-apps/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh
 wget -q -4 -N -O 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
 
-OUTPUT="{{appimage_filename}}" ./linuxdeploy-${ARCH}.AppImage --appimage-extract-and-run --appdir "{{app_name}}.AppDir" --plugin gtk --output appimage
+OUTPUT="{{appimage_filename}}" ./linuxdeploy-${ARCH}.AppImage --appimage-extract-and-run --appdir "{{app_name}}.AppDir" --plugin gtk ${gst_plugin}  --output appimage
 rm -r "{{app_name}}.AppDir"
 mv "{{appimage_filename}}" $OUTDIR

+ 29 - 0
tooling/cli/schema.json

@@ -118,6 +118,9 @@
         },
         "bundle": {
           "active": false,
+          "appimage": {
+            "bundleMediaFramework": false
+          },
           "deb": {
             "files": {}
           },
@@ -245,6 +248,9 @@
           "description": "The bundler configuration.",
           "default": {
             "active": false,
+            "appimage": {
+              "bundleMediaFramework": false
+            },
             "deb": {
               "files": {}
             },
@@ -955,6 +961,17 @@
             "null"
           ]
         },
+        "appimage": {
+          "description": "Configuration for the AppImage bundle.",
+          "default": {
+            "bundleMediaFramework": false
+          },
+          "allOf": [
+            {
+              "$ref": "#/definitions/AppImageConfig"
+            }
+          ]
+        },
         "deb": {
           "description": "Configuration for the Debian bundle.",
           "default": {
@@ -1023,6 +1040,18 @@
         }
       ]
     },
+    "AppImageConfig": {
+      "description": "Configuration for AppImage bundles.",
+      "type": "object",
+      "properties": {
+        "bundleMediaFramework": {
+          "description": "Include additional gstreamer dependencies needed for audio and video playback. This increases the bundle size by ~15-35MB depending on your build system.",
+          "default": false,
+          "type": "boolean"
+        }
+      },
+      "additionalProperties": false
+    },
     "DebConfig": {
       "description": "Configuration for Debian (.deb) bundles.",
       "type": "object",

+ 3 - 0
tooling/cli/src/build.rs

@@ -337,6 +337,9 @@ pub fn command(options: Options) -> Result<()> {
         }
       }
     }
+    if config_.tauri.bundle.appimage.bundle_media_framework {
+      std::env::set_var("APPIMAGE_BUNDLE_GSTREAMER", "1");
+    }
 
     let bundles = bundle_project(settings).with_context(|| "failed to bundle project")?;