Skip to content

Commit

Permalink
Merge pull request #1378 from demergent-labs/robust_installation
Browse files Browse the repository at this point in the history
make the rust installation process much more robust by starting it ov…
  • Loading branch information
lastmjs authored Oct 15, 2023
2 parents a58b34d + c4e64c3 commit f27ab26
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 44 deletions.
12 changes: 5 additions & 7 deletions install_rust_dependencies.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,24 @@ global_azle_rust_bin_dir="$global_azle_rust_dir"/bin
global_azle_logs_dir="$global_azle_rust_dir"/logs
global_azle_cargo_bin="$global_azle_rust_bin_dir"/cargo
global_azle_rustup_bin="$global_azle_rust_bin_dir"/rustup
global_azle_rustc_bin="$global_azle_rust_bin_dir"/rustc
global_azle_wasi2ic_bin="$global_azle_rust_bin_dir"/wasi2ic

export CARGO_TARGET_DIR="$global_azle_config_dir"/rust/target
export CARGO_HOME="$global_azle_rust_dir"
export RUSTUP_HOME="$global_azle_rust_dir"
export CARGO_REGISTRIES_CRATES_IO_PROTOCOL=sparse

function run() {
if [ -e "$global_azle_rustup_bin" ] && $global_azle_rustup_bin target list | grep -q "wasm32-wasi (installed)"; then
update_rustup
else
if ! ([ -e "$global_azle_rustup_bin" ] && [ -e "$global_azle_wasi2ic_bin" ] && [ -e "$global_azle_cargo_bin" ] && [ -e "$global_azle_rustc_bin" ] && $global_azle_rustup_bin target list | grep -q "wasm32-wasi (installed)"); then
mkdir -p "$global_azle_rust_dir"
mkdir -p "$global_azle_logs_dir"

install_rustup
install_wasm32
install_wasi2ic

echo -e "[4/4] 🚀 Launching..."
fi
}

Expand All @@ -35,10 +37,6 @@ function install_rustup() {
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- --no-modify-path -y --default-toolchain="$rust_version" --profile=minimal &> "$global_azle_logs_dir"/install_rustup
}

function update_rustup() {
"$global_azle_rustup_bin" update "$rust_version" &> "$global_azle_logs_dir"/update_rustup
}

function install_wasm32() {
echo -e "[2/4] 🛠️ Commencing development..."
"$global_azle_rustup_bin" target add wasm32-wasi &> "$global_azle_logs_dir"/install_wasm32_wasi
Expand Down
37 changes: 0 additions & 37 deletions src/compiler/install_rust_dependencies.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,10 @@
import { execSync } from 'child_process';
import { existsSync } from 'fs';
import { resolve } from 'path';
import {
GLOBAL_AZLE_RUST_DIR,
GLOBAL_AZLE_RUST_BIN_DIR,
GLOBAL_AZLE_TARGET_DIR
} from './utils';

export function installRustDependencies(
azleVersion: string,
rustVersion: string
) {
if (isWasm32TargetInstalled()) {
return;
}

const installRustDependenciesPath = resolve(
__dirname,
'../../install_rust_dependencies.sh'
Expand All @@ -23,31 +13,4 @@ export function installRustDependencies(
execSync(`"${installRustDependenciesPath}" ${azleVersion} ${rustVersion}`, {
stdio: 'inherit'
});

console.log('[4/4] 🚀 Launching...');
}

function isWasm32TargetInstalled(): boolean {
if (existsSync(`${GLOBAL_AZLE_RUST_BIN_DIR}/rustup`)) {
try {
const stdout = execSync(
`${GLOBAL_AZLE_RUST_BIN_DIR}/rustup target list`,
{
encoding: 'utf-8',
env: {
...process.env,
CARGO_TARGET_DIR: GLOBAL_AZLE_TARGET_DIR,
CARGO_HOME: GLOBAL_AZLE_RUST_DIR,
RUSTUP_HOME: GLOBAL_AZLE_RUST_DIR
}
}
);
return stdout.includes('wasm32-wasi (installed)');
} catch (error) {
console.error(`execSync error: ${error}`);
return false;
}
} else {
return false;
}
}

0 comments on commit f27ab26

Please sign in to comment.