app cargo-appimage

Converts your crate into an AppImage

16 releases (stable)

2.2.0 Nov 27, 2023
2.0.1 Jun 30, 2023
1.4.2 Apr 7, 2022
1.4.0 Jan 23, 2022
0.1.2 May 7, 2021

#187 in Cargo plugins

Download history 44/week @ 2024-06-21 44/week @ 2024-06-28 25/week @ 2024-07-05 9/week @ 2024-07-12 14/week @ 2024-07-19 31/week @ 2024-07-26 59/week @ 2024-08-02 21/week @ 2024-08-09 4/week @ 2024-08-30 10/week @ 2024-09-06 11/week @ 2024-09-13 35/week @ 2024-09-20 62/week @ 2024-09-27 27/week @ 2024-10-04

139 downloads per month

GPL-3.0 license

19KB
312 lines

Cargo AppImage

This a cargo program that allows you to convert your Rust programs into AppImages.

Installation

  1. Make sure that appimagetool is in your path. It can be downloaded from here
  2. Install this program with
cargo install cargo-appimage
  1. cd inside of the root directory of your crate and create an icon called icon.png

    1. Note this can simply be an empty file for development. In fact an empty file is generated if you forget to make one.
  2. (optional) create a section in your Cargo.toml similar to the following with any additional assets to add to the AppImg:

    [package.metadata.appimage]
    assets = ["images", "sounds"]
    
  3. (optional) If you are using external crates that use other programs or are not written in pure rust, you may want to check if you need to embed some shared libraries into your AppImage:

    1. Running cargo appimage with this option in your Cargo.toml will automatically make a libs folder and put all of the shared objects your rust program uses in their respective directories.
    [package.metadata.appimage]
    auto_link = true
    
    1. AppImages aren't supposed to have EVERY library that your executable links to inside of the AppImage, so either:

      1. Manually delete the libraries from the libs folder that you expect will be on every linux system (libc, libgcc, libpthread, ld-linux, libdl, etc.), and then remove the auto_link option from Cargo.toml and rebuild. Then only the libraries remaining in the libs folder should be embedded in the Appimage.

      2. Or, use the auto_link_exclude_list option to specify a list of glob patterns to exclude. For example:

      [package.metadata.appimage]
      auto_link = true
      auto_link_exclude_list = [
          "libc.so*",
          "libdl.so*",
          "libpthread.so*",
      ]
      
      

      On the next build, only library files not matching the glob patterns will be embedded in the Appimage.

  4. run this command

    cargo appimage
    
    1. Note all arguments passed into cargo-appimage are redirected to cargo
    cargo appimage --features=min
    

Docker

Apparently this Dockerfile works

FROM rust:slim

RUN cargo install cargo-appimage
# file package is required by appimagetool
RUN apt-get update && apt-get install -y --no-install-recommends file wget

# Download appimagetool
RUN wget https://github.com/AppImage/AppImageKit/releases/download/continuous/appimagetool-$(uname -m).AppImage -O /usr/local/bin/appimagetool
RUN chmod +x /usr/local/bin/appimagetool
# Path appimagetool magic byte: https://github.com/AppImage/pkg2appimage/issues/373#issuecomment-495754112
RUN sed -i 's|AI\x02|\x00\x00\x00|' /usr/local/bin/appimagetool
# Use appimagetool without fuse: https://github.com/AppImage/AppImageKit/wiki/FUSE#docker
RUN APPIMAGE_EXTRACT_AND_RUN=1 cargo appimage

Dependencies

~1.7–2.9MB
~54K SLoC