forked from prefix-dev/pixi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: preview of
pixi build
and workspaces (prefix-dev#2250)
## Pixi Build This PR will incorporate the first, pre-alpha version of pixi build. This exposes the feature to use source dependencies, which will be built into `.conda` dependencies. --------- Co-authored-by: Bas Zalmstra <[email protected]> Co-authored-by: Bas Zalmstra <[email protected]> Co-authored-by: Ruben Arts <[email protected]> Co-authored-by: nichmor <[email protected]> Co-authored-by: Ruben Arts <[email protected]>
- Loading branch information
1 parent
7553b78
commit 32900a0
Showing
235 changed files
with
14,526 additions
and
7,223 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
[package] | ||
authors.workspace = true | ||
description = "Sets up environments to use for building of pixi.toml files" | ||
edition.workspace = true | ||
homepage.workspace = true | ||
license.workspace = true | ||
name = "pixi_build_frontend" | ||
readme.workspace = true | ||
repository.workspace = true | ||
version = "0.1.0" | ||
|
||
[dependencies] | ||
dashmap = { workspace = true } | ||
futures = { workspace = true } | ||
itertools = { workspace = true } | ||
jsonrpsee = { workspace = true, features = ["client"] } | ||
miette = { workspace = true, features = ["fancy", "serde"] } | ||
pixi_config = { workspace = true } | ||
pixi_consts = { workspace = true } | ||
pixi_manifest = { workspace = true } | ||
pixi_utils = { workspace = true, features = ["rustls-tls"] } | ||
rattler = { workspace = true } | ||
rattler_conda_types = { workspace = true } | ||
rattler_repodata_gateway = { workspace = true, features = ["gateway"] } | ||
rattler_shell = { workspace = true } | ||
rattler_solve = { workspace = true, features = ["resolvo"] } | ||
rattler_virtual_packages = { workspace = true } | ||
regex = { workspace = true } | ||
reqwest-middleware = { workspace = true } | ||
serde = { workspace = true, features = ["derive"] } | ||
serde_json = { workspace = true } | ||
serde_with = { workspace = true } | ||
serde_yaml = { workspace = true } | ||
sha1 = { workspace = true } | ||
thiserror = { workspace = true } | ||
tokio = { workspace = true, features = ["process", "io-std"] } | ||
tokio-util = { workspace = true, features = ["codec"] } | ||
tracing = { workspace = true } | ||
url = "2.5.0" | ||
which = { workspace = true } | ||
|
||
pixi_build_types = { path = "../pixi_build_types" } | ||
|
||
[dev-dependencies] | ||
insta = { workspace = true, features = ["yaml", "filters"] } | ||
rstest = { workspace = true } | ||
tempfile = { workspace = true } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
//! This module is the main entry | ||
use std::{path::PathBuf, sync::Arc}; | ||
|
||
use miette::Diagnostic; | ||
use rattler_conda_types::ChannelConfig; | ||
|
||
use crate::{ | ||
protocol, | ||
protocol_builder::{EnabledProtocols, ProtocolBuilder}, | ||
tool::{ToolCache, ToolContext}, | ||
Protocol, SetupRequest, | ||
}; | ||
|
||
/// The frontend for building packages. | ||
pub struct BuildFrontend { | ||
/// The cache for tools. This is used to avoid re-installing tools. | ||
tool_cache: Arc<ToolCache>, | ||
|
||
/// The channel configuration used by the frontend | ||
channel_config: ChannelConfig, | ||
|
||
/// The cache directory to use or `None` to use the default cache directory. | ||
cache_dir: Option<PathBuf>, | ||
|
||
/// The configuration to use when enabling the protocols. | ||
enabled_protocols: EnabledProtocols, | ||
} | ||
|
||
impl Default for BuildFrontend { | ||
fn default() -> Self { | ||
Self { | ||
tool_cache: Arc::new(ToolCache::new()), | ||
channel_config: ChannelConfig::default_with_root_dir(PathBuf::new()), | ||
cache_dir: None, | ||
enabled_protocols: EnabledProtocols::default(), | ||
} | ||
} | ||
} | ||
|
||
#[derive(thiserror::Error, Debug, Diagnostic)] | ||
pub enum BuildFrontendError { | ||
/// Error while discovering the pixi.toml | ||
#[error(transparent)] | ||
#[diagnostic(transparent)] | ||
DiscoveringManifest(#[from] protocol::DiscoveryError), | ||
/// Error from the build protocol. | ||
#[error(transparent)] | ||
#[diagnostic(transparent)] | ||
Protocol(#[from] protocol::FinishError), | ||
/// Error discovering system-tool | ||
#[error("error discovering system-tool")] | ||
ToolError(#[from] which::Error), | ||
} | ||
|
||
impl BuildFrontend { | ||
/// Specify the channel configuration | ||
pub fn with_channel_config(self, channel_config: ChannelConfig) -> Self { | ||
Self { | ||
channel_config, | ||
..self | ||
} | ||
} | ||
|
||
/// Returns the channel config of the frontend | ||
pub fn channel_config(&self) -> &ChannelConfig { | ||
&self.channel_config | ||
} | ||
|
||
/// Optionally sets the cache directory the backend should use. | ||
pub fn with_opt_cache_dir(self, cache_dir: Option<PathBuf>) -> Self { | ||
Self { cache_dir, ..self } | ||
} | ||
|
||
/// Sets the cache directory the backend should use. | ||
pub fn with_cache_dir(self, cache_dir: PathBuf) -> Self { | ||
Self { | ||
cache_dir: Some(cache_dir), | ||
..self | ||
} | ||
} | ||
|
||
/// Sets the tool context | ||
pub fn with_tool_context(self, context: ToolContext) -> Self { | ||
let tool_cache = ToolCache { | ||
cache: self.tool_cache.cache.clone(), | ||
context, | ||
}; | ||
|
||
Self { | ||
tool_cache: tool_cache.into(), | ||
..self | ||
} | ||
} | ||
|
||
/// Sets the enabling protocols. | ||
pub fn with_enabled_protocols(self, enabled_protocols: EnabledProtocols) -> Self { | ||
Self { | ||
enabled_protocols, | ||
..self | ||
} | ||
} | ||
|
||
/// Constructs a new [`Protocol`] for the given request. This object can be | ||
/// used to build the package. | ||
pub async fn setup_protocol( | ||
&self, | ||
request: SetupRequest, | ||
) -> Result<Protocol, BuildFrontendError> { | ||
// Determine the build protocol to use for the source directory. | ||
let protocol = ProtocolBuilder::discover(&request.source_dir, &self.enabled_protocols)? | ||
.with_channel_config(self.channel_config.clone()) | ||
.with_opt_cache_dir(self.cache_dir.clone()); | ||
|
||
tracing::info!( | ||
"discovered a {} source package at {}", | ||
protocol.name(), | ||
request.source_dir.display() | ||
); | ||
|
||
protocol | ||
.with_backend_override(request.build_tool_override) | ||
.finish(&self.tool_cache, request.build_id) | ||
.await | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
use jsonrpsee::core::traits::ToRpcParams; | ||
use serde::Serialize; | ||
use serde_json::value::RawValue; | ||
|
||
mod stdio; | ||
pub(crate) use stdio::{stdio_transport, Receiver, Sender}; | ||
|
||
/// A helper struct to convert a serializable type into a JSON-RPC parameter. | ||
pub struct RpcParams<T>(pub T); | ||
|
||
impl<T: Serialize> ToRpcParams for RpcParams<T> { | ||
fn to_rpc_params(self) -> Result<Option<Box<RawValue>>, serde_json::Error> { | ||
let json = serde_json::to_string(&self.0)?; | ||
RawValue::from_string(json).map(Some) | ||
} | ||
} | ||
|
||
impl<T> From<T> for RpcParams<T> { | ||
fn from(value: T) -> Self { | ||
Self(value) | ||
} | ||
} |
Oops, something went wrong.