Refine no-std sample.
This commit is contained in:
24
no_std/no_std_test/Cargo.toml
Normal file
24
no_std/no_std_test/Cargo.toml
Normal file
@@ -0,0 +1,24 @@
|
||||
[package]
|
||||
name = "no_std_test"
|
||||
version = "0.1.0"
|
||||
edition = "2018"
|
||||
authors = ["Stephen Chung"]
|
||||
description = "no-std test application"
|
||||
homepage = "https://github.com/jonathandturner/rhai/tree/master/no_std/no_std_test"
|
||||
repository = "https://github.com/jonathandturner/rhai"
|
||||
|
||||
[dependencies]
|
||||
rhai = { path = "../../", features = [ "no_std" ], default_features = false }
|
||||
wee_alloc = { version = "0.4.5", default_features = false }
|
||||
|
||||
[profile.dev]
|
||||
panic = "abort"
|
||||
|
||||
[profile.release]
|
||||
opt-level = "z" # optimize for size
|
||||
debug = false
|
||||
rpath = false
|
||||
lto = "fat"
|
||||
debug-assertions = false
|
||||
codegen-units = 1
|
||||
panic = "abort"
|
18
no_std/no_std_test/README.md
Normal file
18
no_std/no_std_test/README.md
Normal file
@@ -0,0 +1,18 @@
|
||||
`no-std` Test Sample
|
||||
====================
|
||||
|
||||
This sample application is a bare-bones `no-std` build for testing.
|
||||
|
||||
[`wee_alloc`](https://crates.io/crates/wee_alloc) is used as the allocator.
|
||||
|
||||
|
||||
To Compile
|
||||
----------
|
||||
|
||||
The nightly compiler is required:
|
||||
|
||||
```bash
|
||||
cargo +nightly build --release
|
||||
```
|
||||
|
||||
The release build is optimized for size. It can be changed to optimize on speed instead.
|
41
no_std/no_std_test/src/main.rs
Normal file
41
no_std/no_std_test/src/main.rs
Normal file
@@ -0,0 +1,41 @@
|
||||
//! This is a `no-std` application for the that evaluates
|
||||
//! a simple expression and uses the result as the return value.
|
||||
|
||||
#![no_std]
|
||||
#![feature(alloc_error_handler, start, core_intrinsics, lang_items)]
|
||||
|
||||
extern crate alloc;
|
||||
extern crate wee_alloc;
|
||||
|
||||
#[global_allocator]
|
||||
static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT;
|
||||
|
||||
use rhai::{Engine, INT};
|
||||
|
||||
#[start]
|
||||
fn main(_argc: isize, _argv: *const *const u8) -> isize {
|
||||
let engine = Engine::new();
|
||||
|
||||
// Evaluate a simple expression: 40 + 2
|
||||
engine.eval::<INT>("40 + 2").unwrap() as isize
|
||||
}
|
||||
|
||||
#[alloc_error_handler]
|
||||
fn foo(_: core::alloc::Layout) -> ! {
|
||||
core::intrinsics::abort();
|
||||
}
|
||||
|
||||
#[panic_handler]
|
||||
#[lang = "panic_impl"]
|
||||
extern "C" fn rust_begin_panic(_: &core::panic::PanicInfo) -> ! {
|
||||
core::intrinsics::abort();
|
||||
}
|
||||
|
||||
#[lang = "eh_personality"]
|
||||
extern "C" fn eh_personality() {}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn rust_eh_register_frames() {}
|
||||
|
||||
#[no_mangle]
|
||||
extern "C" fn rust_eh_unregister_frames() {}
|
Reference in New Issue
Block a user