tebako 0.7.3 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
data/common.env CHANGED
@@ -1,5 +1,5 @@
1
1
  BUILD_TYPE=Release
2
2
  DEPS=deps
3
3
  INCBIN_TAG=348e36b
4
- DWARFS_WR_TAG=v0.5.4
4
+ DWARFS_WR_TAG=v0.5.5
5
5
  RUBY_VER=3.1.6
data/exe/tebako-packager CHANGED
@@ -48,26 +48,7 @@ begin
48
48
  end
49
49
 
50
50
  Tebako::Packager.pass1(ARGV[1], ARGV[2], ARGV[3], ARGV[4], ARGV[5])
51
- when "stash"
52
- # ARGV[0] -- command
53
- # ARGV[1] -- DATA_SRC_DIR
54
- # ARGV[2] -- RUBY_STASH_DIR
55
- unless ARGV.length == 3
56
- raise Tebako::Error,
57
- "tebako-packager stash command expects 3 arguments, #{ARGV.length} has been provided."
58
- end
59
-
60
- Tebako::Packager.stash(ARGV[1], ARGV[2])
61
- when "strip"
62
- # ARGV[0] -- command
63
- # ARGV[1] -- OSTYPE
64
- # ARGV[2] -- DATA_SRC_DIR
65
- unless ARGV.length == 3
66
- raise Tebako::Error,
67
- "tebako-packager strip command expects 3 arguments, #{ARGV.length} has been provided."
68
- end
69
51
 
70
- Tebako::Stripper.strip(ARGV[1], ARGV[2])
71
52
  when "pass1a"
72
53
  # ARGV[0] -- command
73
54
  # ARGV[1] -- RUBY_SOURCE_DIR
@@ -114,6 +95,16 @@ begin
114
95
  # That shall match CMakeLists.txt settings
115
96
  Tebako::Packager.deploy(ARGV[1], ARGV[4], ARGV[5], ARGV[11], ARGV[7], ARGV[8], ARGV[9])
116
97
 
98
+ when "finalize"
99
+ # ARGV[0] -- command
100
+ # ARGV[1] -- OSTYPE
101
+ # ARGV[2] -- RUBY_SOURCE_DIR
102
+ # ARGV[3] -- APP_NAME
103
+ unless ARGV.length == 4
104
+ raise Tebako::Error,
105
+ "tebako-packager finalize command expects 4 arguments, #{ARGV.length} has been provided."
106
+ end
107
+ Tebako::Packager.finalize(ARGV[1], ARGV[2], ARGV[3])
117
108
  else
118
109
  raise Tebako::Error, "tebako-packager cannot process #{ARGV[0]} command"
119
110
  end
@@ -121,5 +112,4 @@ rescue Tebako::Error => e
121
112
  puts "tebako-packager failed: #{e.message} [#{e.error_code}]"
122
113
  exit(e.error_code)
123
114
  end
124
-
125
115
  exit(0)
data/lib/tebako/cli.rb CHANGED
@@ -61,8 +61,8 @@ module Tebako
61
61
  def clean_ruby
62
62
  puts "Cleaning Ruby sources from tebako packaging environment"
63
63
  suffix = options["Ruby"].nil? ? "" : "_#{options["Ruby"]}"
64
- nmr = "src/_ruby_#{suffix}*"
65
- nms = "stash_#{suffix}"
64
+ nmr = "src/_ruby#{suffix}*"
65
+ nms = "stash#{suffix}*"
66
66
  FileUtils.rm_rf(Dir.glob(File.join(deps, nmr)), secure: true)
67
67
  FileUtils.rm_rf(Dir.glob(File.join(deps, nms)), secure: true)
68
68
  end
@@ -40,12 +40,10 @@ module Tebako
40
40
  RUBY_VERSIONS = {
41
41
  "2.7.8" => "c2dab63cbc8f2a05526108ad419efa63a67ed4074dbbcf9fc2b1ca664cb45ba0",
42
42
  "3.0.7" => "2a3411977f2850431136b0fab8ad53af09fb74df2ee2f4fb7f11b378fe034388",
43
- "3.1.4" => "a3d55879a0dfab1d7141fdf10d22a07dbf8e5cdc4415da1bde06127d5cc3c7b6",
44
- "3.1.5" => "3685c51eeee1352c31ea039706d71976f53d00ab6d77312de6aa1abaf5cda2c5",
45
43
  "3.1.6" => "0d0dafb859e76763432571a3109d1537d976266be3083445651dc68deed25c22",
46
- "3.2.3" => "af7f1757d9ddb630345988139211f1fd570ff5ba830def1cc7c468ae9b65c9ba",
47
- "3.2.4" => "c72b3c5c30482dca18b0f868c9075f3f47d8168eaf626d4e682ce5b59c858692"
48
- # "3.3.3" => "83c05b2177ee9c335b631b29b8c077b4770166d02fa527f3a9f6a40d13f3cce2"
44
+ "3.2.4" => "c72b3c5c30482dca18b0f868c9075f3f47d8168eaf626d4e682ce5b59c858692",
45
+ "3.3.3" => "83c05b2177ee9c335b631b29b8c077b4770166d02fa527f3a9f6a40d13f3cce2",
46
+ "3.3.4" => "fe6a30f97d54e029768f2ddf4923699c416cdbc3a6e96db3e2d5716c7db96a34"
49
47
  }.freeze
