Skip to content

Commit

Permalink
fixup! feature: add ensure node libraries installed on PC
Browse files Browse the repository at this point in the history
  • Loading branch information
maparr committed Sep 20, 2023
1 parent bd4f8b1 commit 5007ccd
Showing 1 changed file with 65 additions and 22 deletions.
87 changes: 65 additions & 22 deletions desktop/checkRequiredLibs.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import { promisify } from 'util';
import { exec as execCallback } from 'child_process';
import path from 'path';
import fs from 'fs';
import { ipcConsts } from '../app/vars';
import { NodeError, NodeErrorLevel, NodeErrorType } from '../shared/types';
import Logger from './logger';
Expand All @@ -8,6 +10,7 @@ import { isLinux, isWindows } from './osSystem';
const logger = Logger({ className: 'getNodeRequiredLibs' });

const exec = promisify(execCallback);
const access = promisify(fs.access);

const generateInstallationError = (packageName, type): NodeError => ({
msg: `Oops! It looks like ${packageName} is missing or not set up on your system. Our application requires ${packageName} support to run properly.\n`,
Expand All @@ -33,36 +36,76 @@ const checkVisualCppRedist = async () => {
}
};

const checkWindowsOpenCLDll = async () => {
const command = 'clinfo -f';
async function checkLibrary(libraryName, directory) {
const libraryPath = path.join(directory, libraryName);

try {
const { stdout, stderr } = await exec(command);
logger.error(ipcConsts.NODE_INSTALLED_LIBRARIES, command, stdout);
logger.error(ipcConsts.NODE_INSTALLED_LIBRARIES, command, stderr);

return Boolean(!stderr && stdout && stdout.trim() !== '');
} catch (error: any) {
logger.error(ipcConsts.NODE_INSTALLED_LIBRARIES, command, error);

await access(libraryPath);
return true;
} catch (error) {
logger.error(ipcConsts.NODE_INSTALLED_LIBRARIES, libraryPath, error);
return false;
}
}
const checkWindowsOpenCLDll = async () => {
// List of common OpenCL library names on Windows
const openCLLibrariesWindows = [
'OpenCL.dll', // Windows common library name
'amdocl.dll', // For AMD GPUs on Windows
'amdocl64.dll', // For AMD GPUs on Windows 64-bit
'IntelOpenCL.dll', // For Intel GPUs on Windows
'IntelOpenCL64.dll', // For Intel GPUs on Windows 64-bit
'nvcuda.dll', // For NVIDIA GPUs on Windows (CUDA)
];

// Common system directories on Windows
const systemDirectories = ['C:\\Windows\\System32', 'C:\\Windows\\SysWow64'];

// eslint-disable-next-line no-restricted-syntax
for (const library of openCLLibrariesWindows) {
// eslint-disable-next-line no-restricted-syntax
for (const directory of systemDirectories) {
// eslint-disable-next-line no-await-in-loop
if (await checkLibrary(library, directory)) {
return true; // Library found
}
}
}

return false;
};

const checkUbuntuOpenCLLibrary = async (): Promise<boolean> => {
const command = 'ldconfig -v 2>&1 | grep libOpenCL.so';

try {
const { stdout, stderr } = await exec(command);
logger.error(ipcConsts.NODE_INSTALLED_LIBRARIES, command, stdout);
logger.error(ipcConsts.NODE_INSTALLED_LIBRARIES, command, stderr);

return Boolean(!stderr && stdout && stdout.trim() !== '');
} catch (error: any) {
logger.error(ipcConsts.NODE_INSTALLED_LIBRARIES, command, error);

return false;
const openCLLibrariesLinux = [
'libOpenCL.so', // Linux common library name
'libOpenCL.so.1', // Linux common library name with version
'libamdocl64.so', // For AMD GPUs on Linux 64-bit
'libIntelOpenCL.so', // For Intel GPUs on Linux
'libnvidia-opencl.so', // For NVIDIA GPUs on Linux
];

const searchCommands = openCLLibrariesLinux.map(
(libraryName) => `ldconfig -v 2>&1 | grep ${libraryName}`
);

// eslint-disable-next-line no-restricted-syntax
for (const searchCommand of searchCommands) {
try {
// eslint-disable-next-line no-await-in-loop
const { stdout, stderr } = await exec(searchCommand);

logger.error(ipcConsts.NODE_INSTALLED_LIBRARIES, searchCommand, stderr);
logger.error(ipcConsts.NODE_INSTALLED_LIBRARIES, searchCommand, stdout);

if (!stderr && stdout) {
return true; // Library found
}
} catch (error) {
// Error occurred, continue searching
}
}

return false; // Library not found
};

type RequiredLibraries = {
Expand Down

0 comments on commit 5007ccd

Please sign in to comment.