#![no_std]
#[allow(
missing_docs,
nonstandard_style,
unsafe_op_in_unsafe_fn,
unused,
clippy::all,
clippy::pedantic,
clippy::nursery,
clippy::restriction,
rustdoc::all,
reason = "generated by bindgen; regenerate with `cargo xtask bindgen`"
)]
mod bindings;
mod midi;
pub use bindings::*;
pub use midi::{
BELA_MIDI_ALREADY_OPEN, BELA_MIDI_MESSAGE_MAX, BELA_MIDI_NO_SUCH_PORT, BelaMidi,
bela_midi_available_messages, bela_midi_delete, bela_midi_get_message, bela_midi_list_ports,
bela_midi_new, bela_midi_read_from, bela_midi_write_output, bela_midi_write_to,
};
#[cfg(test)]
mod shim_compiler {
extern crate std;
use std::borrow::ToOwned;
use std::format;
use std::string::String;
include!("../shim_compiler.rs");
#[test]
fn bela_cxx_is_taken_as_it_stands() {
assert_eq!(
shim_compiler_from("clang++", "aarch64-linux-gnu-gcc"),
Ok("clang++".to_owned()),
"an explicit C++ compiler outranks anything derived"
);
}
#[test]
fn a_c_compiler_ending_in_gcc_answers_for_both() {
assert_eq!(
shim_compiler_from("", "aarch64-linux-gnu-gcc"),
Ok("aarch64-linux-gnu-g++".to_owned())
);
assert_eq!(shim_compiler_from("", "gcc"), Ok("g++".to_owned()));
}
#[test]
fn neither_set_is_the_tap_default() {
assert_eq!(
shim_compiler_from("", ""),
Ok(DEFAULT_CXX.to_owned()),
"the same default scripts/aarch64-bela-linker.sh has"
);
}
#[test]
fn a_c_compiler_nothing_follows_from_is_refused() {
let error = shim_compiler_from("", "clang").unwrap_err();
assert!(
error.contains("BELA_CXX"),
"the message should say what to set, got: {error}"
);
}
#[test]
fn the_archiver_follows_the_compiler_it_belongs_to() {
assert_eq!(
shim_archiver("aarch64-unknown-linux-gnu-g++"),
Some("aarch64-unknown-linux-gnu-ar".to_owned()),
"cc would otherwise look for one named after the target triple"
);
assert_eq!(shim_archiver("g++"), Some("ar".to_owned()));
}
#[test]
fn an_archiver_that_does_not_follow_is_left_to_cc() {
assert_eq!(shim_archiver("clang++"), None);
assert_eq!(shim_archiver("aarch64-linux-gnu-clang++"), None);
}
#[test]
fn a_compiler_named_by_its_path_is_still_one() {
assert_eq!(
shim_compiler_from("", "/usr/bin/gcc"),
Ok("/usr/bin/g++".to_owned())
);
assert_eq!(
shim_compiler_from("", "/opt/tc/bin/aarch64-linux-gnu-gcc"),
Ok("/opt/tc/bin/aarch64-linux-gnu-g++".to_owned())
);
assert_eq!(
shim_archiver("/usr/bin/g++"),
Some("/usr/bin/ar".to_owned()),
"and the archiver beside it"
);
}
#[test]
fn a_compiler_that_merely_ends_in_gcc_is_not_one() {
assert!(shim_compiler_from("", "notgcc").is_err());
assert_eq!(shim_archiver("notg++"), None);
assert_eq!(
shim_archiver("/usr/bin/clang++"),
None,
"a path does not make it one"
);
}
}
#[cfg(test)]
mod shim_header {
extern crate std;
use std::format;
const HEADER: &str = include_str!("../shim/midi.h");
fn defined(name: &str) -> i64 {
let line = HEADER
.lines()
.find(|line| line.starts_with(&format!("#define {name} ")))
.unwrap_or_else(|| panic!("{name} is not defined in shim/midi.h"));
let value = line.split_whitespace().nth(2).expect("a value");
value
.trim_start_matches('(')
.trim_end_matches(')')
.parse()
.expect("a number")
}
#[test]
fn the_constants_match_the_header() {
assert_eq!(
defined("BELA_MIDI_MESSAGE_MAX"),
i64::try_from(super::BELA_MIDI_MESSAGE_MAX).expect("a small buffer size")
);
assert_eq!(
defined("BELA_MIDI_NO_SUCH_PORT"),
i64::from(super::BELA_MIDI_NO_SUCH_PORT)
);
assert_eq!(
defined("BELA_MIDI_ALREADY_OPEN"),
i64::from(super::BELA_MIDI_ALREADY_OPEN)
);
}
}