Merge pull request #321 from voletro/main

Rewrite of setup-system.ps1 for Windows development setup
This commit is contained in:
Oscar Beaumont authored and GitHub committed 2022-07-11 11:41:28 +08:00
commit bcdcacf0e5
4 files changed
+199 -20

No files matched your search

+180 -9
View File
@@ -1,10 +1,181 @@
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 ci parameter to check if running with ci
param(
[Parameter()]
[Switch]$ci
)
$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"
# Get temp folder
$temp = [System.IO.Path]::GetTempPath()
# Get current running dir
$currentLocation = $((Get-Location).path)
# 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 }
}
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 "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.
"@
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."
}
# A GitHub Action takes care of installing node, so this isn't necessary if running in the ci.
if ($ci -eq $True) {
Write-Host
Write-Host "Running with Ci, skipping Node install." -ForegroundColor Yellow
}
else {
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
}
# The ci has LLVM installed already, so we instead just set the env variables.
if ($ci -eq $True) {
Write-Host
Write-Host "Running with Ci, skipping LLVM install." -ForegroundColor Yellow
$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"
} else {
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
if ($ci -eq $True) {
# If running in ci, we need to use GITHUB_ENV and GITHUB_PATH instead of the normal PATH env variables, so we set them here
Add-Content $env:GITHUB_ENV "FFMPEG_DIR=$HOME\$foldername`n"
Add-Content $env:GITHUB_PATH "$HOME\$foldername\bin`n"
}
else {
# 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!"
+10 -10
View File
@@ -36,7 +36,7 @@ jobs:
id: pnpm-cache
run: |
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
- uses: actions/cache@v3
name: Setup pnpm cache
with:
@@ -44,7 +44,7 @@ jobs:
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-pnpm-store-
- name: Install pnpm dependencies
run: pnpm --frozen-lockfile i
@@ -81,7 +81,7 @@ jobs:
with:
version: 7
run_install: false
- name: Install Rust stable
uses: actions-rs/toolchain@v1
with:
@@ -89,7 +89,7 @@ jobs:
profile: minimal
override: true
components: rustfmt, rust-src
- name: Cache Rust Dependencies
uses: Swatinem/rust-cache@v1
with:
@@ -98,10 +98,10 @@ jobs:
- name: Run 'setup-system.sh' script
if: matrix.platform == 'ubuntu-latest' || matrix.platform == 'macos-latest'
run: ./.github/scripts/setup-system.sh
- name: Run 'setup-system.ps1' script
if: matrix.platform == 'windows-latest'
run: ./.github/scripts/setup-system.ps1
run: ./.github/scripts/setup-system.ps1 -ci
- name: Get pnpm store directory
id: pnpm-cache
@@ -116,7 +116,7 @@ jobs:
${{ runner.os }}-pnpm-store-
- name: Install pnpm dependencies
run: pnpm --frozen-lockfile i
- name: Cache Prisma codegen
id: cache-prisma
uses: actions/cache@v3
@@ -127,13 +127,13 @@ jobs:
- name: Generate Prisma client
working-directory: core
if: steps.cache-prisma.outputs.cache-hit != 'true'
run: cargo run --frozen -p prisma-cli --release -- generate
run: cargo run -p prisma-cli --release -- generate
- name: Cargo fetch
run: cargo fetch
- name: Check Core
run: cargo check --frozen -p sdcore --release
run: cargo check -p sdcore --release
- name: Bundle Desktop
run: pnpm desktop tauri build
@@ -141,7 +141,7 @@ jobs:
- name: Build Server
if: matrix.platform == 'ubuntu-latest'
run: |
cargo build --frozen -p server --release
cargo build -p server --release
cp ./target/release/server ./apps/server/server
- name: Determine image name & tag
+2
View File
@@ -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.
+7 -1
View File
@@ -15,7 +15,13 @@
"active": true,
"targets": "all",
"identifier": "com.spacedrive.desktop",
"icon": ["icons/icon.icns"],
"icon": [
"icons/32x32.png",
"icons/128x128.png",
"icons/128x128@2x.png",
"icons/icon.icns",
"icons/icon.ico"
],
"resources": [],
"externalBin": [],
"copyright": "Spacedrive Technology Inc.",