Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add isolated build tools #2479

Open
wants to merge 8 commits into
base: feature/pixi-build
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 14 additions & 43 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 24 additions & 12 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -103,18 +103,30 @@ which = "6.0.3"

# Rattler crates
file_url = "0.1.4"
rattler = { version = "0.28.0", default-features = false }
rattler_cache = { version = "0.2.7", default-features = false }
rattler_conda_types = { version = "0.29.0", default-features = false }
rattler_digest = { version = "1.0.2", default-features = false }
rattler_lock = { version = "0.22.29", default-features = false }
rattler_networking = { version = "0.21.5", default-features = false, features = [
"google-cloud-auth",
] }
rattler_repodata_gateway = { version = "0.21.18", default-features = false }
rattler_shell = { version = "0.22.4", default-features = false }
rattler_solve = { version = "1.1.0", default-features = false }
rattler_virtual_packages = { version = "1.1.7", default-features = false }
# rattler = { version = "0.28.0", default-features = false }
# rattler_cache = { version = "0.2.7", default-features = false }
# rattler_conda_types = { version = "0.29.0", default-features = false }
# rattler_digest = { version = "1.0.2", default-features = false }
# rattler_lock = { version = "0.22.29", default-features = false }
# rattler_networking = { version = "0.21.5", default-features = false, features = [
# "google-cloud-auth",
# ] }
# rattler_repodata_gateway = { version = "0.21.18", default-features = false }
# rattler_shell = { version = "0.22.4", default-features = false }
# rattler_solve = { version = "1.1.0", default-features = false }
# rattler_virtual_packages = { version = "1.1.7", default-features = false }

rattler = { git = "https://github.com/conda/rattler", branch = "feat/pixi-build" }
rattler_cache = { git = "https://github.com/conda/rattler", branch = "feat/pixi-build" }
rattler_conda_types = { git = "https://github.com/conda/rattler", branch = "feat/pixi-build" }
rattler_digest = { git = "https://github.com/conda/rattler", branch = "feat/pixi-build" }
rattler_lock = { git = "https://github.com/conda/rattler", branch = "feat/pixi-build" }
rattler_networking = { git = "https://github.com/conda/rattler", branch = "feat/pixi-build" }
rattler_package_streaming = { git = "https://github.com/conda/rattler", branch = "feat/pixi-build" }
rattler_repodata_gateway = { git = "https://github.com/conda/rattler", branch = "feat/pixi-build" }
rattler_shell = { git = "https://github.com/conda/rattler", branch = "feat/pixi-build" }
rattler_solve = { git = "https://github.com/conda/rattler", branch = "feat/pixi-build" }
rattler_virtual_packages = { git = "https://github.com/conda/rattler", branch = "feat/pixi-build" }

# Bumping this to a higher version breaks the Windows path handling.
url = "2.5.2"
Expand Down
8 changes: 8 additions & 0 deletions crates/pixi_build_frontend/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,18 @@ futures = { workspace = true }
itertools = { workspace = true }
jsonrpsee = { workspace = true, features = ["client"] }
miette = { workspace = true, features = ["fancy", "serde"] }
pixi_config = { workspace = true, features = ["rattler_repodata_gateway"] }
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 }
Expand Down
20 changes: 19 additions & 1 deletion crates/pixi_build_frontend/src/build_frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,12 @@ use std::{path::PathBuf, sync::Arc};
use miette::Diagnostic;
use rattler_conda_types::ChannelConfig;

use crate::{protocol, protocol_builder::ProtocolBuilder, tool::ToolCache, Protocol, SetupRequest};
use crate::{
protocol,
protocol_builder::ProtocolBuilder,
tool::{ToolCache, ToolContext},
Protocol, SetupRequest,
};

/// The frontend for building packages.
pub struct BuildFrontend {
Expand Down Expand Up @@ -70,6 +75,19 @@ impl BuildFrontend {
}
}

/// 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
}
}

