Skip to content

Commit

Permalink
swig rebottle for gnu+linux support
Browse files Browse the repository at this point in the history
  • Loading branch information
ipatch committed Apr 30, 2024
1 parent 2a41e73 commit 7336db3
Showing 1 changed file with 20 additions and 7 deletions.
27 changes: 20 additions & 7 deletions Formula/[email protected]
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ class SwigAT411 < Formula
url "https://downloads.sourceforge.net/project/swig/swig/swig-4.1.1/swig-4.1.1.tar.gz"
sha256 "2af08aced8fcd65cdb5cc62426768914bedc735b1c250325203716f78e39ac9b"
license "GPL-3.0-only"
revision 3
revision 4

livecheck do
url :stable
Expand All @@ -28,6 +28,7 @@ class SwigAT411 < Formula

keg_only :versioned_formula

depends_on "ruby" => :test if OS.linux?
depends_on "pcre2"

uses_from_macos "ruby" => :test
Expand All @@ -47,8 +48,7 @@ def caveats
EOS
end

# NOTE: add upstream python test this formula, #3

# NOTE: add upstream python test to this formula
test do
(testpath/"test.c").write <<~EOS
int add(int x, int y)
Expand All @@ -67,9 +67,22 @@ def caveats
puts Test.add(1, 1)
EOS
system "#{bin}/swig", "-ruby", "test.i"
system ENV.cc, "-c", "test.c"
system ENV.cc, "-c", "test_wrap.c", "-I#{MacOS.sdk_path}/System/Library/Frameworks/Ruby.framework/Headers/"
system ENV.cc, "-bundle", "-undefined", "dynamic_lookup", "test.o", "test_wrap.o", "-o", "test.bundle"
assert_equal "2", shell_output("/usr/bin/ruby run.rb").strip
if OS.mac?
system ENV.cc, "-c", "test.c"
system ENV.cc, "-c", "test_wrap.c", "-I#{MacOS.sdk_path}/System/Library/Frameworks/Ruby.framework/Headers/"
system ENV.cc, "-bundle", "-undefined", "dynamic_lookup", "test.o", "test_wrap.o", "-o", "test.bundle"
else
ruby = Formula["ruby"]
args = Utils.safe_popen_read(
ruby.opt_bin/"ruby", "-e", "'puts RbConfig::CONFIG[\"LIBRUBYARG\"]'"
).chomp
system ENV.cc, "-c", "-fPIC", "test.c"
system ENV.cc, "-c", "-fPIC", "test_wrap.c",
"-I#{ruby.opt_include}/ruby-#{ruby.version.major_minor}.0",
"-I#{ruby.opt_include}/ruby-#{ruby.version.major_minor}.0/x86_64-linux/"
system ENV.cc, "-shared", "test.o", "test_wrap.o", "-o", "test.so",
*args.delete("'").split
end
assert_equal "2", shell_output("ruby run.rb").strip
end
end

0 comments on commit 7336db3

Please sign in to comment.