From 2a9f626ba4b15fb1ceebd1feffa1b3e6ab7ab52d Mon Sep 17 00:00:00 2001 From: John-John Tedro Date: Wed, 25 Dec 2024 20:42:28 +0100 Subject: [PATCH] Remove #[start] entrypoints (closes #897) --- crates/rune/src/runtime/from_value.rs | 10 +++++++--- no-std/Cargo.toml | 2 +- no-std/examples/minimal.rs | 15 +++++++++------ 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/crates/rune/src/runtime/from_value.rs b/crates/rune/src/runtime/from_value.rs index bab86b080..5fecbaed6 100644 --- a/crates/rune/src/runtime/from_value.rs +++ b/crates/rune/src/runtime/from_value.rs @@ -153,9 +153,13 @@ where /// field: u64, /// } /// -/// let mut sources = rune::sources!(entry => { -/// pub fn main() { #{field: 42} } -/// }); +/// let mut sources = rune::sources! { +/// entry => { +/// pub fn main() { +/// #{field: 42} +/// } +/// } +/// }; /// /// let unit = rune::prepare(&mut sources).build()?; /// diff --git a/no-std/Cargo.toml b/no-std/Cargo.toml index 43342e257..94f4303d4 100644 --- a/no-std/Cargo.toml +++ b/no-std/Cargo.toml @@ -12,4 +12,4 @@ rune = { path = "../crates/rune", default-features = false, features = ["alloc"] wee_alloc = "0.4.5" # Pull in your own critical-section implementation. # See: https://github.com/rust-embedded/critical-section/tree/main#usage-in-no-std-binaries -critical-section = { version = "1.1.2", default-features = false } +critical-section = { version = "1.2.0", default-features = false } diff --git a/no-std/examples/minimal.rs b/no-std/examples/minimal.rs index 7c3d503c0..b7bc7d43d 100644 --- a/no-std/examples/minimal.rs +++ b/no-std/examples/minimal.rs @@ -1,5 +1,6 @@ #![no_std] -#![feature(alloc_error_handler, start, core_intrinsics, lang_items, link_cfg)] +#![no_main] +#![feature(alloc_error_handler, core_intrinsics, lang_items, link_cfg)] #![allow(internal_features)] extern crate alloc; @@ -33,6 +34,8 @@ extern "C" fn eh_personality() {} #[no_mangle] pub extern "C" fn _Unwind_Resume() {} +use core::ffi::c_int; + use alloc::sync::Arc; use rune::{Diagnostics, Vm}; @@ -53,10 +56,10 @@ unsafe impl critical_section::Impl for MyCriticalSection { unsafe fn release(_: RawRestoreState) {} } -#[start] -fn main(_argc: isize, _argv: *const *const u8) -> isize { +#[no_mangle] +extern "C" fn main(_argc: c_int, _argv: *const *const u8) -> c_int { match inner_main() { - Ok(output) => output as isize, + Ok(output) => output as c_int, Err(..) => -1, } } @@ -64,13 +67,13 @@ fn main(_argc: isize, _argv: *const *const u8) -> isize { fn inner_main() -> rune::support::Result { let context = rune::Context::with_default_modules()?; - let mut sources = rune::sources!( + let mut sources = rune::sources! { entry => { pub fn main(number) { number + 10 } } - ); + }; let mut diagnostics = Diagnostics::new();