fornwall / rust-script

Run Rust files and expressions as scripts without any setup or compilation step.
https://rust-script.org
Apache License 2.0
1.2k stars 41 forks source link

no_std support with extern main #98

Closed joseluis closed 1 year ago

joseluis commented 1 year ago

This minimal example fails to compile:

#!/usr/bin/env -S rust-script -c
//! ```cargo
//! [dependencies]
//! libc = { version = "0.2", default-features = false }
//! 
//! [profile.release]
//! strip = true
//! lto = true
//! opt-level = "s" # "z"
//! codegen-units = 1
//! panic = "abort"
//! ```

#![no_std]
#![no_main]

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

#[no_mangle]
pub extern "C" fn main(_argc: isize, _argv: *const *const u8) -> isize {
    unsafe {
        libc::printf("hello, world\0".as_ptr() as *const _);
    }
    0
}

I've just sent a PR that updates the contains_main_method making the main detection work.

fornwall commented 1 year ago

Thanks a lot!

Your fix is included in the just released version 0.26.0.