docs: add quixzoom-auth-core product to AAMOS
- Product documentation in docs/products/ - Updated MEMORY.md with product info - quiXzoom Auth Core as AAMOS Identity product
This commit is contained in:
+158
@@ -0,0 +1,158 @@
|
||||
"use strict";
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
var __importDefault = (this && this.__importDefault) || function (mod) {
|
||||
return (mod && mod.__esModule) ? mod : { "default": mod };
|
||||
};
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const child_process_1 = require("child_process");
|
||||
const fs = __importStar(require("fs-extra"));
|
||||
const minimist_1 = __importDefault(require("minimist"));
|
||||
const os = __importStar(require("os"));
|
||||
const path = __importStar(require("path"));
|
||||
// command line flags
|
||||
const buildArgs = (0, minimist_1.default)(process.argv.slice(2));
|
||||
// --config=Debug|Release|RelWithDebInfo
|
||||
const CONFIG = buildArgs.config || (os.platform() === 'win32' ? 'RelWithDebInfo' : 'Release');
|
||||
if (CONFIG !== 'Debug' && CONFIG !== 'Release' && CONFIG !== 'RelWithDebInfo') {
|
||||
throw new Error(`unrecognized config: ${CONFIG}`);
|
||||
}
|
||||
// --arch=x64|ia32|arm64|arm
|
||||
const ARCH = buildArgs.arch || os.arch();
|
||||
if (ARCH !== 'x64' && ARCH !== 'ia32' && ARCH !== 'arm64' && ARCH !== 'arm') {
|
||||
throw new Error(`unrecognized architecture: ${ARCH}`);
|
||||
}
|
||||
// --onnxruntime-build-dir=
|
||||
const ONNXRUNTIME_BUILD_DIR = buildArgs['onnxruntime-build-dir'];
|
||||
// --onnxruntime-generator=
|
||||
const ONNXRUNTIME_GENERATOR = buildArgs['onnxruntime-generator'];
|
||||
// --rebuild
|
||||
const REBUILD = !!buildArgs.rebuild;
|
||||
// --use_dml
|
||||
const USE_DML = !!buildArgs.use_dml;
|
||||
// --use_webgpu
|
||||
const USE_WEBGPU = !!buildArgs.use_webgpu;
|
||||
// --use_cuda
|
||||
const USE_CUDA = !!buildArgs.use_cuda;
|
||||
// --use_tensorrt
|
||||
const USE_TENSORRT = !!buildArgs.use_tensorrt;
|
||||
// --use_coreml
|
||||
const USE_COREML = !!buildArgs.use_coreml;
|
||||
// --use_qnn
|
||||
const USE_QNN = !!buildArgs.use_qnn;
|
||||
// --dll_deps=
|
||||
const DLL_DEPS = buildArgs.dll_deps;
|
||||
// build path
|
||||
const ROOT_FOLDER = path.join(__dirname, '..');
|
||||
const BIN_FOLDER = path.join(ROOT_FOLDER, 'bin');
|
||||
const BUILD_FOLDER = path.join(ROOT_FOLDER, 'build');
|
||||
// if rebuild, clean up the dist folders
|
||||
if (REBUILD) {
|
||||
fs.removeSync(BIN_FOLDER);
|
||||
fs.removeSync(BUILD_FOLDER);
|
||||
}
|
||||
const args = [
|
||||
'cmake-js',
|
||||
REBUILD ? 'reconfigure' : 'configure',
|
||||
`--arch=${ARCH}`,
|
||||
'--CDnapi_build_version=6',
|
||||
`--CDCMAKE_BUILD_TYPE=${CONFIG}`,
|
||||
];
|
||||
if (ONNXRUNTIME_BUILD_DIR && typeof ONNXRUNTIME_BUILD_DIR === 'string') {
|
||||
args.push(`--CDONNXRUNTIME_BUILD_DIR=${ONNXRUNTIME_BUILD_DIR}`);
|
||||
}
|
||||
if (ONNXRUNTIME_GENERATOR && typeof ONNXRUNTIME_GENERATOR === 'string') {
|
||||
args.push(`--CDONNXRUNTIME_GENERATOR=${ONNXRUNTIME_GENERATOR}`);
|
||||
}
|
||||
if (USE_DML) {
|
||||
args.push('--CDUSE_DML=ON');
|
||||
}
|
||||
if (USE_WEBGPU) {
|
||||
args.push('--CDUSE_WEBGPU=ON');
|
||||
}
|
||||
if (USE_CUDA) {
|
||||
args.push('--CDUSE_CUDA=ON');
|
||||
}
|
||||
if (USE_TENSORRT) {
|
||||
args.push('--CDUSE_TENSORRT=ON');
|
||||
}
|
||||
if (USE_COREML) {
|
||||
args.push('--CDUSE_COREML=ON');
|
||||
}
|
||||
if (USE_QNN) {
|
||||
args.push('--CDUSE_QNN=ON');
|
||||
}
|
||||
if (DLL_DEPS) {
|
||||
args.push(`--CDORT_NODEJS_DLL_DEPS=${DLL_DEPS}`);
|
||||
}
|
||||
// set CMAKE_OSX_ARCHITECTURES for macOS build
|
||||
if (os.platform() === 'darwin') {
|
||||
if (ARCH === 'x64') {
|
||||
args.push('--CDCMAKE_OSX_ARCHITECTURES=x86_64');
|
||||
}
|
||||
else if (ARCH === 'arm64') {
|
||||
args.push('--CDCMAKE_OSX_ARCHITECTURES=arm64');
|
||||
}
|
||||
else {
|
||||
throw new Error(`architecture not supported for macOS build: ${ARCH}`);
|
||||
}
|
||||
}
|
||||
// In Windows, "npx cmake-js configure" uses a powershell script to detect the Visual Studio installation.
|
||||
// The script uses the environment variable LIB. If an invalid path is specified in LIB, the script will fail.
|
||||
// So we override the LIB environment variable to remove invalid paths.
|
||||
const envOverride = os.platform() === 'win32' && process.env.LIB
|
||||
? { ...process.env, LIB: process.env.LIB.split(';').filter(fs.existsSync).join(';') }
|
||||
: process.env;
|
||||
// launch cmake-js configure
|
||||
const procCmakejs = (0, child_process_1.spawnSync)('npx', args, { shell: true, stdio: 'inherit', cwd: ROOT_FOLDER, env: envOverride });
|
||||
if (procCmakejs.status !== 0) {
|
||||
if (procCmakejs.error) {
|
||||
console.error(procCmakejs.error);
|
||||
}
|
||||
process.exit(procCmakejs.status === null ? undefined : procCmakejs.status);
|
||||
}
|
||||
// launch cmake to build
|
||||
const procCmake = (0, child_process_1.spawnSync)('cmake', ['--build', '.', '--config', CONFIG], {
|
||||
shell: true,
|
||||
stdio: 'inherit',
|
||||
cwd: BUILD_FOLDER,
|
||||
});
|
||||
if (procCmake.status !== 0) {
|
||||
if (procCmake.error) {
|
||||
console.error(procCmake.error);
|
||||
}
|
||||
process.exit(procCmake.status === null ? undefined : procCmake.status);
|
||||
}
|
||||
+130
@@ -0,0 +1,130 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import { spawnSync } from 'child_process';
|
||||
import * as fs from 'fs-extra';
|
||||
import minimist from 'minimist';
|
||||
import * as os from 'os';
|
||||
import * as path from 'path';
|
||||
|
||||
// command line flags
|
||||
const buildArgs = minimist(process.argv.slice(2));
|
||||
|
||||
// --config=Debug|Release|RelWithDebInfo
|
||||
const CONFIG: 'Debug' | 'Release' | 'RelWithDebInfo' =
|
||||
buildArgs.config || (os.platform() === 'win32' ? 'RelWithDebInfo' : 'Release');
|
||||
if (CONFIG !== 'Debug' && CONFIG !== 'Release' && CONFIG !== 'RelWithDebInfo') {
|
||||
throw new Error(`unrecognized config: ${CONFIG}`);
|
||||
}
|
||||
// --arch=x64|ia32|arm64|arm
|
||||
const ARCH: 'x64' | 'ia32' | 'arm64' | 'arm' = buildArgs.arch || os.arch();
|
||||
if (ARCH !== 'x64' && ARCH !== 'ia32' && ARCH !== 'arm64' && ARCH !== 'arm') {
|
||||
throw new Error(`unrecognized architecture: ${ARCH}`);
|
||||
}
|
||||
// --onnxruntime-build-dir=
|
||||
const ONNXRUNTIME_BUILD_DIR = buildArgs['onnxruntime-build-dir'];
|
||||
// --onnxruntime-generator=
|
||||
const ONNXRUNTIME_GENERATOR = buildArgs['onnxruntime-generator'];
|
||||
// --rebuild
|
||||
const REBUILD = !!buildArgs.rebuild;
|
||||
// --use_dml
|
||||
const USE_DML = !!buildArgs.use_dml;
|
||||
// --use_webgpu
|
||||
const USE_WEBGPU = !!buildArgs.use_webgpu;
|
||||
// --use_cuda
|
||||
const USE_CUDA = !!buildArgs.use_cuda;
|
||||
// --use_tensorrt
|
||||
const USE_TENSORRT = !!buildArgs.use_tensorrt;
|
||||
// --use_coreml
|
||||
const USE_COREML = !!buildArgs.use_coreml;
|
||||
// --use_qnn
|
||||
const USE_QNN = !!buildArgs.use_qnn;
|
||||
// --dll_deps=
|
||||
const DLL_DEPS = buildArgs.dll_deps;
|
||||
|
||||
// build path
|
||||
const ROOT_FOLDER = path.join(__dirname, '..');
|
||||
const BIN_FOLDER = path.join(ROOT_FOLDER, 'bin');
|
||||
const BUILD_FOLDER = path.join(ROOT_FOLDER, 'build');
|
||||
|
||||
// if rebuild, clean up the dist folders
|
||||
if (REBUILD) {
|
||||
fs.removeSync(BIN_FOLDER);
|
||||
fs.removeSync(BUILD_FOLDER);
|
||||
}
|
||||
|
||||
const args = [
|
||||
'cmake-js',
|
||||
REBUILD ? 'reconfigure' : 'configure',
|
||||
`--arch=${ARCH}`,
|
||||
'--CDnapi_build_version=6',
|
||||
`--CDCMAKE_BUILD_TYPE=${CONFIG}`,
|
||||
];
|
||||
if (ONNXRUNTIME_BUILD_DIR && typeof ONNXRUNTIME_BUILD_DIR === 'string') {
|
||||
args.push(`--CDONNXRUNTIME_BUILD_DIR=${ONNXRUNTIME_BUILD_DIR}`);
|
||||
}
|
||||
if (ONNXRUNTIME_GENERATOR && typeof ONNXRUNTIME_GENERATOR === 'string') {
|
||||
args.push(`--CDONNXRUNTIME_GENERATOR=${ONNXRUNTIME_GENERATOR}`);
|
||||
}
|
||||
if (USE_DML) {
|
||||
args.push('--CDUSE_DML=ON');
|
||||
}
|
||||
if (USE_WEBGPU) {
|
||||
args.push('--CDUSE_WEBGPU=ON');
|
||||
}
|
||||
if (USE_CUDA) {
|
||||
args.push('--CDUSE_CUDA=ON');
|
||||
}
|
||||
if (USE_TENSORRT) {
|
||||
args.push('--CDUSE_TENSORRT=ON');
|
||||
}
|
||||
if (USE_COREML) {
|
||||
args.push('--CDUSE_COREML=ON');
|
||||
}
|
||||
if (USE_QNN) {
|
||||
args.push('--CDUSE_QNN=ON');
|
||||
}
|
||||
if (DLL_DEPS) {
|
||||
args.push(`--CDORT_NODEJS_DLL_DEPS=${DLL_DEPS}`);
|
||||
}
|
||||
|
||||
// set CMAKE_OSX_ARCHITECTURES for macOS build
|
||||
if (os.platform() === 'darwin') {
|
||||
if (ARCH === 'x64') {
|
||||
args.push('--CDCMAKE_OSX_ARCHITECTURES=x86_64');
|
||||
} else if (ARCH === 'arm64') {
|
||||
args.push('--CDCMAKE_OSX_ARCHITECTURES=arm64');
|
||||
} else {
|
||||
throw new Error(`architecture not supported for macOS build: ${ARCH}`);
|
||||
}
|
||||
}
|
||||
|
||||
// In Windows, "npx cmake-js configure" uses a powershell script to detect the Visual Studio installation.
|
||||
// The script uses the environment variable LIB. If an invalid path is specified in LIB, the script will fail.
|
||||
// So we override the LIB environment variable to remove invalid paths.
|
||||
const envOverride =
|
||||
os.platform() === 'win32' && process.env.LIB
|
||||
? { ...process.env, LIB: process.env.LIB.split(';').filter(fs.existsSync).join(';') }
|
||||
: process.env;
|
||||
|
||||
// launch cmake-js configure
|
||||
const procCmakejs = spawnSync('npx', args, { shell: true, stdio: 'inherit', cwd: ROOT_FOLDER, env: envOverride });
|
||||
if (procCmakejs.status !== 0) {
|
||||
if (procCmakejs.error) {
|
||||
console.error(procCmakejs.error);
|
||||
}
|
||||
process.exit(procCmakejs.status === null ? undefined : procCmakejs.status);
|
||||
}
|
||||
|
||||
// launch cmake to build
|
||||
const procCmake = spawnSync('cmake', ['--build', '.', '--config', CONFIG], {
|
||||
shell: true,
|
||||
stdio: 'inherit',
|
||||
cwd: BUILD_FOLDER,
|
||||
});
|
||||
if (procCmake.status !== 0) {
|
||||
if (procCmake.error) {
|
||||
console.error(procCmake.error);
|
||||
}
|
||||
process.exit(procCmake.status === null ? undefined : procCmake.status);
|
||||
}
|
||||
+7
@@ -0,0 +1,7 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
// This file is generated by /js/scripts/update-version.ts
|
||||
// Do not modify file content manually.
|
||||
|
||||
module.exports = { nuget: [{ feed: 'nuget', version: '1.27.0' }] };
|
||||
+58
@@ -0,0 +1,58 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
'use strict';
|
||||
|
||||
const metadataVersions = require('./install-metadata-versions.js');
|
||||
|
||||
const metadata = {
|
||||
// Requirements defines a list of manifest to install for a specific platform/architecture combination.
|
||||
requirements: {
|
||||
'win32/x64': [],
|
||||
'win32/arm64': [],
|
||||
'linux/x64': ['cuda12'],
|
||||
'linux/arm64': [],
|
||||
'darwin/x64': [],
|
||||
'darwin/arm64': [],
|
||||
},
|
||||
// Each manifest defines a list of files to install
|
||||
manifests: {
|
||||
'linux/x64:cuda12': {
|
||||
'./libonnxruntime_providers_cuda.so': {
|
||||
package: 'nuget:linux/x64:cuda12',
|
||||
path: 'runtimes/linux-x64/native/libonnxruntime_providers_cuda.so',
|
||||
},
|
||||
'./libonnxruntime_providers_shared.so': {
|
||||
package: 'nuget:linux/x64:cuda12',
|
||||
path: 'runtimes/linux-x64/native/libonnxruntime_providers_shared.so',
|
||||
},
|
||||
'./libonnxruntime_providers_tensorrt.so': {
|
||||
package: 'nuget:linux/x64:cuda12',
|
||||
path: 'runtimes/linux-x64/native/libonnxruntime_providers_tensorrt.so',
|
||||
},
|
||||
},
|
||||
},
|
||||
// Each package defines a list of package metadata. The first available package will be used.
|
||||
packages: {
|
||||
'nuget:win32/x64:cuda12': {
|
||||
name: 'Microsoft.ML.OnnxRuntime.Gpu.Windows',
|
||||
versions: metadataVersions.nuget,
|
||||
},
|
||||
'nuget:linux/x64:cuda12': {
|
||||
name: 'Microsoft.ML.OnnxRuntime.Gpu.Linux',
|
||||
versions: metadataVersions.nuget,
|
||||
},
|
||||
},
|
||||
feeds: {
|
||||
nuget: {
|
||||
type: 'nuget',
|
||||
index: 'https://api.nuget.org/v3/index.json',
|
||||
},
|
||||
nuget_nightly: {
|
||||
type: 'nuget',
|
||||
index: 'https://aiinfra.pkgs.visualstudio.com/PublicPackages/_packaging/ORT-Nightly/nuget/v3/index.json',
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
module.exports = metadata;
|
||||
+306
@@ -0,0 +1,306 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
'use strict';
|
||||
|
||||
const fs = require('fs');
|
||||
const https = require('https');
|
||||
const { execFileSync } = require('child_process');
|
||||
const path = require('path');
|
||||
const os = require('os');
|
||||
const AdmZip = require('adm-zip'); // Use adm-zip instead of spawn
|
||||
|
||||
async function downloadFile(url, dest) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const file = fs.createWriteStream(dest);
|
||||
https
|
||||
.get(url, (res) => {
|
||||
if (res.statusCode !== 200) {
|
||||
file.close();
|
||||
fs.unlinkSync(dest);
|
||||
reject(new Error(`Failed to download from ${url}. HTTP status code = ${res.statusCode}`));
|
||||
return;
|
||||
}
|
||||
|
||||
res.pipe(file);
|
||||
file.on('finish', () => {
|
||||
file.close();
|
||||
resolve();
|
||||
});
|
||||
file.on('error', (err) => {
|
||||
fs.unlinkSync(dest);
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.on('error', (err) => {
|
||||
fs.unlinkSync(dest);
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function downloadJson(url) {
|
||||
return new Promise((resolve, reject) => {
|
||||
https
|
||||
.get(url, (res) => {
|
||||
const { statusCode } = res;
|
||||
const contentType = res.headers['content-type'];
|
||||
|
||||
if (!statusCode) {
|
||||
reject(new Error('No response statud code from server.'));
|
||||
return;
|
||||
}
|
||||
if (statusCode >= 400 && statusCode < 500) {
|
||||
resolve(null);
|
||||
return;
|
||||
} else if (statusCode !== 200) {
|
||||
reject(new Error(`Failed to download build list. HTTP status code = ${statusCode}`));
|
||||
return;
|
||||
}
|
||||
if (!contentType || !/^application\/json/.test(contentType)) {
|
||||
reject(new Error(`unexpected content type: ${contentType}`));
|
||||
return;
|
||||
}
|
||||
res.setEncoding('utf8');
|
||||
let rawData = '';
|
||||
res.on('data', (chunk) => {
|
||||
rawData += chunk;
|
||||
});
|
||||
res.on('end', () => {
|
||||
try {
|
||||
resolve(JSON.parse(rawData));
|
||||
} catch (e) {
|
||||
reject(e);
|
||||
}
|
||||
});
|
||||
res.on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
})
|
||||
.on('error', (err) => {
|
||||
reject(err);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
async function installPackages(packages, manifests, feeds) {
|
||||
// Step.1: resolve packages
|
||||
const resolvedPackages = new Map();
|
||||
for (const packageCandidates of packages) {
|
||||
// iterate all candidates from packagesInfo and try to find the first one that exists
|
||||
for (const { feed, version } of packageCandidates.versions) {
|
||||
const { type, index } = feeds[feed];
|
||||
const pkg = await resolvePackage(type, index, packageCandidates.name, version);
|
||||
if (pkg) {
|
||||
resolvedPackages.set(packageCandidates, pkg);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!resolvedPackages.has(packageCandidates)) {
|
||||
throw new Error(`Failed to resolve package. No package exists for: ${JSON.stringify(packageCandidates)}`);
|
||||
}
|
||||
}
|
||||
|
||||
// Step.2: download packages
|
||||
for (const [pkgInfo, pkg] of resolvedPackages) {
|
||||
const manifestsForPackage = manifests.filter((x) => x.packagesInfo === pkgInfo);
|
||||
await pkg.download(manifestsForPackage);
|
||||
}
|
||||
}
|
||||
|
||||
async function resolvePackage(type, index, packageName, version) {
|
||||
// https://learn.microsoft.com/en-us/nuget/api/overview
|
||||
const nugetPackageUrlResolver = async (index, packageName, version) => {
|
||||
// STEP.1 - get Nuget package index
|
||||
const nugetIndex = await downloadJson(index);
|
||||
if (!nugetIndex) {
|
||||
throw new Error(`Failed to download Nuget index from ${index}`);
|
||||
}
|
||||
|
||||
// STEP.2 - get the base url of "PackageBaseAddress/3.0.0"
|
||||
const packageBaseUrl = nugetIndex.resources.find((x) => x['@type'] === 'PackageBaseAddress/3.0.0')?.['@id'];
|
||||
if (!packageBaseUrl) {
|
||||
throw new Error(`Failed to find PackageBaseAddress in Nuget index`);
|
||||
}
|
||||
|
||||
// STEP.3 - get the package version info
|
||||
const packageInfo = await downloadJson(`${packageBaseUrl}${packageName.toLowerCase()}/index.json`);
|
||||
if (!packageInfo.versions.includes(version.toLowerCase())) {
|
||||
throw new Error(`Failed to find specific package versions for ${packageName} in ${index}`);
|
||||
}
|
||||
|
||||
// STEP.4 - generate the package URL
|
||||
const packageUrl = `${packageBaseUrl}${packageName.toLowerCase()}/${version.toLowerCase()}/${packageName.toLowerCase()}.${version.toLowerCase()}.nupkg`;
|
||||
const packageFileName = `${packageName.toLowerCase()}.${version.toLowerCase()}.nupkg`;
|
||||
|
||||
return {
|
||||
download: async (manifests) => {
|
||||
if (manifests.length === 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Create a temporary directory
|
||||
const tempDir = path.join(os.tmpdir(), `onnxruntime-node-pkgs_${Date.now()}`);
|
||||
fs.mkdirSync(tempDir, { recursive: true });
|
||||
|
||||
try {
|
||||
const packageFilePath = path.join(tempDir, packageFileName);
|
||||
|
||||
// Download the NuGet package
|
||||
console.log(`Downloading ${packageUrl}`);
|
||||
await downloadFile(packageUrl, packageFilePath);
|
||||
|
||||
// Load the NuGet package (which is a ZIP file)
|
||||
let zip;
|
||||
try {
|
||||
zip = new AdmZip(packageFilePath);
|
||||
} catch (err) {
|
||||
throw new Error(`Failed to open NuGet package: ${err.message}`);
|
||||
}
|
||||
|
||||
// Extract only the needed files from the package
|
||||
const extractDir = path.join(tempDir, 'extracted');
|
||||
fs.mkdirSync(extractDir, { recursive: true });
|
||||
|
||||
// Process each manifest and extract/copy files to their destinations
|
||||
for (const manifest of manifests) {
|
||||
const { filepath, pathInPackage } = manifest;
|
||||
|
||||
// Create directory for the target file
|
||||
const targetDir = path.dirname(filepath);
|
||||
fs.mkdirSync(targetDir, { recursive: true });
|
||||
|
||||
// Check if the file exists directly in the zip
|
||||
const zipEntry = zip.getEntry(pathInPackage);
|
||||
if (!zipEntry) {
|
||||
throw new Error(`Failed to find ${pathInPackage} in NuGet package`);
|
||||
}
|
||||
|
||||
console.log(`Extracting ${pathInPackage} to ${filepath}`);
|
||||
|
||||
// Extract just this entry to a temporary location
|
||||
const extractedFilePath = path.join(extractDir, path.basename(pathInPackage));
|
||||
zip.extractEntryTo(zipEntry, extractDir, false, true);
|
||||
|
||||
// Copy to the final destination
|
||||
fs.copyFileSync(extractedFilePath, filepath);
|
||||
}
|
||||
} finally {
|
||||
// Clean up the temporary directory - always runs even if an error occurs
|
||||
try {
|
||||
fs.rmSync(tempDir, { recursive: true });
|
||||
} catch (e) {
|
||||
console.warn(`Failed to clean up temporary directory: ${tempDir}`, e);
|
||||
// Don't rethrow this error as it would mask the original error
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
switch (type) {
|
||||
case 'nuget':
|
||||
return await nugetPackageUrlResolver(index, packageName, version);
|
||||
default:
|
||||
throw new Error(`Unsupported package type: ${type}`);
|
||||
}
|
||||
}
|
||||
|
||||
function tryGetCudaVersion() {
|
||||
// Should only return 11 or 12.
|
||||
|
||||
// try to get the CUDA version from the system ( `nvcc --version` )
|
||||
let ver = 12;
|
||||
try {
|
||||
const nvccVersion = execFileSync('nvcc', ['--version'], { encoding: 'utf8' });
|
||||
const match = nvccVersion.match(/release (\d+)/);
|
||||
if (match) {
|
||||
ver = parseInt(match[1]);
|
||||
if (ver !== 11 && ver !== 12) {
|
||||
throw new Error(`Unsupported CUDA version: ${ver}`);
|
||||
}
|
||||
}
|
||||
} catch (e) {
|
||||
if (e?.code === 'ENOENT') {
|
||||
console.warn('`nvcc` not found. Assuming CUDA 12.');
|
||||
} else {
|
||||
console.warn('Failed to detect CUDA version from `nvcc --version`:', e.message);
|
||||
}
|
||||
}
|
||||
|
||||
// assume CUDA 12 if failed to detect
|
||||
return ver;
|
||||
}
|
||||
|
||||
function parseInstallFlag() {
|
||||
let flag = process.env.ONNXRUNTIME_NODE_INSTALL || process.env.npm_config_onnxruntime_node_install;
|
||||
if (!flag) {
|
||||
for (let i = 0; i < process.argv.length; i++) {
|
||||
if (process.argv[i].startsWith('--onnxruntime-node-install=')) {
|
||||
flag = process.argv[i].split('=')[1];
|
||||
break;
|
||||
} else if (process.argv[i] === '--onnxruntime-node-install') {
|
||||
flag = 'true';
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (flag) {
|
||||
case 'true':
|
||||
case '1':
|
||||
case 'ON':
|
||||
return true;
|
||||
case 'skip':
|
||||
return false;
|
||||
case undefined: {
|
||||
flag = parseInstallCudaFlag();
|
||||
if (flag === 'skip') {
|
||||
return false;
|
||||
}
|
||||
if (flag === 11) {
|
||||
throw new Error('CUDA 11 is no longer supported. Please consider using CPU or upgrade to CUDA 12.');
|
||||
}
|
||||
if (flag === 12) {
|
||||
return 'cuda12';
|
||||
}
|
||||
return undefined;
|
||||
}
|
||||
default:
|
||||
if (!flag || typeof flag !== 'string') {
|
||||
throw new Error(`Invalid value for --onnxruntime-node-install: ${flag}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function parseInstallCudaFlag() {
|
||||
let flag = process.env.ONNXRUNTIME_NODE_INSTALL_CUDA || process.env.npm_config_onnxruntime_node_install_cuda;
|
||||
if (!flag) {
|
||||
for (let i = 0; i < process.argv.length; i++) {
|
||||
if (process.argv[i].startsWith('--onnxruntime-node-install-cuda=')) {
|
||||
flag = process.argv[i].split('=')[1];
|
||||
break;
|
||||
} else if (process.argv[i] === '--onnxruntime-node-install-cuda') {
|
||||
flag = 'true';
|
||||
}
|
||||
}
|
||||
}
|
||||
switch (flag) {
|
||||
case 'true':
|
||||
case '1':
|
||||
case 'ON':
|
||||
return tryGetCudaVersion();
|
||||
case 'v11':
|
||||
return 11;
|
||||
case 'v12':
|
||||
return 12;
|
||||
case 'skip':
|
||||
case undefined:
|
||||
return flag;
|
||||
default:
|
||||
throw new Error(`Invalid value for --onnxruntime-node-install-cuda: ${flag}`);
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
installPackages,
|
||||
parseInstallFlag,
|
||||
};
|
||||
+134
@@ -0,0 +1,134 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
'use strict';
|
||||
|
||||
// This script is written in JavaScript. This is because it is used in "install" script in package.json, which is called
|
||||
// when the package is installed either as a dependency or from "npm ci"/"npm install" without parameters. TypeScript is
|
||||
// not always available.
|
||||
|
||||
// The purpose of this script is to download the required binaries for the platform and architecture.
|
||||
// Currently, most of the binaries are already bundled in the package, except for the files that described in the file
|
||||
// install-metadata.js.
|
||||
//
|
||||
// Some files (eg. the CUDA EP binaries) are not bundled because they are too large to be allowed in the npm registry.
|
||||
// Instead, they are downloaded from the Nuget feed. The script will download the binaries if they are not already
|
||||
// present in the NPM package.
|
||||
|
||||
// Step.1: Check if we should exit early
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const { bootstrap: globalAgentBootstrap } = require('global-agent');
|
||||
const { installPackages, parseInstallFlag } = require('./install-utils.js');
|
||||
|
||||
const INSTALL_METADATA = require('./install-metadata.js');
|
||||
|
||||
// Bootstrap global-agent to honor the proxy settings in
|
||||
// environment variables, e.g. GLOBAL_AGENT_HTTPS_PROXY.
|
||||
// See the https://github.com/gajus/global-agent ReadMe.md regarding environment variables.
|
||||
globalAgentBootstrap();
|
||||
|
||||
// commandline flag:
|
||||
//
|
||||
// --onnxruntime-node-install Force install the files that are not bundled in the package.
|
||||
//
|
||||
// --onnxruntime-node-install=skip Skip the installation of the files that are not bundled in the package.
|
||||
//
|
||||
// --onnxruntime-node-install=cuda12 Force install the CUDA EP binaries for CUDA 12.
|
||||
//
|
||||
// --onnxruntime-node-install-cuda Force install the CUDA EP binaries.
|
||||
// (deprecated, use --onnxruntime-node-install=cuda12)
|
||||
//
|
||||
// --onnxruntime-node-install-cuda=skip Skip the installation of the CUDA EP binaries.
|
||||
// (deprecated, use --onnxruntime-node-install=skip)
|
||||
//
|
||||
//
|
||||
// Alternatively, use environment variable "ONNXRUNTIME_NODE_INSTALL" or "ONNXRUNTIME_NODE_INSTALL_CUDA" (deprecated).
|
||||
//
|
||||
// If the flag is not provided, the script will look up the metadata file to determine the manifest.
|
||||
//
|
||||
|
||||
/**
|
||||
* Possible values:
|
||||
* - undefined: the default behavior. This is the value when no installation flag is specified.
|
||||
*
|
||||
* - false: skip installation. This is the value when the installation flag is set to "skip":
|
||||
* --onnxruntime-node-install=skip
|
||||
*
|
||||
* - true: force installation. This is the value when the installation flag is set with no value:
|
||||
* --onnxruntime-node-install
|
||||
*
|
||||
* - string: the installation flag is set to a specific value:
|
||||
* --onnxruntime-node-install=cuda12
|
||||
*/
|
||||
const INSTALL_FLAG = parseInstallFlag();
|
||||
|
||||
// if installation is skipped, exit early
|
||||
if (INSTALL_FLAG === false) {
|
||||
process.exit(0);
|
||||
}
|
||||
// if installation is not specified, exit early when the installation is local (e.g. `npm ci` in <ORT_ROOT>/js/node/)
|
||||
if (INSTALL_FLAG === undefined) {
|
||||
const npm_config_local_prefix = process.env.npm_config_local_prefix;
|
||||
const npm_package_json = process.env.npm_package_json;
|
||||
const IS_LOCAL_INSTALL =
|
||||
npm_config_local_prefix && npm_package_json && path.dirname(npm_package_json) === npm_config_local_prefix;
|
||||
if (IS_LOCAL_INSTALL) {
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
const PLATFORM = `${os.platform()}/${os.arch()}`;
|
||||
let INSTALL_MANIFEST_NAMES = INSTALL_METADATA.requirements[PLATFORM] ?? [];
|
||||
|
||||
// if installation is specified explicitly, validate the manifest
|
||||
if (typeof INSTALL_FLAG === 'string') {
|
||||
const installations = INSTALL_FLAG.split(',').map((x) => x.trim());
|
||||
for (const installation of installations) {
|
||||
if (INSTALL_MANIFEST_NAMES.indexOf(installation) === -1) {
|
||||
throw new Error(`Invalid installation: ${installation} for platform: ${PLATFORM}`);
|
||||
}
|
||||
}
|
||||
INSTALL_MANIFEST_NAMES = installations;
|
||||
}
|
||||
|
||||
const BIN_FOLDER = path.join(__dirname, '..', 'bin/napi-v6', PLATFORM);
|
||||
const INSTALL_MANIFESTS = [];
|
||||
|
||||
const PACKAGES = new Set();
|
||||
for (const name of INSTALL_MANIFEST_NAMES) {
|
||||
const manifest = INSTALL_METADATA.manifests[`${PLATFORM}:${name}`];
|
||||
if (!manifest) {
|
||||
throw new Error(`Manifest not found: ${name} for platform: ${PLATFORM}`);
|
||||
}
|
||||
|
||||
for (const [filename, { package: pkg, path: pathInPackage }] of Object.entries(manifest)) {
|
||||
const packageCandidates = INSTALL_METADATA.packages[pkg];
|
||||
if (!packageCandidates) {
|
||||
throw new Error(`Package information not found: ${pkg}`);
|
||||
}
|
||||
PACKAGES.add(packageCandidates);
|
||||
|
||||
INSTALL_MANIFESTS.push({
|
||||
filepath: path.normalize(path.join(BIN_FOLDER, filename)),
|
||||
packagesInfo: packageCandidates,
|
||||
pathInPackage,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// If the installation flag is not specified, we do a check to see if the files are already installed.
|
||||
if (INSTALL_FLAG === undefined) {
|
||||
let hasMissingFiles = false;
|
||||
for (const { filepath } of INSTALL_MANIFESTS) {
|
||||
if (!require('fs').existsSync(filepath)) {
|
||||
hasMissingFiles = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!hasMissingFiles) {
|
||||
process.exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
void installPackages(PACKAGES, INSTALL_MANIFESTS, INSTALL_METADATA.feeds);
|
||||
+52
@@ -0,0 +1,52 @@
|
||||
"use strict";
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
var desc = Object.getOwnPropertyDescriptor(m, k);
|
||||
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
||||
desc = { enumerable: true, get: function() { return m[k]; } };
|
||||
}
|
||||
Object.defineProperty(o, k2, desc);
|
||||
}) : (function(o, m, k, k2) {
|
||||
if (k2 === undefined) k2 = k;
|
||||
o[k2] = m[k];
|
||||
}));
|
||||
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
||||
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
||||
}) : function(o, v) {
|
||||
o["default"] = v;
|
||||
});
|
||||
var __importStar = (this && this.__importStar) || (function () {
|
||||
var ownKeys = function(o) {
|
||||
ownKeys = Object.getOwnPropertyNames || function (o) {
|
||||
var ar = [];
|
||||
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
||||
return ar;
|
||||
};
|
||||
return ownKeys(o);
|
||||
};
|
||||
return function (mod) {
|
||||
if (mod && mod.__esModule) return mod;
|
||||
var result = {};
|
||||
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
||||
__setModuleDefault(result, mod);
|
||||
return result;
|
||||
};
|
||||
})();
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs = __importStar(require("fs-extra"));
|
||||
const path = __importStar(require("path"));
|
||||
function updatePackageJson() {
|
||||
const commonPackageJsonPath = path.join(__dirname, '..', '..', 'common', 'package.json');
|
||||
const selfPackageJsonPath = path.join(__dirname, '..', 'package.json');
|
||||
console.log(`=== start to update package.json: ${selfPackageJsonPath}`);
|
||||
const packageCommon = fs.readJSONSync(commonPackageJsonPath);
|
||||
const packageSelf = fs.readJSONSync(selfPackageJsonPath);
|
||||
const version = packageCommon.version;
|
||||
packageSelf.dependencies['onnxruntime-common'] = `${version}`;
|
||||
fs.writeJSONSync(selfPackageJsonPath, packageSelf, { spaces: 2 });
|
||||
console.log('=== finished updating package.json.');
|
||||
}
|
||||
// update version of dependency "onnxruntime-common" before packing
|
||||
updatePackageJson();
|
||||
+20
@@ -0,0 +1,20 @@
|
||||
// Copyright (c) Microsoft Corporation. All rights reserved.
|
||||
// Licensed under the MIT License.
|
||||
|
||||
import * as fs from 'fs-extra';
|
||||
import * as path from 'path';
|
||||
|
||||
function updatePackageJson() {
|
||||
const commonPackageJsonPath = path.join(__dirname, '..', '..', 'common', 'package.json');
|
||||
const selfPackageJsonPath = path.join(__dirname, '..', 'package.json');
|
||||
console.log(`=== start to update package.json: ${selfPackageJsonPath}`);
|
||||
const packageCommon = fs.readJSONSync(commonPackageJsonPath);
|
||||
const packageSelf = fs.readJSONSync(selfPackageJsonPath);
|
||||
const version = packageCommon.version;
|
||||
packageSelf.dependencies['onnxruntime-common'] = `${version}`;
|
||||
fs.writeJSONSync(selfPackageJsonPath, packageSelf, { spaces: 2 });
|
||||
console.log('=== finished updating package.json.');
|
||||
}
|
||||
|
||||
// update version of dependency "onnxruntime-common" before packing
|
||||
updatePackageJson();
|
||||
Reference in New Issue
Block a user