Merge pull request #96 from agbrs/test-runner-char

change to use c_char for arm compat
This commit is contained in:
Corwin 2021-08-01 20:01:23 +01:00 committed by GitHub
commit c5dd1ada6c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 15 additions and 170 deletions

View file

@ -2,12 +2,6 @@
# It is not intended for manual editing. # It is not intended for manual editing.
version = 3 version = 3
[[package]]
name = "adler"
version = "1.0.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe"
[[package]] [[package]]
name = "adler32" name = "adler32"
version = "1.2.0" version = "1.2.0"
@ -161,50 +155,6 @@ dependencies = [
"cfg-if", "cfg-if",
] ]
[[package]]
name = "crossbeam-channel"
version = "0.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "06ed27e177f16d65f0f0c22a213e17c696ace5dd64b14258b52f9417ccb52db4"
dependencies = [
"cfg-if",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-deque"
version = "0.8.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "94af6efb46fef72616855b036a624cf27ba656ffc9be1b9a3c931cfc7749a9a9"
dependencies = [
"cfg-if",
"crossbeam-epoch",
"crossbeam-utils",
]
[[package]]
name = "crossbeam-epoch"
version = "0.9.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4ec02e091aa634e2c3ada4a392989e7c3116673ef0ac5b72232439094d73b7fd"
dependencies = [
"cfg-if",
"crossbeam-utils",
"lazy_static",
"memoffset",
"scopeguard",
]
[[package]]
name = "crossbeam-utils"
version = "0.8.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d82cfc11ce7f2c3faef78d8a684447b40d503d9681acebed6cb728d45940c4db"
dependencies = [
"cfg-if",
"lazy_static",
]
[[package]] [[package]]
name = "deflate" name = "deflate"
version = "0.8.6" version = "0.8.6"
@ -215,12 +165,6 @@ dependencies = [
"byteorder", "byteorder",
] ]
[[package]]
name = "either"
version = "1.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e78d4f1cc4ae33bbfc157ed5d5a5ef3bc29227303d595861deb238fcec4e9457"
[[package]] [[package]]
name = "env_logger" name = "env_logger"
version = "0.8.4" version = "0.8.4"
@ -234,16 +178,6 @@ dependencies = [
"termcolor", "termcolor",
] ]
[[package]]
name = "gif"
version = "0.11.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5a668f699973d0f573d15749b7002a9ac9e1f9c6b220e7b165601334c173d8de"
dependencies = [
"color_quant",
"weezl",
]
[[package]] [[package]]
name = "glob" name = "glob"
version = "0.3.0" version = "0.3.0"
@ -274,14 +208,10 @@ dependencies = [
"bytemuck", "bytemuck",
"byteorder", "byteorder",
"color_quant", "color_quant",
"gif",
"jpeg-decoder",
"num-iter", "num-iter",
"num-rational", "num-rational",
"num-traits", "num-traits",
"png", "png",
"scoped_threadpool",
"tiff",
] ]
[[package]] [[package]]
@ -293,15 +223,6 @@ dependencies = [
"libc", "libc",
] ]
[[package]]
name = "jpeg-decoder"
version = "0.1.22"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "229d53d58899083193af11e15917b5640cd40b29ff475a1fe4ef725deb02d0f2"
dependencies = [
"rayon",
]
[[package]] [[package]]
name = "lazy_static" name = "lazy_static"
version = "1.4.0" version = "1.4.0"
@ -345,15 +266,6 @@ version = "2.3.4"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525" checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
[[package]]
name = "memoffset"
version = "0.6.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9"
dependencies = [
"autocfg",
]
[[package]] [[package]]
name = "mgba-test-runner" name = "mgba-test-runner"
version = "0.1.0" version = "0.1.0"
@ -374,16 +286,6 @@ dependencies = [
"adler32", "adler32",
] ]
[[package]]
name = "miniz_oxide"
version = "0.4.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a92518e98c078586bc6c934028adcca4c92a53d6a958196de835170a01d84e4b"
dependencies = [
"adler",
"autocfg",
]
[[package]] [[package]]
name = "nom" name = "nom"
version = "5.1.2" version = "5.1.2"
@ -435,16 +337,6 @@ dependencies = [
"autocfg", "autocfg",
] ]
[[package]]
name = "num_cpus"
version = "1.13.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "05499f3756671c15885fee9034446956fff3f243d6077b91e5767df161f766b3"
dependencies = [
"hermit-abi",
"libc",
]
[[package]] [[package]]
name = "peeking_take_while" name = "peeking_take_while"
version = "0.1.2" version = "0.1.2"
@ -460,7 +352,7 @@ dependencies = [
"bitflags", "bitflags",
"crc32fast", "crc32fast",
"deflate", "deflate",
"miniz_oxide 0.3.7", "miniz_oxide",
] ]
[[package]] [[package]]
@ -481,31 +373,6 @@ dependencies = [
"proc-macro2", "proc-macro2",
] ]
[[package]]
name = "rayon"
version = "1.5.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c06aca804d41dbc8ba42dfd964f0d01334eceb64314b9ecf7c5fad5188a06d90"
dependencies = [
"autocfg",
"crossbeam-deque",
"either",
"rayon-core",
]
[[package]]
name = "rayon-core"
version = "1.9.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d78120e2c850279833f1dd3582f730c4ab53ed95aeaaaa862a2a5c71b1656d8e"
dependencies = [
"crossbeam-channel",
"crossbeam-deque",
"crossbeam-utils",
"lazy_static",
"num_cpus",
]
[[package]] [[package]]
name = "regex" name = "regex"
version = "1.4.5" version = "1.4.5"
@ -529,18 +396,6 @@ version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2" checksum = "08d43f7aa6b08d49f382cde6a7982047c3426db949b1424bc4b7ec9ae12c6ce2"
[[package]]
name = "scoped_threadpool"
version = "0.1.9"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1d51f5df5af43ab3f1360b429fa5e0152ac5ce8c0bd6485cae490332e96846a8"
[[package]]
name = "scopeguard"
version = "1.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d29ab0c6d3fc0ee92fe66e2d99f700eab17a8d57d1c1d3b748380fb20baa78cd"
[[package]] [[package]]
name = "shlex" name = "shlex"
version = "1.0.0" version = "1.0.0"
@ -571,17 +426,6 @@ dependencies = [
"unicode-width", "unicode-width",
] ]
[[package]]
name = "tiff"
version = "0.6.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9a53f4706d65497df0c4349241deddf35f84cee19c87ed86ea8ca590f4464437"
dependencies = [
"jpeg-decoder",
"miniz_oxide 0.4.4",
"weezl",
]
[[package]] [[package]]
name = "unicode-width" name = "unicode-width"
version = "0.1.8" version = "0.1.8"
@ -606,12 +450,6 @@ version = "0.9.3"
source = "registry+https://github.com/rust-lang/crates.io-index" source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe" checksum = "5fecdca9a5291cc2b8dcf7dc02453fee791a280f3743cb0905f8822ae463b3fe"
[[package]]
name = "weezl"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d8b77fdfd5a253be4ab714e4ffa3c49caf146b4de743e97510c0656cf90f1e8e"
[[package]] [[package]]
name = "which" name = "which"
version = "3.1.1" version = "3.1.1"