50
48
 
51
49
  DEFAULT_RUBY_VERSION = "3.1.6"
@@ -29,6 +29,7 @@ require "fileutils"
29
29
  require "find"
30
30
 
31
31
  require_relative "error"
32
+ require_relative "packager/patch_helpers"
32
33
 
33
34
  # Tebako - an executable packager
34
35
  module Tebako
@@ -65,11 +66,16 @@ module Tebako
65
66
  end
66
67
 
67
68
  def deploy
68
- system("#{gem_command} env")
69
- install_gem("tebako-runtime")
70
- install_gem("bundler", Tebako::BUNDLER_VERSION) if needs_bundler?
71
-
72
- deploy_solution
69
+ Packager::PatchHelpers.with_env(deploy_env) do
70
+ unless Packager::PatchHelpers.ruby31?(@ruby_ver)
71
+ update_rubygems
72
+ patch_after_rubygems_update(@target_dir, @ruby_api_version)
73
+ end
74
+ system("#{gem_command} env")
75
+ install_gem("tebako-runtime")
76
+ install_gem("bundler", BUNDLER_VERSION) if needs_bundler?
77
+ deploy_solution
78
+ end
73
79
  end
74
80
 
75
81
  def deploy_env
@@ -264,6 +270,13 @@ module Tebako
264
270
  end
265
271
  end
266
272
 
273
+ def patch_after_rubygems_update(target_dir, ruby_api_ver)
274
+ # Autoload cannot handle statically linked openssl extension
275
+ # Changing it to require seems to be the simplest solution
276
+ Packager::PatchHelpers.patch_file("#{target_dir}/lib/ruby/site_ruby/#{ruby_api_ver}/rubygems/openssl.rb",
277
+ { "autoload :OpenSSL, \"openssl\"" => "require \"openssl\"" })
278
+ end
279
+
267
280
  def run_with_capture(args)
268
281
  puts " ... @ #{args.join(" ")}"
269
282
  out, st = Open3.capture2e(*args)
@@ -178,13 +178,16 @@ module Tebako
178
178
  "$(WINMAINOBJ) $(EXTOBJS) $(LIBRUBYARG) $(LIBS) -o $@ # tebako patched",
179
179
 
180
180
  "--output-exp=$(RUBY_EXP) \\" =>
181
- "--output-exp=$(RUBY_EXP) --output-lib=$(LIBRUBY) --output-def=tebako.def \\",
181
+ "--output-exp=$(RUBY_EXP) --output-lib=$(LIBRUBY) --output-def=tebako.def \\",
182
182
 
183
- " @rm -f $(PROGRAM)" =>
184
- "# tebako patched @rm -f $(PROGRAM)",
183
+ "--export-all $(LIBRUBY_A) $(LIBS) -o $(PROGRAM)" =>
184
+ "--export-all $(LIBRUBY_A) $(LIBS) -o program-stub.exe # tebako patched",
185
+
186
+ "@rm -f $(PROGRAM)" =>
187
+ "@rm -f program-stub.exe # tebako patched",
185
188
 
186
189
  " $(Q) $(LDSHARED) $(DLDFLAGS) $(OBJS) dmyext.o $(SOLIBS) -o $(PROGRAM)" =>
187
- "# tebako patched $(Q) $(LDSHARED) $(DLDFLAGS) $(OBJS) dmyext.o $(SOLIBS) -o $(PROGRAM)",
190
+ "# tebako patched $(Q) $(LDSHARED) $(DLDFLAGS) $(OBJS) dmyext.o $(SOLIBS) -o $(PROGRAM)",
188
191
 
189
192
  "RUBYDEF = $(DLL_BASE_NAME).def" => GNUMAKEFILE_IN_WINMAIN_SUBST
190
193
  }
@@ -38,23 +38,26 @@ module Tebako
38
38
  class << self
39
39
  def get_patch_map(ostype, deps_lib_dir, ruby_ver)
40
40
  patch_map = get_patch_map_base(ostype, deps_lib_dir, ruby_ver)
41
-
42
41
  patch_map.store("thread_pthread.c", LINUX_MUSL_THREAD_PTHREAD_PATCH) if ostype =~ /linux-musl/
43
-
44
42
  if PatchHelpers.msys?(ostype)
