From cb6a356287893d285d02a5c56e3d7c33573e4bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=ADtor=20Vasconcellos?= Date: Wed, 30 Aug 2023 00:26:13 -0300 Subject: [PATCH] [ENG-1027] Fix build on Windows (#1271) * Fix Vite relativeAliasResolver on Windows - Add Strawberry Perl installation to setup-system.ps1 (stop rust-analyzer from crashing on Windows) - Remove unused imports from desktop windows crate - Add todo for missing sync test match cases * Use path.join instead of doing string concatenation with path.sep by hand --- .github/scripts/setup-system.ps1 | 18 +++++++--- apps/desktop/crates/windows/src/lib.rs | 11 +++--- apps/desktop/vite.config.ts | 2 +- core/crates/sync/tests/lib.rs | 1 + packages/config/vite/relativeAliasResolver.ts | 36 ++++++++++++------- 5 files changed, 43 insertions(+), 25 deletions(-) diff --git a/.github/scripts/setup-system.ps1 b/.github/scripts/setup-system.ps1 index 7d2fc3dbb..3d228d410 100644 --- a/.github/scripts/setup-system.ps1 +++ b/.github/scripts/setup-system.ps1 @@ -147,10 +147,11 @@ To set up your machine for Spacedrive development, this script will do the follo 2) Install Edge Webview 2 3) Install Rust and Cargo 4) Install Rust tools -5) Install Node.js, npm and pnpm -6) Install LLVM $llvmVersion (compiler for ffmpeg-rust) -7) Download the protbuf compiler -8) Download a compatible ffmpeg build +5) Install Strawberry perl (used by to build the openssl-sys crate) +6) Install Node.js, npm and pnpm +7) Install LLVM $llvmVersion (compiler for ffmpeg-rust) +8) Download the protbuf compiler +9) Download a compatible ffmpeg build "@ # Install System dependencies (GitHub Actions already has all of those installed) @@ -214,7 +215,14 @@ https://learn.microsoft.com/windows/package-manager/winget/ $LASTEXITCODE = 0 } - # TODO: Install Strawberry perl, required by debug build of openssl-sys + Write-Host + Write-Host 'Installing Strawberry perl...' -ForegroundColor Yellow + winget install -e --accept-source-agreements --disable-interactivity --id StrawberryPerl.StrawberryPerl + if (-not ($wingetValidExit -contains $LASTEXITCODE)) { + Exit-WithError 'Failed to install Strawberry perl' + } else { + $LASTEXITCODE = 0 + } Write-Host Write-Host 'Installing NodeJS...' -ForegroundColor Yellow diff --git a/apps/desktop/crates/windows/src/lib.rs b/apps/desktop/crates/windows/src/lib.rs index cf11ea539..80e47f2ee 100644 --- a/apps/desktop/crates/windows/src/lib.rs +++ b/apps/desktop/crates/windows/src/lib.rs @@ -2,22 +2,21 @@ use std::{ ffi::{OsStr, OsString}, - os::windows::{ffi::OsStrExt, prelude::OsStringExt}, - path::{Path, PathBuf}, + os::windows::ffi::OsStrExt, + path::Path, }; use normpath::PathExt; use windows::{ - core::{GUID, HSTRING, PCWSTR}, + core::{HSTRING, PCWSTR}, Win32::{ - Foundation::HANDLE, System::Com::{ CoInitializeEx, CoUninitialize, IDataObject, COINIT_APARTMENTTHREADED, COINIT_DISABLE_OLE1DDE, }, UI::Shell::{ - BHID_DataObject, FOLDERID_Profile, IAssocHandler, IShellItem, SHAssocEnumHandlers, - SHCreateItemFromParsingName, SHGetKnownFolderPath, ASSOC_FILTER_RECOMMENDED, + BHID_DataObject, IAssocHandler, IShellItem, SHAssocEnumHandlers, + SHCreateItemFromParsingName, ASSOC_FILTER_RECOMMENDED, }, }, }; diff --git a/apps/desktop/vite.config.ts b/apps/desktop/vite.config.ts index 7eb893525..09c4a5502 100644 --- a/apps/desktop/vite.config.ts +++ b/apps/desktop/vite.config.ts @@ -20,5 +20,5 @@ export default mergeConfig(baseConfig, { server: { port: 8001 }, - plugins: [devtoolsPlugin], + plugins: [devtoolsPlugin] }); diff --git a/core/crates/sync/tests/lib.rs b/core/crates/sync/tests/lib.rs index 26ce3597e..a0ec1da10 100644 --- a/core/crates/sync/tests/lib.rs +++ b/core/crates/sync/tests/lib.rs @@ -156,6 +156,7 @@ async fn bruh() -> Result<(), Box> { ingest::Request::Ingested => { instance2.sync.tx.send(SyncMessage::Ingested).ok(); } + _ => todo!(), } } } diff --git a/packages/config/vite/relativeAliasResolver.ts b/packages/config/vite/relativeAliasResolver.ts index 2949bfcbd..15780cefc 100644 --- a/packages/config/vite/relativeAliasResolver.ts +++ b/packages/config/vite/relativeAliasResolver.ts @@ -5,31 +5,36 @@ import { Alias } from 'vite'; const projectPath = path.resolve(__dirname, '../../../'); const pkgJsonCache = new Map(); +// /src/ or \src\, depending on platform +const SRC_DIR_PATH = `${path.sep}src${path.sep}`; + const resolver: Alias = { find: /^(~\/.+)/, replacement: '$1', async customResolver(source, importer) { let root: null | string = null; + if (importer) importer = path.normalize(importer); + + // source is the path imported on typescript, which always use / as path separator const [_, sourcePath] = source.split('~/'); - const relativeImporter = importer!.replace(projectPath, ''); + const relativeImporter = importer?.replace(projectPath, ''); + if (relativeImporter && relativeImporter.includes(SRC_DIR_PATH)) { + const [pkg] = relativeImporter.split(SRC_DIR_PATH); + root = path.join(projectPath, pkg, 'src'); + } else if (importer) { + const pathObj = path.parse(importer); - if (relativeImporter.includes('/src/')) { - const [pkg] = relativeImporter.split('/src/'); - - root = `${projectPath}${pkg}/src`; - } else { - let parent = importer!; - - while (parent !== '/') { + let parent = pathObj.dir; + while (parent !== pathObj.root) { parent = path.dirname(parent); let hasPkgJson = pkgJsonCache.get(parent); if (hasPkgJson === undefined) try { - await fs.stat(`${parent}/package.json`); + await fs.stat(path.join(parent, 'package.json')); pkgJsonCache.set(parent, (hasPkgJson = true)); } catch { pkgJsonCache.set(parent, (hasPkgJson = false)); @@ -43,12 +48,15 @@ const resolver: Alias = { if (root === null) throw new Error(`Failed to resolve import path ${source} in file ${importer}`); + } else { + throw new Error(`Failed to resolve import path ${source} in file ${importer}`); } - const absolutePath = `${root}/${sourcePath}`; + const absolutePath = path.join(root, sourcePath); - const folderItems = await fs.readdir(path.join(absolutePath, '../')); + const folderItems = await fs.readdir(path.join(absolutePath, '..')); + // sourcePath is derived from the path imported on typescript, which always use / as path separator const item = folderItems.find((i) => i.startsWith(sourcePath.split('/').at(-1)!))!; const fullPath = absolutePath + path.extname(item); @@ -59,8 +67,10 @@ const resolver: Alias = { const directoryItems = await fs.readdir(absolutePath + path.extname(item)); const indexFile = directoryItems.find((i) => i.startsWith('index')); + if (!indexFile) + throw new Error(`Failed to resolve import path ${source} in file ${importer}`); - return `${absolutePath}/${indexFile}`; + return path.join(absolutePath, indexFile); } else { return fullPath; }