WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Commit 2d1696e

Browse files
committed
Add support for extracting XZ-compressed runtime
1 parent a4c3d28 commit 2d1696e

File tree

4 files changed

+50
-6
lines changed

4 files changed

+50
-6
lines changed

native/Cargo.lock

Lines changed: 21 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

native/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ lto = true
2121

2222
[features]
2323
portable = ["dep:phf"]
24-
static = ["reqwest/native-tls-vendored", "bzip2/static"]
24+
static = ["reqwest/native-tls-vendored", "bzip2/static", "xz2/static"]
2525
immutable-runtime = []
2626
linked-runtime = ["dep:blake3"]
2727

@@ -81,6 +81,7 @@ blake3 = { version = "1.5.5", optional = true }
8181

8282
[target.'cfg(target_os = "linux")'.dependencies]
8383
bzip2 = "0.5.0"
84+
xz2 = "0.1.7"
8485
tar = "0.4.43"
8586

8687
[target.'cfg(target_os = "macos")'.dependencies]

native/packages/gentoo/firefoxpwa.ebuild

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,11 @@ SLOT="0"
2929
KEYWORDS="~amd64 ~arm ~arm64"
3030
IUSE="custom-cflags lto static"
3131

32-
# Add app-arch/bzip2 when it finally get pkg-config file
3332
DEPEND="
3433
!static? (
3534
app-arch/zstd:=
35+
app-arch/bzip2:=
36+
app-arch/xz-utils:=
3637
dev-libs/openssl:=
3738
)
3839
"
@@ -75,7 +76,7 @@ src_configure() {
7576
CXX="${CHOST}-clang++"
7677
RUSTFLAGS="-Clinker=clang -Clink-arg=-fuse-ld=lld ${RUSTFLAGS}"
7778

78-
# Fix -flto[=n] not being recognized by clang.
79+
# Fix -flto[=n] not being recognized by clang
7980
if tc-is-clang && is-flag "-flto=*"; then
8081
replace-flags "-flto=*" "-flto"
8182
fi

native/src/components/runtime.rs

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -288,29 +288,50 @@ impl Runtime {
288288
let _7zip = _7Zip::new()?;
289289
let success = _7zip.run(vec!["x", &archive, &format!("-o{}", &extracted)]).context(EXTRACT_ERROR)?.success();
290290
if !success { bail!(EXTRACT_ERROR) }
291+
291292
source.push("core");
293+
292294
} else if #[cfg(platform_linux)] {
295+
use anyhow::bail;
293296
use std::fs::File;
297+
use std::io::Read;
298+
use std::io::Seek;
299+
use std::io::SeekFrom;
294300
use bzip2::read::BzDecoder;
301+
use xz2::read::XzDecoder;
295302
use tar::Archive;
296303

297-
let mut compressed = Archive::new(BzDecoder::new(File::open(&archive)?));
298-
compressed.unpack(&extracted).context(EXTRACT_ERROR)?;
304+
let mut file = File::open(&archive).context(EXTRACT_ERROR)?;
305+
let mut buffer = [0; 3];
306+
file.read_exact(&mut buffer)?;
307+
file.seek(SeekFrom::Start(0))?;
308+
309+
let compressed: Box<dyn std::io::Read> = match &buffer {
310+
b"\x42\x5A\x68" => Box::new(BzDecoder::new(file)),
311+
b"\xFD\x37\x7A" => Box::new(XzDecoder::new(file)),
312+
_ => bail!("Unsupported compression method"),
313+
};
314+
315+
let mut bundle = Archive::new(compressed);
316+
bundle.unpack(&extracted).context(EXTRACT_ERROR)?;
317+
299318
source.push("firefox");
319+
300320
} else if #[cfg(platform_macos)] {
301321
use dmg::Attach;
302322

303323
let info = Attach::new(&archive).with().context(EXTRACT_ERROR)?;
304-
let mut options = CopyOptions::new();
305324
let mut mount_point = info.mount_point.clone();
306325

307326
mount_point.push("Firefox.app");
308327
source.push("Firefox.app");
309328

329+
let mut options = CopyOptions::new();
310330
options.content_only = true;
311331
copy(&mount_point, &source, &options)?;
312332

313333
source.pop();
334+
314335
} else {
315336
panic!("{}", UNSUPPORTED_PLATFORM_ERROR);
316337
}

0 commit comments

Comments
 (0)