onnxruntime/js/web/script/pull-prebuilt-wasm-artifacts.ts

127 lines
4.7 KiB
TypeScript
Raw Normal View History

// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
//
// This script is used to download WebAssembly build artifacts from CI pipeline.
//
// The goal of this script is to save time for ORT Web developers. For most TypeScript tasks, there is no change in the
// WebAssembly side, so there is no need to rebuild WebAssembly.
//
// It performs the following operations:
// 1. query build ID for latest successful build on main branch
// 2. query download URL of build artifacts
// 3. download and unzip the files to folders
//
import fs from 'fs';
import https from 'https';
import jszip from 'jszip';
import path from 'path';
function downloadJson(url: string, onSuccess: (data: any) => void) {
https.get(url, res => {
const {statusCode} = res;
const contentType = res.headers['content-type'];
if (statusCode !== 200) {
throw new Error(`Failed to download build list. HTTP status code = ${statusCode}`);
}
if (!contentType || !/^application\/json/.test(contentType)) {
throw new Error(`unexpected content type: ${contentType}`);
}
res.setEncoding('utf8');
let rawData = '';
res.on('data', (chunk) => {
rawData += chunk;
});
res.on('end', () => {
onSuccess(JSON.parse(rawData));
});
});
}
function downloadZip(url: string, onSuccess: (data: Buffer) => void) {
https.get(url, res => {
const {statusCode} = res;
const contentType = res.headers['content-type'];
if (statusCode !== 200) {
throw new Error(`Failed to download build list. HTTP status code = ${statusCode}`);
}
if (!contentType || !/^application\/zip/.test(contentType)) {
throw new Error(`unexpected content type: ${contentType}`);
}
const chunks: Buffer[] = [];
res.on('data', (chunk) => {
chunks.push(chunk);
});
res.on('end', () => {
onSuccess(Buffer.concat(chunks));
});
});
}
function extractFile(zip: jszip, folder: string, file: string, artifactName: string) {
zip.file(`${artifactName}/${file}`)!.nodeStream()
.pipe(fs.createWriteStream(path.join(folder, file)))
.on('finish', () => {
console.log('# file downloaded and extracted: ' + file);
});
}
console.log('=== Start to pull WebAssembly artifacts from CI ===');
// API reference: https://docs.microsoft.com/en-us/rest/api/azure/devops/build/builds/list
downloadJson(
'https://dev.azure.com/onnxruntime/onnxruntime/_apis/build/builds?api-version=6.1-preview.6' +
'&definitions=161' +
'&resultFilter=succeeded%2CpartiallySucceeded' +
'&$top=1' +
'&repositoryId=Microsoft/onnxruntime' +
'&repositoryType=GitHub' +
'&branchName=refs/heads/main',
data => {
const buildId = data.value[0].id;
console.log(`=== Found latest build on main branch: ${buildId} ===`);
// API reference: https://docs.microsoft.com/en-us/rest/api/azure/devops/build/artifacts/get%20artifact
downloadJson(
`https://dev.azure.com/onnxruntime/onnxruntime/_apis/build/builds/${
buildId}/artifacts?api-version=6.1-preview.5`,
data => {
let zipLink;
for (const v of data.value) {
if (v.name === 'Release_wasm') {
zipLink = v.resource.downloadUrl;
}
}
console.log('=== Ready to download zip files ===');
const WASM_FOLDER = path.join(__dirname, '../dist');
if (!fs.existsSync(WASM_FOLDER)) {
fs.mkdirSync(WASM_FOLDER);
}
const JS_FOLDER = path.join(__dirname, '../lib/wasm/binding');
downloadZip(zipLink, buffer => {
void jszip.loadAsync(buffer).then(zip => {
extractFile(zip, WASM_FOLDER, 'ort-wasm.wasm', 'Release_wasm');
extractFile(zip, WASM_FOLDER, 'ort-wasm-threaded.wasm', 'Release_wasm');
extractFile(zip, WASM_FOLDER, 'ort-wasm-simd.wasm', 'Release_wasm');
extractFile(zip, WASM_FOLDER, 'ort-wasm-simd-threaded.wasm', 'Release_wasm');
Cherry-picks to the release branch (#16017) ### Description Cherry-picks 26 commits to the release branch. Most cherry-picks are clean merges. Except: 1. When I got conflicts in cgmanifest.json and download-deps.yml, I choose to ignore the conflicts and regenerate the two files 2. There were some conflicts in cmake/deps.txt, onnxruntime_c_api.cc PR list: [js/webgpu] fix Transpose with non-float tensor (#15819) [js/web] fix terser reserved symbols for worker (#15864) [JSEP] fix constructor for OrtDevice (#15805) Bump engine.io from 6.4.1 to 6.4.2 in /js/web (#15799) Bump engine.io from 6.4.0 to 6.4.2 in /onnxruntime/test/wasm (#15798) [wasm] revert emsdk to v3.1.19 (#15793) [wasm/JSEP] add threaded build to artifacts (#15777) [js/web] add target ort.webgpu.min.js (#15780) update ort extensions to 94142d8391c9791ec71c38336436319a2d4ac7a0 (#15688) fix: setting builder optimization level to TRT 8.6 default (#15897) Adust GetVersionString() GetBuildInfoString() signatures and move them to OrtApi (#15921) Fix segfault for multiple GPU run (regression) (#15823) android package fix (#15999) [CoreML EP] Minor changes to allow CoreML EP to handle more nodes and models. (#15993) Adding support for conv fp16 fusion on Resnet50v1 (#15474) update onnx release 1.14 for docker files (#15680) Avoid generating training documentation during packaging (#15795) Update Conv-Add-Relu Fusion Transformation (#15834) Fix symbolic shape infer empty value_info (#15842) NhwcFusedConv: Add before Activation (#15837) use __hmul2 instead of __hmul2_rn (#15852) change the EP device to default OrtDevice() for memoryType equals CPU Input (#15903) Fixing NhwcFusedConv fp16 (#15950) fix topo sort in quantization tool (#16003) [doc] add LeakyRelu to coreml supported ops (#15944) [DML EP] Add frequent upload heap flushing (#15960) Co-authored-by: Yulong Wang Co-authored-by: dependabot[bot] Co-authored-by: Guenther Schmuelling Co-authored-by: Shalva Mist Co-authored-by: Maximilian Müller Co-authored-by: Dmitri Smirnov Co-authored-by: pengwa Co-authored-by: Ashwini Khade Co-authored-by: Edward Chen Co-authored-by: Jian Chen Co-authored-by: liqun Fu Co-authored-by: Baiju Meswani Co-authored-by: Tianlei Wu Co-authored-by: Chen Fu Co-authored-by: Ye Wang Co-authored-by: cao lei Co-authored-by: Yufeng Li Co-authored-by: Rachel Guo Co-authored-by: Patrice Vignola
2023-05-19 21:04:43 +00:00
extractFile(zip, WASM_FOLDER, 'ort-wasm-simd.jsep.wasm', 'Release_wasm');
extractFile(zip, WASM_FOLDER, 'ort-wasm-simd-threaded.jsep.wasm', 'Release_wasm');
extractFile(zip, JS_FOLDER, 'ort-wasm.js', 'Release_wasm');
extractFile(zip, JS_FOLDER, 'ort-wasm-threaded.js', 'Release_wasm');
extractFile(zip, JS_FOLDER, 'ort-wasm-threaded.worker.js', 'Release_wasm');
Cherry-picks to the release branch (#16017) ### Description Cherry-picks 26 commits to the release branch. Most cherry-picks are clean merges. Except: 1. When I got conflicts in cgmanifest.json and download-deps.yml, I choose to ignore the conflicts and regenerate the two files 2. There were some conflicts in cmake/deps.txt, onnxruntime_c_api.cc PR list: [js/webgpu] fix Transpose with non-float tensor (#15819) [js/web] fix terser reserved symbols for worker (#15864) [JSEP] fix constructor for OrtDevice (#15805) Bump engine.io from 6.4.1 to 6.4.2 in /js/web (#15799) Bump engine.io from 6.4.0 to 6.4.2 in /onnxruntime/test/wasm (#15798) [wasm] revert emsdk to v3.1.19 (#15793) [wasm/JSEP] add threaded build to artifacts (#15777) [js/web] add target ort.webgpu.min.js (#15780) update ort extensions to 94142d8391c9791ec71c38336436319a2d4ac7a0 (#15688) fix: setting builder optimization level to TRT 8.6 default (#15897) Adust GetVersionString() GetBuildInfoString() signatures and move them to OrtApi (#15921) Fix segfault for multiple GPU run (regression) (#15823) android package fix (#15999) [CoreML EP] Minor changes to allow CoreML EP to handle more nodes and models. (#15993) Adding support for conv fp16 fusion on Resnet50v1 (#15474) update onnx release 1.14 for docker files (#15680) Avoid generating training documentation during packaging (#15795) Update Conv-Add-Relu Fusion Transformation (#15834) Fix symbolic shape infer empty value_info (#15842) NhwcFusedConv: Add before Activation (#15837) use __hmul2 instead of __hmul2_rn (#15852) change the EP device to default OrtDevice() for memoryType equals CPU Input (#15903) Fixing NhwcFusedConv fp16 (#15950) fix topo sort in quantization tool (#16003) [doc] add LeakyRelu to coreml supported ops (#15944) [DML EP] Add frequent upload heap flushing (#15960) Co-authored-by: Yulong Wang Co-authored-by: dependabot[bot] Co-authored-by: Guenther Schmuelling Co-authored-by: Shalva Mist Co-authored-by: Maximilian Müller Co-authored-by: Dmitri Smirnov Co-authored-by: pengwa Co-authored-by: Ashwini Khade Co-authored-by: Edward Chen Co-authored-by: Jian Chen Co-authored-by: liqun Fu Co-authored-by: Baiju Meswani Co-authored-by: Tianlei Wu Co-authored-by: Chen Fu Co-authored-by: Ye Wang Co-authored-by: cao lei Co-authored-by: Yufeng Li Co-authored-by: Rachel Guo Co-authored-by: Patrice Vignola
2023-05-19 21:04:43 +00:00
extractFile(zip, JS_FOLDER, 'ort-wasm-simd.jsep.js', 'Release_wasm');
extractFile(zip, JS_FOLDER, 'ort-wasm-simd-threaded.jsep.js', 'Release_wasm');
});
});
});
});