Commit Graph

417 Commits

Author SHA1 Message Date
John Bampton 9d32d440eb feat(CI): add the GitHub Super Linter
The GitHub Super Linter is a more robust and better supported
tool than the current GitHub Actions we are using.

Running these checks:

ERROR_ON_MISSING_EXEC_BIT: true
VALIDATE_BASH: true
VALIDATE_BASH_EXEC: true
VALIDATE_EDITORCONFIG: true
VALIDATE_MARKDOWN: true
VALIDATE_SHELL_SHFMT: true
VALIDATE_YAML: true

https://github.com/marketplace/actions/super-linter
https://github.com/github/super-linter

Added the GitHub Super Linter badge to the README.

Also updated the pre-commit framework and added
more documentation on pre-commit.

Added one more pre-commit check: check-executables-have-shebangs

Added one extra check for merge conflicts to our
GitHub Actions.

EditorConfig and Markdown linting.

Minor grammar and spelling fixes.

Update linter.yml
2021-04-16 16:37:52 +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
Yukihiro "Matz" Matsumoto 58ab97e300 mruby-config: add --cc and --ld options.
* `--cc` print compiler name
* `--ld` print linker name
2021-04-06 17:25:53 +09:00
Yukihiro "Matz" Matsumoto 384865997d build: provide global defines by build.defines. 2021-03-22 10:58:47 +09:00
John Bampton 15f7b0182d chore: fix spelling 2021-03-07 04:58:15 +10:00
KOBAYASHI Shuji a6a76d8fd2 Add -s option to mrbc for make variable static 2021-02-14 11:55:53 +09:00
Yukihiro "Matz" Matsumoto 5c130e8e7b Do not collect linker options from binary gems; close #5210
Binary gems are mrbgems that set `spec.bins` in their `mrbgem.rake`,
and usually their names are prefixed with `mruby-bin-`.
2021-02-12 10:33:53 +09:00
KOBAYASHI Shuji 3cf0e85ed7 Explicit top level task to clarify in tasks/test.rake 2021-02-07 19:11:54 +09:00
dearblue 9d1a659bc7 Ignore if conf.enable_test does not exist
Because if the configuration file didn't contain any `conf.enable_test`, `rake test` would report an exception and exit.

```console
% cat my_config.rb
MRuby::Build.new { toolchain }

% rake MRUBY_CONFIG=my_config.rb test

  ...SNIP...

rake aborted!
NoMethodError: undefined method `invoke' for nil:NilClass
/var/tmp/mruby/tasks/test.rake:24:in `block (3 levels) in <top (required)>'
Tasks: TOP => test => test:build => test:build:lib
(See full trace by running task with --trace)
```
2021-02-06 18:09:27 +09:00
KOBAYASHI Shuji 67a28b56ab Check if .pi build rules are defined
`.pi` files are created for `.o` files that `build.products` depends on, but
an error will occur if the build rule is unknown, so add a check.

I don't think this situation would normally arise. However, in
`mattn/mruby-onig-regexp`, when using bundled onigmo, onigmo's `.o` files
are added to dependency of `libmruby.a` in the second and subsequent builds,
and mruby does not know the build rule, so the following error had occured.

```console
rake aborted!
Don't know how to build task '/mruby/build/host/mrbgems/mruby-onig-regexp/onigmo-6.2.0/libonig_objs/ascii.pi' (See the list of available tasks with `rake --tasks`)
```
2021-02-04 21:17:58 +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
KOBAYASHI Shuji 3104aed8c6 Split presym_table for reduced program size
Because a structure that is an element of `presym_table` has padding, split
it into individual arrays for name and length.

#### Result (64-bit CPU with full-core gembox)

|        |   mruby    | libmruby.a |
|--------|------------|------------|
| Before | 1,087,444B | 1,476,872B |
| After  | 1,079,340B | 1,469,784B |
2021-01-27 20:47:10 +09:00
KOBAYASHI Shuji d6a9ffa2b5 Rename .i created for presym scan to .pi
This is because compiler's `-save-temps=obj` option creates `.i` with the
same name.
2021-01-27 16:09:12 +09:00
Yukihiro "Matz" Matsumoto 17ecf14511 Revert "Minimize the changes in #5277"
This reverts commit dc51d89ac2.
2021-01-26 10:57:07 +09:00
Yukihiro "Matz" Matsumoto dc51d89ac2 Minimize the changes in #5277
Instead of including `mruby/presym.h` everywhere, we provided the
fallback `mruby/presym.inc` under `include/mruby` directory, and specify
`-I<build-dir>/include` before `-I<top-dir>/include` in `presym.rake`.
So even when someone drops `-I<build-dir>/include` in compiler options,
it just compiles without failure.
2021-01-22 18:38:53 +09:00
KOBAYASHI Shuji 02121cbd65 Fix that sometimes parallel build of test code fails; fix #5284
The cause is that `mrbgem.rake` of` mruby-test` gem is loaded when test
code is requested to be built, but when `mrbgem.rake` is loaded,
`MRuby::Gem.current` is updated, which is not thread safe.

Address this by not loading `mrbgem.rake` in parallel.
2021-01-12 15:41:22 +09:00
KOBAYASHI Shuji 123d15c5ab Remove unneeded check to mrbtest in tasks/presym.rake
With the change in #5267, `build.products` no longer contains `mrbtest` when
`tasks/presym.rake` is loaded.
2021-01-11 16:15:12 +09:00
Yukihiro "Matz" Matsumoto 80a7655b10 Merge pull request #5271 from shuujii/fix-build-error-in-cross-build-with-presym
Fix build error in cross-build with presym
2021-01-10 22:15:52 +09:00
KOBAYASHI Shuji fe28e8617e Fix the condition to remove mrbtest when rake clean 2021-01-10 16:28:14 +09:00
KOBAYASHI Shuji f80d5ece27 Fix build error in cross-build with presym
Fix the following issues.

