Commit Graph

38 Commits

Author SHA1 Message Date
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
Yukihiro "Matz" Matsumoto 273ca4d4f6 tasks/toolchains/gcc.rake: remove -lm on Windows; #5757 2022-07-30 07:33:45 +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 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
Yukihiro "Matz" Matsumoto 66d044ec3e Remove -Wdeclaration-after-statement from gcc options; #5159 2020-11-21 17:05:16 +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
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
take-cheeze 38fdca82c6 Use GNU extension in C++ for cygwin 2019-12-23 20:58:43 +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
KOBAYASHI Shuji 07c6b7f0ab Refine tasks/toolchains/(gcc|clang).rake
- Make sure to specify `-std=gnu99` for C compiler flag.
- Make sure to specify `-Wzero-length-array` for C/C++ compiler flag (Clang).
- Extract similar codes.
2019-09-12 21:45:47 +09:00
KOBAYASHI Shuji e2bb5ce079 Refer also CXX and CC env vars as linker command in gcc and clang toolchain
ref #4292
2019-03-06 20:42:31 +09:00
KOBAYASHI Shuji 31f1b4a553 Remove explicit set of DISABLE_GEMS
`DISABLE_GEMS` is automatically set (or unset); ref #790
2019-02-23 18:29:37 +09:00
dearblue 129a804136 Append cflags for undefined macro 2018-12-22 21:58:58 +09:00
dearblue 366848996a Clear terminated space 2018-09-07 22:32:34 +09:00
Yukihiro "Matz" Matsumoto 6d42195fb2 Add enable_sanitizer method for clang and gcc.
The patch is created by @take_cheese in #3872
2017-12-11 17:14:50 +09:00
Yukihiro "Matz" Matsumoto 1a1f834ade Compile C files by C compiler when C++ files mixed.
ref #3267 #3470

By this commit, mruby do not use C++ ABI mode unless
you specify explicitly. It compiles C files by C
compilers, with C++ exception enabled when it sees
C++ files in your configured mrbgems.

I haven't tried visualcpp, so please submit an issue
if you see any problem with C++ gems on Windows.
2017-02-28 23:27:13 +09:00
Tomasz Dąbrowski d7a6070d22 Fixed language standard mode for GCC (cannot use gnu99 with C++, c++03 used instead) 2016-11-24 09:28:00 +09:00
Tomasz Dąbrowski 44c3859a97 Fix for compiling mruby as C++ on Visual Studio toolchain 2016-11-24 09:28:00 +09:00
asatou d0668cf9c9 Fix build error in ruby 1.8.
Apply change of #2978 to :clang, :gcc, :visualcpp toolchains
2016-01-13 16:02:58 +09:00
Kouhei Sutou 058dc7bd41 Enable -Wwrite-strings by default for GCC 2015-04-18 21:43:40 +09:00
Masaki Muranaka 78176ee7f5 Remove redundant substitutions.
"#{MRUBY_ROOT}/include" is set in Command::Compiler#initialize .
2014-06-08 14:42:21 +09:00
take_cheeze 2063bee7cc Remove use of define_singleton_method. 2014-05-01 22:51:35 +09:00
take_cheeze b4a702f27d Implement header search for gcc and clang. 2014-05-01 16:49:54 +09:00
bggd 3ff4af91a2 remove -Werror=declaration-after-statement 2014-02-24 11:08:23 +09:00
bggd 15b484df38 Add warning for C89-style variable declarations 2014-02-23 16:08:56 +09:00
Yukihiro "Matz" Matsumoto f5bd87b9e6 add CFLAGS as a fallback from CXXFLAGS; ref #1594 2013-11-25 09:51:44 +09:00
crimsonwoods 92916bb4a6 Modify referenced environment variables.
'CXX' is used instead of 'CC'.
'CXXFLAGS' is used instead of 'CFLAGS'.
2013-11-23 21:47:47 -08:00
crimsonwoods caf4d63229 Modify build script for gcc.
Newly added compile option '-std=gnu99' is not necessary for C++.
And 'g++' should be used to compile for C++ source codes, I think.
2013-11-23 19:30:52 -08:00
cremno 53139cbb15 GCC: add -std=gnu99 to CFLAGS
- this change prevents issues like #1539 in the future
- Clang's default is already gnu99 but GCC's is gnu89
- mruby is C99 (+ GNU exts), not C89 (+ GNU exts)
2013-11-18 21:26:50 +01:00
Yuichiro MASUI 0970ca9572 Support to build on pwd != mruby source root 2013-02-23 19:03:59 +09:00
Yuichiro MASUI 5a152c82e6 load MRUBY_CONFIG script after 'build_config.rb' 2013-01-28 18:22:11 +09:00
Yuichiro MASUI dd680b6e67 Add flags_after_libraries 2013-01-24 11:33:56 +09:00
Yuichiro MASUI b1623b9e58 merge master 2013-01-24 11:21:39 +09:00
Yuichiro MASUI f6edd3065c Add C++/Objective-C init in toolchains 2013-01-22 14:06:59 +09:00
Yuichiro MASUI a1c4992905 Added flags_before_libraries to linker 2013-01-21 22:15:15 +09:00
Yuichiro MASUI ced80d2b4b Improved build scripts and config files 2013-01-20 22:48:42 +09:00