mirror of
https://github.com/bytecodealliance/wasm-micro-runtime.git
synced 2025-05-08 20:56:13 +00:00
vscode-extension: Run docker image with the same version as WAMR (#1815)
This commit is contained in:
parent
97d2b5a060
commit
d0c4c7036b
|
@ -6,5 +6,5 @@
|
||||||
docker run --rm -it --name=wasm-debug-server-ctr ^
|
docker run --rm -it --name=wasm-debug-server-ctr ^
|
||||||
-v "%cd%":/mnt ^
|
-v "%cd%":/mnt ^
|
||||||
-p 1234:1234 ^
|
-p 1234:1234 ^
|
||||||
wasm-debug-server:1.0 ^
|
wasm-debug-server:%2 ^
|
||||||
/bin/bash -c "./debug.sh %1"
|
/bin/bash -c "./debug.sh %1"
|
||||||
|
|
|
@ -8,5 +8,5 @@ set -e
|
||||||
docker run --rm -it --name=wasm-debug-server-ctr \
|
docker run --rm -it --name=wasm-debug-server-ctr \
|
||||||
-v "$(pwd)":/mnt \
|
-v "$(pwd)":/mnt \
|
||||||
-p 1234:1234 \
|
-p 1234:1234 \
|
||||||
wasm-debug-server:1.0 \
|
wasm-debug-server:$2 \
|
||||||
/bin/bash -c "./debug.sh $1"
|
/bin/bash -c "./debug.sh $1"
|
||||||
|
|
|
@ -7,5 +7,5 @@
|
||||||
docker run --rm --name=wasm-toolchain-ctr ^
|
docker run --rm --name=wasm-toolchain-ctr ^
|
||||||
-it -v "%cd%":/mnt ^
|
-it -v "%cd%":/mnt ^
|
||||||
--env=PROJ_PATH="%cd%" ^
|
--env=PROJ_PATH="%cd%" ^
|
||||||
wasm-toolchain:1.0 ^
|
wasm-toolchain:%2 ^
|
||||||
/bin/bash -c "./build_wasm.sh %1"
|
/bin/bash -c "./build_wasm.sh %1"
|
||||||
|
|
|
@ -8,5 +8,5 @@ set -e
|
||||||
docker run --rm --name=wasm-toolchain-ctr \
|
docker run --rm --name=wasm-toolchain-ctr \
|
||||||
-it -v "$(pwd)":/mnt \
|
-it -v "$(pwd)":/mnt \
|
||||||
--env=PROJ_PATH="$(pwd)" \
|
--env=PROJ_PATH="$(pwd)" \
|
||||||
wasm-toolchain:1.0 \
|
wasm-toolchain:$2 \
|
||||||
/bin/bash -c "./build_wasm.sh $1"
|
/bin/bash -c "./build_wasm.sh $1"
|
||||||
|
|
|
@ -5,5 +5,5 @@
|
||||||
|
|
||||||
docker run --rm -it --name=wasm-debug-server-ctr ^
|
docker run --rm -it --name=wasm-debug-server-ctr ^
|
||||||
-v "%cd%":/mnt ^
|
-v "%cd%":/mnt ^
|
||||||
wasm-debug-server:1.0 ^
|
wasm-debug-server:%2 ^
|
||||||
/bin/bash -c "./run.sh %1"
|
/bin/bash -c "./run.sh %1"
|
||||||
|
|
|
@ -7,5 +7,5 @@ set -e
|
||||||
|
|
||||||
docker run --rm -it --name=wasm-debug-server-ctr \
|
docker run --rm -it --name=wasm-debug-server-ctr \
|
||||||
-v "$(pwd)":/mnt \
|
-v "$(pwd)":/mnt \
|
||||||
wasm-debug-server:1.0 \
|
wasm-debug-server:$2 \
|
||||||
/bin/bash -c "./run.sh $1"
|
/bin/bash -c "./run.sh $1"
|
||||||
|
|
|
@ -18,7 +18,11 @@ import {
|
||||||
} from './utilities/directoryUtilities';
|
} from './utilities/directoryUtilities';
|
||||||
import { decorationProvider } from './decorationProvider';
|
import { decorationProvider } from './decorationProvider';
|
||||||
import { WasmDebugConfigurationProvider } from './debugConfigurationProvider';
|
import { WasmDebugConfigurationProvider } from './debugConfigurationProvider';
|
||||||
import { isLLDBInstalled, promptInstallLLDB } from './utilities/lldbUtilities';
|
import {
|
||||||
|
isLLDBInstalled,
|
||||||
|
promptInstallLLDB,
|
||||||
|
getWAMRExtensionVersion,
|
||||||
|
} from './utilities/lldbUtilities';
|
||||||
|
|
||||||
let wasmTaskProvider: WasmTaskProvider;
|
let wasmTaskProvider: WasmTaskProvider;
|
||||||
let wasmDebugConfigProvider: WasmDebugConfigurationProvider;
|
let wasmDebugConfigProvider: WasmDebugConfigurationProvider;
|
||||||
|
@ -43,6 +47,8 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
excludeFileArr = new Array(),
|
excludeFileArr = new Array(),
|
||||||
scriptMap = new Map();
|
scriptMap = new Map();
|
||||||
|
|
||||||
|
const wamrVersion = getWAMRExtensionVersion(context);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get OS platform information for differ windows and linux execution script
|
* Get OS platform information for differ windows and linux execution script
|
||||||
*/
|
*/
|
||||||
|
@ -83,7 +89,7 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
typeMap.set('Debug', 'Debug');
|
typeMap.set('Debug', 'Debug');
|
||||||
typeMap.set('Destroy', 'Destroy');
|
typeMap.set('Destroy', 'Destroy');
|
||||||
|
|
||||||
wasmTaskProvider = new WasmTaskProvider(typeMap, scriptMap);
|
wasmTaskProvider = new WasmTaskProvider(typeMap, scriptMap, wamrVersion);
|
||||||
|
|
||||||
vscode.tasks.registerTaskProvider('wasm', wasmTaskProvider);
|
vscode.tasks.registerTaskProvider('wasm', wasmTaskProvider);
|
||||||
|
|
||||||
|
@ -670,7 +676,8 @@ export async function activate(context: vscode.ExtensionContext) {
|
||||||
let _path = curWorkspace.concat(
|
let _path = curWorkspace.concat(
|
||||||
OS_PLATFORM === 'win32'
|
OS_PLATFORM === 'win32'
|
||||||
? '\\'
|
? '\\'
|
||||||
: OS_PLATFORM === 'linux' || OS_PLATFORM === 'darwin'
|
: OS_PLATFORM === 'linux' ||
|
||||||
|
OS_PLATFORM === 'darwin'
|
||||||
? '/'
|
? '/'
|
||||||
: '',
|
: '',
|
||||||
option
|
option
|
||||||
|
|
|
@ -15,7 +15,8 @@ export interface OwnShellOption {
|
||||||
export class WasmTaskProvider implements vscode.TaskProvider {
|
export class WasmTaskProvider implements vscode.TaskProvider {
|
||||||
constructor(
|
constructor(
|
||||||
public _type: Map<string, string>,
|
public _type: Map<string, string>,
|
||||||
public _script: Map<string, string>
|
public _script: Map<string, string>,
|
||||||
|
public _wamrVersion: string
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
buildShellOption: OwnShellOption | undefined;
|
buildShellOption: OwnShellOption | undefined;
|
||||||
|
@ -31,7 +32,11 @@ export class WasmTaskProvider implements vscode.TaskProvider {
|
||||||
let targetName =
|
let targetName =
|
||||||
TargetConfigPanel.BUILD_ARGS.output_file_name.split('.')[0];
|
TargetConfigPanel.BUILD_ARGS.output_file_name.split('.')[0];
|
||||||
|
|
||||||
if (os.platform() === 'linux' || os.platform() === 'darwin' || os.platform() === 'win32') {
|
if (
|
||||||
|
os.platform() === 'linux' ||
|
||||||
|
os.platform() === 'darwin' ||
|
||||||
|
os.platform() === 'win32'
|
||||||
|
) {
|
||||||
/* build */
|
/* build */
|
||||||
this.buildShellOption = {
|
this.buildShellOption = {
|
||||||
cmd:
|
cmd:
|
||||||
|
@ -40,7 +45,7 @@ export class WasmTaskProvider implements vscode.TaskProvider {
|
||||||
: (this._script.get('buildScript') as string),
|
: (this._script.get('buildScript') as string),
|
||||||
options: {
|
options: {
|
||||||
executable: this._script.get('buildScript'),
|
executable: this._script.get('buildScript'),
|
||||||
shellArgs: [targetName, os.platform()],
|
shellArgs: [targetName, this._wamrVersion],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -52,7 +57,7 @@ export class WasmTaskProvider implements vscode.TaskProvider {
|
||||||
: (this._script.get('debugScript') as string),
|
: (this._script.get('debugScript') as string),
|
||||||
options: {
|
options: {
|
||||||
executable: this._script.get('debugScript'),
|
executable: this._script.get('debugScript'),
|
||||||
shellArgs: [targetName],
|
shellArgs: [targetName, this._wamrVersion],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -64,7 +69,7 @@ export class WasmTaskProvider implements vscode.TaskProvider {
|
||||||
: (this._script.get('runScript') as string),
|
: (this._script.get('runScript') as string),
|
||||||
options: {
|
options: {
|
||||||
executable: this._script.get('runScript'),
|
executable: this._script.get('runScript'),
|
||||||
shellArgs: [targetName],
|
shellArgs: [targetName, this._wamrVersion],
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -137,53 +137,73 @@ export function checkFolderName(folderName: string) {
|
||||||
return valid;
|
return valid;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function downloadFile(url: string, destinationPath: string): Promise<void> {
|
export function downloadFile(
|
||||||
|
url: string,
|
||||||
|
destinationPath: string
|
||||||
|
): Promise<void> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const file = fileSystem.createWriteStream(destinationPath);
|
const file = fileSystem.createWriteStream(destinationPath);
|
||||||
const stream = request(url, undefined, (error, response, body) => {
|
const stream = request(url, undefined, (error, response, body) => {
|
||||||
if (response.statusCode !== 200) {
|
if (response.statusCode !== 200) {
|
||||||
reject(new Error(`Download from ${url} failed with ${response.statusMessage}`));
|
reject(
|
||||||
|
new Error(
|
||||||
|
`Download from ${url} failed with ${response.statusMessage}`
|
||||||
|
)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}).pipe(file);
|
}).pipe(file);
|
||||||
stream.on("close", resolve);
|
stream.on('close', resolve);
|
||||||
stream.on("error", reject);
|
stream.on('error', reject);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
export function unzipFile(sourcePath: string, getDestinationFileName: (entryName: string) => string): Promise<string[]> {
|
export function unzipFile(
|
||||||
|
sourcePath: string,
|
||||||
|
getDestinationFileName: (entryName: string) => string
|
||||||
|
): Promise<string[]> {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
const unzippedFilePaths: string[] = [];
|
const unzippedFilePaths: string[] = [];
|
||||||
yauzl.open(sourcePath, { lazyEntries: true }, function(error, zipfile) {
|
yauzl.open(
|
||||||
|
sourcePath,
|
||||||
|
{ lazyEntries: true },
|
||||||
|
function (error, zipfile) {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
zipfile.readEntry();
|
zipfile.readEntry();
|
||||||
zipfile.on("entry", function(entry) {
|
zipfile.on('entry', function (entry) {
|
||||||
// This entry is a directory so skip it
|
// This entry is a directory so skip it
|
||||||
if (/\/$/.test(entry.fileName)) {
|
if (/\/$/.test(entry.fileName)) {
|
||||||
zipfile.readEntry();
|
zipfile.readEntry();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
zipfile.openReadStream(entry, function(error, readStream) {
|
zipfile.openReadStream(entry, function (error, readStream) {
|
||||||
if (error) {
|
if (error) {
|
||||||
reject(error);
|
reject(error);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
readStream.on("end", () => zipfile.readEntry());
|
readStream.on('end', () => zipfile.readEntry());
|
||||||
const destinationFileName = getDestinationFileName(entry.fileName);
|
const destinationFileName = getDestinationFileName(
|
||||||
fileSystem.mkdirSync(path.dirname(destinationFileName), { recursive: true });
|
entry.fileName
|
||||||
|
);
|
||||||
|
fileSystem.mkdirSync(
|
||||||
|
path.dirname(destinationFileName),
|
||||||
|
{ recursive: true }
|
||||||
|
);
|
||||||
|
|
||||||
const file = fileSystem.createWriteStream(destinationFileName);
|
const file =
|
||||||
readStream.pipe(file).on("error", reject);
|
fileSystem.createWriteStream(destinationFileName);
|
||||||
|
readStream.pipe(file).on('error', reject);
|
||||||
unzippedFilePaths.push(destinationFileName);
|
unzippedFilePaths.push(destinationFileName);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
zipfile.on("end", function() {
|
zipfile.on('end', function () {
|
||||||
zipfile.close();
|
zipfile.close();
|
||||||
resolve(unzippedFilePaths);
|
resolve(unzippedFilePaths);
|
||||||
});
|
});
|
||||||
});
|
}
|
||||||
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
|
@ -7,27 +7,41 @@ import * as vscode from 'vscode';
|
||||||
import * as os from 'os';
|
import * as os from 'os';
|
||||||
import * as path from 'path';
|
import * as path from 'path';
|
||||||
import * as fs from 'fs';
|
import * as fs from 'fs';
|
||||||
import { checkIfFileExists, downloadFile, unzipFile } from './directoryUtilities';
|
import {
|
||||||
|
checkIfFileExists,
|
||||||
|
downloadFile,
|
||||||
|
unzipFile,
|
||||||
|
} from './directoryUtilities';
|
||||||
|
|
||||||
const LLDB_RESOURCE_DIR = "resource/debug";
|
const LLDB_RESOURCE_DIR = 'resource/debug';
|
||||||
const LLDB_OS_DOWNLOAD_URL_SUFFIX_MAP: Partial<Record<NodeJS.Platform, string>> = {
|
const LLDB_OS_DOWNLOAD_URL_SUFFIX_MAP: Partial<
|
||||||
"linux": "x86_64-ubuntu-22.04",
|
Record<NodeJS.Platform, string>
|
||||||
"darwin": "universal-macos-latest"
|
> = {
|
||||||
|
linux: 'x86_64-ubuntu-22.04',
|
||||||
|
darwin: 'universal-macos-latest',
|
||||||
};
|
};
|
||||||
|
|
||||||
const WAMR_LLDB_NOT_SUPPORTED_ERROR = new Error("WAMR LLDB is not supported on this platform");
|
const WAMR_LLDB_NOT_SUPPORTED_ERROR = new Error(
|
||||||
|
'WAMR LLDB is not supported on this platform'
|
||||||
|
);
|
||||||
|
|
||||||
function getLLDBUnzipFilePath(destinationFolder: string, filename: string) {
|
function getLLDBUnzipFilePath(destinationFolder: string, filename: string) {
|
||||||
const dirs = filename.split("/");
|
const dirs = filename.split('/');
|
||||||
if (dirs[0] === "inst") {
|
if (dirs[0] === 'inst') {
|
||||||
dirs.shift();
|
dirs.shift();
|
||||||
}
|
}
|
||||||
|
|
||||||
return path.join(destinationFolder, ...dirs);
|
return path.join(destinationFolder, ...dirs);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getWAMRExtensionVersion(
|
||||||
|
context: vscode.ExtensionContext
|
||||||
|
): string {
|
||||||
|
return require(path.join(context.extensionPath, 'package.json')).version;
|
||||||
|
}
|
||||||
|
|
||||||
function getLLDBDownloadUrl(context: vscode.ExtensionContext): string {
|
function getLLDBDownloadUrl(context: vscode.ExtensionContext): string {
|
||||||
const wamrVersion = require(path.join(context.extensionPath, "package.json")).version;
|
const wamrVersion = getWAMRExtensionVersion(context);
|
||||||
const lldbOsUrlSuffix = LLDB_OS_DOWNLOAD_URL_SUFFIX_MAP[os.platform()];
|
const lldbOsUrlSuffix = LLDB_OS_DOWNLOAD_URL_SUFFIX_MAP[os.platform()];
|
||||||
|
|
||||||
if (!lldbOsUrlSuffix) {
|
if (!lldbOsUrlSuffix) {
|
||||||
|
@ -40,15 +54,25 @@ function getLLDBDownloadUrl(context: vscode.ExtensionContext): string {
|
||||||
export function isLLDBInstalled(context: vscode.ExtensionContext): boolean {
|
export function isLLDBInstalled(context: vscode.ExtensionContext): boolean {
|
||||||
const extensionPath = context.extensionPath;
|
const extensionPath = context.extensionPath;
|
||||||
const lldbOSDir = os.platform();
|
const lldbOSDir = os.platform();
|
||||||
const lldbBinaryPath = path.join(extensionPath, LLDB_RESOURCE_DIR, lldbOSDir, "bin", "lldb");
|
const lldbBinaryPath = path.join(
|
||||||
|
extensionPath,
|
||||||
|
LLDB_RESOURCE_DIR,
|
||||||
|
lldbOSDir,
|
||||||
|
'bin',
|
||||||
|
'lldb'
|
||||||
|
);
|
||||||
return checkIfFileExists(lldbBinaryPath);
|
return checkIfFileExists(lldbBinaryPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function promptInstallLLDB(context: vscode.ExtensionContext) {
|
export async function promptInstallLLDB(context: vscode.ExtensionContext) {
|
||||||
const extensionPath = context.extensionPath;
|
const extensionPath = context.extensionPath;
|
||||||
const setupPrompt = "setup";
|
const setupPrompt = 'setup';
|
||||||
const skipPrompt = "skip";
|
const skipPrompt = 'skip';
|
||||||
const response = await vscode.window.showWarningMessage('No LLDB instance found. Setup now?', setupPrompt, skipPrompt);
|
const response = await vscode.window.showWarningMessage(
|
||||||
|
'No LLDB instance found. Setup now?',
|
||||||
|
setupPrompt,
|
||||||
|
skipPrompt
|
||||||
|
);
|
||||||
|
|
||||||
if (response === skipPrompt) {
|
if (response === skipPrompt) {
|
||||||
return;
|
return;
|
||||||
|
@ -61,23 +85,31 @@ export async function promptInstallLLDB(context: vscode.ExtensionContext) {
|
||||||
throw WAMR_LLDB_NOT_SUPPORTED_ERROR;
|
throw WAMR_LLDB_NOT_SUPPORTED_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
const lldbDestinationFolder = path.join(extensionPath, LLDB_RESOURCE_DIR, destinationDir);
|
const lldbDestinationFolder = path.join(
|
||||||
const lldbZipPath = path.join(lldbDestinationFolder, "bundle.zip");
|
extensionPath,
|
||||||
|
LLDB_RESOURCE_DIR,
|
||||||
|
destinationDir
|
||||||
|
);
|
||||||
|
const lldbZipPath = path.join(lldbDestinationFolder, 'bundle.zip');
|
||||||
|
|
||||||
vscode.window.showInformationMessage(`Downloading LLDB...`);
|
vscode.window.showInformationMessage(`Downloading LLDB...`);
|
||||||
|
|
||||||
await downloadFile(downloadUrl, lldbZipPath);
|
await downloadFile(downloadUrl, lldbZipPath);
|
||||||
|
|
||||||
vscode.window.showInformationMessage(`LLDB downloaded to ${lldbZipPath}. Installing...`);
|
vscode.window.showInformationMessage(
|
||||||
|
`LLDB downloaded to ${lldbZipPath}. Installing...`
|
||||||
|
);
|
||||||
|
|
||||||
const lldbFiles = await unzipFile(lldbZipPath, filename => getLLDBUnzipFilePath(lldbDestinationFolder, filename));
|
const lldbFiles = await unzipFile(lldbZipPath, filename =>
|
||||||
|
getLLDBUnzipFilePath(lldbDestinationFolder, filename)
|
||||||
|
);
|
||||||
// Allow execution of lldb
|
// Allow execution of lldb
|
||||||
lldbFiles.forEach(file => fs.chmodSync(file, "0775"));
|
lldbFiles.forEach(file => fs.chmodSync(file, '0775'));
|
||||||
|
|
||||||
vscode.window.showInformationMessage(`LLDB installed at ${lldbDestinationFolder}`);
|
vscode.window.showInformationMessage(
|
||||||
|
`LLDB installed at ${lldbDestinationFolder}`
|
||||||
|
);
|
||||||
|
|
||||||
// Remove the bundle.zip
|
// Remove the bundle.zip
|
||||||
fs.unlink(lldbZipPath, () => {});
|
fs.unlink(lldbZipPath, () => {});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user