From 7ab17d7a4e7edf9e2d581653067399dea79bbe07 Mon Sep 17 00:00:00 2001 From: Corwin Date: Sat, 3 Jul 2021 16:33:15 +0000 Subject: [PATCH] build mgba --- mgba-test-runner/build-mgba.sh | 16 ++++++++++++++++ mgba-test-runner/build.rs | 35 +++++++++++++++++----------------- 2 files changed, 33 insertions(+), 18 deletions(-) create mode 100644 mgba-test-runner/build-mgba.sh diff --git a/mgba-test-runner/build-mgba.sh b/mgba-test-runner/build-mgba.sh new file mode 100644 index 00000000..d291e68b --- /dev/null +++ b/mgba-test-runner/build-mgba.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +MGBA_VERSION=$1 +OUT_DIRECTORY=$2 + +cd ${OUT_DIRECTORY} +curl -L https://github.com/mgba-emu/mgba/archive/refs/tags/${MGBA_VERSION}.tar.gz -o mgba-${MGBA_VERSION}.tar.gz +tar -xvf mgba-${MGBA_VERSION}.tar.gz +cd mgba-${MGBA_VERSION} +rm -rf build +mkdir -p build +cd build +cmake .. -DBUILD_STATIC=ON -DBUILD_SHARED=OFF -DDISABLE_FRONTENDS=ON -DBUILD_GL=OFF -DBUILD_GLES2=OFF -DUSE_DISCORD_RPC=OFF -DUSE_PNG=OFF +make + +cp libmgba.a ../../libmgba-cycle.a diff --git a/mgba-test-runner/build.rs b/mgba-test-runner/build.rs index cfac7ae1..c89d6c21 100644 --- a/mgba-test-runner/build.rs +++ b/mgba-test-runner/build.rs @@ -1,25 +1,25 @@ -use std::{ - env, - path::{self, PathBuf}, -}; +use std::{env, path::PathBuf}; -fn find_mgba_library() -> Option<&'static str> { - const POTENTIAL_LIBRARY_LOCATIONS: &[&str] = - &["/usr/lib/libmgba.so.0.9", "/usr/local/lib/libmgba.so.0.9"]; - - POTENTIAL_LIBRARY_LOCATIONS - .iter() - .find(|file_path| path::Path::new(file_path).exists()) - .copied() -} +const MGBA_VERSION: &str = "0.9.1"; fn main() { - let mgba_library = find_mgba_library().expect("Need mgba 0.9 installed"); + let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); + let mgba_directory = out_path.join(format!("mgba-{}", MGBA_VERSION)); + std::process::Command::new("bash") + .arg("build-mgba.sh") + .arg(MGBA_VERSION) + .arg(&out_path) + .output() + .expect("should be able to build mgba"); + println!("cargo:rustc-link-search={}", out_path.to_str().unwrap()); + println!("cargo:rustc-link-lib=static={}", "mgba-cycle"); + println!("cargo:rustc-link-lib=z"); + println!("cargo:rustc-link-lib=elf"); cc::Build::new() .file("c/test-runner.c") - .object(mgba_library) - .include("c/vendor") + .include(&mgba_directory.join("include")) + .static_flag(true) .compile("test-runner"); let bindings = bindgen::Builder::default() @@ -27,8 +27,7 @@ fn main() { .generate() .expect("Unable to generate bindings"); - let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); bindings - .write_to_file(out_path.join("runner-bindings.rs")) + .write_to_file(&out_path.join("runner-bindings.rs")) .expect("Couldn't write bindings!"); }