Skip to content

Commit

Permalink
Merge pull request #95 from rust-wii/ios
Browse files Browse the repository at this point in the history
❇️ feat(IOS): Add IOS module.
  • Loading branch information
ProfElements authored Jun 16, 2024
2 parents 53b3caf + 37e6617 commit d15a95b
Show file tree
Hide file tree
Showing 8 changed files with 884 additions and 1 deletion.
453 changes: 453 additions & 0 deletions examples/ios/Cargo.lock

Large diffs are not rendered by default.

12 changes: 12 additions & 0 deletions examples/ios/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

[package]
name = "template"
version = "0.1.0"
edition = "2021"

[profile]
dev = { panic = "abort" }
release = { panic = "abort", lto = true, codegen-units = 1, strip = "symbols", opt-level = "s" }

[dependencies]
ogc-rs = { path = "../../" }
30 changes: 30 additions & 0 deletions examples/ios/build.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
use std::process::Command;
fn main() {
let dkp_path = std::env::var("DEVKITPRO").expect("Please set $DEVKITPRO");
println!("cargo:rustc-link-search=native={}/libogc/lib/wii", dkp_path);

//checks if the build folder exists. If it does, it deletes it.
let _ = std::fs::remove_dir_all("build");

let _ = std::fs::create_dir("build");


let libgcc_location = match Command::new("powerpc-eabi-gcc").arg("-print-libgcc-file-name").output() {
Ok(output) => output,
Err(_e) => panic!("Could not find powerpc-eabi-gcc or the libgcc on the host machine!"),
};
let output = libgcc_location.stdout;
let parsed_output =
String::from_utf8(output).expect("powerpc-eabi-gcc command output returned a non-utf8 string.").replace("\n", "");

let _ = match Command::new("powerpc-eabi-ar").arg("x").arg(parsed_output).arg("crtresxfpr.o").arg("crtresxgpr.o").output() {
Ok(output) => output,
Err(_e) => panic!("powerpc-eabi-ar command failed"),
};

std::fs::rename("crtresxgpr.o", "build/crtresxgpr.o").expect("Could not move crtresxgpr.o");
std::fs::rename("crtresxfpr.o", "build/crtresxfpr.o").expect("Could not move crtresxfpr.o");

println!("cargo::rustc-link-arg=build/crtresxgpr.o");
println!("cargo::rustc-link-arg=build/crtresxfpr.o");
}
31 changes: 31 additions & 0 deletions examples/ios/powerpc-unknown-eabi.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"arch": "powerpc",
"cpu": "750",
"data-layout": "E-m:e-p:32:32-Fn32-i64:64-n32",
"dynamic-linking": false,
"env": "newlib",
"executables": true,
"has-elf-tls": false,
"has-rpath": true,
"llvm-target": "powerpc-unknown-eabi",
"linker": "powerpc-eabi-gcc",
"linker-flavor": "gcc",
"linker-is-gnu": true,
"os": "rvl-ios",
"pre-link-args": {
"gcc": [
"-mrvl",
"-meabi",
"-mhard-float"
]
},
"panic-strategy": "abort",
"relocation-model": "static",
"target-endian": "big",
"target-family": "unix",
"target-mcount": "_mcount",
"target-c-int-width": "32",
"target-pointer-width": "32",
"vendor": "nintendo"
}

48 changes: 48 additions & 0 deletions examples/ios/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#![no_std]
#![feature(start)]

use alloc::vec;
use ogc_rs::{
ios::{self, Mode, SeekMode},
print, println,
};

extern crate alloc;

#[start]
fn main(_argc: isize, _argv: *const *const u8) -> isize {
// Try to open SYSCONF
if let Ok(fd) = ios::open(c"/shared2/sys/SYSCONF", Mode::Read) {
// Try to grab size or default to 0;
const GET_FILE_STATS: i32 = 11;
let mut out_buf = [0u8; 8];
let (size, seek_pos) = if ios::ioctl(fd, GET_FILE_STATS, &[], &mut out_buf).is_ok() {
(
usize::try_from(u32::from_be_bytes(out_buf[0..4].try_into().unwrap())).unwrap(),
usize::try_from(u32::from_be_bytes(out_buf[4..8].try_into().unwrap())).unwrap(),
)
} else {
(0usize, 0usize)
};
println!("{:?}, {:?}", size, seek_pos);

if seek_pos != 0 {
// Try to seek to the start
let _ = ios::seek(fd, 0, SeekMode::Start);
}

let mut bytes = vec![0; size];
if let Ok(bytes_read) = ios::read(fd, &mut bytes) {
// SAFETY: I read this much bytes
unsafe { bytes.set_len(bytes_read) };
};

println!("{:?}", bytes);

let _ = ios::close(fd);
}

loop {
core::hint::spin_loop();
}
}
2 changes: 2 additions & 0 deletions powerpc-unknown-eabi.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,9 @@
"pre-link-args": {
"gcc": [
"-mrvl",
"-mcpu=750",
"-meabi",
"-msdata=eabi",
"-mhard-float"
]
},
Expand Down
Loading

0 comments on commit d15a95b

Please sign in to comment.