Skip to content
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
4 changes: 0 additions & 4 deletions crates/apollo_compilation_utils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,3 @@ thiserror.workspace = true
apollo_infra_utils.workspace = true
assert_matches.workspace = true
rstest.workspace = true

[build-dependencies]
apollo_infra_utils.workspace = true
tempfile.workspace = true
65 changes: 0 additions & 65 deletions crates/apollo_compilation_utils/src/build_utils.rs
Original file line number Diff line number Diff line change
@@ -1,71 +1,6 @@
use std::path::Path;
use std::process::Command;

use tempfile::TempDir;

use crate::paths::{legacy_binary_path, shared_folder_dir};

pub fn install_compiler_binary(
binary_name: &str,
required_version: &str,
cargo_install_args: &[&str],
out_dir: &std::path::Path,
) {
let binary_path = legacy_binary_path(out_dir, binary_name);
match Command::new(&binary_path).args(["--version"]).output() {
Ok(binary_version) => {
let binary_version = String::from_utf8(binary_version.stdout)
.expect("Failed to convert the binary version to a string.");
if binary_version.contains(required_version) {
println!("The {binary_name} binary is up to date.");
return;
} else {
println!(
"The {binary_name} binary is not up to date. Installing the required version."
);
std::fs::remove_file(&binary_path).expect("Failed to remove the old binary.");
}
}
Err(_) => {
println!("The {binary_name} binary is not installed. Installing the required version.");
}
}

let temp_cargo_path = TempDir::new().expect("Failed to create a temporary directory.");
let post_install_file_path = temp_cargo_path.path().join("bin").join(binary_name);

let install_command_status = Command::new("cargo")
.args([
"install",
"--root",
temp_cargo_path.path().to_str().expect("Failed to convert cargo_path to str"),
"--locked",
])
.args(cargo_install_args)
.status()
.unwrap_or_else(|_| panic!("Failed to install {binary_name}"));

if !install_command_status.success() {
panic!("Failed to install {binary_name}");
}

// Move the '{binary_name}' executable to a shared location.
std::fs::create_dir_all(shared_folder_dir(out_dir))
.expect("Failed to create shared executables folder");
let move_command_status = Command::new("mv")
.args([post_install_file_path.as_os_str(), binary_path.as_os_str()])
.status()
.expect("Failed to perform mv command.");

if !move_command_status.success() {
panic!("Failed to move the {binary_name} binary to the shared folder.");
}

std::fs::remove_dir_all(temp_cargo_path).expect("Failed to remove the cargo directory.");

println!("Successfully set executable file: {:?}", binary_path.display());
}

/// Verifies that a compiler binary is installed and has the required version.
/// Panics with installation instructions if the binary is missing or has the wrong version.
///
Expand Down
17 changes: 0 additions & 17 deletions crates/apollo_compilation_utils/src/paths.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,6 @@

use std::path::PathBuf;

fn target_dir(out_dir: &std::path::Path) -> std::path::PathBuf {
out_dir
.ancestors()
.nth(3)
.expect("Failed to navigate up three levels from OUT_DIR")
.to_path_buf()
}

pub fn shared_folder_dir(out_dir: &std::path::Path) -> std::path::PathBuf {
target_dir(out_dir).join("shared_executables")
}

/// Returns `<cargo_tools_root>/<binary>-<version>/bin/<binary>`, where
/// `cargo_tools_root` resolves to `$CARGO_TOOLS_ROOT`, else `$CARGO_HOME/tools`,
/// else `$HOME/.cargo/tools`.
Expand All @@ -39,8 +27,3 @@ fn cargo_tools_root() -> PathBuf {
});
cargo_home.join("tools")
}

// TODO(Avi): Remove once build.rs callers are gone.
pub fn legacy_binary_path(out_dir: &std::path::Path, binary_name: &str) -> std::path::PathBuf {
shared_folder_dir(out_dir).join(binary_name)
}
Loading