Skip to content

Commit 488c883

Browse files
wolfvbaszalmstra
andauthored
feat: support build backend secrets (#6101)
Co-authored-by: Bas Zalmstra <4995967+baszalmstra@users.noreply.github.com>
1 parent e36b402 commit 488c883

23 files changed

Lines changed: 233 additions & 35 deletions

File tree

crates/pixi_build_backend/tests/integration/common/model.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -134,6 +134,7 @@ pub(crate) fn convert_test_model_to_project_model_v1(test_model: TestProjectMode
134134
targets: Some(targets_v1),
135135
build_number: None,
136136
build_string_prefix: None,
137+
secrets: std::collections::BTreeSet::new(),
137138
}
138139
}
139140

crates/pixi_build_cmake/src/main.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -141,13 +141,15 @@ impl GenerateRecipe for CMakeGenerator {
141141
}
142142
.render();
143143

144-
generated_recipe.recipe.build.script = Script::from_content(build_script).with_env(
145-
config
146-
.env
147-
.iter()
148-
.map(|(k, v)| (k.clone(), Value::new_concrete(v.clone(), None)))
149-
.collect(),
150-
);
144+
generated_recipe.recipe.build.script = Script::from_content(build_script)
145+
.with_env(
146+
config
147+
.env
148+
.iter()
149+
.map(|(k, v)| (k.clone(), Value::new_concrete(v.clone(), None)))
150+
.collect(),
151+
)
152+
.with_secrets(model.secrets.iter().cloned().collect());
151153

152154
Ok(generated_recipe)
153155
}

crates/pixi_build_mojo/src/main.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,15 @@ impl GenerateRecipe for MojoGenerator {
101101

102102
let build_script = BuildScriptContext { bins, pkg }.render();
103103

104-
generated_recipe.recipe.build.script = Script::from_content(build_script).with_env(
105-
config
106-
.env
107-
.iter()
108-
.map(|(k, v)| (k.clone(), Value::new_concrete(v.clone(), None)))
109-
.collect(),
110-
);
104+
generated_recipe.recipe.build.script = Script::from_content(build_script)
105+
.with_env(
106+
config
107+
.env
108+
.iter()
109+
.map(|(k, v)| (k.clone(), Value::new_concrete(v.clone(), None)))
110+
.collect(),
111+
)
112+
.with_secrets(model.secrets.iter().cloned().collect());
111113

112114
generated_recipe.build_input_globs = Self::globs().collect::<BTreeSet<_>>();
113115

crates/pixi_build_python/src/main.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -376,13 +376,15 @@ impl GenerateRecipe for PythonGenerator {
376376
generated_recipe.recipe.build.python = python;
377377
generated_recipe.recipe.build.noarch = noarch_kind;
378378

379-
generated_recipe.recipe.build.script = Script::from_content(build_script).with_env(
380-
config
381-
.env
382-
.iter()
383-
.map(|(k, v)| (k.clone(), Value::new_concrete(v.clone(), None)))
384-
.collect(),
385-
);
379+
generated_recipe.recipe.build.script = Script::from_content(build_script)
380+
.with_env(
381+
config
382+
.env
383+
.iter()
384+
.map(|(k, v)| (k.clone(), Value::new_concrete(v.clone(), None)))
385+
.collect(),
386+
)
387+
.with_secrets(model.secrets.iter().cloned().collect());
386388

387389
// Add the metadata input globs from the MetadataProvider
388390
generated_recipe

crates/pixi_build_r/src/main.rs

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -201,13 +201,15 @@ impl GenerateRecipe for RGenerator {
201201
}
202202
.render();
203203

204-
generated_recipe.recipe.build.script = Script::from_content(build_script).with_env(
205-
config
206-
.env
207-
.iter()
208-
.map(|(k, v)| (k.clone(), Value::new_concrete(v.clone(), None)))
209-
.collect(),
210-
);
204+
generated_recipe.recipe.build.script = Script::from_content(build_script)
205+
.with_env(
206+
config
207+
.env
208+
.iter()
209+
.map(|(k, v)| (k.clone(), Value::new_concrete(v.clone(), None)))
210+
.collect(),
211+
)
212+
.with_secrets(model.secrets.iter().cloned().collect());
211213

212214
// Add metadata input globs
213215
generated_recipe

crates/pixi_build_ros/src/main.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,8 +216,9 @@ impl GenerateRecipe for RosGenerator {
216216
}
217217
}
218218

219-
generated_recipe.recipe.build.script =
220-
Script::from_content(build_script_content).with_env(script_env);
219+
generated_recipe.recipe.build.script = Script::from_content(build_script_content)
220+
.with_env(script_env)
221+
.with_secrets(model.secrets.iter().cloned().collect());
221222

222223
Ok(generated_recipe)
223224
}

