Skip to content

Commit

Permalink
feat(snap): add lzo to Snap compression options (also as new default) (
Browse files Browse the repository at this point in the history
…#6201)

Signed-off-by: Omer Akram <[email protected]>
Co-authored-by: Maximilian Federle <[email protected]>
  • Loading branch information
om26er and ppd authored Jan 12, 2022
1 parent 604b17b commit c5f8b08
Show file tree
Hide file tree
Showing 11 changed files with 247 additions and 8 deletions.
13 changes: 13 additions & 0 deletions .changeset/spicy-crabs-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
"app-builder-lib": minor
"builder-util": major
---

Default to LZO compression for snap packages.
This greatly improves cold startup performance (https://snapcraft.io/blog/why-lzo-was-chosen-as-the-new-compression-method).
LZO has already been adopted by most desktop-oriented snaps outside of the Electron realm.

For the rare case where developers prefer a smaller file size (XZ) to vastly improved decompression performance (LZO),
provide an option to override the default compression method.

Consumers do not need to update their configuration unless they specifically want to stick to XZ compression.
2 changes: 1 addition & 1 deletion docker/base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ RUN apt-get -qq update && apt-get -qq dist-upgrade && \
apt-get -qq install --no-install-recommends \
qtbase5-dev build-essential autoconf libssl-dev gcc-multilib g++-multilib \
lzip rpm python libcurl4 git git-lfs ssh unzip libarchive-tools \
libxtst6 libsecret-1-dev libopenjp2-tools \
libxtst6 libsecret-1-dev libopenjp2-tools liblzo2-2 \
&& \
# git-lfs
git lfs install && \
Expand Down
19 changes: 18 additions & 1 deletion packages/app-builder-lib/scheme.json
Original file line number Diff line number Diff line change
Expand Up @@ -2141,7 +2141,8 @@
"enum": [
"bzip2",
"gz",
"xz"
"xz",
"lzo"
],
"type": "string"
},
Expand Down Expand Up @@ -5395,6 +5396,22 @@
"string"
]
},
"compression": {
"anyOf": [
{
"enum": [
"xz",
"lzo"
],
"type": "string"
},
{
"type": "null"
}
],
"default": "lzo",
"description": "Sets the compression type for the snap. Can be xz or lzo. Defaults to lzo when not specified."
},
"useTemplateApp": {
"description": "Whether to use template snap. Defaults to `true` if `stagePackages` not specified.",
"type": "boolean"
Expand Down
6 changes: 6 additions & 0 deletions packages/app-builder-lib/src/options/SnapOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,12 @@ export interface SnapOptions extends CommonLinuxOptions, TargetSpecificOptions {
* An optional title for the snap, may contain uppercase letters and spaces. Defaults to `productName`. See [snap format documentation](https://snapcraft.io/docs/snap-format).
*/
readonly title?: string | null

/**
* Sets the compression type for the snap. Can be xz or lzo. Defaults to lzo when not specified.
* @default lzo
*/
readonly compression?: "xz" | "lzo" | null
}

export interface PlugDescriptor {
Expand Down
2 changes: 1 addition & 1 deletion packages/app-builder-lib/src/options/linuxOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export interface LinuxTargetSpecificOptions extends CommonLinuxOptions, TargetSp
* The compression type.
* @default xz
*/
readonly compression?: "gz" | "bzip2" | "xz" | null
readonly compression?: "gz" | "bzip2" | "xz" | "lzo" | null

readonly icon?: string

Expand Down
6 changes: 6 additions & 0 deletions packages/app-builder-lib/src/targets/snap.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,7 @@ export default class SnapTarget extends Target {
version: appInfo.version,
title: options.title || appInfo.productName,
summary: options.summary || appInfo.productName,
compression: options.compression,
description: this.helper.getDescription(options),
architectures: [toLinuxArchString(arch, "snap")],
apps: {
Expand Down Expand Up @@ -207,6 +208,10 @@ export default class SnapTarget extends Target {
}
}

if (snap.compression != null) {
args.push("--compression", snap.compression)
}

if (packager.packagerOptions.effectiveOptionComputed != null && (await packager.packagerOptions.effectiveOptionComputed({ snap, desktopFile, args }))) {
return
}
Expand All @@ -221,6 +226,7 @@ export default class SnapTarget extends Target {
if (this.isUseTemplateApp) {
args.push("--template-url", `electron4:${snapArch}`)
}

await executeAppBuilder(args)

await packager.info.callArtifactBuildCompleted({
Expand Down
1 change: 1 addition & 0 deletions packages/app-builder-lib/templates/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
base: core18
grade: stable
confinement: strict
compression: lzo
parts:
launch-scripts:
plugin: dump
Expand Down
2 changes: 1 addition & 1 deletion packages/builder-util/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"7zip-bin": "~5.1.1",
"@types/debug": "^4.1.6",
"@types/fs-extra": "^9.0.11",
"app-builder-bin": "3.7.1",
"app-builder-bin": "4.1.0",
"bluebird-lst": "^1.0.9",
"builder-util-runtime": "workspace:*",
"chalk": "^4.1.1",
Expand Down
8 changes: 4 additions & 4 deletions pnpm-lock.yaml

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

Loading

0 comments on commit c5f8b08

Please sign in to comment.