Skip to content

Commit aa5d74c

Browse files
authored
Merge pull request #2729 from itowlson/build-commands-plural
Allow multiple commands in a component build section
2 parents e0e39a9 + 7b6c5c8 commit aa5d74c

File tree

3 files changed

+52
-34
lines changed

3 files changed

+52
-34
lines changed

crates/build/src/lib.rs

Lines changed: 29 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -81,39 +81,36 @@ fn build_components(
8181
fn build_component(build_info: ComponentBuildInfo, app_dir: &Path) -> Result<()> {
8282
match build_info.build {
8383
Some(b) => {
84-
terminal::step!(
85-
"Building",
86-
"component {} with `{}`",
87-
build_info.id,
88-
b.command
89-
);
90-
let workdir = construct_workdir(app_dir, b.workdir.as_ref())?;
91-
if b.workdir.is_some() {
92-
println!("Working directory: {}", quoted_path(&workdir));
93-
}
94-
95-
let exit_status = Exec::shell(&b.command)
96-
.cwd(workdir)
97-
.stdout(Redirection::None)
98-
.stderr(Redirection::None)
99-
.stdin(Redirection::None)
100-
.popen()
101-
.map_err(|err| {
102-
anyhow!(
103-
"Cannot spawn build process '{:?}' for component {}: {}",
104-
&b.command,
84+
for command in b.commands() {
85+
terminal::step!("Building", "component {} with `{}`", build_info.id, command);
86+
let workdir = construct_workdir(app_dir, b.workdir.as_ref())?;
87+
if b.workdir.is_some() {
88+
println!("Working directory: {}", quoted_path(&workdir));
89+
}
90+
91+
let exit_status = Exec::shell(command)
92+
.cwd(workdir)
93+
.stdout(Redirection::None)
94+
.stderr(Redirection::None)
95+
.stdin(Redirection::None)
96+
.popen()
97+
.map_err(|err| {
98+
anyhow!(
99+
"Cannot spawn build process '{:?}' for component {}: {}",
100+
&b.command,
101+
build_info.id,
102+
err
103+
)
104+
})?
105+
.wait()?;
106+
107+
if !exit_status.success() {
108+
bail!(
109+
"Build command for component {} failed with status {:?}",
105110
build_info.id,
106-
err
107-
)
108-
})?
109-
.wait()?;
110-
111-
if !exit_status.success() {
112-
bail!(
113-
"Build command for component {} failed with status {:?}",
114-
build_info.id,
115-
exit_status,
116-
);
111+
exit_status,
112+
);
113+
}
117114
}
118115

119116
Ok(())

crates/doctor/src/rustlang/target.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ impl Diagnostic for TargetDiagnostic {
1919
let uses_rust = manifest.components.values().any(|c| {
2020
c.build
2121
.as_ref()
22-
.map(|b| b.command.starts_with("cargo"))
22+
.map(|b| b.commands().any(|c| c.starts_with("cargo")))
2323
.unwrap_or_default()
2424
});
2525

crates/manifest/src/schema/common.rs

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub enum WasiFilesMount {
8383
#[serde(deny_unknown_fields)]
8484
pub struct ComponentBuildConfig {
8585
/// `command = "cargo build"`
86-
pub command: String,
86+
pub command: Commands,
8787
/// `workdir = "components/main"
8888
#[serde(default, skip_serializing_if = "Option::is_none")]
8989
pub workdir: Option<String>,
@@ -92,6 +92,27 @@ pub struct ComponentBuildConfig {
9292
pub watch: Vec<String>,
9393
}
9494

95+
impl ComponentBuildConfig {
96+
/// The commands to execute for the build
97+
pub fn commands(&self) -> impl Iterator<Item = &String> {
98+
let as_vec = match &self.command {
99+
Commands::Single(cmd) => vec![cmd],
100+
Commands::Multiple(cmds) => cmds.iter().collect(),
101+
};
102+
as_vec.into_iter()
103+
}
104+
}
105+
106+
/// Component build command or commands
107+
#[derive(Clone, Debug, Serialize, Deserialize)]
108+
#[serde(untagged)]
109+
pub enum Commands {
110+
/// `command = "cargo build"`
111+
Single(String),
112+
/// `command = ["cargo build", "wac encode compose-deps.wac -d my:pkg=app.wasm --registry fermyon.com"]`
113+
Multiple(Vec<String>),
114+
}
115+
95116
fn is_false(v: &bool) -> bool {
96117
!*v
97118
}

0 commit comments

Comments
 (0)