-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added deploy-time patching to support ffi-compiler/ffi-compiler2 gems (…
- Loading branch information
Showing
6 changed files
with
196 additions
and
9 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,102 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024 [Ribose Inc](https://www.ribose.com). | ||
# All rights reserved. | ||
# This file is a part of tebako | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# 1. Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS | ||
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
|
||
module FFI | ||
module Platform | ||
ARCH = case RbConfig::CONFIG["host_cpu"].downcase | ||
when /amd64|x86_64|x64/ | ||
"x86_64" | ||
when /i\d86|x86|i86pc/ | ||
"i386" | ||
when /ppc64|powerpc64/ | ||
"powerpc64" | ||
when /ppc|powerpc/ | ||
"powerpc" | ||
when /sparcv9|sparc64/ | ||
"sparcv9" | ||
when /arm64|aarch64/ # MacOS calls it "arm64", other operating systems "aarch64" | ||
"aarch64" | ||
when /^arm/ | ||
if OS == "darwin" # Ruby before 3.0 reports "arm" instead of "arm64" as host_cpu on darwin | ||
"aarch64" | ||
else | ||
"arm" | ||
end | ||
else | ||
RbConfig::CONFIG["host_cpu"].downcase | ||
end | ||
|
||
OS = | ||
case RbConfig::CONFIG["host_os"].downcase | ||
when /linux/ | ||
"linux" | ||
when /darwin/ | ||
"darwin" | ||
when /freebsd/ | ||
"freebsd" | ||
when /netbsd/ | ||
"netbsd" | ||
when /openbsd/ | ||
"openbsd" | ||
when /dragonfly/ | ||
"dragonflybsd" | ||
when /sunos|solaris/ | ||
"solaris" | ||
when /mingw|mswin/ | ||
"windows" | ||
else | ||
RbConfig::CONFIG["host_os"].downcase | ||
end | ||
|
||
LIBPREFIX = case OS | ||
when /windows|msys/ | ||
"" | ||
when /cygwin/ | ||
"cyg" | ||
else | ||
"lib" | ||
end | ||
|
||
LIBSUFFIX = case OS | ||
when /darwin/ | ||
"dylib" | ||
when /windows|cygwin|msys/ | ||
"dll" | ||
else | ||
# Punt and just assume a sane unix (i.e. anything but AIX) | ||
# when /linux|bsd|solaris/ | ||
# "so" | ||
"so" | ||
end | ||
|
||
PASS_THROUGH = true | ||
|
||
def self.mac? | ||
RUBY_PLATFORM =~ /darwin/ | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,5 +26,5 @@ | |
# POSSIBILITY OF SUCH DAMAGE. | ||
|
||
module TebakoRuntime | ||
VERSION = "0.4.2" | ||
VERSION = "0.5.0" | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
# frozen_string_literal: true | ||
|
||
# Copyright (c) 2024 [Ribose Inc](https://www.ribose.com). | ||
# All rights reserved. | ||
# This file is a part of tebako | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# 1. Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# 2. Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in the | ||
# documentation and/or other materials provided with the distribution. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED | ||
# TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR | ||
# PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS | ||
# BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
# POSSIBILITY OF SUCH DAMAGE. | ||
|
||
# rubocop:disable Metrics/BlockLength | ||
RSpec.describe TebakoRuntime do | ||
it "provides a stub for ffi gem in pass through mode on Windows" do | ||
if RUBY_PLATFORM =~ /msys|mingw|cygwin/ | ||
if defined?(FFI) | ||
FFI::Platform.send(:remove_const, :OS) | ||
FFI::Platform.send(:remove_const, :ARCH) | ||
FFI::Platform.send(:remove_const, :LIBPREFIX) | ||
FFI::Platform.send(:remove_const, :LIBSUFFIX) | ||
FFI::Platform.send(:remove_const, :PASS_THROUGH) | ||
end | ||
ENV["TEBAKO_PASS_THROUGH"] = "1" | ||
require "ffi" | ||
|
||
expect(defined?(FFI::Platform::OS)).to_not be_nil | ||
expect(defined?(FFI::Platform::ARCH)).to_not be_nil | ||
expect(defined?(FFI::Platform::LIBPREFIX)).to_not be_nil | ||
expect(defined?(FFI::Platform::LIBSUFFIX)).to_not be_nil | ||
expect(FFI::Platform::PASS_THROUGH).to eq(true) | ||
end | ||
end | ||
|
||
after do | ||
if RUBY_PLATFORM =~ /msys|mingw|cygwin/ | ||
ENV.delete("TEBAKO_PASS_THROUGH") | ||
FFI::Platform.send(:remove_const, :OS) | ||
FFI::Platform.send(:remove_const, :ARCH) | ||
FFI::Platform.send(:remove_const, :LIBPREFIX) | ||
FFI::Platform.send(:remove_const, :LIBSUFFIX) | ||
FFI::Platform.send(:remove_const, :PASS_THROUGH) | ||
end | ||
end | ||
end | ||
# rubocop:enable Metrics/BlockLength |
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