Skip to content

Commit

Permalink
feat: allow windows to build with either visual studio 2022 or visual…
Browse files Browse the repository at this point in the history
… studio 2019 (#74)

* Fix Windows build

Will work on either `Visual Studio 17 2022` or `Visual Studio 16 2019`

* CI review

* clippy

* clippy
  • Loading branch information
hansieodendaal authored Nov 13, 2024
1 parent e3ab65c commit 56b408d
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repository = "https://github.com/tari-project/randomx-rs"
homepage = "https://tari.com"
readme = "README.md"
license = "BSD-3-Clause"
version = "1.3.1"
version = "1.3.2"
edition = "2018"
build = "build.rs"

Expand Down
59 changes: 52 additions & 7 deletions build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,61 @@ fn main() {
let target = env::var("TARGET").unwrap();
// println!("target: {}", target);
if host.contains("windows") && target.contains("windows-msvc") {
let c = Command::new("cmake")
let mut err_1 = "".to_string();
let mut err_2 = "".to_string();
let mut err_3 = "".to_string();
let mut success = false;
if let Ok(val) = Command::new("cmake")
.arg("-G")
.arg("Visual Studio 16 2019")
.arg("Visual Studio 17 2022")
.arg(repo_dir.to_str().unwrap())
.output()
.expect("failed to execute CMake");
println!("status: {}", c.status);
std::io::stdout().write_all(&c.stdout).unwrap();
std::io::stderr().write_all(&c.stderr).unwrap();
assert!(c.status.success());
{
if val.status.success() {
success = true;
} else {
err_1 = String::from_utf8_lossy(&val.stderr).to_string();
}
}
if !success {
println!("'Visual Studio 17 2022' not found, trying 'Visual Studio 16 2019'");

// Remove all files (contents) from 'build_dir', but not 'build_dir' itself
if let Ok(dir_list) = fs::read_dir(build_dir) {
for entry in dir_list.flatten() {
let path = entry.path();
if path.is_file() {
let _unused = fs::remove_file(path);
} else if path.is_dir() {
let _unused = fs::remove_dir_all(path);
} else {
// Nothing here
}
}
}

match Command::new("cmake")
.arg("-G")
.arg("Visual Studio 16 2019")
.arg(repo_dir.to_str().unwrap())
.output()
{
Ok(val) => {
if val.status.success() {
success = true;
} else {
err_2 = String::from_utf8_lossy(&val.stderr).to_string();
}
},
Err(err) => err_3 = err.to_string(),
}
}
if !success {
panic!(
"CMake failed with either Visual Studio 2022 (\n{}\n) or 'Visual Studio 16 2019' (\n{}\n) or (\n{}\n)",
err_1, err_2, err_3
);
}

let m = Command::new("cmake")
.arg("--build")
Expand Down

0 comments on commit 56b408d

Please sign in to comment.