Skip to content

Commit

Permalink
ci(windows): Introduce setup-dev-drive.ps1, maximize dev drive usage (#…
Browse files Browse the repository at this point in the history
…6858)

As suggested by @samypr100 on #6680:
#6680 (comment)

## Summary

Instead of using `UV_INTERNAL__TEST_DIR`, it simply exports `TEMP` when
running Windows jobs.

## Test Plan

I'm going to run this manually under ProcMon on my Windows machine and
see where uv writes temp files, hopefully to the dev drive and not
`%(LOCAL)APPDATA%` or something.

I'm going to commit a dummy code change and look at build time changes
in CI.
  • Loading branch information
fasterthanlime authored Aug 30, 2024
1 parent 52bc93e commit 3e207da
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 60 deletions.
67 changes: 15 additions & 52 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -240,22 +240,15 @@ jobs:
labels: "windows-latest-xlarge"
name: "cargo test | windows"
steps:
- name: Create Dev Drive using ReFS
run: |
$Volume = New-VHD -Path C:/uv_dev_drive.vhdx -SizeBytes 20GB |
Mount-VHD -Passthru |
Initialize-Disk -Passthru |
New-Partition -AssignDriveLetter -UseMaximumSize |
Format-Volume -FileSystem ReFS -Confirm:$false -Force
Write-Output $Volume
Write-Output "DEV_DRIVE=$($Volume.DriveLetter):" >> $env:GITHUB_ENV
- uses: actions/checkout@v4

- name: Create Dev Drive using ReFS
run: ${{ github.workspace }}/.github/workflows/setup-dev-drive.ps1

# actions/checkout does not let us clone into anywhere outside ${{ github.workspace }}, so we have to copy the clone...
- name: Copy Git Repo to Dev Drive
run: |
Copy-Item -Path "${{ github.workspace }}" -Destination "${{ env.DEV_DRIVE }}/uv" -Recurse
Copy-Item -Path "${{ github.workspace }}" -Destination "${{ env.UV_WORKSPACE }}" -Recurse
# We do not test with Python patch versions on Windows
# so we can use `setup-python` instead of our bootstrapping code
Expand All @@ -271,40 +264,25 @@ jobs:
- uses: Swatinem/rust-cache@v2
with:
workspaces: ${{ env.DEV_DRIVE }}/uv
env:
CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo
RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup
workspaces: ${{ env.UV_WORKSPACE }}

- name: "Install Rust toolchain"
working-directory: ${{ env.DEV_DRIVE }}/uv
env:
CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo
RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup
working-directory: ${{ env.UV_WORKSPACE }}
run: rustup show

- name: "Install cargo nextest"
uses: taiki-e/install-action@v2
with:
tool: cargo-nextest
env:
CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo
RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup

- name: "Cargo test"
working-directory: ${{ env.DEV_DRIVE }}/uv
env:
CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo
RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup
UV_INTERNAL__TEST_DIR: ${{ env.DEV_DRIVE }}/tmp-uv
working-directory: ${{ env.UV_WORKSPACE }}
run: |
cargo nextest run --no-default-features --features python,pypi --workspace --status-level skip --failure-output immediate-final --no-fail-fast -j 20 --final-status-level slow
- name: "Smoke test"
working-directory: ${{ env.DEV_DRIVE }}/uv
working-directory: ${{ env.UV_WORKSPACE }}
env:
CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo
RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup
# Avoid debug build stack overflows.
UV_STACK_SIZE: 2000000 # 2 megabyte, double the default on windows
run: |
Expand Down Expand Up @@ -518,44 +496,29 @@ jobs:
labels: windows-latest-large
name: "build binary | windows"
steps:
- name: Create Dev Drive using ReFS
run: |
$Volume = New-VHD -Path C:/uv_dev_drive.vhdx -SizeBytes 10GB |
Mount-VHD -Passthru |
Initialize-Disk -Passthru |
New-Partition -AssignDriveLetter -UseMaximumSize |
Format-Volume -FileSystem ReFS -Confirm:$false -Force
Write-Output $Volume
Write-Output "DEV_DRIVE=$($Volume.DriveLetter):" >> $env:GITHUB_ENV
- uses: actions/checkout@v4

