Commit Graph

140 Commits

Author SHA1 Message Date
Yukihiro "Matz" Matsumoto 1e385692d1 Rakefile: remove default build target directories in deep_clean
Ref #6038, #6032
2023-08-24 12:57:27 +09:00
dearblue 14a0cc4b7b Revert "Rake: update task clean to remove bin and build folders" 2023-08-18 22:36:21 +09:00
John Bampton a94a8b1cf0 Rake: update task clean to remove bin and build folders 2023-07-30 03:51:48 +10:00
Yukihiro "Matz" Matsumoto 9b4046f479 Merge pull request #5961 from jbampton/add-docker
Add `Docker` to build and run all `mruby` tests. Run `pre-commit` and generate `YARD` docs with Docker
2023-05-05 22:42:33 +09:00
dearblue 5c19b259e4 Replace "folder" with "directory" for consistency
Also, use "x/y/z directory" instead of "directory x/y/z" if there is no problem.
2023-04-30 18:32:54 +09:00
John Bampton 00d43ad960 Add Docker to build and run all mruby tests
Run `pre-commit` and  generate `YARD` docs with Docker

Update CONTRIBUTING
2023-04-13 00:12:32 +10:00
dearblue c020d8507e Separate rake install related stuff into tasks/install.rake 2023-02-12 21:02:27 +09:00
John Bampton 2bb6eeb7c0 Makefile/Rakefile add target/task for pre-commit install 2023-02-01 13:14:23 +10:00
John Bampton 0075b6f240 Rakefile: remove unnecessary utf-8 encoding comment 2022-12-27 11:20:29 +10:00
John Bampton f5cd3bfa82 Add check and checkupdate to rake --tasks 2022-12-26 14:20:34 +10:00
John Bampton 72f22afc99 Makefile/Rakefile: add checkupdate target
Runs `pre-commit autoupdate`
2022-10-26 12:04:59 +10:00
Yukihiro "Matz" Matsumoto a9d0e9a412 Makefile,Rakefile: rename lint target to check; #5790
The pre-commit check does some static analysis but the term lint is used
as static analysis of software code under the UNIX environment. So we
have renamed the target `check`.
2022-09-17 16:44:24 +09:00
John Bampton b466271f16 Add lint target to the Makefile
Add `lint` task to the Rakefile

Runs `pre-commit run --all-files`
2022-09-16 13:26:25 +10:00
Yukihiro "Matz" Matsumoto e49ae398bd Rakefile: add install target; close #5712
This change is not complete. Contribution is welcome.

- need to update `mruby-config` to refer installed path
- may need to support installing shared library
- need to support cross-compiled binaries
2022-06-03 13:00:12 +09:00
Yukihiro "Matz" Matsumoto 9a9c842cb0 Rakefile: remove GitLab configuration; close #5409
This CI could consume too much CPU time on GitLab. Maybe we should add
resource concious CI configuration on GitLab.
2021-04-13 07:16:21 +09:00
KOBAYASHI Shuji 3a8d7bdf82 Delay test code build until rake test
With this change, the test code will not be built unless `rake test` is
run, so there will be almost no side effects even if `enable_test` is
always set (but, gems specified by `add_test_dependency` are included
in `libmruby.a`).

Also added are `test: build` task, which only builds the test code
(including the main code), and `test: run` task, which only runs tests
independent of build. Therefore, the idiom for building in parallel and
not running tests in parallel is `rake -m test:build && rake test:run`.
2021-01-08 20:36:54 +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 73b4152574 Make it possible that libmruby.a is not created
Previously, `libmruby.a` was created even if only `mruby-bin-mrbc` or`
mruby-compiler` was specified for gem, but by specifying `disable_libmruby`,
the creation of `libmruby.a` can be suppressed.

### Note

The https://github.com/mruby/mruby/pull/5084#issuecomment-723521971
incompatibility seems to be difficult for users to avoid, so the original
behavior has been restored. Therefore, if we need `mrbc` other than the
`host` build, we need to explicitly specify `mruby-bin-mrbc` gem.

