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
// Copyright Proa Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
//! `proa build`: build assets and compile one exact Proa binary through the
//! linked RSJS pipeline.
use std::path::PathBuf;
use anyhow::Result;
use clap::Args;
use crate::lifecycle;
#[derive(Debug, Args)]
pub(crate) struct BuildArgs {
/// Proa project root. Defaults to the nearest root.
#[arg(long)]
root: Option<PathBuf>,
/// Cargo profile override, e.g. release-fast.
#[arg(long)]
profile: Option<String>,
/// Cargo package to build.
#[arg(short = 'p', long)]
package: Option<String>,
/// Cargo binary to build.
#[arg(long)]
bin: Option<String>,
/// Exact Cargo example target to build.
#[arg(long)]
example: Option<String>,
/// Cargo target triple for both descriptor and final compilation.
#[arg(long)]
target: Option<String>,
/// Cargo features enabled for both descriptor and final compilation.
#[arg(long, value_delimiter = ',')]
features: Vec<String>,
/// Enable every Cargo feature.
#[arg(long)]
all_features: bool,
/// Disable Cargo default features.
#[arg(long)]
no_default_features: bool,
/// Require Cargo.lock to remain unchanged.
#[arg(long)]
locked: bool,
/// Disable Cargo network access.
#[arg(long)]
offline: bool,
/// Skip Proa format/lint/site checks.
#[arg(long)]
no_check: bool,
/// Skip asset commands and public catalog publication.
#[arg(long)]
no_assets: bool,
/// Copy the attested final executable to this path after a successful linked build.
/// Without it, a release build of an executable is copied to
/// `<target-dir>/release/<bin>` (`<target-dir>/<triple>/release/<bin>` with
/// `--target`), where `proa start` finds it.
/// With this flag the public asset catalog is written beside the executable as
/// `<PATH>.assets`, and the server loads it from there: the two together are the
/// deployable output.
/// Relative paths are resolved from the Proa project root. For warm rebuilds, prefer
/// the Cargo target directory or a path outside the selected package source tree.
#[arg(long, value_name = "PATH")]
artifact_out: Option<PathBuf>,
/// Enter the linked build with an exact Cargo build command.
/// Example: -- cargo build --release -p app --bin app.
#[arg(last = true)]
command: Vec<String>,
}
pub(crate) fn run(args: BuildArgs) -> Result<()> {
let options = lifecycle::BuildOptions {
root: args.root,
profile: args.profile,
package: args.package,
bin: args.bin,
example: args.example,
target: args.target,
features: args.features,
all_features: args.all_features,
no_default_features: args.no_default_features,
locked: args.locked,
offline: args.offline,
no_check: args.no_check,
no_assets: args.no_assets,
artifact_out: args.artifact_out,
command: args.command,
};
lifecycle::build(options)
}
#[cfg(test)]
mod tests {
use std::path::PathBuf;
use clap::Parser;
use crate::cli::Cli;
use crate::commands::Command;
#[test]
fn build_accepts_an_explicit_artifact_output() {
let cli = Cli::try_parse_from([
"proa",
"build",
"--root",
"/tmp/demo",
"--artifact-out",
"dist/server",
"--package",
"demo",
"--bin",
"server",
])
.unwrap();
let Command::Build(args) = cli.command else {
panic!("expected build command");
};
assert_eq!(args.root, Some(PathBuf::from("/tmp/demo")));
assert_eq!(args.artifact_out, Some(PathBuf::from("dist/server")));
assert_eq!(args.package.as_deref(), Some("demo"));
assert_eq!(args.bin.as_deref(), Some("server"));
}
}