-
Notifications
You must be signed in to change notification settings - Fork 256
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Change side-by-side DLL loading to store dependencies in each extensi…
…on.so file So far ruby.exe and rubyw.exe contained a process-global manifest for side-by-side loading. This way the DLLs bundled to RubyInstaller could be moved to a dedicated directory, so that they aren't loaded accidently by other apps because they are in the PATH. It was introduced in b2bd630 The downside of a global manifest is that the dependent DLLs are always preferred over other DLL versions with the same name. This caused for instance openssl.gem to fail, when the libssl DLL linked at build time was newer than the libssl bundled with RubyInstaller. This patch introduces manifests per extension.so file with dedicated private dependencies. This way the bundled openssl.so is directly linked to it's own libssl.dll by an embedded manifest. It's similar to static linking libssl into openssl.so, but it allows to use unchanged libssl.dll from MINGW packages. If a new openssl.gem version is installed per "gem install openssl", it links to MSYS2/MINGW packages at build time. Since the resulting openssl.so doesn't contain the manifest, it also links to the MINGW packages at run time. Patching extension.so files requires to add all single files recursively as file tasks. Fixes #60
- Loading branch information
Showing
6 changed files
with
165 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
module RubyInstaller | ||
module Build | ||
class ManifestUpdater | ||
def self.update_file(from_fname, manifest_xml_string, to_fname) | ||
image = File.binread(from_fname) | ||
update_blob(image, manifest_xml_string, filename: from_fname) | ||
File.binwrite(to_fname, image) | ||
end | ||
|
||
def self.update_blob(dll_or_exe_data, manifest_xml_string, filename: nil) | ||
# There are two regular options to add a custom manifest: | ||
# 1. Change a given exe file per Microsofts "mt.exe" after the build | ||
# 2. Specify a the manifest while linking with the MINGW toolchain | ||
# | ||
# Since we don't want to depend on particular Microsoft tools and want to avoid additional patching of the ruby build, we do a nifty trick here. | ||
# We patch the exe file manually. | ||
# Removing unnecessary spaces and comments from the embedded XML manifest gives us enough space to add the above XML elements. | ||
# Then the default MINGW manifest gets replaced by our custom XML content. | ||
# The rest of the available bytes is simply padded with spaces, so that we don't change positions within the EXE image. | ||
success = false | ||
dll_or_exe_data.gsub!(/<\?xml.*?<assembly.*?<\/assembly>\n/m) do |m| | ||
success = true | ||
newm = m.gsub(/^\s*<\/assembly>\s*$/, manifest_xml_string + "</assembly>") | ||
.gsub(/<!--.*?-->/m, "") | ||
.gsub(/^ +/, "") | ||
.gsub(/\n+/m, "\n") | ||
|
||
raise "replacement manifest too big #{m.bytesize} < #{newm.bytesize}" if m.bytesize < newm.bytesize | ||
newm + " " * (m.bytesize - newm.bytesize) | ||
end | ||
raise "no manifest found#{ "in #{filename}" if filename}" unless success | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters