summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDario Bartussek <[email protected]>2021-04-20 13:30:33 +0200
committerDario Bartussek <[email protected]>2021-04-20 13:30:33 +0200
commit0d5aa9036ca0ba441d9ca9ecaed2adb3af11846b (patch)
tree9c783b54968c4221c90e667ce60c902b1e6a296f
parentSimple hello world program using libctru (diff)
downloadrust_3ds-0d5aa9036ca0ba441d9ca9ecaed2adb3af11846b.tar.xz
rust_3ds-0d5aa9036ca0ba441d9ca9ecaed2adb3af11846b.zip
Experimental use of Rust std
print! and alloc work so far, panic causes a segfault
-rw-r--r--3ds.json6
-rwxr-xr-xcompile.sh3
-rw-r--r--src/lib.rs23
3 files changed, 16 insertions, 16 deletions
diff --git a/3ds.json b/3ds.json
index edb980d..a2a8957 100644
--- a/3ds.json
+++ b/3ds.json
@@ -2,9 +2,9 @@
"llvm-target": "arm-none-eabihf",
"data-layout": "e-m:e-p:32:32-Fi8-i64:64-v128:64:128-a:0:32-n32-S64",
- "os": "none",
- "env": "eabi",
- "vendor": "unknown",
+ "os": "3ds",
+ "env": "ctru",
+ "vendor": "nintendo",
"arch": "arm",
"target-cpu": "mpcore",
"features": "+strict-align,+v6,+vfp2,-d32",
diff --git a/compile.sh b/compile.sh
index c47a7b4..5228c71 100755
--- a/compile.sh
+++ b/compile.sh
@@ -1,6 +1,7 @@
cargo fmt
-cargo xbuild --target 3ds.json
+# cargo xbuild --target 3ds.json
+cargo +3ds build -Z build-std=core,alloc,std,panic_abort --target 3ds.json
arm-none-eabi-gcc -specs=3dsx.specs -g -march=armv6k -mtune=mpcore -mfloat-abi=hard -mtp=soft -Wl,-Map,rust_3ds.map -Ltarget/3ds/debug -LC:/devkitpro/libctru/lib -lrust_3ds -lctru -lm -o rust_3ds.elf
diff --git a/src/lib.rs b/src/lib.rs
index 1970dfd..f52e22b 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -1,16 +1,12 @@
-#![no_std]
+#![feature(restricted_std)]
-use core::{panic::PanicInfo, ptr::null_mut};
+use core::ptr::null_mut;
use libctru::raw::{
aptMainLoop, c_char, c_int, consoleInit, gfxExit, gfxFlushBuffers, gfxInitDefault,
gfxScreen_t_GFX_TOP, gfxSwapBuffers, gspWaitForEvent, hidKeysDown, hidScanInput,
GSPGPU_Event_GSPGPU_EVENT_VBlank0, KEY_START,
};
-extern "C" {
- fn puts(string: *const c_char);
-}
-
#[no_mangle]
pub extern "C" fn main(_argc: c_int, _argv: *const *const c_char) -> c_int {
unsafe {
@@ -18,7 +14,15 @@ pub extern "C" fn main(_argc: c_int, _argv: *const *const c_char) -> c_int {
consoleInit(gfxScreen_t_GFX_TOP, null_mut());
- puts("Hello World from Rust".as_ptr());
+ libctru::println!("Standard print in next line:");
+ println!("Standard print");
+
+ std::thread::spawn(|| {
+ println!("Hello thread world");
+ })
+ .join();
+
+ libctru::println!("Check end");
while aptMainLoop() {
hidScanInput();
@@ -39,8 +43,3 @@ pub extern "C" fn main(_argc: c_int, _argv: *const *const c_char) -> c_int {
0
}
-
-#[panic_handler]
-fn panic(_info: &PanicInfo) -> ! {
- loop {}
-}