crates/pixi_build_rust/src/main.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ impl GenerateRecipe for RustGenerator {
124124
.chain(system_env_vars.clone())
125125
.collect();
126126

127-
let mut sccache_secrets = Vec::default();
127+
let mut sccache_secrets: BTreeSet<String> = BTreeSet::new();
128128

129129
// Verify if user has set any sccache environment variables
130130
if sccache_envs(&all_env_vars).is_some() {
@@ -185,14 +185,17 @@ impl GenerateRecipe for RustGenerator {
185185
}
186186
.render();
187187

188+
sccache_secrets.extend(model.secrets.iter().cloned());
189+
let secrets = sccache_secrets.into_iter().collect();
190+
188191
generated_recipe.recipe.build.script = Script::from_content(build_script)
189192
.with_env(
190193
config_env
191194
.iter()
192195
.map(|(k, v)| (k.clone(), Value::new_concrete(v.clone(), None)))
193196
.collect(),
194197
)
195-
.with_secrets(sccache_secrets);
198+
.with_secrets(secrets);
196199

197200
// Add the input globs from the Cargo metadata provider
198201
generated_recipe

crates/pixi_build_type_conversions/src/project_model.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,7 @@ pub fn to_project_model_v1(
226226
repository: manifest.package.repository.clone(),
227227
documentation: manifest.package.documentation.clone(),
228228
targets: Some(to_targets_v1(&manifest.targets, channel_config)?),
229+
secrets: manifest.build.secrets.clone(),
229230
};
230231
Ok(project)
231232
}

crates/pixi_build_types/src/project_model.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,14 @@ pub struct ProjectModel {
6565
/// The target of the project, this may contain
6666
/// platform specific configurations.
6767
pub targets: Option<Targets>,
68+
69+
/// Names of environment variables that should be exposed as secrets to
70+
/// the build script. Backends forward these into the generated
71+
/// `build.script.secrets` so rattler-build performs the host-env
72+
/// passthrough at build time. Stored as a set: order is not observable
73+
/// and changing it should not invalidate caches.
74+
#[serde(default, skip_serializing_if = "std::collections::BTreeSet::is_empty")]
75+
pub secrets: std::collections::BTreeSet<String>,
6876
}
6977

7078
impl IsDefault for ProjectModel {
@@ -550,6 +558,7 @@ impl Hash for ProjectModel {
550558
repository,
551559
documentation,
552560
targets,
561+
secrets,
553562
} = self;
554563

555564
StableHashBuilder::<H>::new()
@@ -564,6 +573,7 @@ impl Hash for ProjectModel {
564573
.field("name", name)
565574
.field("readme", readme)
566575
.field("repository", repository)
576+
.field("secrets", secrets)
567577
.field("targets", targets)
568578
.field("version", version)
569579
.finish(state);
@@ -871,6 +881,7 @@ mod tests {
871881
repository: None,
872882
documentation: None,
873883
targets: None,
884+
secrets: std::collections::BTreeSet::new(),
874885
};
875886

876887
let hash1 = calculate_hash(&project_model);
@@ -930,6 +941,7 @@ mod tests {
930941
repository: None,
931942
documentation: None,
932943
targets: None,
944+
secrets: std::collections::BTreeSet::new(),
933945
};
934946

935947
let hash1 = calculate_hash(&project_model);

crates/pixi_manifest/src/build_system.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,12 @@ pub struct PackageBuild {
3838

3939
/// The build number configured by the user.
4040
pub build_number: Option<u64>,
41+
42+
/// Names of environment variables to expose as secrets to the build
43+
/// script. Values are looked up at build time from the host environment by
44+
/// the build backend; only the names live in the manifest. Stored as a
45+
/// set since order is not observable.
46+
pub secrets: std::collections::BTreeSet<String>,
4147
}
4248

4349
impl PackageBuild {
@@ -52,6 +58,7 @@ impl PackageBuild {
5258
target_config: None,
5359
build_string_prefix: None,
5460
build_number: None,
61+
secrets: std::collections::BTreeSet::new(),
5562
}
5663
}
5764
}

0 commit comments

Comments
 (0)