Skip to content

Commit bb6cd82

Browse files
authored
feat: move package fields under [package]. (#2731)
This PR refactors the manifest to move all keys related to a package under the package key itself. It also removes the build-backend table in favor of making backends read the tool section instead. The build backends have been updated.
1 parent c464ed7 commit bb6cd82

File tree

57 files changed

+985
-1080
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+985
-1080
lines changed

Cargo.lock

-1
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/pixi_build_frontend/src/protocols/builders/pixi.rs

+16-46
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@ use miette::Diagnostic;
88
use pixi_consts::consts;
99
use pixi_manifest::{Manifest, PackageManifest, PrioritizedChannel, WorkspaceManifest};
1010
use rattler_conda_types::{ChannelConfig, MatchSpec};
11-
use serde::{de::IntoDeserializer, Deserialize};
1211
use thiserror::Error;
1312
use which::Error;
1413

@@ -143,35 +142,28 @@ impl ProtocolBuilder {
143142
}
144143

145144
fn get_tool_spec(&self, channel_config: &ChannelConfig) -> Result<ToolSpec, FinishError> {
146-
// The tool is either overridden or its not, with pixi the backend is specified in the toml
147-
// so it's unclear if we need to override the tool until this point, lets check that now
145+
// The tool is either overridden or its not, with pixi the backend is specified
146+
// in the toml so it's unclear if we need to override the tool until
147+
// this point, lets check that now
148148
if let Some(backend_override) = self.backend_override.as_ref() {
149-
let tool_name = self
150-
.package_manifest
151-
.build_system
152-
.build_backend
153-
.name
154-
.clone();
149+
let tool_name = self.package_manifest.build.backend.name.clone();
155150
if let Some(tool) = backend_override.overridden_tool(tool_name.as_normalized()) {
156151
return Ok(tool.as_spec());
157152
}
158153
}
159154

160155
// If we get here the tool is not overridden, so we use the isolated variant
161-
let build_system = &self.package_manifest.build_system;
162-
let specs = [(
163-
&build_system.build_backend.name,
164-
&build_system.build_backend.spec,
165-
)]
166-
.into_iter()
167-
.chain(build_system.additional_dependencies.iter())
168-
.map(|(name, spec)| {
169-
spec.clone()
170-
.try_into_nameless_match_spec(channel_config)
171-
.map(|spec| MatchSpec::from_nameless(spec, Some(name.clone())))
172-
})
173-
.collect::<Result<_, _>>()
174-
.map_err(FinishError::SpecConversionError)?;
156+
let build_system = &self.package_manifest.build;
157+
let specs = [(&build_system.backend.name, &build_system.backend.spec)]
158+
.into_iter()
159+
.chain(build_system.additional_dependencies.iter())
160+
.map(|(name, spec)| {
161+
spec.clone()
162+
.try_into_nameless_match_spec(channel_config)
163+
.map(|spec| MatchSpec::from_nameless(spec, Some(name.clone())))
164+
})
165+
.collect::<Result<_, _>>()
166+
.map_err(FinishError::SpecConversionError)?;
175167

176168
// Figure out the channels to use
177169
let channels = build_system.channels.clone().unwrap_or_else(|| {
@@ -184,7 +176,7 @@ impl ProtocolBuilder {
184176

185177
Ok(ToolSpec::Isolated(IsolatedToolSpec {
186178
specs,
187-
command: build_system.build_backend.name.as_source().to_string(),
179+
command: build_system.backend.name.as_source().to_string(),
188180
channels,
189181
}))
190182
}
@@ -210,20 +202,9 @@ impl ProtocolBuilder {
210202
.await
211203
.map_err(FinishError::Tool)?;
212204

213-
let configuration = self
214-
.package_manifest
215-
.build_system
216-
.build_backend
217-
.additional_args
218-
.map_or(serde_json::Value::Null, |value| {
219-
let deserializer = value.into_deserializer();
220-
serde_json::Value::deserialize(deserializer).unwrap_or(serde_json::Value::Null)
221-
});
222-
223205
Ok(JsonRPCBuildProtocol::setup(
224206
self.source_dir,
225207
self.manifest_path,
226-
configuration,
227208
build_id,
228209
self.cache_dir,
229210
tool,
@@ -238,21 +219,10 @@ impl ProtocolBuilder {
238219
ipc: InProcessBackend,
239220
build_id: usize,
240221
) -> Result<JsonRPCBuildProtocol, FinishError> {
241-
let configuration = self
242-
.package_manifest
243-
.build_system
244-
.build_backend
245-
.additional_args
246-
.map_or(serde_json::Value::Null, |value| {
247-
let deserializer = value.into_deserializer();
248-
serde_json::Value::deserialize(deserializer).unwrap_or(serde_json::Value::Null)
249-
});
250-
251222
Ok(JsonRPCBuildProtocol::setup_with_transport(
252223
"<IPC>".to_string(),
253224
self.source_dir,
254225
self.manifest_path,
255-
configuration,
256226
build_id,
257227
self.cache_dir,
258228
Sender::from(ipc.rpc_out),

crates/pixi_build_frontend/src/protocols/builders/rattler_build.rs

-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,6 @@ impl ProtocolBuilder {
145145
Ok(JsonRPCBuildProtocol::setup(
146146
self.source_dir,
147147
self.recipe_dir.join("recipe.yaml"),
148-
serde_json::Value::Null,
149148
build_id,
150149
self.cache_dir,
151150
tool,

crates/pixi_build_frontend/src/protocols/mod.rs

-4
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@ impl JsonRPCBuildProtocol {
147147
async fn setup(
148148
source_dir: PathBuf,
149149
manifest_path: PathBuf,
150-
configuration: serde_json::Value,
151150
build_id: usize,
152151
cache_dir: Option<PathBuf>,
153152
tool: Tool,
@@ -180,7 +179,6 @@ impl JsonRPCBuildProtocol {
180179
backend_identifier,
181180
source_dir,
182181
manifest_path,
183-
configuration,
184182
build_id,
185183
cache_dir,
186184
tx,
@@ -197,7 +195,6 @@ impl JsonRPCBuildProtocol {
197195
source_dir: PathBuf,
198196
// In case of rattler-build it's recipe.yaml
199197
manifest_path: PathBuf,
200-
configuration: serde_json::Value,
201198
build_id: usize,
202199
cache_dir: Option<PathBuf>,
203200
sender: impl TransportSenderT + Send,
@@ -234,7 +231,6 @@ impl JsonRPCBuildProtocol {
234231
RpcParams::from(InitializeParams {
235232
manifest_path: manifest_path.clone(),
236233
cache_directory: cache_dir,
237-
configuration,
238234
}),
239235
)
240236
.await

crates/pixi_build_frontend/tests/diagnostics.rs

+3-71
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@ use std::path::Path;
22

33
use bytes::Bytes;
44
use futures::{SinkExt, StreamExt};
5-
use jsonrpsee::types::Request;
65
use miette::{Diagnostic, GraphicalReportHandler, GraphicalTheme};
76
use pixi_build_frontend::{BuildFrontend, InProcessBackend, SetupRequest};
8-
use pixi_build_types::procedures::initialize::InitializeParams;
97
use pixi_manifest::toml::{ExternalWorkspaceProperties, FromTomlStr, TomlManifest};
10-
use tokio::io::{AsyncBufReadExt, AsyncRead, AsyncWrite, BufReader};
8+
use tokio::io::{AsyncRead, AsyncWrite};
119
use tokio_stream::wrappers::ReceiverStream;
1210
use tokio_util::{
1311
io::{CopyToBytes, SinkWriter, StreamReader},
@@ -136,8 +134,8 @@ async fn test_invalid_backend() {
136134
version = "0.1.0"
137135
name = "project"
138136
139-
[build-system]
140-
build-backend = { name = "ipc", version = "*" }
137+
[package.build]
138+
backend = { name = "ipc", version = "*" }
141139
"#;
142140

143141
let (frontend_tx, backend_rx) = pipe();
@@ -171,72 +169,6 @@ async fn test_invalid_backend() {
171169
insta::assert_snapshot!(snapshot);
172170
}
173171

174-
#[tokio::test]
175-
#[ignore]
176-
async fn test_backend_configuration() {
177-
let toml = r#"
178-
[workspace]
179-
platforms = []
180-
channels = []
181-
preview = ['pixi-build']
182-
183-
[package]
184-
version = "0.1.0"
185-
name = "project"
186-
187-
[build-system]
188-
build-backend = { name = "ipc", version = "*" }
189-
190-
[build-backend.ipc]
191-
hello = "world"
192-
"#;
193-
194-
let source_dir = tempfile::TempDir::new().unwrap();
195-
let manifest = source_dir
196-
.path()
197-
.join(pixi_consts::consts::PROJECT_MANIFEST);
198-
199-
let (frontend_tx, backend_rx) = pipe();
200-
let (backend_tx, frontend_rx) = pipe();
201-
let ipc = InProcessBackend {
202-
rpc_in: Box::new(frontend_rx),
203-
rpc_out: Box::new(frontend_tx),
204-
};
205-
206-
let protocol_setup = tokio::spawn(async move {
207-
let (workspace, package) = TomlManifest::from_toml_str(toml)
208-
.unwrap()
209-
.into_manifests(ExternalWorkspaceProperties::default())
210-
.unwrap();
211-
pixi_build_frontend::pixi_protocol::ProtocolBuilder::new(
212-
source_dir.path().to_path_buf(),
213-
manifest.to_path_buf(),
214-
workspace,
215-
package.unwrap(),
216-
)
217-
.finish_with_ipc(ipc, 0)
218-
.await
219-
.expect_err("the test never sends a response to the initialize request");
220-
});
221-
222-
let read_initialize_message = async move {
223-
let initialize_line = BufReader::new(backend_rx)
224-
.lines()
225-
.next_line()
226-
.await
227-
.unwrap()
228-
.unwrap();
229-
let request: Request = serde_json::from_str(&initialize_line).unwrap();
230-
let init_params: InitializeParams = request.params().parse().unwrap();
231-
drop(backend_tx); // Simulates the backend closing the connection.
232-
init_params
233-
};
234-
235-
let (_, init_params) = tokio::join!(protocol_setup, read_initialize_message);
236-
237-
insta::assert_snapshot!(serde_json::to_string_pretty(&init_params.configuration).unwrap());
238-
}
239-
240172
/// Creates a pipe that connects an async write instance to an async read
241173
/// instance.
242174
pub fn pipe() -> (

crates/pixi_build_types/Cargo.toml

-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,5 @@ version = "0.1.0"
1212
[dependencies]
1313
rattler_conda_types = { workspace = true }
1414
serde = { workspace = true, features = ["derive"] }
15-
serde_json = { workspace = true }
1615
serde_with = { workspace = true }
1716
url = { workspace = true }

crates/pixi_build_types/src/procedures/initialize.rs

-4
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,6 @@ pub struct InitializeParams {
2323
/// The manifest that the build backend should use.
2424
pub manifest_path: PathBuf,
2525

26-
/// Additional configuration to configure the backend. This configuration is
27-
/// specific to the backend.
28-
pub configuration: serde_json::Value,
29-
3026
/// Optionally the cache directory to use for any caching activity.
3127
pub cache_directory: Option<PathBuf>,
3228
}

crates/pixi_manifest/src/build_system.rs

+8-12
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use pixi_spec::BinarySpec;
55
use rattler_conda_types::NamedChannelOrUrl;
66

77
use crate::toml::FromTomlStr;
8-
use crate::{toml::TomlBuildSystem, TomlError};
8+
use crate::{toml::TomlPackageBuild, TomlError};
99

1010
/// A build section in the pixi manifest.
1111
/// that defines what backend is used to build the project.
1212
#[derive(Debug, Clone)]
13-
pub struct BuildSystem {
13+
pub struct PackageBuild {
1414
/// Information about the build backend
15-
pub build_backend: BuildBackend,
15+
pub backend: BuildBackend,
1616

1717
/// Additional dependencies that should be installed alongside the backend.
1818
pub additional_dependencies: IndexMap<rattler_conda_types::PackageName, BinarySpec>,
@@ -29,16 +29,12 @@ pub struct BuildBackend {
2929

3030
/// The spec for the backend
3131
pub spec: BinarySpec,
32-
33-
/// Additional arguments to pass to the build backend. In the manifest these are read from the
34-
/// `[build-backend]` section.
35-
pub additional_args: Option<serde_value::Value>,
3632
}
3733

38-
impl BuildSystem {
34+
impl PackageBuild {
3935
/// Parses the specified string as a toml representation of a build system.
4036
pub fn from_toml_str(source: &str) -> Result<Self, TomlError> {
41-
TomlBuildSystem::from_toml_str(source).and_then(TomlBuildSystem::into_build_system)
37+
TomlPackageBuild::from_toml_str(source).and_then(TomlPackageBuild::into_build_system)
4238
}
4339
}
4440

@@ -49,10 +45,10 @@ mod tests {
4945
#[test]
5046
fn deserialize_build() {
5147
let toml = r#"
52-
build-backend = { name = "pixi-build-python", version = "12.*" }
48+
backend = { name = "pixi-build-python", version = "12.*" }
5349
"#;
5450

55-
let build = BuildSystem::from_toml_str(toml).unwrap();
56-
assert_eq!(build.build_backend.name.as_source(), "pixi-build-python");
51+
let build = PackageBuild::from_toml_str(toml).unwrap();
52+
assert_eq!(build.backend.name.as_source(), "pixi-build-python");
5753
}
5854
}

0 commit comments

Comments
 (0)