-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlib.rs
More file actions
158 lines (157 loc) · 4.08 KB
/
lib.rs
File metadata and controls
158 lines (157 loc) · 4.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
//! # mrubyedge-cli
//!
//! Command-line interface for mruby/edge - a lightweight, WebAssembly-focused mruby VM implementation.
//!
//! ## About mruby/edge
//!
//! mruby/edge is an mruby-compatible virtual machine implementation written in Rust,
//! specifically designed for WebAssembly environments. It aims to provide:
//!
//! - **WebAssembly-first design**: Optimized for running Ruby code in browsers and edge computing environments
//! - **Lightweight runtime**: Minimal footprint and binary size suitable for constrained environments
//! - **mruby compatibility**: Executes mruby bytecode (`.mrb` files) and Ruby source code
//! - **Rust safety**: Built with Rust for memory safety and reliability
//!
//! ## Installation
//!
//! Install mrubyedge-cli using cargo:
//!
//! ```sh
//! cargo install mrubyedge-cli
//! ```
//!
//! Or build from source:
//!
//! ```sh
//! git clone https://github.com/mrubyedge/mrubyedge.git
//! cd mrubyedge
//! cargo build --release -p mrubyedge-cli
//! ```
//!
//! ## Getting Started
//!
//! Create a simple Ruby script `hello.rb`:
//!
//! ```ruby
//! puts "Hello from mruby/edge!"
//! puts RUBY_ENGINE
//! ```
//!
//! Run it with mrbedge:
//!
//! ```sh
//! mrbedge hello.rb
//! # or explicitly
//! mrbedge run hello.rb
//! ```
//!
//! ## Main Features
//!
//! ### `run` - Execute Ruby Scripts
//!
//! The `run` subcommand executes Ruby source files (`.rb`) or compiled mruby bytecode (`.mrb`).
//!
//! **Usage:**
//! ```sh
//! mrbedge run <file>
//! # or simply
//! mrbedge <file>
//! ```
//!
//! **Examples:**
//! ```sh
//! # Run Ruby source
//! mrbedge run script.rb
//!
//! # Run compiled bytecode
//! mrbedge run script.mrb
//! ```
//!
//! ### `compile-mrb` - Compile Ruby to Bytecode
//!
//! Compiles Ruby source code into mruby bytecode format for faster loading and distribution.
//!
//! **Usage:**
//! ```sh
//! mrbedge compile-mrb <input.rb> -o <output.mrb>
//! ```
//!
//! **Examples:**
//! ```sh
//! # Compile a single file
//! mrbedge compile-mrb app.rb -o app.mrb
//!
//! # Run the compiled bytecode
//! mrbedge run app.mrb
//! ```
//!
//! ### `wasm` - Generate WebAssembly Modules
//!
//! Compiles Ruby code directly into a standalone WebAssembly module that can run in browsers
//! or any WebAssembly runtime.
//!
//! **Usage:**
//! ```sh
//! mrbedge wasm <input.rb> -o <output.wasm>
//! ```
//!
//! **Examples:**
//! ```sh
//! # Generate WebAssembly module
//! mrbedge wasm app.rb -o app.wasm
//!
//! # Use in browser or Node.js
//! # The generated WASM can be loaded and executed in any WASM runtime
//! ```
//!
//! **Use Cases:**
//! - Serverless edge computing
//! - Browser-based applications
//! - Microservices with minimal overhead
//! - Cross-platform portable executables
//!
//! **WASI Support:**
//!
//! The `wasm` command can generate both WASI-enabled and non-WASI WebAssembly binaries.
//! By default, it produces WASI-enabled modules. To disable WASI support, use the `--no-wasi` flag.
//!
//! **Import/Export Functions:**
//!
//! You can specify WebAssembly function imports and exports using RBS (Ruby Signature) files.
//! Place RBS files with specific naming conventions alongside your Ruby script:
//!
//! For a Ruby script named `foo.rb`:
//! - **`foo.import.rbs`**: Defines external functions to import from the WebAssembly host
//! - **`foo.export.rbs`**: Defines Ruby functions to export as WebAssembly functions
//!
//! **Example:**
//! ```ruby
//! # app.rb
//! def calculate(x, y)
//! x + y
//! end
//! ```
//!
//! ```rbs
//! # app.export.rbs
//! def calculate: (Integer, Integer) -> Integer
//! ```
//!
//! ```rbs
//! # app.import.rbs
//! def external_log: (String) -> void
//! ```
//!
//! The generated WebAssembly module will expose `Kernel#calculate` and can call `Kernel#external_log`
//! from the host environment.
//!
//! NOTE: Inlined RBS for imports and exports annotations will be supported in future releases.
//!
//! ## Additional Resources
//!
//! - [GitHub Repository](https://github.com/mrubyedge/mrubyedge)
//! - [API Documentation](https://docs.rs/mrubyedge-cli)
//! - [Core VM Documentation](https://docs.rs/mrubyedge)
pub mod rbs_parser;
pub mod subcommands;
pub mod template;