Skip to content

Commit abd9027

Browse files
committed
Add multiple build tasks and compilers
1 parent 8888632 commit abd9027

File tree

4 files changed

+63
-33
lines changed

4 files changed

+63
-33
lines changed

Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,30 @@
1+
use crate::config::BuildTask;
12
use serde::Serialize;
23

34
#[derive(Serialize)]
45
pub struct BuildScriptContext {
5-
pub build_task: String,
6+
pub build_tasks: Vec<BuildTask>,
67
pub manifest_root: std::path::PathBuf,
78
}
89

910
impl BuildScriptContext {
1011
pub fn render(&self) -> String {
11-
format!(
12-
"pixi run --as-is --manifest-path {} {}",
13-
self.manifest_root.to_string_lossy(),
14-
self.build_task
15-
)
12+
self.build_tasks
13+
.iter()
14+
.map(|build_task| {
15+
let env_arg = build_task
16+
.environment
17+
.as_ref()
18+
.map(|env| format!(" -e {}", env))
19+
.unwrap_or_default();
20+
format!(
21+
"pixi run --as-is --manifest-path {}{} {}",
22+
self.manifest_root.to_string_lossy(),
23+
env_arg,
24+
build_task.task
25+
)
26+
})
27+
.collect::<Vec<_>>()
28+
.join("\n")
1629
}
1730
}

crates/pixi-build-pixi/src/config.rs

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,16 @@ use indexmap::IndexMap;
44
use pixi_build_backend::generated_recipe::BackendConfig;
55
use serde::{Deserialize, Serialize};
66

7+
/// A build task with optional environment specification
8+
#[derive(Debug, Deserialize, Serialize, Clone)]
9+
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
10+
pub struct BuildTask {
11+
/// Name of the task to run
12+
pub task: String,
13+
/// Optional environment to run the task in
14+
pub environment: Option<String>,
15+
}
16+
717
#[derive(Debug, Default, Deserialize, Serialize, Clone)]
818
#[serde(rename_all = "kebab-case", deny_unknown_fields)]
919
pub struct PixiBackendConfig {
@@ -15,13 +25,12 @@ pub struct PixiBackendConfig {
1525
/// Extra input globs to include in addition to the default ones
1626
#[serde(default)]
1727
pub extra_input_globs: Vec<String>,
18-
/// Name of the build task in pixi.toml (defaults to "build")
19-
#[serde(default = "default_build_task")]
20-
pub build_task: String,
21-
}
22-
23-
fn default_build_task() -> String {
24-
"build".to_string()
28+
/// Build tasks to run in order, each with optional environment
29+
#[serde(default)]
30+
pub build_tasks: Vec<BuildTask>,
31+
/// List of compilers to use (e.g., ["c", "cxx", "cuda"])
32+
/// If not specified, no compilers will be added
33+
pub compilers: Option<Vec<String>>,
2534
}
2635

2736
impl BackendConfig for PixiBackendConfig {
@@ -53,11 +62,15 @@ impl BackendConfig for PixiBackendConfig {
5362
} else {
5463
target_config.extra_input_globs.clone()
5564
},
56-
build_task: if target_config.build_task == default_build_task() {
57-
self.build_task.clone()
65+
build_tasks: if target_config.build_tasks.is_empty() {
66+
self.build_tasks.clone()
5867
} else {
59-
target_config.build_task.clone()
68+
target_config.build_tasks.clone()
6069
},
70+
compilers: target_config
71+
.compilers
72+
.clone()
73+
.or_else(|| self.compilers.clone()),
6174
})
6275
}
6376
}

crates/pixi-build-pixi/src/main.rs

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@ use build_script::BuildScriptContext;
55
use config::PixiBackendConfig;
66
use miette::IntoDiagnostic;
77
use pixi_build_backend::{
8+
ProjectModel,
89
generated_recipe::{DefaultMetadataProvider, GenerateRecipe, GeneratedRecipe, PythonParams},
910
intermediate_backend::IntermediateBackendInstantiator,
1011
};
1112
use rattler_build::{NormalizedKey, recipe::variable::Variable};
12-
use rattler_conda_types::{PackageName, Platform};
13-
use recipe_stage0::recipe::{ConditionalRequirements, Script};
13+
use rattler_conda_types::{ChannelUrl, Platform};
14+
use recipe_stage0::recipe::Script;
1415
use std::collections::HashSet;
1516
use std::{
1617
collections::{BTreeMap, BTreeSet},
@@ -31,30 +32,33 @@ impl GenerateRecipe for PixiGenerator {
3132
manifest_root: std::path::PathBuf,
3233
host_platform: rattler_conda_types::Platform,
3334
_python_params: Option<PythonParams>,
34-
_variants: &HashSet<NormalizedKey>,
35+
variants: &HashSet<NormalizedKey>,
36+
_channels: Vec<ChannelUrl>,
3537
) -> miette::Result<GeneratedRecipe> {
3638
let mut generated_recipe =
3739
GeneratedRecipe::from_model(model.clone(), &mut DefaultMetadataProvider)
3840
.into_diagnostic()?;
3941

4042
let requirements = &mut generated_recipe.recipe.requirements;
4143

42-
let resolved_requirements = ConditionalRequirements::resolve(
43-
requirements.build.as_ref(),
44-
requirements.host.as_ref(),
45-
requirements.run.as_ref(),
46-
requirements.run_constraints.as_ref(),
47-
Some(host_platform),
48-
);
49-
50-
// Add pixi as a build dependency
51-
let pixi_name = PackageName::new_unchecked("pixi");
52-
if !resolved_requirements.build.contains_key(&pixi_name) {
53-
requirements.build.push("pixi".parse().into_diagnostic()?);
44+
// Add compilers if configured
45+
if let Some(compilers) = &config.compilers {
46+
let model_dependencies = model.dependencies(Some(host_platform));
47+
pixi_build_backend::compilers::add_compilers_to_requirements(
48+
compilers,
49+
&mut requirements.build,
50+
&model_dependencies,
51+
&host_platform,
52+
);
53+
pixi_build_backend::compilers::add_stdlib_to_requirements(
54+
compilers,
55+
&mut requirements.build,
56+
variants,
57+
);
5458
}
5559

5660
let build_script = BuildScriptContext {
57-
build_task: config.build_task.clone(),
61+
build_tasks: config.build_tasks.clone(),
5862
manifest_root,
5963
}
6064
.render();

0 commit comments

Comments
 (0)