Browse Source

Always link ctru, for now

Also add a little extra description helper for unknown error types in
ctru::error
pull/141/head
Ian Chamberlain 1 year ago
parent
commit
7d201d825b
No known key found for this signature in database
GPG Key ID: AE5484D09405AA60
  1. 8
      ctru-rs/src/error.rs
  2. 4
      ctru-sys/Cargo.toml
  3. 23
      ctru-sys/build.rs
  4. 10
      ctru-sys/src/lib.rs

8
ctru-rs/src/error.rs

@ -256,7 +256,13 @@ fn result_code_description_str(result: ctru_sys::Result) -> Cow<'static, str> {
RD_NOT_AUTHORIZED => "not_authorized", RD_NOT_AUTHORIZED => "not_authorized",
RD_TOO_LARGE => "too_large", RD_TOO_LARGE => "too_large",
RD_INVALID_SELECTION => "invalid_selection", RD_INVALID_SELECTION => "invalid_selection",
code => return Cow::Owned(format!("(unknown description: {code:#x})")), code => {
let error = unsafe { CStr::from_ptr(ctru_sys::osStrError(result)) }.to_str();
match error {
Ok(err) => err,
Err(_) => return Cow::Owned(format!("(unknown description: {code:#x})")),
}
}
}) })
} }

4
ctru-sys/Cargo.toml

@ -21,6 +21,10 @@ doxygen-rs = "0.4.2"
itertools = "0.11.0" itertools = "0.11.0"
which = "4.4.0" which = "4.4.0"
[dev-dependencies]
shim-3ds = { git = "https://github.com/rust3ds/shim-3ds.git" }
test-runner = { git = "https://github.com/rust3ds/test-runner.git" }
[package.metadata.docs.rs] [package.metadata.docs.rs]
default-target = "armv6k-nintendo-3ds" default-target = "armv6k-nintendo-3ds"
targets = [] targets = []

23
ctru-sys/build.rs

@ -19,19 +19,28 @@ impl ParseCallbacks for CustomCallbacks {
fn main() { fn main() {
let devkitpro = env::var("DEVKITPRO").unwrap(); let devkitpro = env::var("DEVKITPRO").unwrap();
let devkitarm = env::var("DEVKITARM").unwrap(); let devkitarm = env::var("DEVKITARM").unwrap();
let profile = env::var("PROFILE").unwrap(); let debuginfo = env::var("DEBUG").unwrap();
let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap()); let out_dir = PathBuf::from(env::var("OUT_DIR").unwrap());
println!("cargo:rerun-if-changed=build.rs"); println!("cargo:rerun-if-changed=build.rs");
println!("cargo:rerun-if-env-changed=DEVKITPRO"); println!("cargo:rerun-if-env-changed=DEVKITPRO");
println!("cargo:rustc-link-search=native={devkitpro}/libctru/lib"); println!("cargo:rustc-link-search=native={devkitpro}/libctru/lib");
println!(
"cargo:rustc-link-lib=static={}", let linked_libctru = match debuginfo.as_str() {
match profile.as_str() { // Normally this should just be "true" or "false", but just in case,
"debug" => "ctrud", // we don't support all the different options documented in
// https://doc.rust-lang.org/cargo/reference/profiles.html#debug
// so just default to linking with debuginfo if it wasn't disabled
"0" | "false" | "none" => "ctru",
// TODO https://github.com/rust3ds/cargo-3ds/issues/14#issuecomment-1783991872
// To link properly, this must be the same as the library linked by cargo-3ds
// building the standard library, which is always `ctru` in practice.
// Ideally we should link `ctrud` if debug symbols are requested though:
_ => "ctru", _ => "ctru",
} // _ => "ctrud",
); };
println!("cargo:rustc-link-lib=static={linked_libctru}");
detect_and_track_libctru(); detect_and_track_libctru();

10
ctru-sys/src/lib.rs

@ -3,6 +3,8 @@
#![allow(non_camel_case_types)] #![allow(non_camel_case_types)]
#![allow(non_snake_case)] #![allow(non_snake_case)]
#![allow(clippy::all)] #![allow(clippy::all)]
#![cfg_attr(test, feature(custom_test_frameworks))]
#![cfg_attr(test, test_runner(test_runner::run_gdb))]
pub mod result; pub mod result;
pub use result::*; pub use result::*;
@ -15,10 +17,6 @@ pub unsafe fn errno() -> s32 {
*__errno() *__errno()
} }
// TODO: not sure if there's a better way to do this, but I have gotten myself // Prevent linking errors from the standard `test` library when running `cargo 3ds test --lib`.
// with this a couple times so having the hint seems nice to have.
#[cfg(test)] #[cfg(test)]
compile_error!(concat!( extern crate shim_3ds;
"ctru-sys doesn't have tests and its lib test will fail to build at link time. ",
"Try specifying `--package ctru-rs` to build those tests.",
));

Loading…
Cancel
Save