Skip to content
This repository has been archived by the owner on Jul 17, 2024. It is now read-only.

new: Install rustup if it does not exist. #10

Merged
merged 3 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,18 @@

## 0.3.0

#### 🚀 Updates

- Will now attempt to install `rustup` if it does not exist on the current machine.

#### 🐞 Fixes

- Will now respect the `RUSTUP_HOME` environment variable when locating the `.rustup` store.

#### ⚙️ Internal

- Updated dependencies.

## 0.2.3

#### 🐞 Fixes
Expand Down
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ crate-type = ['cdylib']
extism-pdk = "0.3.4"
proto_pdk = { version = "0.7.7" } # , path = "../../proto/crates/pdk" }
serde = "1.0.188"
toml = "0.8.0"
toml = "0.8.1"

[dev-dependencies]
proto_pdk_test_utils = { version = "0.8.0" } # , path = "../../proto/crates/pdk-test-utils" }
Expand Down
34 changes: 29 additions & 5 deletions src/proto.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,35 @@ pub fn native_install(
) -> FnResult<Json<NativeInstallOutput>> {
let env = get_proto_environment()?;

// Check if rustup is installed (returns `Err` otherwise)
// Install rustup if it does not exist
if !command_exists(&env, "rustup") {
return err!(
"proto requires `rustup` to be installed and available on PATH to use Rust. Please install it and try again."
);
host_log!("Installing rustup");

let is_windows = env.os.is_windows();
let script_path = PathBuf::from("/proto/temp").join(if is_windows {
"rustup-init.exe"
} else {
"rustup-init.sh"
});

if !script_path.exists() {
fs::write(
&script_path,
fetch_url_text(if is_windows {
"https://win.rustup.rs"
} else {
"https://sh.rustup.rs"
})?,
)?;
}

exec_command!(ExecCommandInput {
command: script_path.to_string_lossy().to_string(),
args: vec!["--default-toolchain".into(), "none".into(), "-y".into()],
set_executable: true,
stream: true,
..ExecCommandInput::default()
});
}

let channel = if input.context.version == "canary" {
Expand All @@ -58,7 +82,7 @@ pub fn native_install(

let triple = format!("{}-{}", channel, get_target_triple(&env, NAME)?);

host_log!("Installing target \"{}\" with rustup", triple);
host_log!("Installing target {} with rustup", triple);

// Install if not already installed
let installed_list = exec_command!(pipe, "rustup", ["toolchain", "list"]);
Expand Down