Commit Graph

52 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 07b803e28a docs: replace xml-style markup with markdown in comments
Replace XML-style markup tags in comments with markdown equivalents:
- <code>...</code> to `...` (inline code)
- <tt>...</tt> to `...` (teletype/monospace)
- <i>...</i> to *...* (italics/emphasis)
- +...+ to `...` (parameter/variable references)

Updated 80+ files across core source, headers, mrbgems, and libraries
to use consistent markdown formatting in documentation comments.
Handled edge cases including special characters like <=> operators.

Co-authored-by: Atlassian Rovo Dev
2025-08-14 10:52:49 +09:00
Yukihiro "Matz" Matsumoto 7538ee8f5d gperf: remove obsolete command line options -p and -g 2025-03-28 06:16:00 +09:00
dearblue 79f4a67268 Avoid warnings in lib/**/*.rb
```console
% find -s lib -type f -name '*.rb' -exec ruby -cw {} \;
lib/mruby/build/command.rb:320: warning: `+' after local variable or literal is interpreted as binary operator
lib/mruby/build/command.rb:320: warning: even though it seems like unary operator
Syntax OK
Syntax OK
Syntax OK
Syntax OK
Syntax OK
lib/mruby/gem.rb:469: warning: `&' interpreted as argument prefix
Syntax OK
Syntax OK
Syntax OK
Syntax OK
```
2024-08-12 21:06:31 +09:00
Yukihiro "Matz" Matsumoto fbe21a0321 tools/lrama: bundle Lrama 0.6.9 (copied from CRuby source) 2024-06-10 14:26:26 +09:00
Yukihiro "Matz" Matsumoto 455a5689f3 lib/mruby/build/command.rb: skip mrbgems in parent directory; fix #6029
If `mrbgems` is included in the parent directory path (MRUBY_ROOT), it
confuses gem path and build path.
2023-07-17 13:24:47 +09:00
dearblue a7bee69452 Fixed visibility of MRuby::Command::Compiler#setup_debug
In #5977 it was incorrectly set to `private`.
2023-05-26 21:37:29 +09:00
alpha.netzilla 3409c1f309 lib/mruby/build/command.rb: narrow down poppen mode 2023-05-05 19:23:18 +09:00
Yukihiro "Matz" Matsumoto 5956496267 lib/mruby/build/command.rb: remove unnecessary block parameter; fix #5995 2023-05-03 12:41:52 +09:00
dearblue 0f2c1caa96 Make MRuby::Build#enable_debug compiler flag setting abstract
Previously, compiler flags were only added for GCC or similar.
The situation has not changed, but it has become easier to improve.

I expect `MRuby::Command::Compiler#setup_debug` to be defined as a singleton method inside the block given to `MRuby::Toolchain.new`.
2023-04-09 11:21:50 +09:00
Gwendolyn Boatrite 8b728e4056 Fix cloning gem when destination path contains spaces
This was how clone command was previously being generated, for example:

```
git clone  --recursive --branch "master" --depth 1 https://github.com/mattn/mruby-onig-regexp.git /path/to mruby with spaces/mruby-3.1.0/build/repos/wasm/mruby-onig-regexp
```

Now it's changed so the path is quoted and will work when containing
spaces:

```
git clone  --recursive --branch "master" --depth 1 https://github.com/mattn/mruby-onig-regexp.git "/path/to mruby with spaces/mruby-3.1.0/build/repos/wasm/mruby-onig-regexp"
```

Similar for the other commands.
2022-12-11 17:18:29 -06:00
Chris Reuter 5c4273f944 Added testing support for cross-MinGW builds.
This adds a build_config that will cross-build a Windows executable
using the MinGW cross-compiler and will also run the unit (i.e.
'rake test') using Wine.

For this to work, I made some modifications to the underlying test
scripts as well as some minor changes to a couple of the tests
themselves.
2021-10-21 21:58:45 -04:00
Yukihiro "Matz" Matsumoto 384865997d build: provide global defines by build.defines. 2021-03-22 10:58:47 +09:00
Yukihiro "Matz" Matsumoto 5764ff0740 command.rb: replace %w() to plain []. 2021-03-21 13:23:35 +09:00
KOBAYASHI Shuji a6a76d8fd2 Add -s option to mrbc for make variable static 2021-02-14 11:55:53 +09:00
dearblue 5c3b5f4221 Exclude <build-dir>/mrbc/**/* from rake target rules
Prevents the auto-generated mrbc target source code from being compiled under host conditions.

