SpringMT / zstd-ruby

Ruby binding for zstd(Zstandard - Fast real-time compression algorithm)
https://github.com/facebook/zstd
BSD 3-Clause "New" or "Revised" License
69 stars 16 forks source link

Fix build with Ruby 3.1 on macOS 12.1 #33

Closed mscrivo closed 2 years ago

mscrivo commented 2 years ago

After installing Ruby 3.1 on my Intel x64 mac 12.1, I got the following errors when trying to build zstd:


compiling zstdruby.c
In file included from zstdruby.c:1:
In file included from ./zstdruby.h:4:
In file included from /Users/michaelscrivo/.rbenv/versions/3.1.0/include/ruby-3.1.0/ruby.h:38:
In file included from /Users/michaelscrivo/.rbenv/versions/3.1.0/include/ruby-3.1.0/ruby/ruby.h:25:
In file included from /Users/michaelscrivo/.rbenv/versions/3.1.0/include/ruby-3.1.0/ruby/defines.h:73:
In file included from /Users/michaelscrivo/.rbenv/versions/3.1.0/include/ruby-3.1.0/ruby/backward/2/attributes.h:42:
In file included from /Users/michaelscrivo/.rbenv/versions/3.1.0/include/ruby-3.1.0/ruby/internal/attr/pure.h:25:
/Users/michaelscrivo/.rbenv/versions/3.1.0/include/ruby-3.1.0/ruby/assert.h:132:1: error: '__declspec' attributes are not enabled; use '-fdeclspec' or '-fms-extensions' to enable support for __declspec attributes
RBIMPL_ATTR_NORETURN()
^
/Users/michaelscrivo/.rbenv/versions/3.1.0/include/ruby-3.1.0/ruby/internal/attr/noreturn.h:29:33: note: expanded from macro 'RBIMPL_ATTR_NORETURN'
# define RBIMPL_ATTR_NORETURN() __declspec(noreturn)
                                ^
In file included from zstdruby.c:1:
In file included from ./zstdruby.h:4:
In file included from /Users/michaelscrivo/.rbenv/versions/3.1.0/include/ruby-3.1.0/ruby.h:38:
In file included from /Users/michaelscrivo/.rbenv/versions/3.1.0/include/ruby-3.1.0/ruby/ruby.h:26:
In file included from /Users/michaelscrivo/.rbenv/versions/3.1.0/include/ruby-3.1.0/ruby/internal/anyargs.h:77:```

Adding this compiler flag fixes it and still seems to work on lower Ruby verisons as well.
mscrivo commented 2 years ago

This doesn't appear to be the correct fix .. will do some more testing and re-open if I can figure it out.

SpringMT commented 2 years ago

I fixed this problem in https://github.com/SpringMT/zstd-ruby/pull/35. Can you try to build again?

mscrivo commented 2 years ago

I fixed this problem in #35. Can you try to build again?

works now, thank you so much!

mscrivo commented 2 years ago

After trying to actually run some code using this gem, getting this error:

require': dlopen(/Users/michaelscrivo/affinity/vendor/bundle/ruby/3.1.0/gems/zstd-ruby-1.5.1.0/lib/zstd-ruby/zstdruby.bundle, 0x0009): symbol not found in flat namespace '_HUF_decompress4X1_usingDTable_internal_bmi2_asm_loop' - /Users/michaelscrivo/affinity/vendor/bundle/ruby/3.1.0/gems/zstd-ruby-1.5.1.0/lib/zstd-ruby/zstdruby.bundle (LoadError)

SpringMT commented 2 years ago

I try to fix this problem in https://github.com/SpringMT/zstd-ruby/pull/38. Can you test using this branch fix-asm-support? Ex(in Gemfile)

gem "zstd-ruby", branch: "fix-asm-support"
mscrivo commented 2 years ago

I try to fix this problem in #38. Can you test using this branch fix-asm-support? Ex(in Gemfile)

gem "zstd-ruby", branch: "fix-asm-support"

That seems to have done the trick! Thanks again for the quick turnaround.

SpringMT commented 2 years ago

I released v1.5.1.1 fixed the error. https://rubygems.org/gems/zstd-ruby/versions/1.5.1.1. Thank you for testing and your patience!