Module: Tebako::Packager::PatchLibraries

Defined in:
lib/tebako/packager/patch_libraries.rb

Overview

Ruby patching definitions (pass2)

Constant Summary collapse

DARWIN_BREW_LIBS =

rubocop:disable Style/WordArray

[
  ["zlib", "z"],              ["gdbm", "gdbm"],           ["readline", "readline"], ["libffi", "ffi"],
  ["ncurses", "ncurses"],     ["lz4", "lz4"],             ["xz", "lzma"],           ["libyaml", "yaml"],
  ["boost", "boost_chrono"],  ["double-conversion", "double-conversion"],
  # DwarFS v0.15 compression/hash deps (were staged into deps_lib_dir under the bridge)
  ["xxhash", "xxhash"],               ["zstd", "zstd"],
  ["brotli", "brotlienc"],            ["brotli", "brotlidec"],            ["brotli", "brotlicommon"],
  # DwarFS reader link deps
  ["boost", "boost_filesystem"],      ["boost", "boost_atomic"],
  ["boost", "boost_iostreams"],       ["boost", "boost_program_options"],
  ["boost", "boost_context"],         ["boost", "boost_regex"],
  ["boost", "boost_thread"],
  ["flac", "FLAC"],                   ["flac", "FLAC++"],
  ["libogg", "ogg"]
].freeze
DARWIN_BREW_LIBS_PRE_31 =
[["openssl@1.1", "ssl"], ["openssl@1.1", "crypto"]].freeze
DARWIN_BREW_LIBS_31 =
[["openssl@3", "ssl"], ["openssl@3", "crypto"]].freeze
DARWIN_DEP_LIBS_1 =

DwarFS v0.15 split static libs (installed to deps_lib_dir by libdwarfs). folly/fbthrift are gone; the thrift/fsst/frozen libs are now real .a files. glog/gflags/fmt are no longer linked (fmt is header-only / baked into the DwarFS libs).

[
  "dwarfs_reader", "dwarfs_common",
  "dwarfs_fsst", "dwarfs_frozen", "dwarfs_thrift_lite_v2",
  "dwarfs_metadata_thrift", "dwarfs_compression_thrift",
  "dwarfs_history_thrift", "dwarfs_features_thrift"
].freeze
LIBTEBAKOFS =

rubocop:enable Style/WordArray

"-Wl,--push-state,--whole-archive -l:libtebako-fs.a -Wl,--pop-state"
COMMON_LINUX_LIBRARIES =
[
  LIBTEBAKOFS,            "-l:libdwarfs-wr.a",          "-l:libdwarfs.a",             "LIBCOMPRESSION",
  "-l:libfolly.a",        "-l:libfsst.a",               "-l:libmetadata_thrift.a",    "-l:libthrift_light.a",
  "-l:libxxhash.a",       "-l:libfmt.a",                "-l:libdouble-conversion.a",  "-l:libglog.a",
  "-l:libgflags.a",       "-l:libevent.a"
].freeze
COMMON_ARCHIEVE_LIBRARIES =
[
  "-l:libarchive.a",     "-l:liblz4.a",        "-l:libz.a",             "-l:libzstd.a",
  "-l:libbrotlienc.a",   "-l:libbrotlidec.a",  "-l:libbrotlicommon.a",  "-l:liblzma.a"
].freeze
LINUX_GNU_LIBRARIES =
[
  "-l:libiberty.a",      "-l:libacl.a",          "-l:libssl.a",           "-l:libcrypto.a",
  "-l:libgdbm.a",        "-l:libreadline.a",     "-l:libtinfo.a",         "-l:libffi.a",
  "-l:libncurses.a",     "-l:libjemalloc.a",     "-l:libcrypt.a",         "-l:libanl.a",
  "LIBYAML",             "-l:libboost_system.a", "-l:libboost_chrono.a",  "-l:libutil.a",
  "-l:libstdc++.a",      "-lgcc_eh",             "-l:libunwind.a",        "-l:liblzma.a",
  "-l:librt.a",          "-ldl",                 "-lpthread",             "-lm"
].freeze
LINUX_MUSL_LIBRARIES =
[
  "-l:libiberty.a",       "-l:libacl.a",          "-l:libssl.a",          "-l:libcrypto.a",
  "-l:libreadline.a",     "-l:libgdbm.a",         "-l:libffi.a",          "-l:libncurses.a",
  "-l:libjemalloc.a",     "-l:libcrypt.a",        "LIBYAML",              "-l:libboost_system.a",
  "-l:libboost_chrono.a", "-l:librt.a",           "-l:libstdc++.a",       "-lgcc_eh",
  " -l:libunwind.a",      "-l:liblzma.a",         "-ldl",                 "-lpthread"
].freeze
MSYS_LIBRARIES =
[
  "-l:liblz4.a",             "-l:libz.a",               "-l:libzstd.a",            "-l:liblzma.a",
  "-l:libncurses.a",         "-l:liblzma.a",            "-l:libiberty.a",          "LIBYAML",
  "-l:libffi.a",             "-l:libboost_chrono-mt.a", "-l:libstdc++.a",          "-l:libdl.a",
  "-static-libgcc",          "-static-libstdc++",       "-l:libssl.a",             "-l:libcrypto.a",
  "-l:libz.a",               "-l:libwinpthread.a",      "-lcrypt32",               "-lshlwapi",
  "-lwsock32",               "-liphlpapi",              "-limagehlp",              "-lbcrypt",
  "-lole32",                 "-loleaut32",              "-luuid",                  "-lws2_32"
].freeze

