Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(Linux): Fix libwebkit2gtk-4.0 not available issue #9863

Open
wants to merge 4 commits into
base: 1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changes/fix-webkit2gtk-linux-bug.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'tauri-bundler': 'patch:bug'
---

Fix the `libwebkit2gtk-4.0` bug in Linux by embedding them into the `deb` package. This increases the size of package, but is necessary to make `deb` packages work on Ubuntu 24 and Debian 13 and higher.
83 changes: 82 additions & 1 deletion tooling/bundler/src/bundle/linux/debian.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
// metadata, as well as generating the md5sums file. Currently we do not
// generate postinst or prerm files.

use super::super::common;
use super::super::common::{self, CommandExt};
use crate::Settings;
use anyhow::Context;
use handlebars::Handlebars;
Expand All @@ -41,6 +41,7 @@ use std::{
io::{self, Write},
os::unix::fs::MetadataExt,
path::{Path, PathBuf},
process::Command,
};

use flate2::{write::GzEncoder, Compression};
Expand Down Expand Up @@ -82,6 +83,59 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {

info!(action = "Bundling"; "{} ({})", package_name, package_path.display());

// Copy Webkit Libraries
let _ = copy_lib(
&package_dir,
&mut PathBuf::from("/usr/lib/libwebkit2gtk-4.0.so"),
2,
);
let _ = copy_lib(
&package_dir,
&mut PathBuf::from("/usr/lib/libjavascriptcoregtk-4.0.so"),
2,
);

// Copy icu libraries
let _ = copy_lib(
&package_dir,
&mut PathBuf::from("/usr/lib/libicudata.so"),
1,
);
let _ = copy_lib(
&package_dir,
&mut PathBuf::from("/usr/lib/libicui18n.so"),
1,
);
let _ = copy_lib(&package_dir, &mut PathBuf::from("/usr/lib/libicuio.so"), 1);
let _ = copy_lib(
&package_dir,
&mut PathBuf::from("/usr/lib/libicutest.so"),
1,
);
let _ = copy_lib(&package_dir, &mut PathBuf::from("/usr/lib/libicutu.so"), 1);
let _ = copy_lib(&package_dir, &mut PathBuf::from("/usr/lib/libicuuc.so"), 1);

// Copy jxl libraries
let _ = copy_lib(&package_dir, &mut PathBuf::from("/usr/lib/libjxl.so"), 1);
let _ = copy_lib(
&package_dir,
&mut PathBuf::from("/usr/lib/libjxl_cms.so"),
1,
);
let _ = copy_lib(
&package_dir,
&mut PathBuf::from("/usr/lib/libjxl_threads.so"),
1,
);

// Copy WebKit files. Follow symlinks in case `/usr/lib64` is a symlink to `/usr/lib`
Command::new("sh")
.arg("-c")
.arg(r#"find -L /usr/lib* -name webkit2gtk-4.0 -exec mkdir -p "$(dirname '{}')" \; -exec cp -r --parents '{}' "." \; || true"#)
.current_dir(&package_dir.join("data"))
.output_ok()
.context("Failed to copy the webkit2gtk-4.0 files")?;

let (data_dir, _) = generate_data(settings, &package_dir)
.with_context(|| "Failed to build data folders and files")?;
copy_custom_files(settings, &data_dir).with_context(|| "Failed to copy custom files")?;
Expand Down Expand Up @@ -111,6 +165,33 @@ pub fn bundle_project(settings: &Settings) -> crate::Result<Vec<PathBuf>> {
Ok(vec![package_path])
}

// Copy libwebkit2gtk-4.0 to make it work on Ubuntu 24.04 and later
fn copy_lib(
package_dir: &Path,
lib_path: &mut PathBuf,
to_remove: usize,
) -> crate::Result<PathBuf> {
let target_dir = package_dir.join(format!("data/usr/lib"));

// Follow the symlink
while lib_path.is_symlink() {
let link_name = lib_path.read_link()?;
lib_path.set_file_name(link_name);
}

let mut lib_name = lib_path.clone();

for _ in 0..to_remove {
lib_name = PathBuf::from(lib_name.file_stem().unwrap());
}

// Copy the library file to lib directory
common::copy_file(&lib_path, &target_dir.join(&lib_name))
.with_context(|| format!("Failed to copy the library {}", lib_path.display()))?;

Ok(target_dir)
}

/// Generate the debian data folders and files.
pub fn generate_data(
settings: &Settings,
Expand Down
3 changes: 1 addition & 2 deletions tooling/cli/src/interface/rust.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1057,8 +1057,7 @@ fn tauri_config_to_bundle_settings(
}
}

// provides `libwebkit2gtk-4.0.so.37` and all `4.0` versions have the -37 package name
depends.push("libwebkit2gtk-4.0-37".to_string());
depends.push("libavif-bin".to_string());
depends.push("libgtk-3-0".to_string());
}

Expand Down
Loading