UNPKG

@kubiklabs/wasmkit

Version:

Wasmkit is a development environment to compile, deploy, test, run cosmwasm contracts on different networks.

63 lines (62 loc) 2.56 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.canCompile = exports.getWebAssemblyInstalled = exports.getRustcVersion = void 0; const chalk_1 = __importDefault(require("chalk")); const child_process_1 = require("child_process"); const semver_1 = __importDefault(require("semver")); const install_1 = require("../../builtin-tasks/install"); function getRustcVersion() { try { const versionData = (0, child_process_1.execSync)(`rustc -V`); const [version] = versionData.toString().split(/\s/)[1]?.trim().split('-') || []; const res = semver_1.default.valid(version); if (typeof res === "string") { return res; } else { throw new Error("Invalid rust version"); } } catch (error) { throw new Error("Can't fetch rust version"); } } exports.getRustcVersion = getRustcVersion; function getWebAssemblyInstalled() { try { const stableVersionData = (0, child_process_1.execSync)(`rustup target list --installed --toolchain stable`); const stableVersion = stableVersionData.toString().split(/\n/) || []; if (!stableVersion.includes('wasm32-unknown-unknown')) { console.log(`wasm stable compiler not installed. Try ${chalk_1.default.grey('rustup target add wasm32-unknown-unknown --toolchain stable')}`); return false; } return true; } catch (error) { return false; } } exports.getWebAssemblyInstalled = getWebAssemblyInstalled; async function canCompile(env) { const rustcCurrVersion = getRustcVersion(); const wasmInstalled = getWebAssemblyInstalled(); const wantVersion = env.config.rust?.version ?? rustcCurrVersion; if (!rustcCurrVersion) { console.log(`Warning: rustc not installed.`); console.log("Installing rust"); await (0, install_1.setupRust)(env); } else if (rustcCurrVersion.localeCompare(wantVersion) !== 0) { console.log(`warning: rustc version ${chalk_1.default.green(rustcCurrVersion)} installed, required ${chalk_1.default.green(env.config.rust?.version)}.`); console.log("Updating rust version"); await (0, install_1.setupRust)(env); } if (!wasmInstalled) { (0, child_process_1.execSync)(`rustup target add wasm32-unknown-unknown`); } return true; } exports.canCompile = canCompile;