/// Constructs a new [`Protocol`] for the given request. This object can be
/// used to build the package.
pub async fn setup_protocol(
Expand Down
4 changes: 2 additions & 2 deletions crates/pixi_build_frontend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use rattler_conda_types::MatchSpec;
pub use reporters::{CondaBuildReporter, CondaMetadataReporter};
pub use reporters::{NoopCondaBuildReporter, NoopCondaMetadataReporter};
use tokio::io::{AsyncRead, AsyncWrite};
pub use tool::{IsolatedToolSpec, SystemToolSpec, ToolSpec};
pub use tool::{IsolatedToolSpec, SystemToolSpec, ToolContext, ToolSpec};
use url::Url;

pub use crate::protocol::Protocol;
Expand All @@ -29,7 +29,7 @@ pub enum BackendOverride {
Spec(MatchSpec),

/// Overwrite the backend with a specific tool.
Path(PathBuf),
System(String),

/// Use the given IO for the backend.
Io(InProcessBackend),
Expand Down
1 change: 1 addition & 0 deletions crates/pixi_build_frontend/src/protocol_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ impl ProtocolBuilder {
Self::CondaBuild(protocol) => Ok(Protocol::CondaBuild(
protocol
.finish(tool_cache)
.await
.map_err(FinishError::CondaBuild)?,
)),
}
Expand Down
4 changes: 2 additions & 2 deletions crates/pixi_build_frontend/src/protocols/conda_build/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ impl ProtocolBuilder {
}
}

pub fn finish(self, tool: &ToolCache) -> Result<Protocol, FinishError> {
let tool = tool.instantiate(self.backend_spec)?;
pub async fn finish(self, tool: &ToolCache) -> Result<Protocol, FinishError> {
let tool = tool.instantiate(self.backend_spec).await?;
Ok(Protocol {
_channel_config: self.channel_config,
tool,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,13 @@ impl Protocol {

// Construct a new tool that can be used to invoke conda-render instead of the
// original tool.
let conda_render_executable = tool.executable().with_file_name("conda-render");
let conda_render_executable = if let Some(ext) = tool.executable().extension() {
conda_render_executable.with_extension(ext)
let conda_render_executable = String::from("conda-render");
let conda_render_executable = if cfg!(windows) {
format!("{}.exe", conda_render_executable)
} else {
conda_render_executable
};

let conda_render_tool = tool.with_executable(conda_render_executable);

// TODO: Properly pass channels
Expand Down
11 changes: 9 additions & 2 deletions crates/pixi_build_frontend/src/protocols/pixi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ impl Display for FinishError {
FinishError::Tool(ToolCacheError::Instantiate(tool, err)) => match err {
Error::CannotGetCurrentDirAndPathListEmpty|Error::CannotFindBinaryPath => write!(f, "failed to setup a build backend, the backend tool '{}' could not be found", tool.display()),
Error::CannotCanonicalize => write!(f, "failed to setup a build backend, although the backend tool '{}' can be resolved it could not be canonicalized", tool.display()),
}
},
FinishError::Tool(ToolCacheError::Install(report)) => write!(f, "failed to setup a build backend, the backend tool could not be installed: {}", report),
FinishError::Tool(ToolCacheError::CacheDir(report)) => write!(f, "failed to setup a build backend, the cache dir could not be discovered: {}", report),
}
}
}
Expand Down Expand Up @@ -122,7 +124,12 @@ impl ProtocolBuilder {
let tool_spec = self
.backend_spec
.ok_or(FinishError::NoBuildSection(self.manifest.path.clone()))?;
let tool = tool.instantiate(tool_spec).map_err(FinishError::Tool)?;

let tool = tool
.instantiate(tool_spec)
.await
.map_err(FinishError::Tool)?;

Ok(Protocol::setup(
self.source_dir,
self.manifest.path,
Expand Down
8 changes: 2 additions & 6 deletions crates/pixi_build_frontend/src/protocols/pixi/protocol.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{ffi::OsStr, path::PathBuf, sync::Arc};
use std::{path::PathBuf, sync::Arc};

use futures::TryFutureExt;
use jsonrpsee::{
Expand Down Expand Up @@ -124,11 +124,7 @@ impl Protocol {
.stderr(std::process::Stdio::piped()) // TODO: Capture this?
.spawn()?;

let backend_identifier = tool
.executable()
.file_stem()
.and_then(OsStr::to_str)
.map_or_else(|| "<unknown>".to_string(), ToString::to_string);
let backend_identifier = tool.executable().clone();

// Acquire the stdin/stdout handles.
let stdin = process
Expand Down
Loading
Loading