45
43
  patch_map.merge!(get_msys_patches(ruby_ver))
46
44
  elsif PatchHelpers.ruby3x?(ruby_ver)
47
- # [TODO] Do we really need it for platforms other then Windows ??
48
45
  patch_map.store("common.mk", COMMON_MK_PATCH)
49
46
  end
50
-
51
- patch_map
47
+ extend_patch_map_r33(patch_map, ostype, deps_lib_dir, ruby_ver)
52
48
  end
53
49
 
54
50
  private
55
51
 
56
52
  include Tebako::Packager::PatchBuildsystem
57
53
  include Tebako::Packager::PatchLiterals
54
+ def extend_patch_map_r33(patch_map, ostype, deps_lib_dir, ruby_ver)
55
+ if PatchHelpers.ruby33?(ruby_ver) || PatchHelpers.msys?(ostype)
56
+ patch_map.store("config.status",
57
+ get_config_status_patch(ostype, deps_lib_dir, ruby_ver))
58
+ end
59
+ patch_map
60
+ end
58
61
 
59
62
  def get_dir_c_patch(ostype)
60
63
  pattern = PatchHelpers.msys?(ostype) ? "/* define system APIs */" : "#ifdef HAVE_GETATTRLIST"
@@ -91,21 +94,17 @@ module Tebako
91
94
  end
92
95
 
93
96
  def get_util_c_patch(ruby_ver)
94
- if PatchHelpers.ruby316?(ruby_ver)
97
+ if PatchHelpers.ruby31?(ruby_ver)
95
98
  PatchHelpers.patch_c_file_post("#endif /* !HAVE_GNU_QSORT_R */")
96
99
  else
97
100
  PatchHelpers.patch_c_file_pre("#ifndef S_ISDIR")
98
101
  end
99
102
  end
100
103
 
101
- def get_msys_mkconfig_rb_patches(ruby_ver)
104
+ def get_tool_mkconfig_rb_patch(ostype)
105
+ subst = PatchHelpers.msys?(ostype) ? TOOL_MKCONFIG_RB_SUBST_MSYS : TOOL_MKCONFIG_RB_SUBST
102
106
  {
103
- " if fast[name]" => TOOLS_MKCONFIG_RB_SUBST,
104
- "when /RUBYGEMS/; next" =>
105
- "when /RUBYGEMS/; next\n\n" \
106
- "# Start of tebako patch\n" \
107
- "when /MAINLIBS/; val = #{PatchLibraries.msys_base_libs(ruby_ver)}\n" \
108
- "# End of tebako patch"
107
+ " if fast[name]" => subst
109
108
  }
110
109
  end
111
110
 
@@ -119,10 +118,9 @@ module Tebako
119
118
  end
120
119
 
121
120
  def get_patch_map_base(ostype, deps_lib_dir, ruby_ver)
