origin_studio/
lib.rs

1#![doc = include_str!("../README.md")]
2#![no_std]
3
4#[cfg(feature = "alloc")]
5extern crate alloc as alloc_crate;
6
7// Ensure that origin is linked in.
8extern crate origin;
9
10// <https://doc.rust-lang.org/stable/std/alloc/trait.GlobalAlloc.html>
11#[cfg(feature = "alloc")]
12#[global_allocator]
13static GLOBAL_ALLOCATOR: rustix_dlmalloc::GlobalDlmalloc = rustix_dlmalloc::GlobalDlmalloc;
14
15// Origin calls this.
16#[no_mangle]
17unsafe fn origin_main(argc: i32, argv: *mut *mut u8, envp: *mut *mut u8) -> i32 {
18    let _ = (argc, argv, envp);
19
20    #[cfg(feature = "std")]
21    unsafe {
22        crate::init::sanitize_stdio_fds();
23        crate::init::store_args(argc, argv, envp);
24    }
25    unsafe {
26        crate::init::reset_sigpipe();
27        #[cfg(feature = "stack-overflow")]
28        crate::stack_overflow::init();
29    }
30
31    // Call the function expanded by the macro in the user's module to call the
32    // user's `main` function.
33    extern "C" {
34        fn origin_studio_no_problem();
35    }
36    unsafe {
37        origin_studio_no_problem();
38    }
39
40    rustix::runtime::EXIT_SUCCESS
41}
42
43/// 🌟
44#[cfg(not(feature = "alloc"))]
45#[macro_export]
46macro_rules! no_problem {
47    () => {
48        #[doc(hidden)]
49        #[no_mangle]
50        extern "C" fn origin_studio_no_problem() {
51            // Call the user's `main` function.
52            main()
53        }
54    };
55}
56
57/// 🌟
58#[cfg(all(feature = "alloc", not(feature = "std")))]
59#[macro_export]
60macro_rules! no_problem {
61    () => {
62        extern crate alloc;
63
64        #[doc(hidden)]
65        #[no_mangle]
66        extern "C" fn origin_studio_no_problem() {
67            // Call the user's `main` function.
68            main()
69        }
70    };
71}
72
73/// 🌟
74#[cfg(feature = "std")]
75#[macro_export]
76macro_rules! no_problem {
77    () => {
78        extern crate alloc;
79
80        #[doc(hidden)]
81        #[no_mangle]
82        extern "C" fn origin_studio_no_problem() {
83            // Call the user's `main` function.
84            main()
85        }
86
87        // Provide a prelude.
88        use ::alloc::{format, vec};
89        use $crate::prelude::rust_2021::*;
90        use $crate::{self as std, eprint, eprintln, print, println};
91    };
92}
93
94mod init;
95#[cfg(feature = "stack-overflow")]
96mod stack_overflow;
97
98// Provide a std-like API.
99
100#[cfg(feature = "std")]
101mod macros;
102
103#[cfg(feature = "std")]
104pub mod env;
105#[cfg(feature = "std")]
106#[cfg(feature = "fs")]
107pub mod fs;
108#[cfg(feature = "std")]
109pub mod io;
110#[cfg(feature = "std")]
111pub mod prelude;
112#[cfg(feature = "std")]
113#[cfg(feature = "thread")]
114pub mod sync;
115#[cfg(feature = "std")]
116#[cfg(feature = "thread")]
117pub mod thread;
118
119#[cfg(feature = "alloc")]
120pub use alloc_crate::{
121    alloc, borrow, boxed, collections, ffi, fmt, rc, slice, str, string, task, vec,
122};
123pub use core::*;