Skip to content

Commit

Permalink
feat: add first iteration of isolated build tools
Browse files Browse the repository at this point in the history
  • Loading branch information
nichmor committed Nov 14, 2024
1 parent 8601e7b commit aa60818
Show file tree
Hide file tree
Showing 21 changed files with 486 additions and 104 deletions.
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
22 changes: 20 additions & 2 deletions crates/pixi_build_frontend/src/build_frontend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,17 @@ 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 {
/// The cache for tools. This is used to avoid re-installing tools.
tool_cache: Arc<ToolCache>,
pub tool_cache: Arc<ToolCache>,

/// The channel configuration used by the frontend
channel_config: ChannelConfig,
Expand Down Expand Up @@ -70,6 +75,19 @@ impl BuildFrontend {
}
}

/// Sets the tool configuration
pub fn with_tool_config(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
2 changes: 1 addition & 1 deletion 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 Down
2 changes: 2 additions & 0 deletions crates/pixi_build_frontend/src/protocol_builder.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use std::path::{Path, PathBuf};

use rattler_conda_types::ChannelConfig;
use reqwest_middleware::ClientWithMiddleware;

use crate::{
conda_build_protocol, pixi_protocol,
Expand Down Expand Up @@ -107,6 +108,7 @@ impl ProtocolBuilder {
Self::CondaBuild(protocol) => Ok(Protocol::CondaBuild(
protocol
.finish(tool_cache)
.await
.map_err(FinishError::CondaBuild)?,
)),
}
Expand Down
5 changes: 3 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 @@ -8,6 +8,7 @@ use std::{
use miette::Diagnostic;
pub use protocol::Protocol;
use rattler_conda_types::{ChannelConfig, MatchSpec, ParseStrictness::Strict};
use reqwest_middleware::ClientWithMiddleware;
use thiserror::Error;

use crate::{
Expand Down Expand Up @@ -96,8 +97,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
12 changes: 9 additions & 3 deletions crates/pixi_build_frontend/src/protocols/conda_build/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,18 @@ 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_executable = if let Some(ext) = tool.executable().extension() {
// conda_render_executable.with_extension(ext)
// } else {
// conda_render_executable
// };
let conda_render_tool = tool.with_executable(conda_render_executable);

// TODO: Properly pass channels
Expand Down
8 changes: 7 additions & 1 deletion crates/pixi_build_frontend/src/protocols/pixi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use pixi_consts::consts;
use pixi_manifest::Manifest;
pub use protocol::{InitializeError, Protocol};
use rattler_conda_types::ChannelConfig;
use reqwest_middleware::ClientWithMiddleware;
pub(crate) use stderr::{stderr_null, stderr_stream};
use thiserror::Error;
use which::Error;
Expand Down Expand Up @@ -122,7 +123,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
10 changes: 5 additions & 5 deletions crates/pixi_build_frontend/src/protocols/pixi/protocol.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,18 @@ impl Protocol {
) -> Result<Self, InitializeError> {
match tool.try_into_executable() {
Ok(tool) => {
eprintln!("Spawning tool: {:?}", tool.executable());
// Spawn the tool and capture stdin/stdout.
let mut process = tokio::process::Command::from(tool.command())
.stdout(std::process::Stdio::piped())
.stdin(std::process::Stdio::piped())
.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();
// .file_stem()
// .and_then(OsStr::to_str)
// .map_or_else(|| "<unknown>".to_string(), ToString::to_string);

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

0 comments on commit aa60818

Please sign in to comment.