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
use crate::BundleFormat;
use crate::Platform;
use crate::{cli::*, Renderer};
// use crate::RendererArg;
// use crate::PlatformAlias;
use target_lexicon::Triple;
const HELP_HEADING: &str = "Target Options";
/// A single target to build for
#[derive(Clone, Debug, Default, Deserialize, Parser)]
pub(crate) struct TargetArgs {
/// Build platform: supports Web, MacOS, Windows, Linux, iOS, Android, and Server
///
/// The platform implies a combination of the target alias, renderer, and bundle format flags.
///
/// You should generally prefer to use the `--web`, `--webview`, or `--native` flags to set the renderer
/// or the `--wasm`, `--macos`, `--windows`, `--linux`, `--ios`, or `--android` flags to set the target alias
/// instead of this flag. The renderer, target alias, and bundle format will be inferred if you only pass one.
#[clap(flatten)]
pub(crate) platform: Platform,
/// Which renderer to use? By default, this is usually inferred from the platform.
#[clap(long, value_enum, help_heading = HELP_HEADING)]
pub(crate) renderer: Option<Renderer>,
/// The bundle format to target for the build: supports web, macos, windows, linux, ios, android, and server
#[clap(long, value_enum, help_heading = HELP_HEADING)]
pub(crate) bundle: Option<BundleFormat>,
/// Build in release mode [default: false]
#[clap(long, short, help_heading = HELP_HEADING)]
#[serde(default)]
pub(crate) release: bool,
/// The package to build
#[clap(short, long, help_heading = HELP_HEADING)]
pub(crate) package: Option<String>,
/// Build a specific binary [default: ""]
#[clap(long, help_heading = HELP_HEADING)]
pub(crate) bin: Option<String>,
/// Build a specific example [default: ""]
#[clap(long, help_heading = HELP_HEADING)]
pub(crate) example: Option<String>,
/// Build the app with custom a profile
#[clap(long, help_heading = HELP_HEADING)]
pub(crate) profile: Option<String>,
/// Space separated list of features to activate
#[clap(long, help_heading = HELP_HEADING)]
pub(crate) features: Vec<String>,
/// Don't include the default features in the build
#[clap(long, help_heading = HELP_HEADING)]
pub(crate) no_default_features: bool,
/// Include all features in the build
#[clap(long, help_heading = HELP_HEADING)]
pub(crate) all_features: bool,
/// Rustc platform triple
#[clap(long, help_heading = HELP_HEADING)]
pub(crate) target: Option<Triple>,
/// Extra arguments passed to `cargo`
///
/// To see a list of args, run `cargo rustc --help`
///
/// This can include stuff like, "--locked", "--frozen", etc. Note that `dx` sets many of these
/// args directly from other args in this command.
#[clap(long, help_heading = HELP_HEADING)]
pub(crate) cargo_args: Option<String>,
/// Extra arguments passed to `rustc`. This can be used to customize the linker, or other flags.
///
/// For example, specifign `dx build --rustc-args "-Clink-arg=-Wl,-blah"` will pass "-Clink-arg=-Wl,-blah"
/// to the underlying the `cargo rustc` command:
///
/// cargo rustc -- -Clink-arg=-Wl,-blah
///
#[clap(long, help_heading = HELP_HEADING)]
pub(crate) rustc_args: Option<String>,
/// Skip collecting assets from dependencies [default: false]
#[clap(long, help_heading = HELP_HEADING)]
#[serde(default)]
pub(crate) skip_assets: bool,
/// Inject scripts to load the wasm and js files for your dioxus app if they are not already present [default: true]
#[clap(long, default_value_t = true, help_heading = HELP_HEADING, num_args = 0..=1)]
pub(crate) inject_loading_scripts: bool,
/// Experimental: Bundle split the wasm binary into multiple chunks based on `#[wasm_split]` annotations [default: false]
#[clap(long, default_value_t = false, help_heading = HELP_HEADING)]
pub(crate) wasm_split: bool,
/// Generate debug symbols for the wasm binary [default: true]
///
/// This will make the binary larger and take longer to compile, but will allow you to debug the
/// wasm binary
#[clap(long, default_value_t = true, help_heading = HELP_HEADING, num_args = 0..=1)]
pub(crate) debug_symbols: bool,
/// Keep the name section in the wasm binary, useful for profiling and debugging [default: false]
///
/// Unlike --debug-symbols which preserves DWARF debug info (requiring a browser extension to
/// read), the name section allows tools like console_error_panic_hook to print backtraces with
/// human-readable function names without any browser extension.
#[clap(long, default_value_t = false, help_heading = HELP_HEADING)]
pub(crate) keep_names: bool,
/// The name of the device we are hoping to upload to. By default, dx tries to upload to the active
/// simulator. If the device name is passed, we will upload to that device instead.
///
/// This performs a search among devices, and fuzzy matches might be found.
#[arg(long, default_missing_value=Some("".into()), num_args=0..=1)]
pub(crate) device: Option<String>,
/// The base path the build will fetch assets relative to. This will override the
/// base path set in the `dioxus` config.
#[clap(long, help_heading = HELP_HEADING)]
pub(crate) base_path: Option<String>,
/// Should dx attempt to codesign the app bundle?
#[clap(long, default_value_t = false, help_heading = HELP_HEADING, num_args = 0..=1)]
pub(crate) codesign: bool,
/// The path to the Apple entitlements file to used to sign the resulting app bundle.
///
/// On iOS, this is required for deploy to a device and some configurations in the simulator.
#[clap(long, help_heading = HELP_HEADING)]
pub(crate) apple_entitlements: Option<PathBuf>,
/// The Apple team ID to use when signing the app bundle.
///
/// Usually this is an email or name associated with your Apple Developer account, usually in the
/// format `Signing Name (GXTEAMID123)`.
///
/// This is passed directly to the `codesign` tool.
///
/// ```
/// codesign --force --entitlements <entitlements_file> --sign <apple_team_id> <app_bundle>
/// ```
#[clap(long, help_heading = HELP_HEADING)]
pub(crate) apple_team_id: Option<String>,
/// The folder where DX stores its temporary artifacts for things like hotpatching, build caches,
/// window position, etc. This is meant to be stable within an invocation of the CLI, but you can
/// persist it by setting this flag.
#[clap(long, help_heading = HELP_HEADING)]
pub(crate) session_cache_dir: Option<PathBuf>,
/// The target for the client build, used for specifying which target the server should end up in
/// when merging `@client and @server` targets together.
#[clap(long, help_heading = HELP_HEADING)]
pub(crate) client_target: Option<String>,
/// Automatically pass `--features=js_cfg` when building for wasm targets. This is enabled by default.
#[clap(long, default_value_t = true, help_heading = HELP_HEADING, num_args = 0..=1)]
pub(crate) wasm_js_cfg: bool,
/// The Windows subsystem to use when building for Windows targets. This can be either `CONSOLE` or `WINDOWS`.
///
/// By default, DX uses `WINDOWS` since it assumes a GUI application, but you can override this behavior with this flag.
///
/// See <https://learn.microsoft.com/en-us/cpp/build/reference/subsystem-specify-subsystem?view=msvc-170> for more information.
#[clap(long, help_heading = HELP_HEADING)]
pub(crate) windows_subsystem: Option<String>,
/// Output raw JSON diagnostics from cargo instead of processing them [default: false]
///
/// When enabled, cargo's JSON output will be relayed directly to stdout without any processing or formatting by DX.
/// This is useful for integration with other tools that expect cargo's raw JSON format.
#[clap(long, help_heading = HELP_HEADING)]
#[serde(default)]
pub(crate) raw_json_diagnostics: bool,
}
impl Anonymized for TargetArgs {
fn anonymized(&self) -> Value {
json! {{
"renderer": self.renderer,
"bundle": self.bundle,
"platform": self.platform,
"release": self.release,
"package": self.package,
"bin": self.bin,
"example": self.example.is_some(),
"profile": self.profile.is_some(),
"features": !self.features.is_empty(),
"no_default_features": self.no_default_features,
"all_features": self.all_features,
"target": self.target.as_ref().map(|t| t.to_string()),
"skip_assets": self.skip_assets,
"inject_loading_scripts": self.inject_loading_scripts,
"wasm_split": self.wasm_split,
"debug_symbols": self.debug_symbols,
"keep_names": self.keep_names,
"device": self.device,
"base_path": self.base_path.is_some(),
"cargo_args": self.cargo_args.is_some(),
"rustc_args": self.rustc_args.is_some(),
"raw_json_diagnostics": self.raw_json_diagnostics,
}}
}
}