Skip to content
Merged
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
2 changes: 2 additions & 0 deletions Cargo.lock

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

4 changes: 4 additions & 0 deletions crates/uv-build-frontend/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -862,6 +862,10 @@ impl SourceBuild {
}

impl SourceBuildTrait for SourceBuild {
fn into_build_dir(self) -> TempDir {
self.temp_dir
}

async fn metadata(&mut self) -> Result<Option<PathBuf>, AnyErrorBuild> {
Ok(self.get_metadata_without_build().await?)
}
Expand Down
22 changes: 17 additions & 5 deletions crates/uv-dispatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
//! [installer][`uv_installer`] and [build][`uv_build`] through [`BuildDispatch`]
//! implementing [`BuildContext`].

use std::ffi::{OsStr, OsString};
use std::path::Path;

use anyhow::{Context, Result};
use futures::FutureExt;
use itertools::Itertools;
use rustc_hash::FxHashMap;
use std::ffi::{OsStr, OsString};
use std::path::Path;
use thiserror::Error;
use tracing::{debug, instrument, trace};

use uv_build_backend::check_direct_build;
use uv_build_frontend::{SourceBuild, SourceBuildContext};
use uv_cache::Cache;
Expand All @@ -35,8 +35,8 @@ use uv_resolver::{
PythonRequirement, Resolver, ResolverEnvironment,
};
use uv_types::{
AnyErrorBuild, BuildContext, BuildIsolation, BuildStack, EmptyInstalledPackages, HashStrategy,
InFlight,
AnyErrorBuild, BuildArena, BuildContext, BuildIsolation, BuildStack, EmptyInstalledPackages,
HashStrategy, InFlight,
};
use uv_workspace::WorkspaceCache;

Expand Down Expand Up @@ -179,6 +179,10 @@ impl BuildContext for BuildDispatch<'_> {
&self.shared_state.git
}

fn build_arena(&self) -> &BuildArena {
&self.shared_state.build_arena
}

fn capabilities(&self) -> &IndexCapabilities {
&self.shared_state.capabilities
}
Expand Down Expand Up @@ -521,6 +525,8 @@ pub struct SharedState {
index: InMemoryIndex,
/// The downloaded distributions.
in_flight: InFlight,
/// Build directories for any PEP 517 builds executed during resolution or installation.
build_arena: BuildArena,
}

impl SharedState {
Expand All @@ -533,6 +539,7 @@ impl SharedState {
Self {
git: self.git.clone(),
capabilities: self.capabilities.clone(),
build_arena: self.build_arena.clone(),
..Default::default()
}
}
Expand All @@ -556,4 +563,9 @@ impl SharedState {
pub fn capabilities(&self) -> &IndexCapabilities {
&self.capabilities
}

/// Return the [`BuildArena`] used by the [`SharedState`].
pub fn build_arena(&self) -> &BuildArena {
&self.build_arena
}
}
24 changes: 19 additions & 5 deletions crates/uv-distribution/src/source/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2276,6 +2276,7 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
fs::create_dir_all(&cache_shard)
.await
.map_err(Error::CacheWrite)?;

// Try a direct build if that isn't disabled and the uv build backend is used.
let disk_filename = if let Some(name) = self
.build_context
Expand All @@ -2296,7 +2297,8 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
// In the uv build backend, the normalized filename and the disk filename are the same.
name.to_string()
} else {
self.build_context
let builder = self
.build_context
.setup_build(
source_root,
subdirectory,
Expand All @@ -2313,10 +2315,17 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
self.build_stack.cloned().unwrap_or_default(),
)
.await
.map_err(|err| Error::Build(err.into()))?
.wheel(temp_dir.path())
.await
.map_err(Error::Build)?
.map_err(|err| Error::Build(err.into()))?;

// Build the wheel.
let wheel = builder.wheel(temp_dir.path()).await.map_err(Error::Build)?;

// Store a reference to the build context.
self.build_context
.build_arena()
.push(builder.into_build_dir());

wheel
};

// Read the metadata from the wheel.
Expand Down Expand Up @@ -2398,6 +2407,11 @@ impl<'a, T: BuildContext> SourceDistributionBuilder<'a, T> {
return Ok(None);
};

// Store a reference to the build context.
self.build_context
.build_arena()
.push(builder.into_build_dir());

// Read the metadata from disk.
debug!("Prepared metadata for: {source}");
let content = fs::read(dist_info.join("METADATA"))
Expand Down
2 changes: 2 additions & 0 deletions crates/uv-types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ uv-redacted = { workspace = true }
uv-workspace = { workspace = true }

anyhow = { workspace = true }
boxcar = { workspace = true }
rustc-hash = { workspace = true }
tempfile = { workspace = true }
thiserror = { workspace = true }

[features]
Expand Down
13 changes: 13 additions & 0 deletions crates/uv-types/src/builds.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::sync::Arc;
use tempfile::TempDir;
use uv_pep508::PackageName;
use uv_python::PythonEnvironment;

Expand Down Expand Up @@ -37,3 +39,14 @@ impl BuildIsolation<'_> {
}
}
}

/// An arena of temporary directories used for builds.
#[derive(Default, Debug, Clone)]
pub struct BuildArena(Arc<boxcar::Vec<TempDir>>);

impl BuildArena {
/// Push a new temporary directory into the arena.
pub fn push(&self, temp_dir: TempDir) {
self.0.push(temp_dir);
}
}
8 changes: 8 additions & 0 deletions crates/uv-types/src/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ use std::path::{Path, PathBuf};

use anyhow::Result;
use rustc_hash::FxHashSet;
use tempfile::TempDir;

use crate::BuildArena;
use uv_cache::Cache;
use uv_configuration::{BuildKind, BuildOptions, BuildOutput, ConfigSettings, SourceStrategy};
use uv_distribution_filename::DistFilename;
Expand Down Expand Up @@ -67,6 +69,9 @@ pub trait BuildContext {
/// Return a reference to the Git resolver.
fn git(&self) -> &GitResolver;

/// Return a reference to the build arena.
fn build_arena(&self) -> &BuildArena;

/// Return a reference to the discovered registry capabilities.
fn capabilities(&self) -> &IndexCapabilities;

Expand Down Expand Up @@ -148,6 +153,9 @@ pub trait BuildContext {
/// You can either call only `wheel()` to build the wheel directly, call only `metadata()` to get
/// the metadata without performing the actual or first call `metadata()` and then `wheel()`.
pub trait SourceBuildTrait {
/// Return the temporary build directory.
fn into_build_dir(self) -> TempDir;

/// A wrapper for `uv_build::SourceBuild::get_metadata_without_build`.
///
/// For PEP 517 builds, this calls `prepare_metadata_for_build_wheel`
Expand Down
Loading