Browse Source

Link pthread-3ds via Cargo instead of static lib

This fixes the panic issue (not calling `panic_count::increase`) as well
as the missing debug info. The static lib contained a second copy of the
rust std, which caused these issues.

A side effect of removing this std is that the linker fix and pthread
library modules need to be "reachable" from the main module for Rust to
link them correctly. If the init methods of the modules are not called
somewhere, then a linker error will be emitted saying some symbols are
not found. The linker fix module didn't need this before because the
std included in the pthread static lib required those symbols, so they
were included. Now that the std is linked in later, Rust thinks these
symbols are unused (hence the init method).

Also moved the linker fix to be a dependency on ctru-rs. ctru-sys should
just be about interfacing with libctru.
pull/10/head
AzureMarker 3 years ago
parent
commit
9d177faa90
No known key found for this signature in database
GPG Key ID: 47A133F3BF9D03D3
  1. 2
      ctru-rs/Cargo.toml
  2. 9
      ctru-rs/src/lib.rs
  3. 1
      ctru-sys/Cargo.toml
  4. 15
      ctru-sys/build.rs
  5. BIN
      ctru-sys/libpthread_3ds.a
  6. 1
      ctru-sys/src/lib.rs

2
ctru-rs/Cargo.toml

@ -11,6 +11,8 @@ name = "ctru"
[dependencies] [dependencies]
ctru-sys = { path = "../ctru-sys", version = "0.4" } ctru-sys = { path = "../ctru-sys", version = "0.4" }
linker-fix-3ds = { git = "https://github.com/AzureMarker/rust-linker-fix-3ds.git" }
pthread-3ds = { git = "https://github.com/AzureMarker/pthread-3ds.git" }
libc = "0.2" libc = "0.2"
bitflags = "1.0.0" bitflags = "1.0.0"
widestring = "0.2.2" widestring = "0.2.2"

9
ctru-rs/src/lib.rs

@ -8,6 +8,15 @@ extern crate widestring;
extern crate ctru_sys as libctru; extern crate ctru_sys as libctru;
/// Call this somewhere to force Rust to link some required crates
/// (ex. pthread-3ds). The call doesn't need to execute, just exist.
///
/// See https://github.com/rust-lang/rust/issues/47384
pub fn init() {
linker_fix_3ds::init();
pthread_3ds::init();
}
pub mod applets; pub mod applets;
pub mod console; pub mod console;
pub mod error; pub mod error;

1
ctru-sys/Cargo.toml

@ -7,4 +7,3 @@ links = "ctru"
[dependencies] [dependencies]
libc = { version = "0.2", default-features = false } libc = { version = "0.2", default-features = false }
linker-fix-3ds = { git = "https://github.com/Meziu/rust-linker-fix-3ds.git" }

15
ctru-sys/build.rs

@ -2,20 +2,9 @@ use std::env;
fn main() { fn main() {
let dkp_path = env::var("DEVKITPRO").unwrap(); let dkp_path = env::var("DEVKITPRO").unwrap();
let manifest_path = env::var("CARGO_MANIFEST_DIR").unwrap();
let profile = env::var("PROFILE").unwrap(); let profile = env::var("PROFILE").unwrap();
println!("cargo:rustc-link-search=native={}/libctru/lib", dkp_path); println!("cargo:rustc-link-search=native={}/libctru/lib", dkp_path);
println!("cargo:rustc-link-search=native={}", manifest_path);
println!(
"cargo:rustc-link-search=native={}/devkitARM/arm-none-eabi/lib/armv6k/fpu",
dkp_path
);
println!(
"cargo:rustc-link-search=native={}/devkitARM/lib/gcc/arm-none-eabi/11.1.0/armv6k/fpu",
dkp_path
);
println!( println!(
"cargo:rustc-link-lib=static={}", "cargo:rustc-link-lib=static={}",
match profile.as_str() { match profile.as_str() {
@ -23,8 +12,4 @@ fn main() {
_ => "ctru", _ => "ctru",
} }
); );
println!("cargo:rustc-link-lib=static=gcc");
println!("cargo:rustc-link-lib=static=sysbase");
println!("cargo:rustc-link-lib=static=c");
println!("cargo:rustc-link-lib=static=pthread_3ds");
} }

BIN
ctru-sys/libpthread_3ds.a

Binary file not shown.

1
ctru-sys/src/lib.rs

@ -4,6 +4,5 @@
#![no_std] #![no_std]
extern crate libc; extern crate libc;
extern crate linker_fix_3ds;
include!("bindings.rs"); include!("bindings.rs");

Loading…
Cancel
Save