Skip to content

Commit

Permalink
Support packaging Robrix into app bundles using cargo-packager
Browse files Browse the repository at this point in the history
* Add `before-packaging-command` binary that actually builds Robrix
  and handles the correct Robrix-specific and Makepad-specific steps
  as "callbacks" that get invoked by `cargo-packager`.
* Add package metadata to `Cargo.toml` that specifies all the
  packaging metadata required for Robrix.
* Add Robrix icon, `.dmg` background, and other related packaging files.

* Depend on our fork of Makepad that adds the `apple_bundle` cfg option,
  which supports querying an app bundle's resource path on macOS, tvOS, and iOS.
  This works by having Makepad prepend the resource path onto all
  resource file paths, which is `Contents/Resources/` for Apple bundles.
  * This is implemented via `NSBundle::resourcePath`.
  • Loading branch information
kevinaboos committed Oct 9, 2024
1 parent 4f5189b commit acacf5d
Show file tree
Hide file tree
Showing 12 changed files with 921 additions and 35 deletions.
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
## Cargo generated directory
/target
.vscode
## cargo-packager generated directory
/dist

.vscode
.DS_Store

## Temp hack to support login on mobile platforms.
Expand Down
64 changes: 32 additions & 32 deletions Cargo.lock

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

96 changes: 95 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ metadata.makepad-auto-version = "zqpv-Yj-K7WNVK2I8h5Okhho46Q="

[dependencies]
# makepad-widgets = { git = "https://github.com/makepad/makepad", branch = "rik" }
makepad-widgets = { git = "https://github.com/kevinaboos/makepad", branch = "modal_sends_dismissed_action_to_inner_modal_content" }
makepad-widgets = { git = "https://github.com/kevinaboos/makepad", branch = "apple_bundle_resource_path" }


## Including this crate automatically configures all `robius-*` crates to work with Makepad.
robius-use-makepad = "0.1.0"
Expand Down Expand Up @@ -98,3 +99,96 @@ all-features = true
# Temporarily include all debug info even for release builds.
[profile.release]
debug = "full"




## Configuration for `cargo packager`
[package.metadata.packager]
product_name = "Robrix"
identifier = "org.robius.robrix"
category = "SocialNetworking"
authors = ["Project Robius <[email protected]>", "Kevin Boos <[email protected]>"]
publisher = "robius"
license_file = "LICENSE-MIT"
copyright = "Copyright 2023-2024, Project Robius"
homepage = "https://github.com/project-robius"
### Note: there is an 80-character max for each line of the `long_description`.
long_description = """
Robrix is a multi-platform Matrix chat client written in pure Rust
using the Makepad UI framework (https://github.com/makepad/makepad)
and the Project Robius app dev framework and platform abstractions
(https://github.com/project-robius).
Robrix runs on all major desktop and mobile platforms:
macOS, Windows, Linux, Android, and iOS.
"""
icons = ["./packaging/robrix_logo_alpha.png"]
out_dir = "./dist"

## The below command uses cargo-metadata to determine the path of the `makepad_widgets` crate on the host build system,
## and copies the `makepad-widgets/resources` directory to the `./dist/resources/makepad_widgets` directory.
## We also copy the Robrix project's `resources/` directory to the `./dist/resources/robrix` directory.
##
## This is necessary because the `cargo packager` command only supports defining resources at a known path
## (see the below `resources = [...]` block below),
## so we need to copy the resources to a known fixed (static) path before packaging,
## such that cargo-packager can locate them and include them in the final package.
before-packaging-command = """
cargo run --manifest-path packaging/before-packaging-command/Cargo.toml \
before-packaging \
--binary-name robrix \
--path-to-binary ./target/release/robrix
"""

## See the above paragraph comments for more info on how we create/populate the below `src` directories.
resources = [
{ src = "./dist/resources/makepad_widgets", target = "makepad_widgets" },
{ src = "./dist/resources/robrix", target = "robrix" },
]

## We then build the entire Robrix project and set the `MAKEPAD_PACKAGE_DIR` env var to the proper value.
## * For macOS app bundles, this should be set to `./` because the default working directory
## for macOS app bundles is the `Contents/Resources/` directory, which is already where the resources are.
## * For Debian `.deb` packages, this should be set to `/usr/lib/<main-binary-name>`,
## which is currently `/usr/lib/robrix`.
## This is the directory in which `dpkg` copies app resource files to when installing the `.deb` package.
## * On Linux, we also strip the binaries of unneeded content, as required for Debian packages.
## * For Debian and Pacman (still a to-do!) packages, we also auto-generate the list of dependencies required by Robrix.
##
before-each-package-command = """
cargo run --manifest-path packaging/before-packaging-command/Cargo.toml \
before-each-package \
--binary-name robrix \
--path-to-binary ./target/release/robrix
"""

deep_link_protocols = [
{ schemes = ["robrix", "matrix"], role = "viewer" }, ## `name` is left as default
]

[package.metadata.packager.deb]
depends = "./dist/depends_deb.txt"
desktop_template = "./packaging/robrix.desktop"
section = "utils"

[package.metadata.packager.macos]
minimum_system_version = "11.0"
frameworks = [ ]
signing_identity = "Developer ID Application: AppChef Inc. (SFVQ5V48GD)"


## Configuration for `cargo packager`'s generation of a macOS `.dmg`.
[package.metadata.packager.dmg]
background = "./packaging/Robrix macOS dmg background.png"
window_size = { width = 960, height = 540 }
app_position = { x = 200, y = 250 }
application_folder_position = { x = 760, y = 250 }


## Configuration for `cargo packager`'s generation of a Windows `.exe` setup installer.
[package.metadata.packager.nsis]
## See this: <https://nsis.sourceforge.io/Docs/Chapter4.html#varconstant>
appdata_paths = [
"$APPDATA/$PUBLISHER/$PRODUCTNAME",
"$LOCALAPPDATA/$PRODUCTNAME",
]
2 changes: 1 addition & 1 deletion LICENSE-MIT
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2023 Project Robius Developers
Copyright (c) 2023-2024 Project Robius Developers

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

Expand Down
Binary file added packaging/Robrix macOS dmg background.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions packaging/before-packaging-command/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
## Cargo generated directory
/target

.vscode
.DS_Store

Loading

0 comments on commit acacf5d

Please sign in to comment.