Skip to content

Commit

Permalink
Add support for extracting XZ-compressed runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
filips123 committed Jan 15, 2025
1 parent a4c3d28 commit 2d1696e
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 6 deletions.
21 changes: 21 additions & 0 deletions native/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion native/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"]

Expand Down Expand Up @@ -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]
Expand Down
5 changes: 3 additions & 2 deletions native/packages/gentoo/firefoxpwa.ebuild
Original file line number Diff line number Diff line change
Expand Up @@ -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:=
)
"
Expand Down Expand Up @@ -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
Expand Down
27 changes: 24 additions & 3 deletions native/src/components/runtime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<dyn std::io::Read> = 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);
}
Expand Down

0 comments on commit 2d1696e

Please sign in to comment.