From 0813351f1f3b5d50bfecbaa43f738b5a72c0cb64 Mon Sep 17 00:00:00 2001 From: Luke Parker Date: Sun, 15 Sep 2024 00:57:43 -0400 Subject: [PATCH] OUT_DIR > artifacts --- Cargo.lock | 2 +- networks/ethereum/build-contracts/Cargo.toml | 2 +- networks/ethereum/build-contracts/src/lib.rs | 4 ++-- networks/ethereum/schnorr/Cargo.toml | 2 +- networks/ethereum/schnorr/build.rs | 8 +++++++- networks/ethereum/schnorr/src/lib.rs | 3 ++- networks/ethereum/schnorr/src/tests.rs | 19 +++++++++++++------ 7 files changed, 27 insertions(+), 13 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 353206e9..1338ae26 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1320,7 +1320,7 @@ dependencies = [ [[package]] name = "build-solidity-contracts" -version = "0.1.0" +version = "0.1.1" [[package]] name = "bumpalo" diff --git a/networks/ethereum/build-contracts/Cargo.toml b/networks/ethereum/build-contracts/Cargo.toml index cb47a28d..41d1f993 100644 --- a/networks/ethereum/build-contracts/Cargo.toml +++ b/networks/ethereum/build-contracts/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "build-solidity-contracts" -version = "0.1.0" +version = "0.1.1" description = "A helper function to build Solidity contracts" license = "MIT" repository = "https://github.com/serai-dex/serai/tree/develop/networks/ethereum/build-contracts" diff --git a/networks/ethereum/build-contracts/src/lib.rs b/networks/ethereum/build-contracts/src/lib.rs index 93ab253e..4fee315a 100644 --- a/networks/ethereum/build-contracts/src/lib.rs +++ b/networks/ethereum/build-contracts/src/lib.rs @@ -4,7 +4,7 @@ use std::{path::PathBuf, fs, process::Command}; -/// Build contracts placed in `contracts/`, outputting to `artifacts/`. +/// Build contracts from the specified path, outputting the artifacts to the specified path. /// /// Requires solc 0.8.25. pub fn build(contracts_path: &str, artifacts_path: &str) -> Result<(), String> { @@ -33,7 +33,7 @@ pub fn build(contracts_path: &str, artifacts_path: &str) -> Result<(), String> { #[rustfmt::skip] let args = [ "--base-path", ".", - "-o", "./artifacts", "--overwrite", + "-o", artifacts_path, "--overwrite", "--bin", "--bin-runtime", "--abi", "--via-ir", "--optimize", "--no-color", diff --git a/networks/ethereum/schnorr/Cargo.toml b/networks/ethereum/schnorr/Cargo.toml index d9bb77b0..5c9c1596 100644 --- a/networks/ethereum/schnorr/Cargo.toml +++ b/networks/ethereum/schnorr/Cargo.toml @@ -6,7 +6,7 @@ license = "AGPL-3.0-only" repository = "https://github.com/serai-dex/serai/tree/develop/networks/ethereum/schnorr" authors = ["Luke Parker ", "Elizabeth Binks "] edition = "2021" -rust-version = "1.79" +rust-version = "1.81" [package.metadata.docs.rs] all-features = true diff --git a/networks/ethereum/schnorr/build.rs b/networks/ethereum/schnorr/build.rs index 8e310b60..300f8949 100644 --- a/networks/ethereum/schnorr/build.rs +++ b/networks/ethereum/schnorr/build.rs @@ -1,3 +1,9 @@ +use std::{env, fs}; + fn main() { - build_solidity_contracts::build("contracts", "artifacts").unwrap(); + let artifacts_path = env::var("OUT_DIR").unwrap().to_string() + "/ethereum-schnorr-contract"; + if !fs::exists(&artifacts_path).unwrap() { + fs::create_dir(&artifacts_path).unwrap(); + } + build_solidity_contracts::build("contracts", &artifacts_path).unwrap(); } diff --git a/networks/ethereum/schnorr/src/lib.rs b/networks/ethereum/schnorr/src/lib.rs index 79e2e094..3f67fbbf 100644 --- a/networks/ethereum/schnorr/src/lib.rs +++ b/networks/ethereum/schnorr/src/lib.rs @@ -4,7 +4,8 @@ #![allow(non_snake_case)] /// The initialization bytecode of the Schnorr library. -pub const INIT_BYTECODE: &str = include_str!("../artifacts/Schnorr.bin"); +pub const INIT_BYTECODE: &str = + include_str!(concat!(env!("OUT_DIR"), "/ethereum-schnorr-contract/Schnorr.bin")); mod public_key; pub use public_key::PublicKey; diff --git a/networks/ethereum/schnorr/src/tests.rs b/networks/ethereum/schnorr/src/tests.rs index 1c3509cc..62bb8542 100644 --- a/networks/ethereum/schnorr/src/tests.rs +++ b/networks/ethereum/schnorr/src/tests.rs @@ -17,11 +17,11 @@ use alloy_node_bindings::{Anvil, AnvilInstance}; use crate::{PublicKey, Signature}; -#[allow(warnings)] -#[allow(needless_pass_by_value)] -#[allow(clippy::all)] -#[allow(clippy::ignored_unit_patterns)] -#[allow(clippy::redundant_closure_for_method_calls)] +#[expect(warnings)] +#[expect(needless_pass_by_value)] +#[expect(clippy::all)] +#[expect(clippy::ignored_unit_patterns)] +#[expect(clippy::redundant_closure_for_method_calls)] mod abi { alloy_sol_types::sol!("contracts/tests/Schnorr.sol"); pub(crate) use TestSchnorr::*; @@ -40,7 +40,14 @@ async fn setup_test() -> (AnvilInstance, Arc>, Addre let _: () = provider .raw_request( "anvil_setCode".into(), - [address.to_string(), include_str!("../artifacts/TestSchnorr.bin-runtime").to_string()], + [ + address.to_string(), + include_str!(concat!( + env!("OUT_DIR"), + "/ethereum-schnorr-contract/TestSchnorr.bin-runtime" + )) + .to_string(), + ], ) .await .unwrap();