Skip to content

Commit

Permalink
feat: add config option to control excluded libs in AppImage (#148)
Browse files Browse the repository at this point in the history
* Added config feature to control excluded libs in build_appimage.sh

Co-authored-by: Janrupf <[email protected]>

* Update .changes/excluded-libs-appiamge.md

* Update crates/packager/src/config/mod.rs

Co-authored-by: Lucas Nogueira <[email protected]>

---------

Co-authored-by: Janrupf <[email protected]>
  • Loading branch information
jan-br and Janrupf committed Jan 30, 2024
1 parent f7bbfe2 commit 57b379a
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 1 deletion.
6 changes: 6 additions & 0 deletions .changes/excluded-libs-appiamge.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
"cargo-packager": minor
"@crabnebula/packager": minor
---

Added config option to control excluded libs when packaging AppImage
10 changes: 10 additions & 0 deletions bindings/packager/nodejs/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,16 @@
"additionalProperties": {
"type": "string"
}
},
"excludedLibs": {
"description": "List of globs of libraries to exclude from the final APpImage. For example, to exclude libnss3.so, you'd specify `libnss3*`",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
}
},
"additionalProperties": false
Expand Down
4 changes: 4 additions & 0 deletions bindings/packager/nodejs/src-ts/config.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -450,6 +450,10 @@ export interface AppImageConfig {
linuxdeployPlugins?: {
[k: string]: string;
} | null;
/**
* List of globs of libraries to exclude from the final APpImage. For example, to exclude libnss3.so, you'd specify `libnss3*`
*/
excludedLibs?: string[] | null;
}
/**
* The Linux pacman configuration.
Expand Down
10 changes: 10 additions & 0 deletions crates/packager/schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -810,6 +810,16 @@
"additionalProperties": {
"type": "string"
}
},
"excludedLibs": {
"description": "List of globs of libraries to exclude from the final APpImage. For example, to exclude libnss3.so, you'd specify `libnss3*`",
"type": [
"array",
"null"
],
"items": {
"type": "string"
}
}
},
"additionalProperties": false
Expand Down
4 changes: 4 additions & 0 deletions crates/packager/src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -267,6 +267,10 @@ pub struct AppImageConfig {
/// you'd specify `gtk` as the key and its url as the value.
#[serde(alias = "linuxdeploy-plugins", alias = "linuxdeploy_plugins")]
pub linuxdeploy_plugins: Option<HashMap<String, String>>,
/// List of globs of libraries to exclude from the final AppImage.
/// For example, to exclude libnss3.so, you'd specify `libnss3*`
#[serde(alias = "excluded-libraries", alias = "excluded_libraries")]
pub excluded_libs: Option<Vec<String>>,
}

impl AppImageConfig {
Expand Down
2 changes: 1 addition & 1 deletion crates/packager/src/package/appimage/appimage
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@ cd ..
# and so appimagelauncher doesn't inject itself and the binary runs directly
dd if=/dev/zero bs=1 count=3 seek=8 conv=notrunc of="{{packager_tools_path}}/linuxdeploy-{{linuxdeploy_arch}}.AppImage"

OUTPUT="{{appimage_path}}" "{{packager_tools_path}}/linuxdeploy-{{linuxdeploy_arch}}.AppImage" --appimage-extract-and-run --appdir "{{app_name}}.AppDir" {{linuxdeploy_plugins}} --output appimage
OUTPUT="{{appimage_path}}" "{{packager_tools_path}}/linuxdeploy-{{linuxdeploy_arch}}.AppImage" --appimage-extract-and-run --appdir "{{app_name}}.AppDir" {{linuxdeploy_plugins}} {{excluded_libs}} --output appimage
10 changes: 10 additions & 0 deletions crates/packager/src/package/appimage/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,16 @@ pub(crate) fn package(ctx: &Context) -> crate::Result<Vec<PathBuf>> {
.join(" ");
sh_map.insert("linuxdeploy_plugins", to_json(linuxdeploy_plugins));

let excluded_libraries = config
.appimage()
.and_then(|a| a.excluded_libs.clone())
.unwrap_or_default()
.into_iter()
.map(|library| format!("--exclude-library {}", library))
.collect::<Vec<_>>()
.join(" ");
sh_map.insert("excluded_libs", to_json(excluded_libraries));

let larger_icon = icons
.iter()
.filter(|i| i.width == i.height)
Expand Down

0 comments on commit 57b379a

Please sign in to comment.