Skip to content

Commit

Permalink
samples: Primitive Rust sample
Browse files Browse the repository at this point in the history
  • Loading branch information
kosmas12 committed Sep 27, 2021
1 parent f2c634f commit 090fea1
Show file tree
Hide file tree
Showing 4 changed files with 71 additions and 0 deletions.
15 changes: 15 additions & 0 deletions samples/rust/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[package]
name = "xboxrusttest"
version = "0.1.0"
authors = ["Kosmas Raptis <[email protected]>"]
edition = "2018"

[profile.dev]
panic = "abort"

[profile.release]
panic = "abort"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
2 changes: 2 additions & 0 deletions samples/rust/Cross.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[target.i686-pc-windows-gnu]
image = "rustembedded/cross:i686-pc-windows-gnu"
26 changes: 26 additions & 0 deletions samples/rust/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
PROJECT_NAME = xboxrusttest
XISO_NAME = rusttest
XBE_TITLE = rusttest
NXDK_DIR = /home/$(USER)/rust_nxdk
OUTPUT_DIR = bin
RUSTFLAGS := --target i686-pc-windows-gnu

CXBE = $(NXDK_DIR)/tools/cxbe/cxbe
XISO = $(NXDK_DIR)/tools/extract-xiso/build/extract-xiso

EXEC_DIR = target/i686-pc-windows-gnu/release

ifeq ($(DEBUG),y)
EXEC_DIR = target/i686-pc-windows-gnu/debug
else
RUSTFLAGS += --release
endif

all:
@mkdir -p $(OUTPUT_DIR)
@cross build $(RUSTFLAGS)
@cp $(EXEC_DIR)/$(PROJECT_NAME).exe ./main.exe
$(CXBE) -OUT:default.xbe -TITLE:$(XBE_TITLE) ./main.exe
@mv default.xbe $(OUTPUT_DIR)
$(XISO) -c $(OUTPUT_DIR) $(XISO_NAME).iso

28 changes: 28 additions & 0 deletions samples/rust/src/main.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#![no_main]
#![no_std]

use core::panic::PanicInfo;

#[panic_handler]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}

pub fn hello() -> i32 {
12345678
}

#[no_mangle]
fn main() {
hello();
}

#[no_mangle]
pub extern "C" fn _start() -> ! {
main();
loop {}
}

#[no_mangle] pub extern fn rust_eh_register_frames () {}
#[no_mangle] pub extern fn rust_eh_unregister_frames () {}

0 comments on commit 090fea1

Please sign in to comment.