Class Method Summary collapse

Class Method Details

.darwin_libraries(deps_lib_dir, ruby_ver, with_compression) ⇒ Object



142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# File 'lib/tebako/packager/patch_libraries.rb', line 142

def darwin_libraries(deps_lib_dir, ruby_ver, with_compression)
  libs = String.new

  DARWIN_DEP_LIBS_1.each { |lib| libs << "#{deps_lib_dir}/lib#{lib}.a " }
  process_brew_libs!(libs, ruby_ver.ruby31? ? DARWIN_BREW_LIBS_31 : DARWIN_BREW_LIBS_PRE_31)
  process_brew_libs!(libs, DARWIN_BREW_LIBS)

  # DwarFS compression codecs self-register via static initializers, so force_load the
  # (de)compressor libs to keep them (the reader would otherwise drop the unreferenced ones).
  compression_lib =
    if with_compression
      "-force_load #{deps_lib_dir}/libdwarfs_decompressor.a " \
      "-force_load #{deps_lib_dir}/libdwarfs_compressor.a"
    else
      ""
    end
  "-ltebako-fs -ldwarfs-wr #{compression_lib} #{libs} #{deps_lib_dir}/libjemalloc.a -lc++ -lc++abi"
end

.linux_gnu_libraries(ruby_ver, with_compression) ⇒ Object



109
110
111
112
# File 'lib/tebako/packager/patch_libraries.rb', line 109

def linux_gnu_libraries(ruby_ver, with_compression)
  libraries = COMMON_LINUX_LIBRARIES + COMMON_ARCHIEVE_LIBRARIES + LINUX_GNU_LIBRARIES
  linux_libraries(libraries, ruby_ver, with_compression)
end

.linux_libraries(libraries, ruby_ver, with_compression) ⇒ Object



119
120
121
122
123
124
125
126
127
128
129
130
# File 'lib/tebako/packager/patch_libraries.rb', line 119

def linux_libraries(libraries, ruby_ver, with_compression)
  libraries.map! do |lib|
    if lib == "LIBYAML"
      PatchHelpers.yaml_reference(ruby_ver)
    elsif lib == "LIBCOMPRESSION"
      with_compression ? "-Wl,--push-state,--whole-archive -l:libdwarfs_compression.a -Wl,--pop-state" : ""
    else
      lib
    end
  end
  libraries.join(" ")
end

.linux_musl_libraries(ruby_ver, with_compression) ⇒ Object



114
115
116
117
# File 'lib/tebako/packager/patch_libraries.rb', line 114

def linux_musl_libraries(ruby_ver, with_compression)
  libraries = COMMON_LINUX_LIBRARIES + COMMON_ARCHIEVE_LIBRARIES + LINUX_MUSL_LIBRARIES
  linux_libraries(libraries, ruby_ver, with_compression)
end

.mlibs(ostype, deps_lib_dir, ruby_ver, with_compression) ⇒ Object

..................................................... Notes re linux libraries

  1. This order is important: -lgcc_eh -l:libunwind.a -l:liblzma.a lzma is used to process debug sections. gcc_eh shall be linked before unwind to avoid duplicate symbols.
  2. -lgcc_eh assumes -static-libgcc (applied in CMakeLists.ext, RUBY_C_FLAGS)
  3. -static-libstdc++ did not work, not sure why [TODO ?]
  4. When clang is used linker links libraries specified in exensions in such way that they are linked shared (libz, libffi, libreadline, libncurses, libtinfo, ... ) Using stuff like -l:libz.a does not help; there is a reference to libz.so anyway. This is fixed by ext/extmk.rb patch [TODO ?] .....................................................


173
174
175
176
177
178
179
180
181
182
183
184
# File 'lib/tebako/packager/patch_libraries.rb', line 173

def mlibs(ostype, deps_lib_dir, ruby_ver, with_compression)
  scmb = ScenarioManagerBase.new(ostype)
  if scmb.msys?
    msys_libraries(ruby_ver, with_compression)
  elsif scmb.macos?
    darwin_libraries(deps_lib_dir, ruby_ver, with_compression)
  elsif scmb.musl?
    linux_musl_libraries(ruby_ver, with_compression)
  else
    linux_gnu_libraries(ruby_ver, with_compression)
  end
end

.msys_libraries(ruby_ver, with_compression) ⇒ Object



132
133
134
135
136
# File 'lib/tebako/packager/patch_libraries.rb', line 132

def msys_libraries(ruby_ver, with_compression)
  libraries = with_compression ? ["-Wl,-Bstatic"] : []
  libraries = libraries + COMMON_LINUX_LIBRARIES + MSYS_LIBRARIES
  linux_libraries(libraries, ruby_ver, with_compression)
end

.process_brew_libs!(libs, brew_libs) ⇒ Object



138
139
140
# File 'lib/tebako/packager/patch_libraries.rb', line 138

def process_brew_libs!(libs, brew_libs)
  brew_libs.each { |lib| libs << "#{PatchHelpers.get_prefix_macos(lib[0]).chop}/lib/lib#{lib[1]}.a " }
end