diff --git a/native/Cargo.lock b/native/Cargo.lock index ebeafaf9..70db483c 100644 --- a/native/Cargo.lock +++ b/native/Cargo.lock @@ -799,6 +799,7 @@ dependencies = [ "web_app_manifest", "windows", "windows-registry 0.3.0", + "xz2", ] [[package]] @@ -1539,6 +1540,17 @@ dependencies = [ "imgref", ] +[[package]] +name = "lzma-sys" +version = "0.1.20" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "5fda04ab3764e6cde78b9974eec4f779acaba7c4e84b36eca3cf77c581b85d27" +dependencies = [ + "cc", + "libc", + "pkg-config", +] + [[package]] name = "maybe-rayon" version = "0.1.1" @@ -3651,6 +3663,15 @@ version = "0.1.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "ec7a2a501ed189703dba8b08142f057e887dfc4b2cc4db2d343ac6376ba3e0b9" +[[package]] +name = "xz2" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "388c44dc09d76f1536602ead6d325eb532f5c122f17782bd57fb47baeeb767e2" +dependencies = [ + "lzma-sys", +] + [[package]] name = "yoke" version = "0.7.5" diff --git a/native/Cargo.toml b/native/Cargo.toml index e8bfe9a2..3589a460 100644 --- a/native/Cargo.toml +++ b/native/Cargo.toml @@ -21,7 +21,7 @@ lto = true [features] portable = ["dep:phf"] -static = ["reqwest/native-tls-vendored", "bzip2/static"] +static = ["reqwest/native-tls-vendored", "bzip2/static", "xz2/static"] immutable-runtime = [] linked-runtime = ["dep:blake3"] @@ -81,6 +81,7 @@ blake3 = { version = "1.5.5", optional = true } [target.'cfg(target_os = "linux")'.dependencies] bzip2 = "0.5.0" +xz2 = "0.1.7" tar = "0.4.43" [target.'cfg(target_os = "macos")'.dependencies] diff --git a/native/packages/gentoo/firefoxpwa.ebuild b/native/packages/gentoo/firefoxpwa.ebuild index c179dacd..64fc9735 100644 --- a/native/packages/gentoo/firefoxpwa.ebuild +++ b/native/packages/gentoo/firefoxpwa.ebuild @@ -29,10 +29,11 @@ SLOT="0" KEYWORDS="~amd64 ~arm ~arm64" IUSE="custom-cflags lto static" -# Add app-arch/bzip2 when it finally get pkg-config file DEPEND=" !static? ( app-arch/zstd:= + app-arch/bzip2:= + app-arch/xz-utils:= dev-libs/openssl:= ) " @@ -75,7 +76,7 @@ src_configure() { CXX="${CHOST}-clang++" RUSTFLAGS="-Clinker=clang -Clink-arg=-fuse-ld=lld ${RUSTFLAGS}" - # Fix -flto[=n] not being recognized by clang. + # Fix -flto[=n] not being recognized by clang if tc-is-clang && is-flag "-flto=*"; then replace-flags "-flto=*" "-flto" fi diff --git a/native/src/components/runtime.rs b/native/src/components/runtime.rs index f341f342..505e69cd 100644 --- a/native/src/components/runtime.rs +++ b/native/src/components/runtime.rs @@ -288,29 +288,50 @@ impl Runtime { let _7zip = _7Zip::new()?; let success = _7zip.run(vec!["x", &archive, &format!("-o{}", &extracted)]).context(EXTRACT_ERROR)?.success(); if !success { bail!(EXTRACT_ERROR) } + source.push("core"); + } else if #[cfg(platform_linux)] { + use anyhow::bail; use std::fs::File; + use std::io::Read; + use std::io::Seek; + use std::io::SeekFrom; use bzip2::read::BzDecoder; + use xz2::read::XzDecoder; use tar::Archive; - let mut compressed = Archive::new(BzDecoder::new(File::open(&archive)?)); - compressed.unpack(&extracted).context(EXTRACT_ERROR)?; + let mut file = File::open(&archive).context(EXTRACT_ERROR)?; + let mut buffer = [0; 3]; + file.read_exact(&mut buffer)?; + file.seek(SeekFrom::Start(0))?; + + let compressed: Box = match &buffer { + b"\x42\x5A\x68" => Box::new(BzDecoder::new(file)), + b"\xFD\x37\x7A" => Box::new(XzDecoder::new(file)), + _ => bail!("Unsupported compression method"), + }; + + let mut bundle = Archive::new(compressed); + bundle.unpack(&extracted).context(EXTRACT_ERROR)?; + source.push("firefox"); + } else if #[cfg(platform_macos)] { use dmg::Attach; let info = Attach::new(&archive).with().context(EXTRACT_ERROR)?; - let mut options = CopyOptions::new(); let mut mount_point = info.mount_point.clone(); mount_point.push("Firefox.app"); source.push("Firefox.app"); + let mut options = CopyOptions::new(); options.content_only = true; copy(&mount_point, &source, &options)?; source.pop(); + } else { panic!("{}", UNSUPPORTED_PLATFORM_ERROR); }