portable_mruby 0.1.1 → 0.1.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 4ada6422e257bade3658f643305f46bc48a9810605fd49fc60ab6f7f818f74f1
4
- data.tar.gz: a6e95aca26683ad89fbae6fe730b6374353dbe0fedfa830b5de492583679c46a
3
+ metadata.gz: 4c13244dc25d6b73ad04ec765cf3ccc28a087acb97c543af230d8faf85a6d316
4
+ data.tar.gz: a9557729a1483f51272561bffddff6ce2608766ea4e875642678d5ed096dccc8
5
5
  SHA512:
6
- metadata.gz: b3bbb058a12480116b90847cdaebb2256a8e5baacdcc6fcb0dbe03f376dfb61b0af91f9b37ba648527df5ee4c4a7a55c44caaec084adb608ef6591d4325c66f0
7
- data.tar.gz: 24d0bd7cc714d2f10f94debfe8fdf09305cd720e25db5f2bbf19ad15b7c42c5e1b904b84c41a7a002420abe0a55adc252a871de1dd2f51a8442891502826e894
6
+ metadata.gz: 9944881585d3517ed4a2a7ee8a355b34a61ae11734333ea97ea22e3498c74177fa17438e60a55e99e3db8c7c16fb749fd181471494e4360d44b3cf68363f9015
7
+ data.tar.gz: 4c34af1415fddfd3465bc1fcc0b9c80b8e9b3c6249ac92b91a76131abfbfc9e5993e742b12238c82b5fb1ea24b591637a28e70c5ebe0ae26afc0eacab0149a80
data/README.md CHANGED
@@ -9,10 +9,11 @@ Build truly portable Ruby executables that run on Linux, macOS, Windows, FreeBSD
9
9
  gem install portable_mruby
10
10
 
11
11
  # Create a Ruby program
12
- echo 'puts "Hello from #{RUBY_ENGINE}!"' > hello.rb
12
+ mkdir myapp
13
+ echo 'puts "Hello from #{RUBY_ENGINE}!"' > myapp/hello.rb
13
14
 
14
15
  # Build portable executable
15
- portable-mruby build -e hello.rb -o hello.com
16
+ portable-mruby build -d myapp -o hello.com
16
17
 
17
18
  # Run it (works on Linux, macOS, Windows, FreeBSD, OpenBSD, NetBSD)
18
19
  ./hello.com
@@ -38,16 +39,13 @@ A single binary runs on:
38
39
  gem install portable_mruby
39
40
  ```
40
41
 
41
- On first build, the Cosmopolitan toolchain (~400MB) will be automatically downloaded to `~/.portable-mruby/cosmocc/`.
42
+ On first build, the Cosmopolitan toolchain (~60MB) will be automatically downloaded to `~/.portable-mruby/cosmocc/`.
42
43
 
43
44
  ## Usage
44
45
 
45
46
  ### Basic Usage
46
47
 
47
48
  ```bash
48
- # Build all .rb files in current directory
49
- portable-mruby build -o myapp.com
50
-
51
49
  # Build all .rb files in a directory
52
50
  portable-mruby build -d src/ -o myapp.com
53
51
 
@@ -55,14 +53,18 @@ portable-mruby build -d src/ -o myapp.com
55
53
  ./myapp.com
56
54
  ```
57
55
 
56
+ All `.rb` files in the directory (recursively) are compiled and executed in sorted order.
57
+
58
58
  ### With Entry Point
59
59
 
60
+ When you have multiple files and need a specific file to run last (e.g., your main program that uses classes defined in other files):
61
+
60
62
  ```bash
61
63
  # Specify an entry file (runs last, after all other files)
62
- portable-mruby build -e main.rb -d src/ -o myapp.com
64
+ portable-mruby build -d src/ -e main.rb -o myapp.com
63
65
  ```
64
66
 
65
- All `.rb` files are compiled and executed in sorted order. If `--entry` is specified, that file runs last.
67
+ **Important:** The `-e` (entry) path is relative to the `-d` (directory) path. In the example above, it looks for `src/main.rb`.
66
68
 
67
69
  ### Options
68
70
 
@@ -70,8 +72,8 @@ All `.rb` files are compiled and executed in sorted order. If `--entry` is speci
70
72
  Usage: portable-mruby build [options]
71
73
 
72
74
  Options:
73
- -e, --entry FILE Entry point Ruby file (runs last)
74
- -d, --dir DIR Source directory (default: .)
75
+ -d, --dir DIR Source directory containing .rb files (required)
76
+ -e, --entry FILE Entry point Ruby file, relative to -d (runs last)
75
77
  -o, --output FILE Output binary name (default: app.com)
76
78
  --mruby-source DIR Build mruby from custom source directory
77
79
  -v, --verbose Verbose output
@@ -90,25 +92,27 @@ If you need custom mruby gems or configuration, you can build from source:
90
92
  git clone https://github.com/mruby/mruby.git ~/mruby
91
93
 
92
94
  # Build using your custom mruby
93
- portable-mruby build -e main.rb --mruby-source ~/mruby -o myapp.com
95
+ portable-mruby build -d src/ --mruby-source ~/mruby -o myapp.com
94
96
  ```
