From 7a719f6026a467247dedaf5bd20761845d013f00 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sun, 8 Dec 2024 12:29:31 +0100 Subject: [PATCH 1/3] Fix broken link in build_system.md --- docs/build_system.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/build_system.md b/docs/build_system.md index 0b771d202f..f5d456fe17 100644 --- a/docs/build_system.md +++ b/docs/build_system.md @@ -66,7 +66,7 @@ The script generates the templates when importing. Then when `mx build` builds TruffleRuby and the `prism` mx project inside, it runs `make`. -Then the `prism bindings` mx project is built, which contains the [bindings](https://github.com/oracle/truffleruby/blob/master/src/main/c/prism_bindings/src/prism_bindings.c) +Then the `prism bindings` mx project is built, which contains the [bindings](https://github.com/oracle/truffleruby/blob/vm-24.1.1/src/main/c/yarp_bindings/src/yarp_bindings.c) and links to `libprism.a` (to avoid exporting symbols, so no conflict when installing the prism gem). ### Building prism as part of JRuby From 71f62340ba0bd138a646c66f77055a571571f859 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sun, 8 Dec 2024 12:38:02 +0100 Subject: [PATCH 2/3] Remove dead code --- ext/prism/extconf.rb | 6 ------ 1 file changed, 6 deletions(-) diff --git a/ext/prism/extconf.rb b/ext/prism/extconf.rb index 682fdcf982..20ba28fe46 100644 --- a/ext/prism/extconf.rb +++ b/ext/prism/extconf.rb @@ -107,12 +107,6 @@ def make(env, target) # By default, all symbols are hidden in the shared library. append_cflags("-fvisibility=hidden") -# We need to link against the libprism.a archive, which is built by the -# project's `Makefile`. We'll build it if it doesn't exist yet, and then add it -# to `mkmf`'s list of local libraries. -archive_target = "build/libprism.a" -archive_path = File.expand_path("../../#{archive_target}", __dir__) - def src_list(path) srcdir = path.dup RbConfig.expand(srcdir) # mutates srcdir :-/ From b760aa40695a7ea2d6cd6dbebddd4e33a853a257 Mon Sep 17 00:00:00 2001 From: Benoit Daloze Date: Sun, 8 Dec 2024 12:44:28 +0100 Subject: [PATCH 3/3] Update build system docs with the latest changes --- docs/build_system.md | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/docs/build_system.md b/docs/build_system.md index f5d456fe17..98581f3898 100644 --- a/docs/build_system.md +++ b/docs/build_system.md @@ -16,9 +16,9 @@ The main solution for the second point seems a Makefile, otherwise many of the u ## General Design 1. Templates are generated by `templates/template.rb` -4. The `Makefile` compiles both `libprism.a` and `libprism.{so,dylib,dll}` from the `src/**/*.c` and `include/**/*.h` files -5. The `Rakefile` `:compile` task ensures the above prerequisites are done, then calls `make`, - and uses `Rake::ExtensionTask` to compile the C extension (using its `extconf.rb`), which uses `libprism.a` +2. The `Makefile` compiles both `libprism.a` and `libprism.{so,dylib,dll}` from the `src/**/*.c` and `include/**/*.h` files +3. The `Rakefile` `:compile` task ensures the above prerequisites are done, then calls `make`, + and uses `Rake::ExtensionTask` to compile the C extension (using its `extconf.rb`) This way there is minimal duplication, and each layer builds on the previous one and has its own responsibilities. @@ -35,14 +35,11 @@ loaded per process (i.e., at most one version of the prism *gem* loaded in a pro ### Building the prism gem by `gem install/bundle install` The gem contains the pre-generated templates. -When installing the gem, `extconf.rb` is used and that: -* runs `make build/libprism.a` -* compiles the C extension with mkmf - -When installing the gem on JRuby and TruffleRuby, no C extension is built, so instead of the last step, -there is Ruby code using FFI which uses `libprism.{so,dylib,dll}` -to implement the same methods as the C extension, but using serialization instead of many native calls/accesses -(JRuby does not support C extensions, serialization is faster on TruffleRuby than the C extension). + +When installing the gem on CRuby, `extconf.rb` is used and that compiles the C extension with mkmf, including both the extension files and the sources of prism itself. + +When installing the gem on JRuby and TruffleRuby, no C extension is built, so instead the `extconf.rb` runs `make build/libprism.{so,dylib,dll}`. +There is Ruby code using FFI which uses `libprism.{so,dylib,dll}` to implement the same methods as the C extension, but using serialization instead of many native calls/accesses (JRuby does not support C extensions, serialization is faster on TruffleRuby than the C extension). ### Building the prism gem from git, e.g. `gem "prism", github: "ruby/prism"`