From df4a074b6bdba1255c4423d23abe77ef5364257f Mon Sep 17 00:00:00 2001 From: vincent Date: Thu, 4 Feb 2021 15:27:38 +0800 Subject: [PATCH] rust: use git clone evmc source before build and link loader --- bindings/rust/evmc-client/build.rs | 39 +++++++++++++++++++++++++++--- 1 file changed, 35 insertions(+), 4 deletions(-) diff --git a/bindings/rust/evmc-client/build.rs b/bindings/rust/evmc-client/build.rs index 07b68b437..02f7be8fb 100644 --- a/bindings/rust/evmc-client/build.rs +++ b/bindings/rust/evmc-client/build.rs @@ -14,17 +14,48 @@ // You should have received a copy of the GNU Affero General Public License // along with this program. If not, see . -use std::path::Path; +use std::env; +use std::path::{Path, PathBuf}; +use std::process::Command; extern crate cmake; use cmake::Config; -fn build_link_evmc_tools() { - let dst = Config::new("../../../").build(); +macro_rules! get(($name:expr) => (ok!(env::var($name)))); +macro_rules! ok(($expression:expr) => ($expression.unwrap())); + +const REPOSITORY: &'static str = "https://github.com/second-state/evmc.git"; +const TAG: &'static str = "v7.4.0-rust-evmc-client-rc.2"; + +fn run(name: &str, mut configure: F) +where + F: FnMut(&mut Command) -> &mut Command, +{ + let mut command = Command::new(name); + let configured = configure(&mut command); + if !ok!(configured.status()).success() { + panic!("failed to execute {:?}", configured); + } +} + +fn build_from_src() { + let source = PathBuf::from(&get!("CARGO_MANIFEST_DIR")).join(format!("target/evmc-{}", TAG)); + if !Path::new(&source.join(".git")).exists() { + run("git", |command| { + command + .arg("clone") + .arg(format!("--branch={}", TAG)) + .arg("--recursive") + .arg(REPOSITORY) + .arg(&source) + }); + } + + let dst = Config::new(source).build(); let evmc_path = Path::new(&dst).join("build/lib/loader"); println!("cargo:rustc-link-search=native={}", evmc_path.display()); println!("cargo:rustc-link-lib=static=evmc-loader"); } fn main() { - build_link_evmc_tools(); + build_from_src(); }