diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 8697dd2..fa568d8 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -29,7 +29,7 @@ jobs: ci: uses: nanvix/workflows/.github/workflows/nanvix-ci.yml@v2.0.1 with: - zutil-version: "v0.8.2" + zutil-version: "v0.8.5" platforms: "[\"microvm\"]" process-modes: "[\"standalone\"]" memory-sizes: "[\"256mb\"]" diff --git a/.nanvix/nanvix.toml b/.nanvix/nanvix.toml index 958dd91..6b03cb6 100644 --- a/.nanvix/nanvix.toml +++ b/.nanvix/nanvix.toml @@ -1,7 +1,7 @@ [package] name = "nanvix-python" version = "3.12.3" -nanvix-version = "0.12.547" +nanvix-version = "0.13.16" [builds] [builds.matrix] diff --git a/z.ps1 b/z.ps1 index 452d53d..0baaa92 100644 --- a/z.ps1 +++ b/z.ps1 @@ -1,168 +1,168 @@ -# Copyright(c) The Maintainers of Nanvix. -# Licensed under the MIT License. - -# Thin wrapper that delegates to the nanvix-zutil CLI. -# Self-bootstraps nanvix-zutil into .nanvix\venv\ if it is not already installed. - -param( - [Parameter(ValueFromRemainingArguments = $true)] - [string[]]$ZArgs -) - -$ErrorActionPreference = 'Stop' - -$zutilVersion = if ($env:NANVIX_ZUTIL_VERSION) { - $env:NANVIX_ZUTIL_VERSION -} -else { - "0.8.2" -} -$zutilVersion = $zutilVersion -replace "^v", "" - -# z.ps1 lives at the repository root, so use its directory directly -# instead of relying on git to discover the top-level checkout directory. -$repoRoot = $PSScriptRoot -$venvDir = Join-Path $repoRoot ".nanvix\venv" -$venvPython = Join-Path $venvDir "Scripts\python.exe" -$venvZutil = Join-Path $venvDir "Scripts\nanvix-zutil.exe" - -# Windows compatibility shim: nanvix-zutil references os.getuid/os.getgid -# which are unavailable on Windows. Stub them before importing the package. -# NOTE: Use single quotes inside the Python code so that PowerShell does not -# strip the quotes when passing the string to python.exe -c. -$ShimCode = @' -import os,sys;os.getuid=getattr(os,'getuid',lambda:0);os.getgid=getattr(os,'getgid',lambda:0);from nanvix_zutil.__main__ import main;sys.exit(main()) -'@ - -$zutilGlobalVersion = try { - & nanvix-zutil --version 2>$null -} -catch { - $null -} - -function Bootstrap { - # Pin nanvix-zutil version for reproducible bootstrapping. - # Override with NANVIX_ZUTIL_VERSION env var if needed. - Write-Information "nanvix-zutil not found -- bootstrapping nanvix-zutil==${zutilVersion}..." -InformationAction Continue - - $wheelUrl = "https://github.com/nanvix/zutils/releases/download/v${zutilVersion}/nanvix_zutil-${zutilVersion}-py3-none-any.whl" - - # Discover a Python 3 interpreter. - $venvArgs = @("-m", "venv") - if (Test-Path $venvDir) { - $venvArgs += "--clear" - } - $venvArgs += $venvDir - - if (Get-Command py -ErrorAction SilentlyContinue) { - & py -3 @venvArgs - } - elseif (Get-Command python -ErrorAction SilentlyContinue) { - & python @venvArgs - } - elseif (Get-Command python3 -ErrorAction SilentlyContinue) { - & python3 @venvArgs - } - else { - throw "Python 3 not found. Install Python 3 and ensure py, python, or python3 is on PATH." - } - if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) { - throw "venv creation failed (exit code $LASTEXITCODE)" - } - & $venvPython -m pip install --quiet "nanvix-zutil[lint] @ $($wheelUrl)" - if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) { - throw "pip install failed (exit code $LASTEXITCODE)" - } -} - -# Prefer the venv copy if it exists; otherwise use the global install. -$bin = $null -if ((-not (Test-Path $venvDir)) -and (-not $zutilGlobalVersion)) { - Bootstrap - if (-not (Test-Path $venvZutil)) { - throw "Bootstrap completed but $venvZutil not found." - } - $bin = $venvZutil -} -elseif (Test-Path $venvZutil) { - # Use the shim to check version -- running the exe directly fails on - # Windows because os.getuid/os.getgid are unavailable (see FIXME above). - $venvVersion = try { - & $venvPython -c $ShimCode --version 2>$null - } - catch { - $null - } - if ($venvVersion -ne "nanvix-zutil ${zutilVersion}") { - Write-Warning "Venv nanvix-zutil version mismatch. Expected ${zutilVersion}, found ${venvVersion}. Re-bootstrapping..." - Bootstrap - if (-not (Test-Path $venvZutil)) { - throw "Bootstrap completed but $venvZutil not found." - } - } - $bin = $venvZutil -} -elseif ((Test-Path $venvDir) -and (-not $zutilGlobalVersion)) { - Write-Warning "Incomplete venv detected (binary missing). Re-running bootstrap..." - Bootstrap - if (-not (Test-Path $venvZutil)) { - throw "Bootstrap completed but $venvZutil not found." - } - $bin = $venvZutil -} -else { - $bin = "nanvix-zutil" - if ($zutilGlobalVersion -ne "nanvix-zutil ${zutilVersion}") { - Write-Warning "nanvix-zutil global install does not match expected version. Expected ${zutilVersion}, found ${zutilGlobalVersion}." - } -} - -# Extract --with-nanvix PATH before forwarding to nanvix-zutil. -$filteredArgs = [System.Collections.Generic.List[string]]::new() -$i = 0 -while ($i -lt $ZArgs.Count) { - if ($ZArgs[$i] -eq '--with-nanvix') { - if ($i + 1 -ge $ZArgs.Count) { - throw "ERROR: --with-nanvix requires a path argument" - } - $item = Get-Item -LiteralPath $ZArgs[$i + 1] -ErrorAction Stop - if (-not $item.PSIsContainer) { - throw "ERROR: --with-nanvix path is not a directory: $($ZArgs[$i + 1])" - } - $env:WITH_NANVIX = $item.FullName - $i += 2 - } - elseif ($ZArgs[$i] -match '^--with-nanvix=(.+)$') { - $item = Get-Item -LiteralPath $Matches[1] -ErrorAction Stop - if (-not $item.PSIsContainer) { - throw "ERROR: --with-nanvix path is not a directory: $($Matches[1])" - } - $env:WITH_NANVIX = $item.FullName - $i++ - } - else { - $filteredArgs.Add($ZArgs[$i]) - $i++ - } -} - -$filteredArray = $filteredArgs.ToArray() - -if ($bin -eq $venvZutil) { - & $venvPython -c $ShimCode @filteredArray -} -else { - & $bin @filteredArray -} - -$ec = $LASTEXITCODE - -# On Windows the venv's python.exe is locked while it runs, so the Python -# distclean command cannot delete it. Now that the interpreter has exited the -# lock is released and the shell can safely remove the venv directory. -if ($filteredArray -and $filteredArray[0] -eq "distclean" -and (Test-Path $venvDir)) { - Remove-Item $venvDir -Recurse -Force -ErrorAction SilentlyContinue -} - -exit $ec +# Copyright(c) The Maintainers of Nanvix. +# Licensed under the MIT License. + +# Thin wrapper that delegates to the nanvix-zutil CLI. +# Self-bootstraps nanvix-zutil into .nanvix\venv\ if it is not already installed. + +param( + [Parameter(ValueFromRemainingArguments = $true)] + [string[]]$ZArgs +) + +$ErrorActionPreference = 'Stop' + +$zutilVersion = if ($env:NANVIX_ZUTIL_VERSION) { + $env:NANVIX_ZUTIL_VERSION +} +else { + "0.8.5" +} +$zutilVersion = $zutilVersion -replace "^v", "" + +# z.ps1 lives at the repository root, so use its directory directly +# instead of relying on git to discover the top-level checkout directory. +$repoRoot = $PSScriptRoot +$venvDir = Join-Path $repoRoot ".nanvix\venv" +$venvPython = Join-Path $venvDir "Scripts\python.exe" +$venvZutil = Join-Path $venvDir "Scripts\nanvix-zutil.exe" + +# Windows compatibility shim: nanvix-zutil references os.getuid/os.getgid +# which are unavailable on Windows. Stub them before importing the package. +# NOTE: Use single quotes inside the Python code so that PowerShell does not +# strip the quotes when passing the string to python.exe -c. +$ShimCode = @' +import os,sys;os.getuid=getattr(os,'getuid',lambda:0);os.getgid=getattr(os,'getgid',lambda:0);from nanvix_zutil.__main__ import main;sys.exit(main()) +'@ + +$zutilGlobalVersion = try { + & nanvix-zutil --version 2>$null +} +catch { + $null +} + +function Bootstrap { + # Pin nanvix-zutil version for reproducible bootstrapping. + # Override with NANVIX_ZUTIL_VERSION env var if needed. + Write-Information "nanvix-zutil not found -- bootstrapping nanvix-zutil==${zutilVersion}..." -InformationAction Continue + + $wheelUrl = "https://github.com/nanvix/zutils/releases/download/v${zutilVersion}/nanvix_zutil-${zutilVersion}-py3-none-any.whl" + + # Discover a Python 3 interpreter. + $venvArgs = @("-m", "venv") + if (Test-Path $venvDir) { + $venvArgs += "--clear" + } + $venvArgs += $venvDir + + if (Get-Command py -ErrorAction SilentlyContinue) { + & py -3 @venvArgs + } + elseif (Get-Command python -ErrorAction SilentlyContinue) { + & python @venvArgs + } + elseif (Get-Command python3 -ErrorAction SilentlyContinue) { + & python3 @venvArgs + } + else { + throw "Python 3 not found. Install Python 3 and ensure py, python, or python3 is on PATH." + } + if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) { + throw "venv creation failed (exit code $LASTEXITCODE)" + } + & $venvPython -m pip install --quiet "nanvix-zutil[lint] @ $($wheelUrl)" + if ($LASTEXITCODE -and $LASTEXITCODE -ne 0) { + throw "pip install failed (exit code $LASTEXITCODE)" + } +} + +# Prefer the venv copy if it exists; otherwise use the global install. +$bin = $null +if ((-not (Test-Path $venvDir)) -and (-not $zutilGlobalVersion)) { + Bootstrap + if (-not (Test-Path $venvZutil)) { + throw "Bootstrap completed but $venvZutil not found." + } + $bin = $venvZutil +} +elseif (Test-Path $venvZutil) { + # Use the shim to check version -- running the exe directly fails on + # Windows because os.getuid/os.getgid are unavailable (see FIXME above). + $venvVersion = try { + & $venvPython -c $ShimCode --version 2>$null + } + catch { + $null + } + if ($venvVersion -ne "nanvix-zutil ${zutilVersion}") { + Write-Warning "Venv nanvix-zutil version mismatch. Expected ${zutilVersion}, found ${venvVersion}. Re-bootstrapping..." + Bootstrap + if (-not (Test-Path $venvZutil)) { + throw "Bootstrap completed but $venvZutil not found." + } + } + $bin = $venvZutil +} +elseif ((Test-Path $venvDir) -and (-not $zutilGlobalVersion)) { + Write-Warning "Incomplete venv detected (binary missing). Re-running bootstrap..." + Bootstrap + if (-not (Test-Path $venvZutil)) { + throw "Bootstrap completed but $venvZutil not found." + } + $bin = $venvZutil +} +else { + $bin = "nanvix-zutil" + if ($zutilGlobalVersion -ne "nanvix-zutil ${zutilVersion}") { + Write-Warning "nanvix-zutil global install does not match expected version. Expected ${zutilVersion}, found ${zutilGlobalVersion}." + } +} + +# Extract --with-nanvix PATH before forwarding to nanvix-zutil. +$filteredArgs = [System.Collections.Generic.List[string]]::new() +$i = 0 +while ($i -lt $ZArgs.Count) { + if ($ZArgs[$i] -eq '--with-nanvix') { + if ($i + 1 -ge $ZArgs.Count) { + throw "ERROR: --with-nanvix requires a path argument" + } + $item = Get-Item -LiteralPath $ZArgs[$i + 1] -ErrorAction Stop + if (-not $item.PSIsContainer) { + throw "ERROR: --with-nanvix path is not a directory: $($ZArgs[$i + 1])" + } + $env:WITH_NANVIX = $item.FullName + $i += 2 + } + elseif ($ZArgs[$i] -match '^--with-nanvix=(.+)$') { + $item = Get-Item -LiteralPath $Matches[1] -ErrorAction Stop + if (-not $item.PSIsContainer) { + throw "ERROR: --with-nanvix path is not a directory: $($Matches[1])" + } + $env:WITH_NANVIX = $item.FullName + $i++ + } + else { + $filteredArgs.Add($ZArgs[$i]) + $i++ + } +} + +$filteredArray = $filteredArgs.ToArray() + +if ($bin -eq $venvZutil) { + & $venvPython -c $ShimCode @filteredArray +} +else { + & $bin @filteredArray +} + +$ec = $LASTEXITCODE + +# On Windows the venv's python.exe is locked while it runs, so the Python +# distclean command cannot delete it. Now that the interpreter has exited the +# lock is released and the shell can safely remove the venv directory. +if ($filteredArray -and $filteredArray[0] -eq "distclean" -and (Test-Path $venvDir)) { + Remove-Item $venvDir -Recurse -Force -ErrorAction SilentlyContinue +} + +exit $ec diff --git a/z.sh b/z.sh index 2f094f3..12a998d 100755 --- a/z.sh +++ b/z.sh @@ -7,7 +7,7 @@ set -euo pipefail -PINNED_VERSION="0.8.2" +PINNED_VERSION="0.8.5" RAW_ZUTIL_VERSION="${NANVIX_ZUTIL_VERSION:-$PINNED_VERSION}" ZUTIL_VERSION="${RAW_ZUTIL_VERSION#v}" REPO_ROOT="$(cd -- "$(dirname -- "${BASH_SOURCE[0]}")" >/dev/null 2>&1 && pwd -P)"