122
- mcrb_subst = PatchHelpers.msys?(ostype) ? get_msys_mkconfig_rb_patches(ruby_ver) : TOOL_MKCONFIG_RB_PATCH
123
121
  {
124
122
  "template/Makefile.in" => template_makefile_in_patch(ostype, deps_lib_dir, ruby_ver),
125
- "tool/mkconfig.rb" => mcrb_subst,
123
+ "tool/mkconfig.rb" => get_tool_mkconfig_rb_patch(ostype),
126
124
  "dir.c" => get_dir_c_patch(ostype), "dln.c" => get_dln_c_patch(ostype, ruby_ver),
127
125
  "io.c" => get_io_c_patch(ostype, ruby_ver), "main.c" => MAIN_C_PATCH,
128
126
  "file.c" => PatchHelpers.patch_c_file_pre("/* define system APIs */"),
@@ -135,7 +133,7 @@ module Tebako
135
133
  {
136
134
  "MAINLIBS = #{yjit_libs}@MAINLIBS@" =>
137
135
  "# -- Start of tebako patch -- \n" \
138
- "MAINLIBS = #{yjit_libs}#{PatchLibraries.mlibs(ostype, deps_lib_dir, ruby_ver)}" \
136
+ "MAINLIBS = #{yjit_libs}#{PatchLibraries.mlibs(ostype, deps_lib_dir, ruby_ver, true)}\n" \
139
137
  "# -- End of tebako patch -- \n"
140
138
  }
141
139
  end
@@ -57,10 +57,14 @@ module Tebako
57
57
  "$(EXTOBJS) $(LIBRUBYARG_STATIC) $(OUTFLAG)$@\n" \
58
58
  "# -- End of tebako patch --"
59
59
 
60
- TEMPLATE_MAKEFILE_IN_BASE_PATTERN =
60
+ TEMPLATE_MAKEFILE_IN_BASE_PATTERN_PRE_3_3 =
61
61
  "\t\t$(Q) $(PURIFY) $(CC) $(EXE_LDFLAGS) $(XLDFLAGS) $(MAINOBJ) $(EXTOBJS) " \
62
62
  "$(LIBRUBYARG) $(MAINLIBS) $(LIBS) $(EXTLIBS) $(OUTFLAG)$@"
63
63
 
64
+ TEMPLATE_MAKEFILE_IN_BASE_PATTERN =
65
+ "\t\t$(Q) $(PURIFY) $(CC) $(EXE_LDFLAGS) $(XLDFLAGS) $(MAINOBJ) $(EXTOBJS) " \
66
+ "$(LIBRUBYARG) $(MAINLIBS) $(EXTLIBS) $(OUTFLAG)$@"
67
+
64
68
  TEMPLATE_MAKEFILE_IN_BASE_PATCH =
65
69
  "# -- Start of tebako patch --\n" \
66
70
  "\t\t$(Q) $(PURIFY) $(CC) $(EXE_LDFLAGS) $(MAINOBJ) " \
@@ -73,13 +77,23 @@ module Tebako
73
77
  "$(EXTOBJS) $(LIBRUBYARG_STATIC) $(OUTFLAG)$@\n" \
74
78
  "# -- End of tebako patch --"
75
79
 
76
- def template_makefile_in_patch_two(ostype, ruby_ver)
80
+ def template_makefile_in_subst(ostype, ruby_ver)
77
81
  if PatchHelpers.msys?(ostype)
78
- { TEMPLATE_MAKEFILE_IN_BASE_PATTERN => TEMPLATE_MAKEFILE_IN_BASE_PATCH_MSYS }
79
- elsif PatchHelpers.ruby31?(ruby_ver)
80
- { TEMPLATE_MAKEFILE_IN_BASE_PATTERN => TEMPLATE_MAKEFILE_IN_BASE_PATCH }
82
+ TEMPLATE_MAKEFILE_IN_BASE_PATCH_MSYS
83
+ elsif !PatchHelpers.ruby31?(ruby_ver)
84
+ TEMPLATE_MAKEFILE_IN_BASE_PATCH_PRE_3_1
85
+ else
86
+ TEMPLATE_MAKEFILE_IN_BASE_PATCH
87
+ end
88
+ end
89
+
90
+ def template_makefile_in_patch_two(ostype, ruby_ver)
91
+ if !PatchHelpers.ruby31?(ruby_ver)
92
+ { TEMPLATE_MAKEFILE_IN_BASE_PATTERN_PRE_3_1 => template_makefile_in_subst(ostype, ruby_ver) }
93
+ elsif !PatchHelpers.ruby33?(ruby_ver)
94
+ { TEMPLATE_MAKEFILE_IN_BASE_PATTERN_PRE_3_3 => template_makefile_in_subst(ostype, ruby_ver) }
81
95
  else
82
- { TEMPLATE_MAKEFILE_IN_BASE_PATTERN_PRE_3_1 => TEMPLATE_MAKEFILE_IN_BASE_PATCH_PRE_3_1 }
96
+ { TEMPLATE_MAKEFILE_IN_BASE_PATTERN => template_makefile_in_subst(ostype, ruby_ver) }
83
97
  end
84
98
  end
85
99
 
@@ -94,10 +108,30 @@ module Tebako
94
108
  # End of tebako patch
95
109
  SUBST
96
110
 
111
+ def get_config_status_pattern(ostype)
112
+ case ostype
113
+ when /linux-/
114
+ "S[\"MAINLIBS\"]=\"-lz -lrt -lrt -ldl -lcrypt -lm -lpthread \""
115
+ when /darwin/
116
+ "S[\"MAINLIBS\"]=\"-ldl -lobjc -lpthread \""
117
+ when /msys/
118
+ "S[\"MAINLIBS\"]=\"-lshell32 -lws2_32 -liphlpapi -limagehlp -lshlwapi -lbcrypt \""
119
+ else
120
+ raise Tebako::Error, "Unknown ostype #{ostype}"
121
+ end
122
+ end
123
+
124
+ def get_config_status_patch(ostype, deps_lib_dir, ruby_ver)
125
+ {
126
+ get_config_status_pattern(ostype) =>
127
+ "S[\"MAINLIBS\"]=\"#{PatchLibraries.mlibs(ostype, deps_lib_dir, ruby_ver, false)}\""
128
+ }
129
+ end
130
+
97
131
  # Other MSYS (GNUMakefile) specific patches
98
132
  # - The same issue with libraries as for Makefile above
99
133
  # - 'Kill' ruby.exp regeneration on pass2
100
- # since we want to use outpu from pass1 for implib generation
134
+ # since we want to use output from pass1 for implib generation
101
135
  # [VERY UGLY HACK]
102
136
  # - Introduce LIBRUBY dependency on static extensions
103
137
  # This is an addition to COMMON_MK_PATCH specified above
@@ -62,10 +62,18 @@ module Tebako
62
62
  out
63
63
  end
64
64
 
65
+ def exe_suffix(ostype)
66
+ msys?(ostype) ? ".exe" : ""
67
+ end
68
+
65
69
  def msys?(ostype)
66
70
  ostype =~ /msys|cygwin|mingw/
67
71
  end
68
72
 
73
+ def macos?(ostype)
74
+ ostype =~ /darwin/
75
+ end
76
+
69
77
  def patch_c_file_pre(pattern)
70
78
  {
71
79
  pattern => "#{PatchLiterals::C_FILE_SUBST}\n#{pattern}"
@@ -108,10 +116,6 @@ module Tebako
108
116
  ruby3x?(ruby_ver) && ruby_ver[2].to_i >= 1
109
117
  end
110
118
 
111
- def ruby316?(ruby_ver)
112
- ruby3x?(ruby_ver) && ruby_ver[2] == "1" && ruby_ver[4].to_i >= 6
113
- end
114
-
115
119
  def ruby32?(ruby_ver)
116
120
  ruby3x?(ruby_ver) && ruby_ver[2].to_i >= 2
117
121
  end
@@ -40,32 +40,101 @@ module Tebako
40
40
  DARWIN_BREW_LIBS = [
41
41
  ["zlib", "z"], ["gdbm", "gdbm"], ["readline", "readline"], ["libffi", "ffi"],
42
42
  ["ncurses", "ncurses"], ["fmt", "fmt"], ["lz4", "lz4"], ["xz", "lzma"],
43
- ["libyaml", "yaml"], ["boost", "boost_chrono"],
44
- ["double-conversion", "double-conversion"]
43
+ ["libyaml", "yaml"], ["boost", "boost_chrono"], ["double-conversion", "double-conversion"]
45
44
  ].freeze
46
45
 
47
46
  DARWIN_BREW_LIBS_PRE_31 = [["openssl@1.1", "ssl"], ["openssl@1.1", "crypto"]].freeze
48
47
 
49
- DARWIN_BREW_LIBS_31 = [["libyaml", "yaml"], ["openssl@3", "ssl"], ["openssl@3", "crypto"]].freeze
48
+ DARWIN_BREW_LIBS_31 = [["openssl@3", "ssl"], ["openssl@3", "crypto"]].freeze
50
49
 
51
- DARWIN_DEP_LIBS = ["glog", "gflags", "brotlienc", "brotlidec", "brotlicommon"].freeze
50
+ DARWIN_DEP_LIBS_1 = ["folly", "fsst", "metadata_thrift", "thrift_light", "xxhash", "zstd"].freeze
51
+ DARWIN_DEP_LIBS_2 = ["glog", "gflags", "brotlienc", "brotlidec", "brotlicommon"].freeze
52
52
  # rubocop:enable Style/WordArray
53
53
 
54
+ COMMON_LINUX_LIBRARIES = [
55
+ "-l:libdwarfs-wr.a", "-l:libtebako-fs.a", "-l:libdwarfs.a", "LIBCOMPRESSION",
56
+ "-l:libfolly.a", "-l:libfsst.a", "-l:libmetadata_thrift.a", "-l:libthrift_light.a",
57
+ "-l:libxxhash.a", "-l:libfmt.a", "-l:libdouble-conversion.a", "-l:libglog.a",
58
+ "-l:libgflags.a", "-l:libevent.a"
59
+ ].freeze
60
+
61
+ COMMON_ARCHIEVE_LIBRARIES = [
62
+ "-l:libarchive.a", "-l:liblz4.a", "-l:libz.a", "-l:libzstd.a",
63
+ "-l:libbrotlienc.a", "-l:libbrotlidec.a", "-l:libbrotlicommon.a", "-l:liblzma.a"
64
+ ].freeze
65
+
66
+ LINUX_GNU_LIBRARIES = [
67
+ "-l:libiberty.a", "-l:libacl.a", "-l:libssl.a", "-l:libcrypto.a",
68
+ "-l:libgdbm.a", "-l:libreadline.a", "-l:libtinfo.a", "-l:libffi.a",
69
+ "-l:libncurses.a", "-l:libjemalloc.a", "-l:libcrypt.a", "-l:libanl.a",
70
+ "LIBYAML", "-l:libboost_system.a", "-l:libboost_chrono.a", "-l:libutil.a",
71
+ "-l:libstdc++.a", "-lgcc_eh", "-l:libunwind.a", "-l:liblzma.a",
72
+ "-l:librt.a", "-ldl", "-lpthread", "-lm"
73
+ ].freeze
74
+
75
+ LINUX_MUSL_LIBRARIES = [
76
+ "-l:libiberty.a", "-l:libacl.a", "-l:libssl.a", "-l:libcrypto.a",
77
+ "-l:libreadline.a", "-l:libgdbm.a", "-l:libffi.a", "-l:libncurses.a",
78
+ "-l:libjemalloc.a", "-l:libcrypt.a", "LIBYAML", "-l:libboost_system.a",
79
+ "-l:libboost_chrono.a", "-l:librt.a", "-l:libstdc++.a", "-lgcc_eh",
80
+ " -l:libunwind.a", "-l:liblzma.a", "-ldl", "-lpthread"
81
+ ].freeze
82
+
83
+ MSYS_LIBRARIES = [
84
+ "-l:liblz4.a", "-l:libz.a", "-l:libzstd.a", "-l:liblzma.a",
85
+ "-l:libncurses.a", "-l:libunwind.a", "-l:liblzma.a", "-l:libiberty.a",
86
+ "LIBYAML", "-l:libffi.a", "-l:libboost_system-mt.a", "-l:libboost_chrono-mt.a",
87
+ "-l:libstdc++.a", "-l:libdl.a", "-static-libgcc", "-static-libstdc++",
88
+ "-l:libssl.a", "-l:libcrypto.a", "-l:libz.a", "-l:libwinpthread.a",
89
+ "-lcrypt32", "-lshlwapi", "-lwsock32", "-liphlpapi",
90
+ "-limagehlp", "-lbcrypt", "-lole32", "-loleaut32",
91
+ "-luuid", "-lws2_32"
92
+ ].freeze
93
+
94
+ def linux_gnu_libraries(ruby_ver, with_compression)
95
+ libraries = COMMON_LINUX_LIBRARIES + COMMON_ARCHIEVE_LIBRARIES + LINUX_GNU_LIBRARIES
96
+ linux_libraries(libraries, ruby_ver, with_compression)
97
+ end
98
+
99
+ def linux_musl_libraries(ruby_ver, with_compression)
100
+ libraries = COMMON_LINUX_LIBRARIES + COMMON_ARCHIEVE_LIBRARIES + LINUX_MUSL_LIBRARIES
101
+ linux_libraries(libraries, ruby_ver, with_compression)
102
+ end
103
+
104
+ def linux_libraries(libraries, ruby_ver, with_compression)
105
+ libraries.map! do |lib|
106
+ if lib == "LIBYAML"
107
+ PatchHelpers.yaml_reference(ruby_ver)
108
+ elsif lib == "LIBCOMPRESSION"
109
+ with_compression ? "-Wl,--push-state,--whole-archive -l:libdwarfs_compression.a -Wl,--pop-state" : ""
110
+ else
111
+ lib
112
+ end
113
+ end
114
+ libraries.join(" ")
115
+ end
116
+
117
+ def msys_libraries(ruby_ver, with_compression)
118
+ libraries = with_compression ? ["-Wl,-Bstatic"] : []
119
+ libraries = libraries + COMMON_LINUX_LIBRARIES + MSYS_LIBRARIES
120
+ linux_libraries(libraries, ruby_ver, with_compression)
121
+ end
122
+
54
123
  def process_brew_libs!(libs, brew_libs)
55
124
  brew_libs.each { |lib| libs << "#{PatchHelpers.get_prefix_macos(lib[0]).chop}/lib/lib#{lib[1]}.a " }
56
125
  end
57
126
 
58
- def darwin_libs(deps_lib_dir, ruby_ver)
127
+ def darwin_libraries(deps_lib_dir, ruby_ver, with_compression)
59
128
  libs = String.new
60
129
 
130
+ DARWIN_DEP_LIBS_1.each { |lib| libs << "#{deps_lib_dir}/lib#{lib}.a " }
61
131
  process_brew_libs!(libs, PatchHelpers.ruby31?(ruby_ver) ? DARWIN_BREW_LIBS_31 : DARWIN_BREW_LIBS_PRE_31)
62
132
  process_brew_libs!(libs, DARWIN_BREW_LIBS)
63
133
 
64
- DARWIN_DEP_LIBS.each { |lib| libs << "#{deps_lib_dir}/lib#{lib}.a " }
65
- <<~SUBST
66
- -ltebako-fs -ldwarfs-wr -ldwarfs -force_load #{deps_lib_dir}/libdwarfs_compression.a -lfolly -lfsst -lmetadata_thrift -lthrift_light -lxxhash \
67
- -lzstd #{libs} -ljemalloc -lc++ -lc++abi
68
- SUBST
134
+ DARWIN_DEP_LIBS_2.each { |lib| libs << "#{deps_lib_dir}/lib#{lib}.a " }
135
+
136
+ compression_lib = with_compression ? "-force_load #{deps_lib_dir}/libdwarfs_compression.a" : ""
137
+ "-ltebako-fs -ldwarfs-wr -ldwarfs #{compression_lib} #{libs} -ljemalloc -lc++ -lc++abi"
69
138
  end
70
139
 
71
140
  # .....................................................
@@ -80,66 +149,16 @@ module Tebako
80
149
  # This is fixed by ext/extmk.rb patch [TODO ?]
81
150
  # .....................................................
82
151
 
83
- def linux_common_libs
84
- <<~SUBST
85
- -l:libtebako-fs.a -l:libdwarfs-wr.a -l:libdwarfs.a -Wl,--push-state,--whole-archive -l:libdwarfs_compression.a -Wl,--pop-state -l:libfolly.a -l:libfsst.a \\
86
- -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 \\
87
- SUBST
88
- end
89
-
90
- def common_enc_libs
91
- "-l:liblz4.a -l:libz.a -l:libzstd.a -l:libbrotlienc.a -l:libbrotlidec.a -l:libbrotlicommon.a -l:liblzma.a"
92
- end
93
-
94
- def linux_gnu_libs(ruby_ver)
95
- <<~SUBST
96
- #{linux_common_libs} \
97
- -l:libarchive.a -l:libiberty.a -l:libacl.a -l:libssl.a -l:libcrypto.a #{common_enc_libs} \\
98
- -l:libgdbm.a -l:libreadline.a -l:libtinfo.a -l:libffi.a -l:libncurses.a -l:libjemalloc.a -l:libcrypt.a -l:libanl.a #{PatchHelpers.yaml_reference(ruby_ver)} \\
99
- -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
100
- SUBST
101
- end
102
-
103
- def linux_musl_libs(ruby_ver)
104
- <<~SUBST
105
- #{linux_common_libs} \
106
- -l:libiberty.a -l:libacl.a -l:libssl.a -l:libcrypto.a #{common_enc_libs} -l:libreadline.a \\
107
- -l:libgdbm.a -l:libffi.a -l:libncurses.a -l:libjemalloc.a -l:libcrypt.a #{PatchHelpers.yaml_reference(ruby_ver)} -l:libboost_system.a -l:libboost_chrono.a \\
108
- -l:librt.a -l:libstdc++.a -lgcc_eh -l:libunwind.a -l:liblzma.a -ldl -lpthread
109
- SUBST
110
- end
111
-
112
- # Used for mkconfig.rb
113
- def msys_base_libs(ruby_ver)
114
- <<~SUBST
115
- "-l:libtebako-fs.a -l:libdwarfs-wr.a -l:libdwarfs.a -l:libdwarfs_compression.a -l:libfolly.a -l:libfsst.a " \\
116
- "-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 " \\
117
- "-l:liblz4.a -l:libz.a -l:libzstd.a -l:liblzma.a -l:libncurses.a -l:libunwind.a -l:liblzma.a -l:libiberty.a #{PatchHelpers.yaml_reference(ruby_ver)} " \\
118
- "-l:libffi.a -l:libboost_system-mt.a -l:libboost_chrono-mt.a -l:libstdc++.a -l:libdl.a -static-libgcc -static-libstdc++ -l:libssl.a -l:libcrypto.a " \\
119
- "-l:libz.a -l:libwinpthread.a -lcrypt32 -lshlwapi -lwsock32 -liphlpapi -limagehlp -lbcrypt -lole32 -loleaut32 -luuid"
120
- SUBST
121
- end
122
-
123
- # Used in Makefile
124
- def msys_libs(ruby_ver)
125
- <<~SUBST
126
- -Wl,-Bstatic #{linux_common_libs} \
127
- -l:liblz4.a -l:libz.a -l:libzstd.a -l:liblzma.a -l:libncurses.a -l:libunwind.a -l:liblzma.a -l:libiberty.a #{PatchHelpers.yaml_reference(ruby_ver)} \\
128
- -l:libffi.a -l:libboost_system-mt.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 \\
129
- -l:libwinpthread.a -lcrypt32 -lshlwapi -lwsock32 -liphlpapi -limagehlp -lshlwapi -lbcrypt -lws2_32 -lole32 -loleaut32 -luuid
130
- SUBST
131
- end
132
-
133
- def mlibs(ostype, deps_lib_dir, ruby_ver) # rubocop:disable Metrics/MethodLength
152
+ def mlibs(ostype, deps_lib_dir, ruby_ver, with_compression) # rubocop:disable Metrics/MethodLength
134
153
  case ostype
135
154
  when /linux-gnu/
136
- linux_gnu_libs(ruby_ver)
155
+ linux_gnu_libraries(ruby_ver, with_compression)
137
156
  when /linux-musl/
138
- linux_musl_libs(ruby_ver)
157
+ linux_musl_libraries(ruby_ver, with_compression)
139
158
  when /darwin/
140
- darwin_libs(deps_lib_dir, ruby_ver)
159
+ darwin_libraries(deps_lib_dir, ruby_ver, with_compression)
141
160
  when /msys/
142
- msys_libs(ruby_ver)
161
+ msys_libraries(ruby_ver, with_compression)
143
162
  else
144
163
  raise Tebako::Error, "Unknown ostype #{ostype}"
145
164
  end
@@ -30,25 +30,23 @@ module Tebako
30
30
  module Packager
31
31
  # Ruby patching literals (pass2)
32
32
  module PatchLiterals
33
- TOOL_MKCONFIG_RB_PATCH = {
34
- " if fast[name]" => <<~SUBST
35
- # -- Start of tebako patch --
36
- v_head_comp = " CONFIG[\\"prefix\\"] \#{eq} "
37
- if v_head_comp == v[0...(v_head_comp.length)]
38
- v = "\#{v[0...(v_head_comp.length)]}'/__tebako_memfs__'
39
- "
40
- end
41
- v_head_comp = " CONFIG[\\"RUBY_EXEC_PREFIX\\"] \#{eq} "
42
- if v_head_comp == v[0...(v_head_comp.length)]
33
+ TOOL_MKCONFIG_RB_SUBST = <<~SUBST
34
+ # -- Start of tebako patch --
35
+ v_head_comp = " CONFIG[\\"prefix\\"] \#{eq} "
36
+ if v_head_comp == v[0...(v_head_comp.length)]
43
37
  v = "\#{v[0...(v_head_comp.length)]}'/__tebako_memfs__'
44
- "
45
- end
46
- # -- End of tebako patch --
47
- if fast[name]
48
- SUBST
49
- }.freeze
38
+ "
39
+ end
40
+ v_head_comp = " CONFIG[\\"RUBY_EXEC_PREFIX\\"] \#{eq} "
41
+ if v_head_comp == v[0...(v_head_comp.length)]
42
+ v = "\#{v[0...(v_head_comp.length)]}'/__tebako_memfs__'
43
+ "
44
+ end
45
+ # -- End of tebako patch --
46
+ if fast[name]
47
+ SUBST
50
48
 
51
- TOOLS_MKCONFIG_RB_SUBST = <<~SUBST
49
+ TOOL_MKCONFIG_RB_SUBST_MSYS = <<~SUBST
52
50
  # -- Start of tebako patch --
53
51
  v_head_comp = " CONFIG[\\"prefix\\"] \#{eq} "
54
52
  if v_head_comp == v[0...(v_head_comp.length)]
@@ -31,6 +31,7 @@ require "pathname"
31
31
 
32
32
  require_relative "error"
33
33
  require_relative "deploy_helper"
34
+ require_relative "stripper"
34
35
  require_relative "packager/pass1"
35
36
  require_relative "packager/pass1a"
36
37
  require_relative "packager/pass2"
@@ -79,14 +80,22 @@ module Tebako
79
80
 
80
81
  deploy_helper = Tebako::DeployHelper.new(fs_root, fs_entrance, fs_mount_point, target_dir, pre_dir)
81
82
  deploy_helper.config(os_type, ruby_ver)
83
+ deploy_helper.deploy
84
+ Tebako::Stripper.strip(os_type, target_dir)
85
+ end
82
86
 
83
- PatchHelpers.with_env(deploy_helper.deploy_env) do
84
- unless PatchHelpers.ruby31?(ruby_ver)
85
- deploy_helper.update_rubygems
86
- patch_after_rubygems_update(target_dir, deploy_helper.ruby_api_version)
87
- end
88
- deploy_helper.deploy
87
+ def finalize(os_type, src_dir, app_name)
88
+ exe_suffix = Packager::PatchHelpers.exe_suffix(os_type)
89
+ src_name = File.join(src_dir, "ruby#{exe_suffix}")
90
+ package_name = "#{app_name}#{exe_suffix}"
91
+ # [TODO] On MSys strip sometimes creates a broken executable
92
+ # https://github.com/tamatebako/tebako/issues/172
93
+ if Packager::PatchHelpers.msys?(os_type)
94
+ FileUtils.cp(src_name, package_name)
95
+ else
96
+ Tebako::Stripper.strip_file(src_name, package_name)
89
97
  end
98
+ puts "Created tebako package at \"#{package_name}\""
90
99
  end
91
100
 
92
101
  # Init
@@ -188,13 +197,6 @@ module Tebako
188
197
  end
189
198
  ruby_version
190
199
  end
191
-
192
- def patch_after_rubygems_update(target_dir, ruby_api_ver)
193
- # Autoload cannot handle statically linked openssl extension
194
- # Changing it to require seems to be the simplest solution
195
- PatchHelpers.patch_file("#{target_dir}/lib/ruby/site_ruby/#{ruby_api_ver}/rubygems/openssl.rb",
196
- { "autoload :OpenSSL, \"openssl\"" => "require \"openssl\"" })
197
- end
198
200
  end
199
201
  end
200
202
  end