Module: Yarp::ExtConf
- Defined in:
- ext/yarp/extconf.rb
Class Method Summary collapse
- .build_dir ⇒ Object
- .build_shared_rubyparser ⇒ Object
- .build_static_rubyparser ⇒ Object
- .build_target_rubyparser(target) ⇒ Object
- .configure ⇒ Object
- .configure_c_extension ⇒ Object
- .configure_rubyparser ⇒ Object
- .debug_mode_build? ⇒ Boolean
- .include_dir ⇒ Object
- .print_help ⇒ Object
- .root_dir ⇒ Object
- .static_link? ⇒ Boolean
Class Method Details
.build_dir ⇒ Object
90 91 92 |
# File 'ext/yarp/extconf.rb', line 90 def build_dir File.join(root_dir, "build") end |
.build_shared_rubyparser ⇒ Object
63 64 65 |
# File 'ext/yarp/extconf.rb', line 63 def build_shared_rubyparser build_target_rubyparser "build/librubyparser.#{RbConfig::CONFIG["SOEXT"]}" end |
.build_static_rubyparser ⇒ Object
67 68 69 |
# File 'ext/yarp/extconf.rb', line 67 def build_static_rubyparser build_target_rubyparser "build/librubyparser.a" end |
.build_target_rubyparser(target) ⇒ Object
71 72 73 74 75 76 77 78 79 80 |
# File 'ext/yarp/extconf.rb', line 71 def build_target_rubyparser(target) Dir.chdir(root_dir) do if !File.exist?("include/yarp/ast.h") && Dir.exist?(".git") # this block only exists to support building the gem from a "git" source, # normally we package up the configure and other files in the gem itself system("templates/template.rb", exception: true) end system("make", target, exception: true) end end |
.configure ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
# File 'ext/yarp/extconf.rb', line 8 def configure unless RUBY_ENGINE == "ruby" # On non-CRuby we only need the shared library, so build only that and not the C extension. # We also avoid `require "mkmf"` as that prepends the LLVM toolchain to PATH on TruffleRuby, # but we want to use the native toolchain here since librubyparser is run natively. build_shared_rubyparser File.write("Makefile", "all install clean:\n\t@#{RbConfig::CONFIG["NULLCMD"]}\n") return end require "mkmf" configure_c_extension configure_rubyparser create_makefile("yarp/yarp") if static_link? File.open('Makefile', 'a') do |mf| mf.puts mf.puts '# Automatically rebuild the extension if librubyparser.a changed' mf.puts '$(TARGET_SO): $(LOCAL_LIBS)' end end end |
.configure_c_extension ⇒ Object
33 34 35 36 |
# File 'ext/yarp/extconf.rb', line 33 def configure_c_extension append_cflags("-DYARP_DEBUG_MODE_BUILD") if debug_mode_build? append_cflags("-fvisibility=hidden") end |
.configure_rubyparser ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'ext/yarp/extconf.rb', line 38 def configure_rubyparser if static_link? static_archive_path = File.join(build_dir, "librubyparser.a") unless File.exist?(static_archive_path) build_static_rubyparser end $LOCAL_LIBS << " #{static_archive_path}" else shared_library_path = File.join(build_dir, "librubyparser.#{RbConfig::CONFIG["SOEXT"]}") unless File.exist?(shared_library_path) build_shared_rubyparser end unless find_library("rubyparser", "yp_parser_init", build_dir) raise "could not link against #{File.basename(shared_library_path)}" end end find_header("yarp.h", include_dir) or raise "yarp.h is required" # Explicitly look for the extension header in the parent directory # because we want to consistently look for yarp/extension.h in our # source files to line up with our mirroring in CRuby. find_header("yarp/extension.h", File.join(__dir__, "..")) or raise "yarp/extension.h is required" end |
.debug_mode_build? ⇒ Boolean
124 125 126 |
# File 'ext/yarp/extconf.rb', line 124 def debug_mode_build? enable_config("debug-mode-build", ENV["YARP_DEBUG_MODE_BUILD"] || false) end |
.include_dir ⇒ Object
86 87 88 |
# File 'ext/yarp/extconf.rb', line 86 def include_dir File.join(root_dir, "include") end |
.print_help ⇒ Object
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'ext/yarp/extconf.rb', line 94 def print_help print(<<~TEXT) USAGE: ruby #{$PROGRAM_NAME} [options] Flags that are always valid: --enable-static --disable-static Enable or disable static linking against librubyparser. The default is to statically link. --enable-debug-mode-build Enable debug mode build. You may also use set YARP_DEBUG_MODE_BUILD environment variable. --help Display this message. Environment variables used: YARP_DEBUG_MODE_BUILD Equivalent to `--enable-debug-mode-build` when set, even if nil or blank. TEXT end |
.root_dir ⇒ Object
82 83 84 |
# File 'ext/yarp/extconf.rb', line 82 def root_dir File.("../..", __dir__) end |
.static_link? ⇒ Boolean
120 121 122 |
# File 'ext/yarp/extconf.rb', line 120 def static_link? enable_config("static", true) end |