Due to the above changes, `build_config/boxing.rb` etc. will not work, but I
have added` mruby-bin-mrbc` to `default.gembox` to fix it. I don't think
this change is a big deal because originally `mruby-compiler` was included.
2020-12-05 09:16:08 +09:00
KOBAYASHI Shuji e1fa01b9c8 Remove build/presym{,.inc} by rake clean [ci skip]
Currently, adding gems to build configuration and rebuilding does not
regenerate `presym`, which can lead to build errors.

Therefore in this case we need to remove the `presym` file and then rebuild
mruby, but when the` presym` file is regenerated we will need to recompile
most of the files, so it seems useful to have the `presym` file deleted by
`rake clean`.
2020-12-02 23:15:29 +09:00
KOBAYASHI Shuji 5c205e6ea1 Revert "Create presym files for each build target" (58ba883e)
Due to the above changes, it may not work with the existing build
configurations in cross-compilation (even if we can build without presym),
therefore revert it once (ref https://github.com/mruby/mruby/pull/5202#issuecomment-735412643). Sorry for the lack of consideration.
2020-12-01 12:16:55 +09:00
KOBAYASHI Shuji fdce0e712b Fix build failure; ref #5194
Fix the following two issues:

1. Compile failure when external gem is specified.
   * https://github.com/mruby/mruby/pull/5194#issuecomment-734303442
2. When there are multiple build targets, presym parsing sometimes fails or
   output result of presym is broken.
   * https://github.com/mruby/mruby/pull/5194#issuecomment-734322142

The root cause of 2 is unknown, but it seems to occur when presym parsing is
performed in parallel, therefore I change them so that they are not run in
parallel.
2020-11-27 07:59:57 +09:00
KOBAYASHI Shuji 58ba883ee9 Create presym files for each build target
Previously, presym files were always created in `build/{presym,presym.inc}`.
However, this constraint is inconvenient because it is common to use
multiple build configurations and build targets in a single mruby tree.
Therefore, change to create presym file for each build target.
2020-11-26 19:05:07 +09:00
KOBAYASHI Shuji db00fb238b Optimize presym_find
Chang to compare string length first.

### Benchmark

#### Code

* https://github.com/shuujii/mruby-presym_find-benchmark

#### Result

```console
Previous: 10.240772M i/s (25M times in 2.441222s)
     New: 16.412985M i/s (25M times in 1.523184s)
```
2020-11-24 16:30:52 +09:00
Abinoam Praxedes Marques Junior 4803c872e2 Fix #5177 - set MRUBY_CONFIG early 2020-11-23 15:18:22 -03: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 1c7a1926a3 Move global function for build to lib/mruby/core_ext.rb
Because `_pp` is originally defined in `lib/mruby/core_ext.rb`, other global
functions are moved to the file.
2020-11-22 16:53:13 +09:00
KOBAYASHI Shuji 551bf0c635 Move some .rake files to tasks directory for consistency 2020-11-21 15:36:46 +09:00
KOBAYASHI Shuji 56a60fa7b7 Move lib/mruby-core-ext.rb to lib/mruby/core_ext.rb for consistency 2020-11-20 16:58:08 +09:00
Yukihiro "Matz" Matsumoto aae8237335 Scan all active C source files; ref 600e333
In addition, `include/mruby.h` will be scanned for error class symbols.
2020-11-17 09:00:06 +09:00
KOBAYASHI Shuji e334c02a50 Fix paths of gem files to be scanned for presym
When building from outside `MRUBY_ROOT` (e.g. `rake -f`), gem files were not
scanned.
2020-11-15 20:16:12 +09:00
Yukihiro "Matz" Matsumoto 600e3330b3 Scan source files only from cdump enabled gems. 2020-11-14 18:52:57 +09:00
KOBAYASHI Shuji 89f591485b Change name and usage of presym macros
To be also able to build mruby without presym in the future. However,
`MRB_QSYM` has been removed and changed as follows:

### Example

|       Type                | Symbol |  Previous Style  |   New Style    |
|---------------------------|--------|------------------|----------------|
| Operator                  | &      | MRB_QSYM(and)    | MRB_OPSYM(and) |
| Class Variable            | @@foo  | MRB_QSYM(00_foo) | MRB_CVSYM(foo) |
| Instance Variable         | @foo   | MRB_QSYM(0_foo)  | MRB_IVSYM(foo) |
| Method with Bang          | foo!   | MRB_QSYM(foo_b)  | MRB_SYM_B(foo) |
| Method with Question mark | foo?   | MRB_QSYM(foo_p)  | MRB_SYM_Q(foo) |
| Mmethod with Equal        | foo=   | MRB_QSYM(foo_e)  | MRB_SYM_E(foo) |

This change makes it possible to define, for example, `MRB_IVSYM(foo)` as
`mrb_intern_lit(mrb, "@" "foo")`, which is useful if we support building
without presym in the future.
2020-11-13 13:41:20 +09:00
KOBAYASHI Shuji 82a2a5657c Reduce recompilation when updating presym target files
Fix that updating presym target files would recompile almost all files even
if symbols did not change.
2020-11-03 16:03:46 +09:00
KOBAYASHI Shuji 9a5c78dc26 Fix parallel build
When `rake -m` and so on are used to build in parallel, building may be
started before presym files are generated. Then, for example, the following
error occurs and this issue is fixed.

```console
In file included from /Users/shuujii/mruby/mruby/include/mruby.h:92:
/mruby/mruby/include/mruby/presym.h:16:10: fatal error: '../build/presym.inc' file not found
#include <../build/presym.inc>
         ^~~~~~~~~~~~~~~~~~~~~
```
2020-11-02 14:13:33 +09:00
Yukihiro "Matz" Matsumoto e4d4192c3a Exclude symbols from mruby-test gem only used for tests. 2020-10-29 23:16:54 +09:00
KOBAYASHI Shuji 81c2108819 Revert MRUBY_TARGET mechanism; ref #5096
* In explanation of mruby, the expression `build_config.rb` is frequently
  used including official documents, so I think that it will not make sense
  if the file is no longer used.
* The `MRUBY_TARGET` mechanism seems to have little improvement, so I don't
  think it should be changed to avoid unnecessary confusion.
* `MRUBY_TARGET` and `MRuby.targets` represent somewhat different things,
  so using the same term "target" is a bit confusing.

The mechanism that can be written short when using a file under
`build_config` (renamed from `target`) directory remains
(`build_config/${MRUBY_CONFIG}.rb` is used if the path specified
in `MRUBY_CONFIG` doesn't exist).
2020-10-19 15:03:22 +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
Yukihiro "Matz" Matsumoto 7932523052 Remove host-debug internal target.
Target `host-debug` to use `host` internal target with debugging
configuration.
2020-10-12 18:20:23 +09:00
Kondo Uchio ed97c1779e Remove duplicated pattern 2020-10-12 18:20:21 +09:00
Uchio Kondo 0d8793047d Scan ruby files in directories 2020-10-12 18:20:20 +09:00
Kondo Uchio cbb46f6975 Exact match to allowed method/variable names 2020-10-12 18:20:20 +09:00
Uchio Kondo 0c242e278d Ensure exact match for symbols like foo!/foo?/foo=
e.g. symbols like "foo[]=" make invalid C codes
2020-10-12 18:20:20 +09:00
Yukihiro "Matz" Matsumoto 932b93fd12 Skip C comments from scan target; close #5072
The original PR was skipping Ruby comments as well, but caused some
issues in test suites.
2020-10-12 18:20:19 +09:00
Yukihiro "Matz" Matsumoto afcf19b727 Scan source code lines from downloaded mrbgems; fix #5071 2020-10-12 18:20:18 +09:00
Yukihiro "Matz" Matsumoto b7fe929232 Update Rakefile.
So that you can omit `host` target. Now `host-debug` works.
2020-10-12 16:21:51 +09:00
Yukihiro "Matz" Matsumoto ef9df5dc7d Allow MRUBY_CONFIG to specify target file out of source tree. 2020-10-12 16:21:39 +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 f1c06eef7c Scan more symbols from Ruby files by rake gensym. 2020-10-12 16:21:09 +09:00
Yukihiro "Matz" Matsumoto a68f005fd7 Remove remaining chomp:true option from Rakefile. 2020-10-12 16:21:05 +09:00
Yukihiro "Matz" Matsumoto 26da07db15 Avoid using chomp:true option to File.readlines.
The option is not available in the old version of Ruby.
2020-10-12 16:21:04 +09:00