-
Notifications
You must be signed in to change notification settings - Fork 17
/
Cargo.toml
176 lines (157 loc) · 8.12 KB
/
Cargo.toml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
[workspace]
resolver = "2"
members = [
"moxin-runner",
"moxin-protocol",
"moxin-backend",
"moxin-fake-backend",
]
[package]
name = "moxin"
version = "0.1.0"
edition = "2021"
description = "Desktop app for downloading and chatting with AI LLMs"
## Rename the binary to `_moxin_app` to avoid naming conflicts
## with the `moxin` binary defined by the `moxin-runner` crate.
[[bin]]
name = "_moxin_app"
path = "src/main.rs"
[dependencies]
moxin-protocol = { path = "moxin-protocol" }
moxin-backend = { path = "moxin-backend" }
moxin-fake-backend = { path = "moxin-fake-backend" }
makepad-widgets = { git = "https://github.com/jmbejar/makepad", branch = "moxin-release-v1" }
robius-open = "0.1.0"
robius-url-handler = { git = "https://github.com/project-robius/robius-url-handler" }
chrono = "0.4"
directories = "5.0.1"
unicode-segmentation = "1.10.1"
anyhow = "1.0"
serde_json = "1.0"
serde = { version = "1.0.197", features = ["derive"] }
lipsum = "0.9"
rand = "0.8.5"
rfd = "0.14.1"
## Configuration for `cargo packager`
[package.metadata.packager]
product_name = "Moxin"
identifier = "com.moxin-org.moxin"
category = "Utility"
authors = ["Moxin Organization <[email protected]>"]
publisher = "moxin-org"
license_file = "LICENSE"
copyright = "Copyright 2023-2024, Project Robius, Moxin Organization"
homepage = "https://github.com/moxin-org"
### Note: there is an 80-character max for each line of the `long_description`.
long_description = """
Moxin is a desktop app that lets you browse AI Large Language Models (LLMs),
download them, and run them locally to chat with the models.
Moxin uses the Makepad UI framework (https://github.com/makepad/makepad)
and Project Robius platform abstractions (https://github.com/project-robius),
and currently runs on major desktop platforms: macOS and Linux
(Windows support is coming soon).
Moxin uses the WasmEdge WASM runtime (https://github.com/WasmEdge/WasmEdge)
to locally run the AI models efficiently across varying hardware.
"""
icons = ["./packaging/app_icon128x128.png"]
out_dir = "./dist"
## Note: the `moxin-runner` crate binary is named `moxin`,
## while the main `moxin` crate binary is named `_moxin_app`.
## This is to avoid naming conflicts when packaging the binaries,
## and also ensures that the `moxin-runner` binary is the "main" binary
## that gets executed when the user runs "moxin" from the command line.
binaries = [
{ path = "moxin", main = true },
{ path = "_moxin_app", main = false },
]
## 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 Moxin project's `resources/` directory to the `./dist/resources/moxin` 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.
##
## In addition, on macOS only, we must download the WasmEdge plugins in order to include them
## in the macOS app bundle. This is because macOS apps must include all dependencies in order to pass notarization.
before-packaging-command = """
mkdir -p ./dist/resources/makepad_widgets/ \
&& cp -r `cargo metadata --format-version 1 | sed -e 's/,\"/,\\n\"/g' | grep 'widgets/Cargo.toml\"' | sed -e 's/\"manifest_path\":\"//g' -e 's/Cargo.toml\",/resources/g'` ./dist/resources/makepad_widgets/ \
&& mkdir -p ./dist/resources/moxin/ \
&& cp -r ./resources ./dist/resources/moxin/; \
\
export CARGO_PACKAGER_HOST_OS=`rustc --print cfg | grep target_os= | sed -e 's/target_os=\"//g' -e 's/\"//g'`; \
echo "\n\nPackaging on host platform '$CARGO_PACKAGER_HOST_OS'\n\n"; \
if [ "$CARGO_PACKAGER_HOST_OS" = macos ]; then \
mkdir -p ./wasmedge \
&& curl -sfL --show-error https://github.com/WasmEdge/WasmEdge/releases/download/0.13.5/WasmEdge-0.13.5-darwin_arm64.tar.gz | bsdtar -xf- -C ./wasmedge \
&& mkdir -p ./wasmedge/WasmEdge-0.13.5-Darwin/plugin \
&& curl -sf --location --progress-bar --show-error https://github.com/WasmEdge/WasmEdge/releases/download/0.13.5/WasmEdge-plugin-wasi_nn-ggml-0.13.5-darwin_arm64.tar.gz | bsdtar -xf- -C ./wasmedge/WasmEdge-0.13.5-Darwin/plugin; \
fi; \
"""
## 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/moxin", target = "moxin" },
]
## We then build the entire Moxin project and set the `MAKEPAD_PACKAGE_DIR` env var to the proper value.
## * For macOS app bundles, this should be set to `../Resources`.
## This only works because the `moxin-runner` binary sets the current working directory
## to the directory where the binary is located, which is `Moxin.app/Contents/MacOS/`.
## (See the `run_moxin` function in `moxin-runner/src/main.rs` for more details.)
## In a macOS app bundle, the resources directory is in `Moxin.app/Context/Resources/`,
## so that's why we set `MAKEPAD_PACKAGE_DIR` to `../Resources` --- it must be relative to the binary's location,
## which is up one parent directory.
## * For Debian `.deb` packages, this should be set to `/usr/lib/<main-binary-name>`,
## which is currently `/usr/lib/moxin-runner`.
## 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 packages, we also auto-generate the list of dependencies required by moxin,
## making sure to add `curl` since it is used by an invocation in `moxin-runner`.
##
before-each-package-command = """
export CARGO_PACKAGER_HOST_OS=`rustc --print cfg | grep target_os= | sed -e 's/target_os=\"//g' -e 's/\"//g'`; \
echo -e "\n\n================================================\n Packaging '$CARGO_PACKAGER_FORMAT' on host platform '$CARGO_PACKAGER_HOST_OS'\n================================================\n\n"; \
if [ "$CARGO_PACKAGER_HOST_OS" = macos ]; then \
MAKEPAD_PACKAGE_DIR=../Resources cargo build --workspace --release --features macos_bundle \
&& install_name_tool -add_rpath "@executable_path/../Frameworks" ./target/release/_moxin_app; \
elif [ "$CARGO_PACKAGER_HOST_OS" = linux ]; then \
if [ "$CARGO_PACKAGER_FORMAT" = appimage ]; then \
MAKEPAD_PACKAGE_DIR=../../usr/lib/moxin cargo build --workspace --release; \
else \
MAKEPAD_PACKAGE_DIR=/usr/lib/moxin cargo build --workspace --release --features "reqwest/native-tls-vendored"; \
if [ "$CARGO_PACKAGER_FORMAT" = deb ]; then \
for path in $(ldd target/release/_moxin_app | awk '{print $3}'); do \
basename "$path" ; \
done \
| xargs dpkg -S 2> /dev/null | awk '{print $1}' | awk -F ':' '{print $1}' | sort | uniq > ./dist/depends_deb.txt; \
echo "curl" >> ./dist/depends_deb.txt; \
fi; \
fi \
&& strip --strip-unneeded --remove-section=.comment --remove-section=.note target/release/_moxin_app target/release/moxin; \
else exit 2; \
fi; \
"""
deep_link_protocols = [
{ schemes = ["moxin"], role = "viewer" }, ## `name` is left as default
]
[package.metadata.packager.deb]
depends = "./dist/depends_deb.txt"
desktop_template = "./packaging/moxin.desktop"
section = "utils"
[package.metadata.packager.appimage]
## `curl` is needed for `moxin-runner` to auto-install wasmedge.
bins = [ "/usr/bin/curl" ]
[package.metadata.packager.macos]
minimum_system_version = "11.0"
frameworks = [
"./wasmedge/WasmEdge-0.13.5-Darwin/lib/libwasmedge.0.dylib",
"./wasmedge/WasmEdge-0.13.5-Darwin/plugin/libwasmedgePluginWasiNN.dylib",
]
## Configuration for `cargo packager`'s generation of a macOS `.dmg`.
[package.metadata.packager.dmg]
background = "./packaging/Moxin macOS dmg background.png"
window_size = { width = 960, height = 540 }
app_position = { x = 200, y = 250 }
application_folder_position = { x = 760, y = 250 }