diff --git a/.github/scripts/setup-system.ps1 b/.github/scripts/setup-system.ps1 index 9a8a206b5..786cdd824 100644 --- a/.github/scripts/setup-system.ps1 +++ b/.github/scripts/setup-system.ps1 @@ -1,10 +1,160 @@ -Write-Host "This script is currently being used by CI and will need some more work before anyone can use it like the 'setup-system.sh' script for macOS and Linux!" +# Get temp folder +$temp = [System.IO.Path]::GetTempPath() -$VCINSTALLDIR = $(& "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath) -Add-Content $env:GITHUB_ENV "LIBCLANG_PATH=${VCINSTALLDIR}\VC\Tools\LLVM\x64\bin`n" -Invoke-WebRequest "https://www.gyan.dev/ffmpeg/builds/ffmpeg-release-full-shared.7z" -OutFile ffmpeg-release-full-shared.7z -7z x ffmpeg-release-full-shared.7z -mkdir ffmpeg -mv ffmpeg-*/* ffmpeg/ -Add-Content $env:GITHUB_ENV "FFMPEG_DIR=${pwd}\ffmpeg`n" -Add-Content $env:GITHUB_PATH "${pwd}\ffmpeg\bin`n" \ No newline at end of file +# Get current running dir +$currentLocation = $((Get-Location).path) + +$Host.UI.RawUI.WindowTitle = "Spacedrive DE Setup (Administrator)" +$Host.UI.RawUI.BackgroundColor = "Black" + +# Check to see if a command exists (eg if an app is installed) +Function CheckCommand { + + Param ($command) + + $oldPreference = $ErrorActionPreference + + $ErrorActionPreference = 'stop' + + try { if (Get-Command $command) { RETURN $true } } + + Catch { RETURN $false } + + Finally { $ErrorActionPreference = $oldPreference } + +} + +Clear-Host + +Write-Host "Spacedrive Development Environment Setup" -ForegroundColor Magenta +Write-Host @" + +To set up your machine for Spacedrive development, this script will do the following: + +1) Check for Rust and Cargo + +2) Install pnpm (if not installed) + +3) Install the latest version of Node.js using pnpm + +4) Install LLVM (compiler for ffmpeg-rust) + +4) Download ffmpeg and set as an environment variable + +"@ + +Write-Host "Press the Enter key to begin, or press CTRL + C to stop." -ForegroundColor Gray + +Read-Host + +Write-Host "Checking for Rust and Cargo..." -ForegroundColor Yellow +Start-Sleep -Milliseconds 150 + +$cargoCheck = CheckCommand cargo + +if ($cargoCheck -eq $false) { + Write-Host @" +Cargo is not installed. + +To use Spacedrive on Windows, Cargo needs to be installed. +The Visual Studio C++ Build tools are also required. +Instructions can be found here: + +https://tauri.app/v1/guides/getting-started/prerequisites/#setting-up-windows + +Once you have installed Cargo, re-run this script. + +"@ + Write-Host "Press the Enter key to close." -ForegroundColor Gray + Read-Host + Exit +} +else { + Write-Host "Cargo is installed." +} + +Write-Host +Write-Host "Checking for pnpm..." -ForegroundColor Yellow +Start-Sleep -Milliseconds 150 + +$pnpmCheck = CheckCommand pnpm +if ($pnpmCheck -eq $false) { + + Write-Host "pnpm is not installed. Installing now." + Write-Host "Running the pnpm installer..." + + #pnpm installer taken from https://pnpm.io + Invoke-WebRequest https://get.pnpm.io/install.ps1 -useb | Invoke-Expression + + # Reset the PATH env variables to make sure pnpm is accessible + $env:PNPM_HOME = [System.Environment]::GetEnvironmentVariable("PNPM_HOME", "User") + $env:Path = [System.Environment]::ExpandEnvironmentVariables([System.Environment]::GetEnvironmentVariable("Path", "User")) + +} +else { + Write-Host "pnpm is installed." +} + +Write-Host +Write-Host "Using pnpm to install the latest version of Node..." -ForegroundColor Yellow +Write-Host "This will set your global Node version to the latest!" +Start-Sleep -Milliseconds 150 + +# Runs the pnpm command to use the latest version of node, which also installs it +Start-Process -Wait -FilePath "pnpm" -ArgumentList "env use --global latest" -PassThru -Verb runAs + +Write-Host +Write-Host "Downloading the LLVM installer..." -ForegroundColor Yellow +# Downloads latest installer for LLVM +$filenamePattern = "*-win64.exe" +$releasesUri = "https://api.github.com/repos/llvm/llvm-project/releases/latest" +$downloadUri = ((Invoke-RestMethod -Method GET -Uri $releasesUri).assets | Where-Object name -like $filenamePattern ).browser_download_url + +Start-BitsTransfer -Source $downloadUri -Destination "$temp\llvm.exe" + +Write-Host +Write-Host "Running the LLVM installer..." -ForegroundColor Yellow +Write-Host "Please follow the instructions to install LLVM." +Write-Host "Ensure you add LLVM to your PATH." + +Start-Process "$temp\llvm.exe" -Wait + +Write-Host +Write-Host "Downloading the latest ffmpeg build..." -ForegroundColor Yellow + +# Downloads the latest shared build of ffmpeg from GitHub +$filenamePattern = "*-full_build-shared.zip" +$releasesUri = "https://api.github.com/repos/GyanD/codexffmpeg/releases/latest" +$downloadUri = ((Invoke-RestMethod -Method GET -Uri $releasesUri).assets | Where-Object name -like $filenamePattern ).browser_download_url +$filename = ((Invoke-RestMethod -Method GET -Uri $releasesUri).assets | Where-Object name -like $filenamePattern ).name +$remove = ".zip" +$foldername = $filename.Substring(0, ($filename.Length - $remove.Length)) + +Start-BitsTransfer -Source $downloadUri -Destination "$temp\ffmpeg.zip" + +Write-Host +Write-Host "Expanding ffmpeg zip..." -ForegroundColor Yellow + +Expand-Archive "$temp\ffmpeg.zip" $HOME -ErrorAction SilentlyContinue + +Remove-Item "$temp\ffmpeg.zip" + +Write-Host +Write-Host "Setting environment variables..." -ForegroundColor Yellow + +# Sets environment variable for ffmpeg +[System.Environment]::SetEnvironmentVariable('FFMPEG_DIR', "$HOME\$foldername", [System.EnvironmentVariableTarget]::User) + +Write-Host +Write-Host "Copying Required .dll files..." -ForegroundColor Yellow + +# Create target\debug folder, continue if already exists +New-Item -Path $currentLocation\target\debug -ItemType Directory -ErrorAction SilentlyContinue + +# Copies all .dll required for rust-ffmpeg to target\debug folder +Get-ChildItem "$HOME\$foldername\bin" -recurse -filter *.dll | Copy-Item -Destination "$currentLocation\target\debug" + +Write-Host +Write-Host "Your machine has been setup for Spacedrive development!" +Write-Host "Press the Enter key to close." -ForegroundColor Gray +Read-Host \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 942c66d63..7c7f383f2 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -41,6 +41,8 @@ This project uses [Cargo](https://doc.rust-lang.org/cargo/getting-started/instal - `$ cd spacedrive` - For Linux or MacOS users run: `./.github/scripts/setup-system.sh` - This will install FFMPEG and any other required dependencies for Spacedrive to build. +- For Windows users run using PowerShell: `.\.github\scripts\setup-system.ps1` + - This will install pnpm, LLVM, FFMPEG and any other required dependencies for Spacedrive to build. - `$ pnpm i` - `$ pnpm prep` - Runs all necessary codegen & builds required dependencies.