Skip to content

Commit

Permalink
Merge pull request #4 from rust-ml/enzyme-rust
Browse files Browse the repository at this point in the history
Enzyme rust
  • Loading branch information
ZuseZ4 authored Dec 5, 2021
2 parents f9a1fd5 + f3ddf5e commit 7c66c75
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 5 deletions.
22 changes: 22 additions & 0 deletions .packaging/rust/src/downloader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,21 @@ use std::io::BufReader;
use std::path::PathBuf;
use tar::Archive;
use curl::easy::Easy;
use std::process::Command;

fn run_and_printerror(command: &mut Command) {
println!("Running: `{:?}`", command);
match command.status() {
Ok(status) => {
if !status.success() {
panic!("Failed: `{:?}` ({})", command, status);
}
}
Err(error) => {
panic!("Failed: `{:?}` ({})", command, error);
}
}
}

fn unpack(tar_gz_file: &str, dst: &str) -> Result<(), std::io::Error> {
let path = tar_gz_file;
Expand Down Expand Up @@ -76,6 +91,13 @@ pub fn download_tarball(repo_url: &str, download_filename: PathBuf) -> Result<()
}

pub fn download(to_download: &str) -> Result<(), String> {
if to_download == "enzyme" {
let mut git = Command::new("git");
let dst_dir = utils::get_enzyme_repo_path();
git.args(&["clone", "https://github.com/wsmoses/Enzyme", dst_dir.to_str().unwrap()]);
run_and_printerror(&mut git);
return Ok(());
}
let repo = match to_download {
"enzyme" => utils::get_remote_enzyme_tarball_path(),
"rustc" => utils::get_remote_rustc_tarball_path(),
Expand Down
1 change: 1 addition & 0 deletions .packaging/rust/src/generate_api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use std::fs;

pub fn generate_bindings() -> Result<(), String> {
let header_path = utils::get_capi_path();
dbg!(&header_path);

// tell cargo to re-run the builder if the header has changed
println!("cargo:rerun-if-changed={}", header_path.display());
Expand Down
4 changes: 2 additions & 2 deletions .packaging/rust/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ fn main() {
}

fn get_enzyme() -> Result<(), String> {
enzyme_build::download("rustc")?;
//enzyme_build::download("rustc")?;
enzyme_build::download("enzyme")?;
enzyme_build::build("rustc")?;
//enzyme_build::build("rustc")?;
enzyme_build::generate_bindings()?;
enzyme_build::build("enzyme")?;
Ok(())
Expand Down
11 changes: 8 additions & 3 deletions .packaging/rust/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use dirs;
use std::fs;
use std::path::PathBuf;

const ENZYME_VER: &str = "0.0.20";
const ENZYME_VER: &str = "0.0.23";
const RUSTC_VER: &str = "1.56.0";

pub fn clean_directory(path: PathBuf) {
Expand Down Expand Up @@ -31,9 +31,14 @@ pub fn get_enzyme_base_path() -> PathBuf {
dbg!(&enzyme_base_path);
enzyme_base_path
}
fn get_enzyme_subdir_path() -> PathBuf {
pub fn get_enzyme_repo_path() -> PathBuf {
let path = get_enzyme_base_path()
.join("Enzyme-".to_owned() + ENZYME_VER)
.join("Enzyme-".to_owned() + ENZYME_VER);
assert_existence(path.clone());
path
}
fn get_enzyme_subdir_path() -> PathBuf {
let path = get_enzyme_repo_path()
.join("enzyme");
assert_existence(path.clone());
path
Expand Down

0 comments on commit 7c66c75

Please sign in to comment.