* https://github.com/mruby/mruby/pull/5220#issuecomment-757204258
* https://github.com/mruby/mruby/pull/5220#issuecomment-757205572
2021-01-10 10:21:45 +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 0dfcaaed63 Use namespaces according to Rake conventions
Change the Rake task to one that uses namespaces as follows (previous task
names can also be used for compatibility).

| Previous Task  |    New Task    |
|----------------|----------------|
| api_doc        | doc:api        |
| capi_doc       | doc:capi       |
| clean_doc      | doc:clean      |
| clean_api_doc  | doc:clean:api  |
| clean_capi_doc | doc:clean:capi |
| view_api       | doc:view:api   |
| view_capi      | doc:view:capi  |
| gitlab_config  | gitlab:config  |
| gitlab_dockers | gitlab:dockers |
2021-01-07 17:31:05 +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 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 cb7eb202ce Fix incorrect regexp creation in tasks/presym.rake 2020-11-27 20:07:16 +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 0cb3a7186c Add tools/* to target directory for presym parsing 2020-11-26 22:05:59 +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
Yukihiro "Matz" Matsumoto 66d044ec3e Remove -Wdeclaration-after-statement from gcc options; #5159 2020-11-21 17:05:16 +09:00
Yukihiro "Matz" Matsumoto c6c18c32b0 Merge pull request #5162 from shuujii/move-some-.rake-files-to-tasks-directory-for-consistency
Move some `.rake` files to `tasks` directory for consistency
2020-11-21 16:07:03 +09:00
KOBAYASHI Shuji 551bf0c635 Move some .rake files to tasks directory for consistency 2020-11-21 15:36:46 +09:00
KOBAYASHI Shuji 98d0f1b98e Improve determining C++ compiler in tasks/toolchains/gcc.rake
* Consider CC envvar as C compiler on which to make the decision.
* Consider the case where C compiler is `ccache gcc`, etc.
2020-11-21 12:25:50 +09:00
KOBAYASHI Shuji e941fb7866 Remove redundant command execution in header_search_paths
There is no need to execute command in duplicate for the same
reason as #5128.
2020-11-14 17:19:38 +09:00
Yukihiro "Matz" Matsumoto c1ad4c4261 Restore original name for default build_config_name; ref #5098 2020-10-29 10:46:20 +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
Rory OConnell 5592c7413a Remove compiler feature detection 2020-10-12 18:20:14 +09:00
Rory OConnell dae0de4461 Add call to malloc_trim on a full GC 2020-10-12 18:20:12 +09:00
Yukihiro "Matz" Matsumoto 8a87549315 Rename float configuration option names.
- `MRB_WITHOUT_FLOAT` => `MRB_NO_FLOAT`
- `MRB_USE_FLOAT` => `MRB_USE_FLOAT32`

The former is to use `USE_XXX` naming convention. The latter is to make
sure `float` is 32bit float and not floating point number in general.
2020-10-12 16:21:40 +09:00
Yukihiro "Matz" Matsumoto 24ad5f35b1 Removed unnecessary dependency from all.
`libmruby.flags.mak` is only required from `mruby-config` gem.
2020-10-12 16:20:54 +09:00
Yukihiro "Matz" Matsumoto fdbfeaf533 Build process updated:
You have to specify `TARGET` to specify a configuration, e.g.

```
rake TARGET=host-debug all test
```

When you port `mruby` to a new configuration:
1. copy an existing configuration under `target` directory
2. modify the new configuration file
3. build using the new configuration
4. send PR if you please
2020-10-12 16:20:47 +09:00
dearblue fde95a7db5 Improve rake benchmark
- Use POSIX format instead of GNU extension for `time` command.
  For example FreeBSD's `time(1)` does not have GNU extensions available.
- Sort `benchmark/bm_*.rb`.
  This is because the order of the bar graph cannot be uniquely
  determined depending on the result of `Dir.glob`.
2020-08-04 22:04:05 +09:00
KOBAYASHI Shuji 49896a4d28 Fix ${build_dir}/mrbgems/gem_init.c generation condition; ref #5010
The `${build_dir}/mrbgems/gem_init.c` generation condition has been changed
at #5010, but it is somewhat insufficient, for example, there was a problem
with `rake && rake test`, which was also regenerated in `rake test`.
2020-07-14 19:55:23 +09:00
Kondo Uchio 690b2aa761 Detect newly added mrbgems when re-creating gem_init.c 2020-05-26 23:15:00 +09:00
dsisnero c7ab4cf616 fix for quoting visualcpp 2020-04-01 12:31:48 -06: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
Reckordp 7c85a1ff07 Increase flexibility of CrossBuild 2020-03-08 14:23:55 +07:00
Yukihiro "Matz" Matsumoto ff57c0278f Remove broken MRB_INT16 configuration option. 2020-01-15 21:32:00 +09:00
KOBAYASHI Shuji b96fa664b0 Use rake instead of minirake in .gitlab-ci.yml
There was an error in the `.gitlab-ci.yml` generation script, so it was also
fixed.
2019-12-30 17:46:22 +09:00