View file

@ -12,7 +12,7 @@ debug = true
[dependencies] [dependencies]
regex = "1" regex = "1"
anyhow = "1.0" anyhow = "1.0"
image = "0.23" image = { version = "0.23.14", default-features = false, features = [ "png", "bmp" ] }
[build-dependencies] [build-dependencies]
cc = { version = "1.0", features = ["parallel"] } cc = { version = "1.0", features = ["parallel"] }

View file

@ -5,12 +5,18 @@ const MGBA_VERSION: &str = "0.9.1";
fn main() { fn main() {
let out_path = PathBuf::from(env::var("OUT_DIR").unwrap()); let out_path = PathBuf::from(env::var("OUT_DIR").unwrap());
let mgba_directory = out_path.join(format!("mgba-{}", MGBA_VERSION)); let mgba_directory = out_path.join(format!("mgba-{}", MGBA_VERSION));
std::process::Command::new("bash") let out = std::process::Command::new("bash")
.arg("build-mgba.sh") .arg("build-mgba.sh")
.arg(MGBA_VERSION) .arg(MGBA_VERSION)
.arg(&out_path) .arg(&out_path)
.output() .output()
.expect("should be able to build mgba"); .expect("should be able to build mgba");
if !out.status.success() {
panic!(
"failed to build mgba!\n{}",
String::from_utf8_lossy(&out.stderr),
);
}
println!("cargo:rustc-link-search={}", out_path.to_str().unwrap()); println!("cargo:rustc-link-search={}", out_path.to_str().unwrap());
println!("cargo:rustc-link-lib=static={}", "mgba-cycle"); println!("cargo:rustc-link-lib=static={}", "mgba-cycle");
println!("cargo:rustc-link-lib=elf"); println!("cargo:rustc-link-lib=elf");

View file

@ -1,6 +1,7 @@
use std::ffi::c_void; use std::ffi::c_void;
use std::ffi::CStr; use std::ffi::CStr;
use std::ffi::CString; use std::ffi::CString;
use std::os::raw::c_char;
#[allow( #[allow(
non_upper_case_globals, non_upper_case_globals,
@ -37,7 +38,7 @@ impl VideoBuffer {
impl MGBA { impl MGBA {
pub fn new(filename: &str) -> Result<Self, anyhow::Error> { pub fn new(filename: &str) -> Result<Self, anyhow::Error> {
let c_str = CString::new(filename).expect("should be able to make cstring from filename"); let c_str = CString::new(filename).expect("should be able to make cstring from filename");
let mgba = unsafe { bindings::new_runner(c_str.as_ptr() as *mut i8) }; let mgba = unsafe { bindings::new_runner(c_str.as_ptr() as *mut c_char) };
if mgba.is_null() { if mgba.is_null() {
Err(anyhow::anyhow!("could not create core")) Err(anyhow::anyhow!("could not create core"))
} else { } else {
@ -59,7 +60,7 @@ impl MGBA {
} }
pub fn set_logger(&mut self, mut logger: impl FnMut(&str)) { pub fn set_logger(&mut self, mut logger: impl FnMut(&str)) {
unsafe { unsafe {
let callback = generate_c_callback(move |message: *mut i8| { let callback = generate_c_callback(move |message: *mut c_char| {
logger( logger(
CStr::from_ptr(message) CStr::from_ptr(message)
.to_str() .to_str()
@ -73,7 +74,7 @@ impl MGBA {
unsafe fn generate_c_callback<F>(f: F) -> bindings::callback unsafe fn generate_c_callback<F>(f: F) -> bindings::callback
where where
F: FnMut(*mut i8), F: FnMut(*mut c_char),
{ {
let data = Box::into_raw(Box::new(f)); let data = Box::into_raw(Box::new(f));
@ -84,9 +85,9 @@ where
} }
} }
extern "C" fn call_closure<F>(data: *mut c_void, message: *mut i8) extern "C" fn call_closure<F>(data: *mut c_void, message: *mut c_char)
where where
F: FnMut(*mut i8), F: FnMut(*mut c_char),
{ {
let callback_ptr = data as *mut F; let callback_ptr = data as *mut F;
let callback = unsafe { &mut *callback_ptr }; let callback = unsafe { &mut *callback_ptr };