This is because a build error occurred when `conf.enable_cxx_exception` was set.
2021-02-06 16:37:15 +09:00
KOBAYASHI Shuji d90abc648e Change .o.d back to .d because .pi.d is no longer created 2021-01-31 15:08:37 +09:00
KOBAYASHI Shuji c858cba3e9 Refine preprocess_options; ref d95ffb036
If we modify an option that may have been specified by users, we may
make unintended changes, so it is better not to modify it as much as
possible, IMO.
2021-01-28 18:42:19 +09:00
Yukihiro "Matz" Matsumoto d95ffb0362 Stop generating build/<build>/src/*.pi.d. 2021-01-28 15:58:35 +09:00
KOBAYASHI Shuji 456878ba06 Improve source scanning for presym
The accuracy is greatly improved by using the C preprocessor to scan C
sources for presym. C preprocessor can perfectly interpret all comments and
preprocessor directives, so it can detect all symbols defined, for example
`mrbgems/mruby-socket/src/const.cstub`.

Also, as described later, this change will greatly improve the accuracy of
presym detection from Ruby sources.

## Result

The number of lines in the `presym` file for all gems is as follows:

  ```console
  Previous:   999 (false positive = 89, undetected = 297)
  New:       1207
  ```

## Build process

The new build process (with presym) is as follows:

1. Build `mrbc` without presym (more on building without presym later).
2. Compile Ruby sources to C struct format with the `mrbc` created in
   step 1, and create` mrblib.c` and `gem_init.c`. Note that the symbols
   in the created files are output as `MRB_SYM` family macros or
   `mrb_intern_lit` instead of IDs (details will be described later).
3. C preprocessor processes C sources including the created files of
   step 2 and outputs them as `.i` files. In these files, for example,
   `MRB_IVSYM(foo)` is converted to `<@! "@" "foo" !@>` and
   `mrb_define_module(mrb, "Foo")` is converted to `<@! "Foo" !@>`.
4. Scan the files created in step 3 and create `presym` and` presym.inc`
   files.

The files created in step 2 should output all static symbols defined in Ruby
sources, including local variables, so we can detect all presyms by just
scanning C sources without scanning Ruby sources directly.

Further, by this process, the files to be scanned becomes the same as the
files to be compiled, so that there is no excess or deficiency.

## Related changes

The following changes have been made in relation to realizing this feature.

### Allow build without presym

It enables build without presym to achieve the "Build process: 1". This
incorporates #5202, see its issue for details.

Note that when presym is enabled, even adding a local variable to a Ruby
source may change contents of presym and require recompilation of almost
all C sources. This is inconvenient, especially during trial and error in
development, but this feature is also useful because it does not cause
this problem if presym is disabled.

### Automatically create build target for `mrbc` without presym

The `mrbc` used in the "Build process: 1" will be built by automatically
creating a build target for it. The build name is `SOURCE_BUILD_NAME/mrbc`.

### Constantize output of C struct format by `mrbc`

To realizing the "Build process: 2", as mentioned above, symbol IDs are not
output directly in C struct format output by `mrbc`. As a result, the output
becomes constant regardless of the state of presym at the time of `mrbc`
build, and it is possible to detect symbols of Ruby sources in the same way
as other C sources.

Note that `mrb_intern_lit` is used for symbols that do not become presym,
but in this state, the corresponding element in the symbol array cannot be
statically initialized, so it is initialized at run time (therefore, in this
case, the `const` qualifier is not added to the symbol array).

### Specify arbitrary `mrbc` file

To realizing the "Build process: 2", enabled to specify `mrbc` created by
another build target or pre-built` mrbc`. Use `MRuby::Build#mrbcfile =` to
specify it explicitly. You can omit the "Build process: 1" by specifying
pre-built `mrbc`, and you can always use an optimized build to compile Ruby
sources faster. I think changes that affect the output of `mrbc` are rare,
so in many cases it helps to improve efficiency.

With presym, the build will be a little slower due to more build steps, but
this feature will improve it a bit.

### Create presym files for each build target

This feature was proposed at #5194 and merged once, but was reverted in
5c205e6e due to problems especially with cross-compilation. It has been
introduced again because this change solves the problem.

The presym files will be created below.

* `build/NAME/presym`
* `build/NAME/include/mruby/presym.inc`

### Other changes

* Because presym detection accuracy is greatly improved as mentioned above,
  `MRuby::Gem::Specification#cdump?` is set to true by default, and
  `disable_cdump` is added instead of `enable_cdump`. Also, support for gem
  specific presym files has been discontinued (https://github.com/mruby/mruby/issues/5151#issuecomment-730967232).
* Previously, `mrbc` was automatically created for the `host` build, but it
  will not be created if the build target for `mrbc` mentioned above is
  automatically created. At this time, `mrbc` file of the `mrbc` build is
  copied to` bin/`.
* Two types of `.d` files will be created, `.o.d` and `.i.d`. oThis is
  because if `.i` depends on `presym.inc`, the dependency will circulate, so
  the `.d` file cannot be shared.
* Changed file created with `enable_cxx_exception` to `X-cxx.cxx` from
  `X.cxx` to use the mruby standard Rake rule.

### Note

Almost all C sources will need to be recompiled if there are any changes to
`persym.inc` (if not recompiled properly, it will often result in run-time
error). If `gcc` toolchain is used, dependencies are resolved by the `.d`
file, so it become automatically recompile target, but if not (e.g. MSVC),
it is necessary to manually make it recompile target.

Also, even if `gcc` toolchain is used, it may not become recompile target if
external gems does not use the mruby standard Rake rule. In particular, if
the standard rule is overwritten, such as
https://github.com/mruby/mruby/pull/5112/files, `.d` file will not be read,
so be careful.
2020-12-13 15:27:53 +09:00
KOBAYASHI Shuji 038bad2f41 Allow compiler name in build log to be customized
For example, in the case of the C++ compiler, it is output as
`CXX  build/host/src/gc.cxx -> build/host/src/gc.cxx.o` (FYI, in the case
of `enable_cxx_abi`, it outputs `CC ...` because the option to compile as
C++ is added to C compiler).
2020-11-25 15:11:36 +09:00
KOBAYASHI Shuji 2b0f908017 Raise an exception instead of exiting when mrbc fails 2020-11-23 16:32:10 +09:00
KOBAYASHI Shuji 2a97e97db4 Refine build log for generated files
* Output `GEN` log for generated files
* `MRBC` log is outputted one for each `mrbc` execution

#### Before this patch:

```console
CC    src/array.c -> build/host/src/array.o
(snip)
GEN   mrblib/*.rb -> build/host/mrblib/mrblib.c
      MRBC mrblib/00class.rb
      MRBC mrblib/10error.rb
(snip)
CC    mrbgems/mruby-time/src/time.c -> build/host/mrbgems/mruby-time/src/time.o
      MRBC mrbgems/mruby-time/mrblib/time.rb
(snip)
CC    mrbgems/mruby-socket/test/sockettest.c -> build/host/mrbgems/mruby-socket/test/sockettest.o
      MRBC mrbgems/mruby-socket/test/addrinfo.rb
      MRBC mrbgems/mruby-socket/test/basicsocket.rb
(snip)
```

#### After this patch:

```console
GEN   build/presym
GEN   build/presym.inc
CC    src/array.c -> build/host/src/array.o
(snip)
GEN   mrblib/*.rb -> build/host/mrblib/mrblib.c
      MRBC mrblib/00class.rb
           mrblib/10error.rb
(snip)
CC    mrbgems/mruby-time/src/time.c -> build/host/mrbgems/mruby-time/src/time.o
GEN   build/host/mrbgems/mruby-time/gem_init.c
      MRBC mrbgems/mruby-time/mrblib/time.rb
(snip)
CC    mrbgems/mruby-socket/test/sockettest.c -> build/host/mrbgems/mruby-socket/test/sockettest.o
GEN   build/host/mrbgems/mruby-socket/gem_test.c
      MRBC mrbgems/mruby-socket/test/addrinfo.rb
      MRBC mrbgems/mruby-socket/test/basicsocket.rb
(snip)
```
2020-11-22 20:31:01 +09:00
KOBAYASHI Shuji 08df172e91 Remove unused constant in lib/mruby/build/command.rb 2020-11-14 16:50:00 +09:00
KOBAYASHI Shuji 0c55b85fb0 Simplify MRuby::Command#_run to avoid duplicated compilation
ref: https://github.com/mruby/mruby/pull/4959#discussion_r402086196

Compiles twice because it falls back to `build.filename(command)` when
`command` fails. This process was added at 9968af4 to support `ccache gcc`
etc. At that time, it seems that it was necessary because
`build.filename(command)` quoted the whole `command`, but now it does not
quote, so we can just run `build.filename(command)`.

### Example

  ```console
  $ echo 1 > src/a.c
  $ rake -v
  ```

#### Before this patch:

  ```console
  (snip)
  gcc -std=gnu99 -g -O3 -Wall -Wundef -Wdeclaration-after-statement -Werror-implicit-function-declaration -Wwrite-strings -I"/mruby/mruby/include" -MMD -o "/mruby/mruby/build/host/src/a.o" -c "/mruby/mruby/src/a.c"
  /mruby/mruby/src/a.c:1:1: error: expected identifier or '('
  1
  ^
  1 error generated.
  gcc -std=gnu99 -g -O3 -Wall -Wundef -Wdeclaration-after-statement -Werror-implicit-function-declaration -Wwrite-strings -I"/mruby/mruby/include" -MMD -o "/mruby/mruby/build/host/src/a.o" -c "/mruby/mruby/src/a.c"
  /mruby/mruby/src/a.c:1:1: error: expected identifier or '('
  1
  ^
  1 error generated.
  rake aborted!
  (snip)
  ```

#### After this patch:

  ```console
  (snip)
  gcc -std=gnu99 -g -O3 -Wall -Wundef -Wdeclaration-after-statement -Werror-implicit-function-declaration -Wwrite-strings -I"/mruby/mruby/include" -MMD -o "/mruby/mruby/build/host/src/a.o" -c "/mruby/mruby/src/a.c"
  /mruby/mruby/src/a.c:1:1: error: expected identifier or '('
  1
  ^
  1 error generated.
  rake aborted!
  (snip)
  ```
2020-11-13 21:49:12 +09:00
Yukihiro "Matz" Matsumoto 5b40bb8d15 Avoid using C struct dump for test Ruby code.
Files under `test/t` and `mrbgem/*/test` are for tests, not for actual
execution. So symbols in those files need not to be pre-allocated. This
change slightly reduce the memory consumption.
2020-10-14 15:52:14 +09:00
Rory OConnell 5592c7413a Remove compiler feature detection 2020-10-12 18:20:14 +09:00
Rory OConnell 2b05cf48d0 Work around removing tmp dir 2020-10-12 18:20:13 +09:00
Rory OConnell cfe8b0c81d Add methods for asking about compiler features 2020-10-12 18:20:12 +09:00
Yukihiro "Matz" Matsumoto 52507b1083 Generate C struct from irep instead of binary dump. 2020-10-12 16:21:10 +09:00
Yukihiro "Matz" Matsumoto e440681a06 Merge pull request #5081 from wataash/d-format-comment
*.d format is version-independent
2020-09-17 21:05:42 +09:00
Wataru Ashihara ea3b02e387 *.d format is version-independent
As pointed out by @shuujii on https://github.com/mruby/mruby/pull/5079 ,
multi-path in single-line could be appear even with older-gcc or clang.
2020-09-17 21:04:45 +09:00
Wataru Ashihara 069d9bb4d7 Fix skipping reading file 2020-09-17 20:30:17 +09:00
Wataru Ashihara e8723a4f3f Fix *.d parsing with gcc 9.3.0
Before this commit:

  $ rake
  ...
  $ rm build/host/src/gc.o
  $ rake
  rake aborted!
  Don't know how to build task '/home/foo/mruby/build/host/src/gc.o' (See the list of available tasks with `rake --tasks`)
  ...

After this commit:

  $ rake
  ...
  $ rm build/host/src/gc.o
  $ rake
  CC    src/gc.c -> build/host/src/gc.o
  ...

With gcc 9.3.0 on Ubuntu 20.04, build/host/src/array.d looks like:

  /build/host/src/array.o: /src/array.c \
   /include/mruby.h /include/mrbconf.h \
   /include/mruby/common.h \
   ...
   /include/mruby/range.h \
   /src/value_array.h

and it has been parsed to:

  [
                                           # /src/array.c missing
    "/include/mruby.h /include/mrbconf.h", # incorrectly parsed
    "/include/mruby/common.h",
    ...
    "/src/value_array.h",
  ]

After this change, *.d will be parsed correctly.

  [
    "/src/array.c",
    "/include/mruby.h",
    "/include/mrbconf.h",
    "/include/mruby/common.h",
    ...
    "/src/value_array.h",
  ]
2020-09-17 20:02:55 +09:00
mimaki a8ab74a6dc Merged cygwin_filename() into filename() because Cygwin pathnames are in UNIX format. 2020-04-08 13:27:14 +09:00
Yukihiro "Matz" Matsumoto 3cef380b20 Revert part of #4959
To prevent infinite loop on errors; reported by @shuujii
2020-04-04 11:50:59 +09:00
Dominic Sisneros e3875ae8c5 build when directories and files have spaces
Modified the build to quote filenames so that it builds when files have spaces
2020-04-01 11:55:35 -06:00
KOBAYASHI Shuji bb98fd78c3 Use Rake.verbose instead of $verbose and $pp_show in build scripts
The incompatibility that the commands of `FileUtils` origin output verbose
by default due to the changes in d8a5163b and 26e6e75b is also fixed.
2019-12-28 17:03:37 +09:00
KOBAYASHI Shuji 26e6e75ba6 Use Rake DSL instead of commands of FileUtils
- Respect `--verbose(-v)` and `--dry-run(-n)` options.
- Silence warnings to keyword arguments on Ruby 2.7.
2019-12-27 16:49:32 +09:00
dearblue f08d9b288d Use git checkout instead of git reset
With this change, if the checkout fails, it will stop with an error.

The purpose is to avoid deleting working branch history when
developing gem.
2019-12-22 15:09:29 +09:00
dearblue dc15c2838f Display directory with git command 2019-12-22 14:26:00 +09:00
dearblue acef52c35e Perform shellquote on referenced string 2019-12-21 17:25:22 +09:00
mimaki f68212cc7a Fix file/directory name parameter for git command. 2019-10-29 20:56:12 +09:00
take-cheeze 4877dbf2a9 Print mrbc command on verbose mode 2019-10-19 01:42:34 +09:00
KOBAYASHI Shuji be76cec342 Fix warnings for invalid C++ option with enable_cxx_abi; ref #3618, #4703 2019-09-13 17:14:37 +09:00
Yukihiro "Matz" Matsumoto 90bffaa2a6 Merge pull request #4180 from take-cheeze/lock_file
Support lock file for git.
2019-08-21 17:17:30 +09:00
KOBAYASHI Shuji 66909dfe86 Consider -MP flag specified when parsing .d file
`-MP` flag is used in `tasks/toolchains/android.rake`.
2019-07-12 14:23:35 +09:00
Yukihiro "Matz" Matsumoto 8d37a3575b Revert "Add support for CC="gcc --option ..." again"
This reverts commit d5c8868346.
2019-05-17 22:37:45 +09:00
Kouhei Sutou d5c8868346 Add support for CC="gcc --option ..." again
If $rake_root_fiber is used, sh runs command in another Fiber. If
command is ran in another Fiber, "rescue RuntimEerror" can't rescue
exception for system(...) failure.

How to reproduce:

    $ CC="gcc -std=gnu99" ./minirake
    (in /home/kou/work/ruby/mruby.kou)
    CC    mrbgems/mruby-compiler/core/codegen.c -> build/test/mrbgems/mruby-compiler/core/codegen.o
    sh: 1: gcc -std=gnu99: not found
    rake aborted!
    Command Failed: ["gcc -std=gnu99" -g -std=gnu99 ...]
2019-05-17 17:59:24 +09:00
KOBAYASHI Shuji 37fb5f929f Fix typo in lib/mruby/build/command.rb 2019-02-21 19:47:00 +09:00
take-cheeze b6850f88a1 Support lock file for git. 2018-12-06 11:47:17 +09:00