Skip to content

Commit

Permalink
Merge pull request #12 from godaddy/libc_suffix
Browse files Browse the repository at this point in the history
Support non GNU Lib C library file names with load_library
  • Loading branch information
dalibor committed Jan 25, 2023
2 parents 40a837f + a379a23 commit 1c4543c
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 16 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
strategy:
matrix:
os: [ ubuntu-20.04, macos-11 ]
ruby: [ 2.5, 2.6, 2.7, 3.0, 3.1 ]
ruby: [ 2.5, 2.6, 2.7, 3.0, 3.1, 3.2 ]
fail-fast: false

steps:
Expand Down Expand Up @@ -67,7 +67,7 @@ jobs:
strategy:
matrix:
include:
- { os: ubuntu-20.04, ruby: 3.1 }
- { os: ubuntu-20.04, ruby: 3.2 }
fail-fast: false

steps:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- name: Setup Ruby
uses: ruby/setup-ruby@v1
with:
ruby-version: 3.0
ruby-version: 3.2
bundler: default
bundler-cache: true

Expand Down
2 changes: 1 addition & 1 deletion .ruby-version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
3.1.0
3.2.0
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
## [Unreleased]

## [0.2.1] - 2023-01-25

- Support non GNU Lib C library file names with `load_library`
- Add Ruby 3.2 to the test matrix

## [0.2.0] - 2022-03-18

- Remove default `MINIMUM_ALLOCATION` to allow for smaller buffers
Expand Down
4 changes: 3 additions & 1 deletion lib/cobhan.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ def library_file_name(name)
cpu_arch = CPU_ARCHS[FFI::Platform::ARCH]
raise UnsupportedPlatformError, "Unsupported CPU: #{FFI::Platform::ARCH}" unless cpu_arch

"#{name}-#{cpu_arch}.#{ext}"
libc_suffix = RbConfig::CONFIG['host_os'] == 'linux-musl' ? '-musl' : ''

"#{name}-#{cpu_arch}#{libc_suffix}.#{ext}"
end

def load_library(lib_root_path, name, functions)
Expand Down
2 changes: 1 addition & 1 deletion lib/cobhan/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Cobhan
VERSION = '0.2.0'
VERSION = '0.2.1'
end
17 changes: 10 additions & 7 deletions spec/cobhan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,18 @@ def self.add_int32(first, second)
describe 'library_file_name' do
it 'returns file name for supported OS / ARCH combinations' do
{
['linux', 'x86_64'] => 'lib-x64.so',
['linux', 'aarch64'] => 'lib-arm64.so',
['darwin', 'x86_64'] => 'lib-x64.dylib',
['darwin', 'aarch64'] => 'lib-arm64.dylib',
['windows', 'x86_64'] => 'lib-x64.dll',
['windows', 'aarch64'] => 'lib-arm64.dll'
}.each_pair do |(os, arch), file|
['linux', 'x86_64', 'linux'] => 'lib-x64.so',
['linux', 'aarch64', 'linux'] => 'lib-arm64.so',
['linux', 'x86_64', 'linux-musl'] => 'lib-x64-musl.so',
['linux', 'aarch64', 'linux-musl'] => 'lib-arm64-musl.so',
['darwin', 'x86_64', 'darwin20'] => 'lib-x64.dylib',
['darwin', 'aarch64', 'darwin20'] => 'lib-arm64.dylib',
['windows', 'x86_64', 'mswin'] => 'lib-x64.dll',
['windows', 'aarch64', 'mswin'] => 'lib-arm64.dll'
}.each_pair do |(os, arch, host_os), file|
stub_const('FFI::Platform::OS', os)
stub_const('FFI::Platform::ARCH', arch)
stub_const('RbConfig::CONFIG', { 'host_os' => host_os })

expect(CobhanApp.library_file_name('lib')).to eq(file)
end
Expand Down
2 changes: 1 addition & 1 deletion spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# frozen_string_literal: true

if ENV['COVERAGE'] == 'true'
if ENV.fetch('COVERAGE', nil) == 'true'
require 'simplecov'
require 'simplecov-console'

Expand Down
4 changes: 2 additions & 2 deletions spec/support/build_binary.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ def build_binary(lib_root_path, lib_name)

return if File.exist?(lib_path)

if ENV['AUTO_CONFIRM_BUILD'] != 'true'
if ENV.fetch('AUTO_CONFIRM_BUILD', nil) != 'true'
puts "#{lib_path} is not present, do you want to build it? [y/N]"
input = $stdin.gets.chomp
abort('Aborted.') unless input.downcase == 'y'
end

Dir.mkdir(lib_root_path) unless File.exist?(lib_root_path)
Dir.mkdir_p(lib_root_path)
system("./spec/support/#{lib_name}/build.sh", exception: true)
end

0 comments on commit 1c4543c

Please sign in to comment.