|
| 1 | +# Build System |
| 2 | + |
| 3 | +There are many ways to build YARP, which means the build system is a bit more complicated than usual. |
| 4 | + |
| 5 | +## General Design |
| 6 | + |
| 7 | +1. Templates are generated by `templates/template.rb` |
| 8 | +2. `autoconf` creates `./configure` and `autoheader` creates `config.h.in` (both files are platform-independent) |
| 9 | +3. `./configure` creates `include/yarp/config.h` (which contains `HAVE_*` macros, platform-specific) and the `Makefile` |
| 10 | +4. The `Makefile` compiles both `librubyparser.a` and `librubyparser.so/dylib/dll` from the `*.c` and `*.h` files |
| 11 | +5. The `Rakefile` `:compile` task ensures the above prerequisites are done, then calls `make`, |
| 12 | + and uses `Rake::ExtensionTask` to compile the C extension (using its `extconf.rb`), which uses `librubyparser.a` |
| 13 | + |
| 14 | +This way there is minimal duplication, and each layer builds on the previous one and has its own responsibilities. |
| 15 | + |
| 16 | +The static library exports no symbols, to avoid any conflict. |
| 17 | +The shared library exports some symbols, and this is fine since there should only be one librubyparser shared library |
| 18 | +loaded per process (i.e., at most one version of the yarp *gem* loaded in a process, only the gem uses the shared library). |
| 19 | + |
| 20 | +## The various ways to build YARP |
| 21 | + |
| 22 | +### Building from ruby/yarp repository with `bundle exec rake` |
| 23 | + |
| 24 | +`rake` calls `make` and then uses `Rake::ExtensionTask` to compile the C extension (see above). |
| 25 | + |
| 26 | +### Building the yarp gem by `gem install/bundle install` |
| 27 | + |
| 28 | +The gem contains the pre-generated templates, as well as `configure` and `config.h.in` |
| 29 | +When installing the gem, `extconf.rb` is used and that: |
| 30 | +* runs `./configure` which creates the `Makefile` and `include/yarp/config.h` |
| 31 | +* runs `make build/librubyparser.a` |
| 32 | +* compiles the C extension with mkmf |
| 33 | + |
| 34 | +When installing the gem on JRuby and TruffleRuby, no C extension is built, so instead of the last step, |
| 35 | +there is Ruby code using Fiddle which uses `librubyparser.so/dylib/dll` |
| 36 | +to implement the same methods as the C extension, but using serialization instead of many native calls/accesses |
| 37 | +(JRuby does not support C extensions, serialization is faster on TruffleRuby than the C extension). |
| 38 | + |
| 39 | +### Building the yarp gem from git, e.g. `gem 'yarp', github: 'ruby/yarp'` |
| 40 | + |
| 41 | +The same as above, except the `extconf.rb` additionally runs first: |
| 42 | +* `templates/template.rb` to generate the templates |
| 43 | +* `autoconf` and `autoheader` to generate `configure` and `config.h.in` |
| 44 | + |
| 45 | +Because of course those files are not part of the git repository. |
| 46 | + |
| 47 | +### Building YARP as part of CRuby |
| 48 | + |
| 49 | +[This script](https://github.com/ruby/ruby/blob/32e828bb4a6c65a392b2300f3bdf93008c7b6f25/tool/sync_default_gems.rb#L399-L426) imports YARP sources in CRuby. |
| 50 | + |
| 51 | +The script generates the templates when importing. |
| 52 | + |
| 53 | +`include/yarp/config.h` is replaced by `#include "ruby/config.h"`. |
| 54 | +It is assumed that CRuby's `./configure` is a superset of YARP's configure checks. |
| 55 | + |
| 56 | +YARP's `autotools` is not used at all in CRuby and in fact YARP's `Makefile` is not used either. |
| 57 | +Instead, CRuby's `autotools` setup is used, and `CRuby`'s Makefiles are used. |
| 58 | + |
| 59 | +### Building YARP as part of TruffleRuby |
| 60 | + |
| 61 | +[This script](https://github.com/oracle/truffleruby/blob/master/tool/import-yarp.sh) imports YARP sources in TruffleRuby. |
| 62 | +The script generates the templates when importing. |
| 63 | +It also generates `configure` and `config.h.in` (to avoid needing `autotools` on every machine building TruffleRuby). |
| 64 | + |
| 65 | +Then when `mx build` builds TruffleRuby and the `yarp` mx project inside, it: |
| 66 | +* runs `./configure` |
| 67 | +* runs `make` |
| 68 | + |
| 69 | +Then the `yarp bindings` mx project is built, which contains the [bindings](https://github.com/oracle/truffleruby/blob/master/src/main/c/yarp_bindings/src/yarp_bindings.c) |
| 70 | +and links to `librubyparser.a` (to avoid exporting symbols, so no conflict when installing the yarp gem). |
| 71 | + |
| 72 | +### Building YARP as part of JRuby |
| 73 | + |
| 74 | +TODO, probably similar to TruffleRuby. |
0 commit comments