- name: Create Dev Drive using ReFS
run: ${{ github.workspace }}/.github/workflows/setup-dev-drive.ps1

# actions/checkout does not let us clone into anywhere outside ${{ github.workspace }}, so we have to copy the clone...
- name: Copy Git Repo to Dev Drive
run: |
Copy-Item -Path "${{ github.workspace }}" -Destination "${{ env.DEV_DRIVE }}/uv" -Recurse
- uses: rui314/setup-mold@v1
Copy-Item -Path "${{ github.workspace }}" -Destination "${{ env.UV_WORKSPACE }}" -Recurse
- uses: Swatinem/rust-cache@v2
with:
workspaces: ${{ env.DEV_DRIVE }}/uv
env:
CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo
RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup
workspaces: ${{ env.UV_WORKSPACE }}

- name: "Build"
working-directory: ${{ env.DEV_DRIVE }}/uv
env:
CARGO_HOME: ${{ env.DEV_DRIVE }}/.cargo
RUSTUP_HOME: ${{ env.DEV_DRIVE }}/.rustup
working-directory: ${{ env.UV_WORKSPACE }}
run: cargo build

- name: "Upload binary"
uses: actions/upload-artifact@v4
with:
name: uv-windows-${{ github.sha }}
path: ${{ env.DEV_DRIVE }}/uv/target/debug/uv.exe
path: ${{ env.UV_WORKSPACE }}/target/debug/uv.exe
retention-days: 1

ecosystem-test:
Expand Down
24 changes: 24 additions & 0 deletions .github/workflows/setup-dev-drive.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# This creates a 20GB dev drive, and exports all required environment
# variables so that rustup, uv and others all use the dev drive as much
# as possible.
$Volume = New-VHD -Path C:/uv_dev_drive.vhdx -SizeBytes 20GB |
Mount-VHD -Passthru |
Initialize-Disk -Passthru |
New-Partition -AssignDriveLetter -UseMaximumSize |
Format-Volume -FileSystem ReFS -Confirm:$false -Force

Write-Output $Volume

$Drive = "$($Volume.DriveLetter):"
$Tmp = "$($Drive)/uv-tmp"

Write-Output `
"DEV_DRIVE=$($Drive)" `
"TMP=$($Tmp)" `
"TEMP=$($Tmp)" `
"UV_INTERNAL__TEST_DIR=$($Tmp)" `
"RUSTUP_HOME=$($Drive)/.rustup" `
"CARGO_HOME=$($Drive)/.cargo" `
"UV_WORKSPACE=$($Drive)/uv" `
>> $env:GITHUB_ENV

1 change: 1 addition & 0 deletions crates/distribution-types/src/installed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ impl InstalledDist {

let name = PackageName::from_str(name)?;
let version = Version::from_str(version).map_err(|err| anyhow!(err))?;

return if let Some(direct_url) = Self::direct_url(path)? {
match Url::try_from(&direct_url) {
Ok(url) => Ok(Some(Self::Url(InstalledDirectUrlDist {
Expand Down
9 changes: 1 addition & 8 deletions crates/uv-cache/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,14 +135,7 @@ impl Cache {

/// Create a temporary cache directory.
pub fn temp() -> Result<Self, io::Error> {
let temp_dir =
if let Ok(test_dir) = std::env::var("UV_INTERNAL__TEST_DIR").map(PathBuf::from) {
let uv_cache_dir = test_dir.join("uv-cache");
let _ = fs_err::create_dir_all(&uv_cache_dir);
tempfile::tempdir_in(uv_cache_dir)?
} else {
tempfile::tempdir()?
};
let temp_dir = tempfile::tempdir()?;
Ok(Self {
root: temp_dir.path().to_path_buf(),
refresh: Refresh::None(Timestamp::now()),
Expand Down

0 comments on commit 3e207da

Please sign in to comment.