95
97
 
96
98
  ## Example
97
99
 
98
100
  Create a simple Ruby program:
99
101
 
100
- ```ruby
101
- # main.rb
102
+ ```bash
103
+ mkdir hello
104
+ cat > hello/main.rb << 'EOF'
102
105
  name = ARGV[0] || 'World'
103
106
  puts "Hello, #{name}!"
104
107
  puts "Running on: #{RUBY_ENGINE} #{RUBY_VERSION}"
105
108
  puts "Time: #{Time.now}"
109
+ EOF
106
110
  ```
107
111
 
108
112
  Build it:
109
113
 
110
114
  ```bash
111
- portable-mruby build --entry main.rb --output hello.com
115
+ portable-mruby build -d hello -o hello.com
112
116
  ```
113
117
 
114
118
  Run it anywhere:
@@ -130,7 +134,7 @@ myapp/
130
134
  ```
131
135
 
132
136
  ```ruby
133
- # lib/greeter.rb
137
+ # myapp/lib/greeter.rb
134
138
  class Greeter
135
139
  def initialize(name)
136
140
  @name = name
@@ -143,16 +147,19 @@ end
143
147
  ```
144
148
 
145
149
  ```ruby
146
- # main.rb
150
+ # myapp/main.rb
147
151
  greeter = Greeter.new(ARGV[0] || 'World')
148
152
  puts greeter.greet
149
153
  ```
150
154
 
151
155
  ```bash
152
- portable-mruby build -e main.rb -d myapp/ -o greeter.com
156
+ # Build with main.rb as entry point (runs last, after lib/greeter.rb)
157
+ portable-mruby build -d myapp -e main.rb -o greeter.com
153
158
  ./greeter.com Ruby # => Hello, Ruby!
154
159
  ```
155
160
 
161
+ Files are loaded in sorted order (`lib/greeter.rb` before `main.rb`), but `-e main.rb` ensures it runs last regardless of sort order.
162
+
156
163
  ## Build Process
157
164
 
158
165
  1. Ruby source files are compiled to mruby bytecode using `mrbc`
@@ -174,7 +181,7 @@ gem install portable_mruby
174
181
 
175
182
  ### Build fails with cosmocc errors
176
183
 
177
- Ensure you have enough disk space (~300MB for cosmocc). You can also manually install cosmocc:
184
+ Ensure you have enough disk space (~60MB for cosmocc download, ~200MB extracted). You can also manually install cosmocc:
178
185
 
179
186
  ```bash
180
187
  mkdir -p ~/.portable-mruby/cosmocc
@@ -187,7 +194,7 @@ unzip cosmocc.zip
187
194
 
188
195
  ```bash
189
196
  export COSMO_ROOT=/path/to/cosmocc
190
- portable-mruby build -e main.rb -o app.com
197
+ portable-mruby build -d src/ -o app.com
191
198
  ```
192
199
 
193
200
  ## License
@@ -52,6 +52,26 @@ module PortableMruby
52
52
  }
53
53
  }
54
54
 
55
+ /* Call __main__ if defined (optional entry point) */
56
+ /* Supports both __main__(argv) and __main__() signatures */
57
+ if (!mrb->exc && mrb_respond_to(mrb, mrb_top_self(mrb), mrb_intern_lit(mrb, "__main__"))) {
58
+ mrb_value full_argv = mrb_ary_new_capa(mrb, argc);
59
+ for (i = 0; i < argc; i++) {
60
+ mrb_ary_push(mrb, full_argv, mrb_str_new_cstr(mrb, argv[i]));
61
+ }
62
+ /* Try calling with argv first */
63
+ mrb_funcall(mrb, mrb_top_self(mrb), "__main__", 1, full_argv);
64
+ /* If ArgumentError (wrong number of args), retry without args */
65
+ if (mrb->exc && mrb_obj_is_kind_of(mrb, mrb_obj_value(mrb->exc), mrb_class_get(mrb, "ArgumentError"))) {
66
+ mrb->exc = NULL;
67
+ mrb_funcall(mrb, mrb_top_self(mrb), "__main__", 0);
68
+ }
69
+ if (mrb->exc) {
70
+ mrb_print_error(mrb);
71
+ return_value = 1;
72
+ }
73
+ }
74
+
55
75
  mrb_close(mrb);
56
76
  return return_value;
57
77
  }
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PortableMruby
4
- VERSION = "0.1.1"
4
+ VERSION = "0.1.2"
5
5
  MRUBY_VERSION = "3.4.0"
6
6
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: portable_mruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Chris Hasinski