-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathmod.rs
More file actions
2103 lines (1957 loc) · 80.1 KB
/
mod.rs
File metadata and controls
2103 lines (1957 loc) · 80.1 KB
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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Copyright 2023-2023 CrabNebula Ltd.
// SPDX-License-Identifier: Apache-2.0
// SPDX-License-Identifier: MIT
//! Configuration type and associated utilities.
use std::{
collections::HashMap,
ffi::OsString,
fmt::{self, Display},
fs,
path::{Path, PathBuf},
};
use relative_path::PathExt;
use serde::{Deserialize, Serialize};
use url::Url;
use crate::{util, Error};
mod builder;
mod category;
pub use builder::*;
pub use category::AppCategory;
pub use cargo_packager_utils::PackageFormat;
/// **macOS-only**. Corresponds to CFBundleTypeRole
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[derive(Default)]
pub enum BundleTypeRole {
/// CFBundleTypeRole.Editor. Files can be read and edited.
#[default]
Editor,
/// CFBundleTypeRole.Viewer. Files can be read.
Viewer,
/// CFBundleTypeRole.Shell
Shell,
/// CFBundleTypeRole.QLGenerator
QLGenerator,
/// CFBundleTypeRole.None
None,
}
impl Display for BundleTypeRole {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Self::Editor => write!(f, "Editor"),
Self::Viewer => write!(f, "Viewer"),
Self::Shell => write!(f, "Shell"),
Self::QLGenerator => write!(f, "QLGenerator"),
Self::None => write!(f, "None"),
}
}
}
/// A file association configuration.
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[non_exhaustive]
pub struct FileAssociation {
/// File extensions to associate with this app. e.g. 'png'
pub extensions: Vec<String>,
/// The mime-type e.g. 'image/png' or 'text/plain'. **Linux-only**.
#[serde(alias = "mime-type", alias = "mime_type")]
pub mime_type: Option<String>,
/// The association description. **Windows-only**. It is displayed on the `Type` column on Windows Explorer.
pub description: Option<String>,
/// The name. Maps to `CFBundleTypeName` on macOS. Defaults to the first item in `ext`
pub name: Option<String>,
/// The app's role with respect to the type. Maps to `CFBundleTypeRole` on macOS.
/// Defaults to [`BundleTypeRole::Editor`]
#[serde(default)]
pub role: BundleTypeRole,
}
impl FileAssociation {
/// Creates a new [`FileAssociation`] using provided extensions.
pub fn new<I, S>(extensions: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
Self {
extensions: extensions.into_iter().map(Into::into).collect(),
mime_type: None,
description: None,
name: None,
role: BundleTypeRole::default(),
}
}
/// Set the extenstions to associate with this app. e.g. 'png'.
pub fn extensions<I, S>(mut self, extensions: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.extensions = extensions.into_iter().map(Into::into).collect();
self
}
/// Set the mime-type e.g. 'image/png' or 'text/plain'. **Linux-only**.
pub fn mime_type<S: Into<String>>(mut self, mime_type: S) -> Self {
self.mime_type.replace(mime_type.into());
self
}
/// Se the association description. **Windows-only**. It is displayed on the `Type` column on Windows Explorer.
pub fn description<S: Into<String>>(mut self, description: S) -> Self {
self.description.replace(description.into());
self
}
/// Set he name. Maps to `CFBundleTypeName` on macOS. Defaults to the first item in `ext`
pub fn name<S: Into<String>>(mut self, name: S) -> Self {
self.name.replace(name.into());
self
}
/// Set he app's role with respect to the type. Maps to `CFBundleTypeRole` on macOS.
/// Defaults to [`BundleTypeRole::Editor`]
pub fn role(mut self, role: BundleTypeRole) -> Self {
self.role = role;
self
}
}
/// Deep link protocol
#[derive(Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[non_exhaustive]
pub struct DeepLinkProtocol {
/// URL schemes to associate with this app without `://`. For example `my-app`
pub schemes: Vec<String>,
/// The protocol name. **macOS-only** and maps to `CFBundleTypeName`. Defaults to `<bundle-id>.<schemes[0]>`
pub name: Option<String>,
/// The app's role for these schemes. **macOS-only** and maps to `CFBundleTypeRole`.
#[serde(default)]
pub role: BundleTypeRole,
}
impl DeepLinkProtocol {
/// Creates a new [`DeepLinkProtocol``] using provided schemes.
pub fn new<I, S>(schemes: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
Self {
schemes: schemes.into_iter().map(Into::into).collect(),
name: None,
role: BundleTypeRole::default(),
}
}
/// Set the name. Maps to `CFBundleTypeName` on macOS. Defaults to the first item in `ext`
pub fn name<S: Into<String>>(mut self, name: S) -> Self {
self.name.replace(name.into());
self
}
/// Set he app's role with respect to the type. Maps to `CFBundleTypeRole` on macOS.
/// Defaults to [`BundleTypeRole::Editor`]
pub fn role(mut self, role: BundleTypeRole) -> Self {
self.role = role;
self
}
}
/// The Linux Debian configuration.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[non_exhaustive]
pub struct DebianConfig {
/// The list of Debian dependencies.
pub depends: Option<Dependencies>,
/// Path to a custom desktop file Handlebars template.
///
/// Available variables: `categories`, `comment` (optional), `exec`, `icon` and `name`.
///
/// Default file contents:
/// ```text
/// [Desktop Entry]
/// Categories={{categories}}
/// {{#if comment}}
/// Comment={{comment}}
/// {{/if}}
/// Exec={{exec}} {{exec_arg}}
/// Icon={{icon}}
/// Name={{name}}
/// Terminal=false
/// Type=Application
/// {{#if mime_type}}
/// MimeType={{mime_type}}
/// {{/if}}
/// ```
///
/// The `{{exec_arg}}` will be set to:
/// * "%F", if at least one [Config::file_associations] was specified but no deep link protocols were given.
/// * The "%F" arg means that your application can be invoked with multiple file paths.
/// * "%U", if at least one [Config::deep_link_protocols] was specified.
/// * The "%U" arg means that your application can be invoked with multiple URLs.
/// * If both [Config::file_associations] and [Config::deep_link_protocols] were specified,
/// the "%U" arg will be used, causing the file paths to be passed to your app as `file://` URLs.
/// * An empty string "" (nothing) if neither are given.
/// * This means that your application will never be invoked with any URLs or file paths.
///
/// To specify a custom `exec_arg`, just use plaintext directly instead of `{{exec_arg}}`:
/// ```text
/// Exec={{exec}} %u
/// ```
///
/// See more here: <https://specifications.freedesktop.org/desktop-entry-spec/desktop-entry-spec-latest.html#exec-variables>.
#[serde(alias = "desktop-template", alias = "desktop_template")]
pub desktop_template: Option<PathBuf>,
/// Define the section in Debian Control file. See : <https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections>
pub section: Option<String>,
/// Change the priority of the Debian Package. By default, it is set to `optional`.
/// Recognized Priorities as of now are : `required`, `important`, `standard`, `optional`, `extra`
pub priority: Option<String>,
/// List of custom files to add to the deb package.
/// Maps a dir/file to a dir/file inside the debian package.
pub files: Option<HashMap<String, String>>,
/// Name to use for the `Package` field in the Debian Control file.
/// Defaults to [`Config::product_name`] converted to kebab-case.
#[serde(alias = "package-name", alias = "package_name")]
pub package_name: Option<String>,
}
impl DebianConfig {
/// Creates a new [`DebianConfig`].
pub fn new() -> Self {
Self::default()
}
/// Set the list of Debian dependencies directly using an iterator of strings.
pub fn depends<I, S>(mut self, depends: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.depends.replace(Dependencies::List(
depends.into_iter().map(Into::into).collect(),
));
self
}
/// Set the list of Debian dependencies indirectly via a path to a file,
/// which must contain one dependency (a package name) per line.
pub fn depends_path<P>(mut self, path: P) -> Self
where
P: Into<PathBuf>,
{
self.depends.replace(Dependencies::Path(path.into()));
self
}
/// Set the path to a custom desktop file Handlebars template.
///
/// Available variables: `categories`, `comment` (optional), `exec`, `icon` and `name`.
///
/// Default file contents:
/// ```text
/// [Desktop Entry]
/// Categories={{categories}}
/// {{#if comment}}
/// Comment={{comment}}
/// {{/if}}
/// Exec={{exec}} {{exec_arg}}
/// Icon={{icon}}
/// Name={{name}}
/// Terminal=false
/// Type=Application
/// {{#if mime_type}}
/// MimeType={{mime_type}}
/// {{/if}}
/// ```
pub fn desktop_template<P: Into<PathBuf>>(mut self, desktop_template: P) -> Self {
self.desktop_template.replace(desktop_template.into());
self
}
/// Define the section in Debian Control file. See : <https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections>
pub fn section<S: Into<String>>(mut self, section: S) -> Self {
self.section.replace(section.into());
self
}
/// Change the priority of the Debian Package. By default, it is set to `optional`.
/// Recognized Priorities as of now are : `required`, `important`, `standard`, `optional`, `extra`
pub fn priority<S: Into<String>>(mut self, priority: S) -> Self {
self.priority.replace(priority.into());
self
}
/// Set the list of custom files to add to the deb package.
/// Maps a dir/file to a dir/file inside the debian package.
pub fn files<I, S, T>(mut self, files: I) -> Self
where
I: IntoIterator<Item = (S, T)>,
S: Into<String>,
T: Into<String>,
{
self.files.replace(
files
.into_iter()
.map(|(k, v)| (k.into(), v.into()))
.collect(),
);
self
}
}
/// A list of dependencies specified as either a list of Strings
/// or as a path to a file that lists the dependencies, one per line.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(untagged)]
#[non_exhaustive]
pub enum Dependencies {
/// The list of dependencies provided directly as a vector of Strings.
List(Vec<String>),
/// A path to the file containing the list of dependences, formatted as one per line:
/// ```text
/// libc6
/// libxcursor1
/// libdbus-1-3
/// libasyncns0
/// ...
/// ```
Path(PathBuf),
}
impl Dependencies {
/// Returns the dependencies as a list of Strings.
pub fn to_list(&self) -> crate::Result<Vec<String>> {
match self {
Self::List(v) => Ok(v.clone()),
Self::Path(path) => {
let trimmed_lines = fs::read_to_string(path)
.map_err(|e| Error::IoWithPath(path.clone(), e))?
.lines()
.filter_map(|line| {
let trimmed = line.trim();
if !trimmed.is_empty() {
Some(trimmed.to_owned())
} else {
None
}
})
.collect();
Ok(trimmed_lines)
}
}
}
}
/// The Linux AppImage configuration.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[non_exhaustive]
pub struct AppImageConfig {
/// List of libs that exist in `/usr/lib*` to be include in the final AppImage.
/// The libs will be searched for, using the command
/// `find -L /usr/lib* -name <libname>`
pub libs: Option<Vec<String>>,
/// List of binary paths to include in the final AppImage.
/// For example, if you want `xdg-open`, you'd specify `/usr/bin/xdg-open`
pub bins: Option<Vec<String>>,
/// List of custom files to add to the appimage package.
/// Maps a dir/file to a dir/file inside the appimage package.
pub files: Option<HashMap<String, String>>,
/// A map of [`linuxdeploy`](https://github.com/linuxdeploy/linuxdeploy)
/// plugin name and its URL to be downloaded and executed while packaing the appimage.
/// For example, if you want to use the
/// [`gtk`](https://raw.githubusercontent.com/linuxdeploy/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh) plugin,
/// 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 {
/// Creates a new [`DebianConfig`].
pub fn new() -> Self {
Self::default()
}
/// Set the list of libs that exist in `/usr/lib*` to be include in the final AppImage.
/// The libs will be searched for using, the command
/// `find -L /usr/lib* -name <libname>`
pub fn libs<I, S>(mut self, libs: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.libs
.replace(libs.into_iter().map(Into::into).collect());
self
}
/// Set the list of binary paths to include in the final AppImage.
/// For example, if you want `xdg-open`, you'd specify `/usr/bin/xdg-open`
pub fn bins<I, S>(mut self, bins: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.bins
.replace(bins.into_iter().map(Into::into).collect());
self
}
/// Set the list of custom files to add to the appimage package.
/// Maps a dir/file to a dir/file inside the appimage package.
pub fn files<I, S, T>(mut self, files: I) -> Self
where
I: IntoIterator<Item = (S, T)>,
S: Into<String>,
T: Into<String>,
{
self.files.replace(
files
.into_iter()
.map(|(k, v)| (k.into(), v.into()))
.collect(),
);
self
}
/// Set the map of [`linuxdeploy`](https://github.com/linuxdeploy/linuxdeploy)
/// plugin name and its URL to be downloaded and executed while packaing the appimage.
/// For example, if you want to use the
/// [`gtk`](https://raw.githubusercontent.com/linuxdeploy/linuxdeploy-plugin-gtk/master/linuxdeploy-plugin-gtk.sh) plugin,
/// you'd specify `gtk` as the key and its url as the value.
pub fn linuxdeploy_plugins<I, S, T>(mut self, linuxdeploy_plugins: I) -> Self
where
I: IntoIterator<Item = (S, T)>,
S: Into<String>,
T: Into<String>,
{
self.linuxdeploy_plugins.replace(
linuxdeploy_plugins
.into_iter()
.map(|(k, v)| (k.into(), v.into()))
.collect(),
);
self
}
}
/// The Linux pacman configuration.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[non_exhaustive]
pub struct PacmanConfig {
/// List of custom files to add to the pacman package.
/// Maps a dir/file to a dir/file inside the pacman package.
pub files: Option<HashMap<String, String>>,
/// List of softwares that must be installed for the app to build and run.
///
/// See : <https://wiki.archlinux.org/title/PKGBUILD#depends>
pub depends: Option<Dependencies>,
/// Additional packages that are provided by this app.
///
/// See : <https://wiki.archlinux.org/title/PKGBUILD#provides>
pub provides: Option<Vec<String>>,
/// Packages that conflict or cause problems with the app.
/// All these packages and packages providing this item will need to be removed
///
/// See : <https://wiki.archlinux.org/title/PKGBUILD#conflicts>
pub conflicts: Option<Vec<String>>,
/// Only use if this app replaces some obsolete packages.
/// For example, if you rename any package.
///
/// See : <https://wiki.archlinux.org/title/PKGBUILD#replaces>
pub replaces: Option<Vec<String>>,
/// Source of the package to be stored at PKGBUILD.
/// PKGBUILD is a bash script, so version can be referred as ${pkgver}
pub source: Option<Vec<String>>,
}
impl PacmanConfig {
/// Creates a new [`PacmanConfig`].
pub fn new() -> Self {
Self::default()
}
/// Set the list of custom files to add to the pacman package.
/// Maps a dir/file to a dir/file inside the pacman package.
pub fn files<I, S, T>(mut self, files: I) -> Self
where
I: IntoIterator<Item = (S, T)>,
S: Into<String>,
T: Into<String>,
{
self.files.replace(
files
.into_iter()
.map(|(k, v)| (k.into(), v.into()))
.collect(),
);
self
}
/// Set the list of pacman dependencies directly using an iterator of strings.
pub fn depends<I, S>(mut self, depends: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.depends.replace(Dependencies::List(
depends.into_iter().map(Into::into).collect(),
));
self
}
/// Set the list of pacman dependencies indirectly via a path to a file,
/// which must contain one dependency (a package name) per line.
pub fn depends_path<P>(mut self, path: P) -> Self
where
P: Into<PathBuf>,
{
self.depends.replace(Dependencies::Path(path.into()));
self
}
/// Set the list of additional packages that are provided by this app.
pub fn provides<I, S>(mut self, provides: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.provides
.replace(provides.into_iter().map(Into::into).collect());
self
}
/// Set the list of packages that conflict with the app.
pub fn conflicts<I, S>(mut self, conflicts: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.conflicts
.replace(conflicts.into_iter().map(Into::into).collect());
self
}
/// Set the list of obsolete packages that are replaced by this package.
pub fn replaces<I, S>(mut self, replaces: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.replaces
.replace(replaces.into_iter().map(Into::into).collect());
self
}
/// Set the list of sources where the package will be stored.
pub fn source<I, S>(mut self, source: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.source
.replace(source.into_iter().map(Into::into).collect());
self
}
}
/// Position coordinates struct.
#[derive(Default, Copy, Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Position {
/// X coordinate.
pub x: u32,
/// Y coordinate.
pub y: u32,
}
/// Size struct.
#[derive(Default, Copy, Debug, PartialEq, Eq, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct Size {
/// Width.
pub width: u32,
/// Height.
pub height: u32,
}
/// The Apple Disk Image (.dmg) configuration.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[non_exhaustive]
pub struct DmgConfig {
/// Image to use as the background in dmg file. Accepted formats: `png`/`jpg`/`gif`.
pub background: Option<PathBuf>,
/// Position of volume window on screen.
pub window_position: Option<Position>,
/// Size of volume window.
#[serde(alias = "window-size", alias = "window_size")]
pub window_size: Option<Size>,
/// Position of application file on window.
#[serde(alias = "app-position", alias = "app_position")]
pub app_position: Option<Position>,
/// Position of application folder on window.
#[serde(
alias = "application-folder-position",
alias = "application_folder_position"
)]
pub app_folder_position: Option<Position>,
}
impl DmgConfig {
/// Creates a new [`DmgConfig`].
pub fn new() -> Self {
Self::default()
}
/// Set an image to use as the background in dmg file. Accepted formats: `png`/`jpg`/`gif`.
pub fn background<P: Into<PathBuf>>(mut self, path: P) -> Self {
self.background.replace(path.into());
self
}
/// Set the poosition of volume window on screen.
pub fn window_position(mut self, position: Position) -> Self {
self.window_position.replace(position);
self
}
/// Set the size of volume window.
pub fn window_size(mut self, size: Size) -> Self {
self.window_size.replace(size);
self
}
/// Set the poosition of app file on window.
pub fn app_position(mut self, position: Position) -> Self {
self.app_position.replace(position);
self
}
/// Set the position of application folder on window.
pub fn app_folder_position(mut self, position: Position) -> Self {
self.app_folder_position.replace(position);
self
}
}
/// Notarization authentication credentials.
#[derive(Clone, Debug)]
pub enum MacOsNotarizationCredentials {
/// Apple ID authentication.
AppleId {
/// Apple ID.
apple_id: OsString,
/// Password.
password: OsString,
/// Team ID.
team_id: OsString,
},
/// App Store Connect API key.
ApiKey {
/// API key issuer.
issuer: OsString,
/// API key ID.
key_id: OsString,
/// Path to the API key file.
key_path: PathBuf,
},
/// Keychain profile with a stored app-specific password for notarytool to use
/// Passwords can be generated at https://account.apple.com when signed in with your developer account.
/// The password must then be stored in your keychain for notarytool to access,
/// using the following, with the appopriate Apple and Team IDs:
/// `xcrun notarytool store-credentials --apple-id "name@example.com" --team-id "ABCD123456"`
/// This will prompt for a keychain profile name, and the password itself.
/// This setting can only be provided as an environment variable "APPLE_KEYCHAIN_PROFILE"
KeychainProfile {
/// The keychain profile name (as provided when the password was stored using notarytool)
keychain_profile: OsString,
},
}
/// The macOS configuration.
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[non_exhaustive]
pub struct MacOsConfig {
/// MacOS frameworks that need to be packaged with the app.
///
/// Each string can either be the name of a framework (without the `.framework` extension, e.g. `"SDL2"`),
/// in which case we will search for that framework in the standard install locations (`~/Library/Frameworks/`, `/Library/Frameworks/`, and `/Network/Library/Frameworks/`),
/// or a path to a specific framework bundle (e.g. `./data/frameworks/SDL2.framework`). Note that this setting just makes cargo-packager copy the specified frameworks into the OS X app bundle
/// (under `Foobar.app/Contents/Frameworks/`); you are still responsible for:
///
/// - arranging for the compiled binary to link against those frameworks (e.g. by emitting lines like `cargo:rustc-link-lib=framework=SDL2` from your `build.rs` script)
///
/// - embedding the correct rpath in your binary (e.g. by running `install_name_tool -add_rpath "@executable_path/../Frameworks" path/to/binary` after compiling)
pub frameworks: Option<Vec<String>>,
/// A version string indicating the minimum MacOS version that the packaged app supports (e.g. `"10.11"`).
/// If you are using this config field, you may also want have your `build.rs` script emit `cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.11`.
#[serde(alias = "minimum-system-version", alias = "minimum_system_version")]
pub minimum_system_version: Option<String>,
/// The exception domain to use on the macOS .app package.
///
/// This allows communication to the outside world e.g. a web server you're shipping.
#[serde(alias = "exception-domain", alias = "exception_domain")]
pub exception_domain: Option<String>,
/// Code signing identity.
///
/// This is typically of the form: `"Developer ID Application: TEAM_NAME (TEAM_ID)"`.
#[serde(alias = "signing-identity", alias = "signing_identity")]
pub signing_identity: Option<String>,
/// Codesign certificate (base64 encoded of the p12 file).
///
/// Note: this field cannot be specified via a config file or Cargo package metadata.
#[serde(skip)]
pub signing_certificate: Option<OsString>,
/// Password of the codesign certificate.
///
/// Note: this field cannot be specified via a config file or Cargo package metadata.
#[serde(skip)]
pub signing_certificate_password: Option<OsString>,
/// Notarization authentication credentials.
///
/// Note: this field cannot be specified via a config file or Cargo package metadata.
#[serde(skip)]
pub notarization_credentials: Option<MacOsNotarizationCredentials>,
/// Provider short name for notarization.
#[serde(alias = "provider-short-name", alias = "provider_short_name")]
pub provider_short_name: Option<String>,
/// Path to the entitlements.plist file.
pub entitlements: Option<String>,
/// Path to the Info.plist file for the package.
#[serde(alias = "info-plist-path", alias = "info_plist_path")]
pub info_plist_path: Option<PathBuf>,
/// Path to the embedded.provisionprofile file for the package.
#[serde(
alias = "embedded-provisionprofile-path",
alias = "embedded_provisionprofile_path"
)]
pub embedded_provisionprofile_path: Option<PathBuf>,
/// Apps that need to be packaged within the app.
#[serde(alias = "embedded-apps", alias = "embedded_apps")]
pub embedded_apps: Option<Vec<String>>,
/// Whether this is a background application. If true, the app will not appear in the Dock.
///
/// Sets the `LSUIElement` flag in the macOS plist file.
#[serde(default, alias = "background_app", alias = "background-app")]
pub background_app: bool,
}
impl MacOsConfig {
/// Creates a new [`MacOsConfig`].
pub fn new() -> Self {
Self::default()
}
/// MacOS frameworks that need to be packaged with the app.
///
/// Each string can either be the name of a framework (without the `.framework` extension, e.g. `"SDL2"`),
/// in which case we will search for that framework in the standard install locations (`~/Library/Frameworks/`, `/Library/Frameworks/`, and `/Network/Library/Frameworks/`),
/// or a path to a specific framework bundle (e.g. `./data/frameworks/SDL2.framework`). Note that this setting just makes cargo-packager copy the specified frameworks into the OS X app bundle
/// (under `Foobar.app/Contents/Frameworks/`); you are still responsible for:
///
/// - arranging for the compiled binary to link against those frameworks (e.g. by emitting lines like `cargo:rustc-link-lib=framework=SDL2` from your `build.rs` script)
///
/// - embedding the correct rpath in your binary (e.g. by running `install_name_tool -add_rpath "@executable_path/../Frameworks" path/to/binary` after compiling)
pub fn frameworks<I, S>(mut self, frameworks: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.frameworks
.replace(frameworks.into_iter().map(Into::into).collect());
self
}
/// A version string indicating the minimum MacOS version that the packaged app supports (e.g. `"10.11"`).
/// If you are using this config field, you may also want have your `build.rs` script emit `cargo:rustc-env=MACOSX_DEPLOYMENT_TARGET=10.11`.
pub fn minimum_system_version<S: Into<String>>(mut self, minimum_system_version: S) -> Self {
self.minimum_system_version
.replace(minimum_system_version.into());
self
}
/// The exception domain to use on the macOS .app package.
///
/// This allows communication to the outside world e.g. a web server you're shipping.
pub fn exception_domain<S: Into<String>>(mut self, exception_domain: S) -> Self {
self.exception_domain.replace(exception_domain.into());
self
}
/// Code signing identity.
pub fn signing_identity<S: Into<String>>(mut self, signing_identity: S) -> Self {
self.signing_identity.replace(signing_identity.into());
self
}
/// Provider short name for notarization.
pub fn provider_short_name<S: Into<String>>(mut self, provider_short_name: S) -> Self {
self.provider_short_name.replace(provider_short_name.into());
self
}
/// Path to the entitlements.plist file.
pub fn entitlements<S: Into<String>>(mut self, entitlements: S) -> Self {
self.entitlements.replace(entitlements.into());
self
}
/// Path to the Info.plist file for the package.
pub fn info_plist_path<S: Into<PathBuf>>(mut self, info_plist_path: S) -> Self {
self.info_plist_path.replace(info_plist_path.into());
self
}
/// Path to the embedded.provisionprofile file for the package.
pub fn embedded_provisionprofile_path<S: Into<PathBuf>>(
mut self,
embedded_provisionprofile_path: S,
) -> Self {
self.embedded_provisionprofile_path
.replace(embedded_provisionprofile_path.into());
self
}
/// Apps that need to be packaged within the app.
pub fn embedded_apps<I, S>(mut self, embedded_apps: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.embedded_apps
.replace(embedded_apps.into_iter().map(Into::into).collect());
self
}
}
/// Linux configuration
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[non_exhaustive]
pub struct LinuxConfig {
/// Flag to indicate if desktop entry should be generated.
#[serde(
default = "default_true",
alias = "generate-desktop-entry",
alias = "generate_desktop_entry"
)]
pub generate_desktop_entry: bool,
}
/// A wix language.
#[derive(Debug, Clone, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(untagged)]
#[non_exhaustive]
pub enum WixLanguage {
/// Built-in wix language identifier.
Identifier(String),
/// Custom wix language.
Custom {
/// Idenitifier of this language, for example `en-US`
identifier: String,
/// The path to a locale (`.wxl`) file. See <https://wixtoolset.org/documentation/manual/v3/howtos/ui_and_localization/build_a_localized_version.html>.
path: Option<PathBuf>,
},
}
impl Default for WixLanguage {
fn default() -> Self {
Self::Identifier("en-US".into())
}
}
/// The wix format configuration
#[derive(Clone, Debug, Default, Deserialize, Serialize)]
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[serde(rename_all = "camelCase", deny_unknown_fields)]
#[non_exhaustive]
pub struct WixConfig {
/// The app languages to build. See <https://docs.microsoft.com/en-us/windows/win32/msi/localizing-the-error-and-actiontext-tables>.
pub languages: Option<Vec<WixLanguage>>,
/// By default, the packager uses an internal template.
/// This option allows you to define your own wix file.
pub template: Option<PathBuf>,
/// List of merge modules to include in your installer.
/// For example, if you want to include [C++ Redis merge modules]
///
/// [C++ Redis merge modules]: https://wixtoolset.org/docs/v3/howtos/redistributables_and_install_checks/install_vcredist/
#[serde(alias = "merge-modules", alias = "merge_modules")]
pub merge_modules: Option<Vec<PathBuf>>,
/// A list of paths to .wxs files with WiX fragments to use.
#[serde(alias = "fragment-paths", alias = "fragment_paths")]
pub fragment_paths: Option<Vec<PathBuf>>,
/// List of WiX fragments as strings. This is similar to `config.wix.fragments_paths` but
/// is a string so you can define it inline in your config.
///
/// ```text
/// <?xml version="1.0" encoding="utf-8"?>
/// <Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
/// <Fragment>
/// <CustomAction Id="OpenNotepad" Directory="INSTALLDIR" Execute="immediate" ExeCommand="cmd.exe /c notepad.exe" Return="check" />
/// <InstallExecuteSequence>
/// <Custom Action="OpenNotepad" After="InstallInitialize" />
/// </InstallExecuteSequence>
/// </Fragment>
/// </Wix>
/// ```
pub fragments: Option<Vec<String>>,
/// The ComponentGroup element ids you want to reference from the fragments.
#[serde(alias = "component-group-refs", alias = "component_group_refs")]
pub component_group_refs: Option<Vec<String>>,
/// The Component element ids you want to reference from the fragments.
#[serde(alias = "component-refs", alias = "component_refs")]
pub component_refs: Option<Vec<String>>,
/// The CustomAction element ids you want to reference from the fragments.
#[serde(alias = "custom-action-refs", alias = "custom_action_refs")]
pub custom_action_refs: Option<Vec<String>>,
/// The FeatureGroup element ids you want to reference from the fragments.
#[serde(alias = "feature-group-refs", alias = "feature_group_refs")]
pub feature_group_refs: Option<Vec<String>>,
/// The Feature element ids you want to reference from the fragments.
#[serde(alias = "feature-refs", alias = "feature_refs")]
pub feature_refs: Option<Vec<String>>,
/// The Merge element ids you want to reference from the fragments.
#[serde(alias = "merge-refs", alias = "merge_refs")]
pub merge_refs: Option<Vec<String>>,
/// Path to a bitmap file to use as the installation user interface banner.
/// This bitmap will appear at the top of all but the first page of the installer.
///
/// The required dimensions are 493px × 58px.
#[serde(alias = "banner-path", alias = "banner_path")]
pub banner_path: Option<PathBuf>,
/// Path to a bitmap file to use on the installation user interface dialogs.
/// It is used on the welcome and completion dialogs.
/// The required dimensions are 493px × 312px.
#[serde(alias = "dialog-image-path", alias = "dialog_image_path")]
pub dialog_image_path: Option<PathBuf>,
/// Enables FIPS compliant algorithms.
#[serde(default, alias = "fips-compliant", alias = "fips_compliant")]
pub fips_compliant: bool,
}
impl WixConfig {
/// Creates a new [`WixConfig`].
pub fn new() -> Self {
Self::default()
}
/// Set the app languages to build. See <https://docs.microsoft.com/en-us/windows/win32/msi/localizing-the-error-and-actiontext-tables>.
pub fn languages<I: IntoIterator<Item = WixLanguage>>(mut self, languages: I) -> Self {
self.languages.replace(languages.into_iter().collect());
self
}
/// By default, the packager uses an internal template.
/// This option allows you to define your own wix file.
pub fn template<P: Into<PathBuf>>(mut self, template: P) -> Self {
self.template.replace(template.into());
self
}
/// Set a list of merge modules to include in your installer.
/// For example, if you want to include [C++ Redis merge modules]
///
/// [C++ Redis merge modules]: https://wixtoolset.org/docs/v3/howtos/redistributables_and_install_checks/install_vcredist/
pub fn merge_modules<I, P>(mut self, merge_modules: I) -> Self
where
I: IntoIterator<Item = P>,
P: Into<PathBuf>,
{
self.merge_modules
.replace(merge_modules.into_iter().map(Into::into).collect());
self
}
/// Set a list of paths to .wxs files with WiX fragments to use.
pub fn fragment_paths<I, S>(mut self, fragment_paths: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<PathBuf>,
{