Skip to content

Commit 4ef5a94

Browse files
tigerrosmarc2332
andauthored
docs: Create publishing chapter (#407)
* Create * Mention example and link to optimizing docs * remove extra quotes * Update publishing.md * Update publishing.md * add converting note * Update publishing.md * Update publishing.md * Update publishing.md --------- Co-authored-by: Marc Espin <[email protected]>
1 parent 7bf5654 commit 4ef5a94

File tree

2 files changed

+87
-2
lines changed

2 files changed

+87
-2
lines changed

book/src/SUMMARY.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,5 +21,4 @@
2121
- [Animating](./guides/animating.md)
2222
- [Virtualizing](./guides/virtualizing.md)
2323
- [Devtools](./guides/devtools.md)
24-
- [Publishing]()
25-
24+
- [Publishing](./guides/publishing.md)

book/src/guides/publishing.md

Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Publishing
2+
3+
> ⚠️ Before publishing, you should consider removing insecure metadata.
4+
> For example, images might have EXIF location data in them.
5+
6+
**Freya** produces a self-contained executable in `target/release`, so you can technically distribute that.
7+
However, you might want to create an installer instead. You can use executable packagers of your choice, but
8+
for a more automated and "Rusty" version, you can use [**cargo-packager**](https://github.com/crabnebula-dev/cargo-packager), which is basically an abstraction
9+
over executable packagers, which you would have to set up yourself.
10+
11+
There is an [example](https://github.com/marc2332/freya/tree/main/examples/installer) you can check out.
12+
13+
## `cargo-packager` installation
14+
15+
Run:
16+
17+
```
18+
cargo install cargo-packager --locked
19+
```
20+
21+
## Usage
22+
23+
Add this to your `Cargo.toml`:
24+
25+
```
26+
[package.metadata.packager]
27+
before-packaging-command = "cargo build --release" # Before packaging, packager will run this command.
28+
product-name = "My App" # By default, the crate name will be shown, but you probably prefer "My App" over "my-app".
29+
```
30+
31+
And run:
32+
33+
```
34+
cargo packager --release
35+
```
36+
37+
And there you go! You should now have an installer in `target/release` for your current OS.
38+
To publish your app on a different OS, see the next section, [Configuration](#configuration).
39+
40+
## Configuration
41+
42+
We used a very bare-bones example, so make sure to check out all configuration options in the [Config struct](https://docs.rs/cargo-packager/latest/cargo_packager/config/struct.Config.html)
43+
in the `cargo-packager` API docs. Note that underscores should be hyphens when you use TOML.
44+
45+
One crucial configuration field is `formats`.
46+
This is a list of installers that `cargo-packager` should generate, and by default, it's your current OS.
47+
You can have a look at the list on [GitHub](https://github.com/crabnebula-dev/cargo-packager#supported-packages), or on the [API docs](https://docs.rs/cargo-packager/latest/cargo_packager/config/enum.PackageFormat.html).
48+
49+
### Changing the executable icon on Windows
50+
51+
`cargo-packager` will change the icon for platforms other than Windows using the [`icons`](https://docs.rs/cargo-packager/latest/cargo_packager/config/struct.Config.html#structfield.icons)
52+
field, but it does not do it on Windows (yet?).
53+
54+
Anyway, the `cargo-packager` team recommends using [`winresource`](https://crates.io/crates/winresource)
55+
(as opposed to [`winres`](https://crates.io/crates/winres) which is not maintained).
56+
Before using it, make sure that you have the requirements that are listed on its page.
57+
58+
Add it to your build dependencies in `Cargo.toml`:
59+
60+
```toml
61+
[build-dependencies]
62+
winresource = "0.1.7"
63+
```
64+
65+
And add this to your `build.rs` file (make sure you link it in your `Cargo.toml`):
66+
67+
```rs
68+
// Change this to your icon's location
69+
const ICON: &str = "assets/icons/icon.ico";
70+
71+
fn main() {
72+
if std::env::var("CARGO_CFG_TARGET_OS").unwrap() == "windows" {
73+
let mut res = winresource::WindowsResource::new();
74+
res.set_icon(ICON);
75+
res.compile().unwrap();
76+
}
77+
}
78+
```
79+
80+
To convert more common formats like `.png` or `.jpg` to an `.ico`, you can use [imagemagick](https://imagemagick.org).
81+
Once installed, run `magick convert your_icon.png icon.ico`.
82+
83+
# Optimizing
84+
85+
The ["Optimizing" chapter](https://dioxuslabs.com/learn/0.4/cookbook/optimizing) in the Dioxus docs applies in Freya too.
86+
Note that WebAssembly-related tips are irrelevant.

0 commit comments

Comments
 (0)