#![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;
mod ne10;
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,
};
pub use ne10::{
ne10_fft_alloc_r2c_float32, ne10_fft_c2r_1d_float32_neon, ne10_fft_cpx_float32_t,
ne10_fft_destroy_r2c_float32, ne10_fft_r2c_1d_float32_neon, ne10_fft_r2c_state_float32_t,
};
#[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-unknown-linux-gnu-gcc",
"aarch64-linux-gnu-gcc"
),
Ok("clang++".to_owned()),
"an explicit C++ compiler outranks anything derived, even a resolved linker"
);
}
#[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 a_resolved_gcc_linker_answers_for_the_shim_too() {
assert_eq!(
shim_compiler_from("", "aarch64-unknown-linux-gnu-gcc", ""),
Ok("aarch64-unknown-linux-gnu-g++".to_owned())
);
assert_eq!(shim_compiler_from("", "gcc", ""), Ok("g++".to_owned()));
}
#[test]
fn a_resolved_linker_outranks_a_stale_bela_cc() {
assert_eq!(
shim_compiler_from("", "aarch64-unknown-linux-gnu-gcc", "gcc"),
Ok("aarch64-unknown-linux-gnu-g++".to_owned())
);
}
#[test]
fn the_wrapper_as_the_resolved_linker_falls_through_to_bela_cc() {
assert_eq!(
shim_compiler_from("", "scripts/aarch64-bela-linker.sh", "gcc"),
Ok("g++".to_owned())
);
assert_eq!(
shim_compiler_from(
"",
"/Users/dev/bela-rs/scripts/aarch64-bela-linker.sh",
"aarch64-linux-gnu-gcc"
),
Ok("aarch64-linux-gnu-g++".to_owned()),
"an absolute path still matches by its last segment"
);
assert_eq!(
shim_compiler_from("", "scripts/aarch64-bela-linker.sh", ""),
Ok(DEFAULT_CXX.to_owned()),
"and with BELA_CC unset too, the tap default"
);
}
#[test]
fn the_abi_check_takes_the_c_compiler_as_it_stands() {
assert_eq!(
abi_compiler_from("aarch64-linux-gnu-gcc", "", "clang++"),
Some("aarch64-linux-gnu-gcc".to_owned())
);
}
#[test]
fn the_abi_check_follows_the_resolved_linker() {
assert_eq!(
abi_compiler_from("", "aarch64-unknown-linux-gnu-gcc", ""),
Some("aarch64-unknown-linux-gnu-gcc".to_owned())
);
assert_eq!(
abi_compiler_from("gcc", "scripts/aarch64-bela-linker.sh", ""),
Some("gcc".to_owned()),
"the wrapper names no compiler of its own, so BELA_CC answers"
);
}
#[test]
fn the_abi_check_derives_a_c_compiler_from_a_cxx_one() {
assert_eq!(
abi_compiler_from("", "", "aarch64-linux-gnu-g++"),
Some("aarch64-linux-gnu-gcc".to_owned())
);
assert_eq!(
abi_compiler_from("", "", "clang++"),
Some("clang".to_owned())
);
assert_eq!(
abi_compiler_from("", "", ""),
Some("aarch64-unknown-linux-gnu-gcc".to_owned()),
"with nothing set, the tap's C compiler beside DEFAULT_CXX"
);
}
#[test]
fn a_cxx_compiler_nothing_follows_from_skips_the_abi_check() {
assert_eq!(abi_compiler_from("", "", "my-cross-compiler"), None);
}
#[test]
fn the_abi_archiver_follows_a_gcc_name() {
assert_eq!(
abi_archiver("aarch64-linux-gnu-gcc"),
Some("aarch64-linux-gnu-ar".to_owned())
);
assert_eq!(abi_archiver("gcc"), Some("ar".to_owned()));
assert_eq!(
abi_archiver("clang"),
None,
"clang wants llvm-ar, not an ar beside it; cc resolves that"
);
}
#[test]
fn a_resolved_linker_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 link_args {
extern crate std;
use std::borrow::ToOwned;
use std::format;
use std::string::{String, ToString};
use std::vec;
use std::vec::Vec;
include!("../link_args.rs");
fn args(values: &[&str]) -> Vec<String> {
values.iter().map(|value| (*value).to_owned()).collect()
}
#[test]
fn no_arguments_still_publishes_a_zero_count() {
assert_eq!(
encode_link_args(&[]),
vec![("LINK_ARGS_COUNT".to_owned(), "0".to_owned())],
"a dependent has to see a count of zero, not an absent key, \
to tell \"nothing to add\" apart from \"never ran\""
);
}
#[test]
fn arguments_are_indexed_from_zero_in_order() {
assert_eq!(
encode_link_args(&args(&["--sysroot=/opt/bela", "-Bfoo"])),
vec![
("LINK_ARGS_COUNT".to_owned(), "2".to_owned()),
("LINK_ARGS_0".to_owned(), "--sysroot=/opt/bela".to_owned()),
("LINK_ARGS_1".to_owned(), "-Bfoo".to_owned()),
]
);
}
#[test]
fn whitespace_in_an_argument_survives_uninterpreted() {
let value = "--sysroot=/Volumes/Bela Sysroot";
assert_eq!(
encode_link_args(&args(&[value])),
vec![
("LINK_ARGS_COUNT".to_owned(), "1".to_owned()),
("LINK_ARGS_0".to_owned(), value.to_owned()),
]
);
}
}
#[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)
);
}
}