Skip to content

Commit

Permalink
Made fastauth test builds during compile-time
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaoticTempest committed May 29, 2024
1 parent a0119e3 commit 3939d63
Show file tree
Hide file tree
Showing 3 changed files with 87 additions and 8 deletions.
5 changes: 5 additions & 0 deletions integration-tests/fastauth/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ mpc-recovery = { path = "../../mpc-recovery" }
[dev-dependencies]
test-log = { version = "0.2.12", features = ["log", "trace"] }

[build-dependencies]
anyhow = "1"
async-process = "1"
tokio = { version = "1", features = ["full"] }


[workspace] # used to ignore higher level workspace

Expand Down
85 changes: 82 additions & 3 deletions integration-tests/fastauth/build.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,82 @@
// HACK: need this build script so that env var OUT_DIR gets set:
// https://doc.rust-lang.org/cargo/reference/environment-variables.html#environment-variables-cargo-sets-for-crates
fn main() {}
use std::path::Path;
use std::{env, io};

use anyhow::Context;
use async_process::{Command, ExitStatus, Stdio};

const PACKAGE: &str = "mpc-recovery";
const TARGET_FOLDER: &str = "target";

fn target_dir() -> io::Result<std::path::PathBuf> {
let out_dir = env::var("OUT_DIR").map_err(|err| {
io::Error::new(
io::ErrorKind::NotFound,
format!("could not find OUT_DIR environment variable: {err:?}"),
)
})?;
let mut out_dir = Path::new(&out_dir);
loop {
if out_dir.ends_with(TARGET_FOLDER) {
break Ok(out_dir.to_path_buf());
}

match out_dir.parent() {
Some(parent) => out_dir = parent,
// We've reached the root directory and didn't find "target"
None => {
break Err(io::Error::new(
io::ErrorKind::NotFound,
"could not find /target",
))
}
}
}
}

async fn build_package(
release: bool,
package: &str,
target_dir: Option<impl AsRef<Path>>,
) -> anyhow::Result<ExitStatus> {
let mut cmd = Command::new("cargo");
cmd.arg("build")
.arg("--package")
.arg(package)
.envs(std::env::vars())
.stdout(Stdio::inherit())
.stderr(Stdio::inherit());

if release {
cmd.arg("--release");
}

if let Some(target_dir) = target_dir {
cmd.arg("--target-dir").arg(target_dir.as_ref().as_os_str());
}

Ok(cmd.spawn()?.status().await?)
}

pub async fn build_mpc(release: bool) -> anyhow::Result<ExitStatus> {
build_package(
release,
PACKAGE,
Some(target_dir().context("could not find /target while building mpc-recovery")?),
)
.await
}

fn main() -> anyhow::Result<()> {
println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-changed=../../mpc-recovery/");

#[cfg(not(feature = "flamegraph"))]
{
let release = true;
let rt = tokio::runtime::Runtime::new().unwrap();
rt.block_on(async {
build_mpc(release).await?;
Ok(())
})
}
}
5 changes: 0 additions & 5 deletions integration-tests/fastauth/src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,6 @@ pub struct Context<'a> {

pub async fn setup(docker_client: &DockerClient) -> anyhow::Result<Context<'_>> {
let release = true;
#[cfg(not(feature = "flamegraph"))]
if !crate::mpc::build(release).await?.success() {
anyhow::bail!("failed to prebuild MPC service");
}

let gcp_project_id = GCP_PROJECT_ID;
let docker_network = NETWORK;
docker_client.create_network(docker_network).await?;
Expand Down

0 comments on commit 3939d63

Please sign in to comment.