Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 20 additions & 26 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,12 @@ jobs:
name: ${{ matrix.os }} ruby-${{ matrix.ruby }}
strategy:
matrix:
os: [ ubuntu-20.04, macos-11 ]
ruby: [ 2.5, 2.6, 2.7, 3.0, 3.1, 3.2 ]
os: [ ubuntu-22.04, macos-15 ]
ruby: [ 2.7, 3.0, 3.1, 3.2, 3.3, 3.4, 4.0 ]
fail-fast: false

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup Ruby
uses: ruby/setup-ruby@v1
Expand All @@ -29,29 +29,25 @@ jobs:
bundler-cache: true

- name: Setup Go
uses: actions/setup-go@v2
uses: actions/setup-go@v6.3.0
with:
go-version: '1.20.5'
go-version: '1.24'

- name: Build Linux
if: matrix.os == 'ubuntu-20.04'
if: matrix.os == 'ubuntu-22.04'
shell: bash
run: |
BUILD_DIR="tmp"
mkdir $BUILD_DIR
cp -R spec/support/libcobhandemo/* $BUILD_DIR
cd tmp
GOOS=linux GOARCH=amd64 go build -buildmode=c-shared -ldflags='-s -w' -o libcobhandemo-x64.so libcobhandemo.go
mkdir -p tmp
cd spec/support/libcobhandemo
CGO_ENABLED=1 GOOS=linux GOARCH=amd64 go build -buildmode=c-shared -ldflags='-s -w' -o ../../../tmp/libcobhandemo-x64.so .

- name: Build Darwin
if: matrix.os == 'macos-11'
if: matrix.os == 'macos-15'
shell: bash
run: |
BUILD_DIR="tmp"
mkdir $BUILD_DIR
cp -R spec/support/libcobhandemo/* $BUILD_DIR
cd tmp
GOOS=darwin GOARCH=amd64 go build -buildmode=c-shared -ldflags='-s -w' -o libcobhandemo-x64.dylib libcobhandemo.go
mkdir -p tmp
cd spec/support/libcobhandemo
CGO_ENABLED=1 GOOS=darwin GOARCH=arm64 go build -buildmode=c-shared -ldflags='-s -w' -o ../../../tmp/libcobhandemo-arm64.dylib .

- name: Run specs
run: |
Expand All @@ -67,16 +63,16 @@ jobs:
strategy:
matrix:
include:
- { os: ubuntu-20.04, ruby: 3.2 }
- { os: ubuntu-22.04, ruby: 3.2 }
fail-fast: false

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v2
uses: actions/setup-go@v6.3.0
with:
go-version: '1.20.5'
go-version: '1.24'

- name: Install OS dependencies
shell: bash
Expand All @@ -87,11 +83,9 @@ jobs:
- name: Build Linux ARM64
shell: bash
run: |
BUILD_DIR="tmp"
mkdir $BUILD_DIR
cp -R spec/support/libcobhandemo/* $BUILD_DIR
cd tmp
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc go build -v -buildmode=c-shared -ldflags='-s -w' -o libcobhandemo-arm64.so libcobhandemo.go
mkdir -p tmp
cd spec/support/libcobhandemo
CGO_ENABLED=1 GOOS=linux GOARCH=arm64 CC=aarch64-linux-gnu-gcc go build -v -buildmode=c-shared -ldflags='-s -w' -o ../../../tmp/libcobhandemo-arm64.so .

- name: Run specs and rubocop checks
shell: bash
Expand Down
3 changes: 3 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,6 @@ Style/BlockDelimiters:

Style/HashAsLastArrayItem:
Enabled: false

Style/EmptyClassDefinition:
Enabled: false
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ source 'https://rubygems.org'
# Specify your gem's dependencies in cobhan.gemspec
gemspec

gem 'json', '~> 2.7.0' # Pin to avoid ARM64 compilation issues with 2.19.0
gem 'rake', '~> 13.0'
gem 'rspec', '~> 3.10.0'
gem 'rubocop', '~> 1.7'
Expand Down
16 changes: 15 additions & 1 deletion spec/cobhan_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def self.add_int32(first, second)
expect {
CobhanApp.add_int32(1, 2)
}.to raise_error(NoMethodError) do |e|
expect(e.message).to include("undefined method `addInt32'")
expect(e.message).to include("undefined method `addInt32'").or include("undefined method 'addInt32'")
end

CobhanApp.load_library(
Expand All @@ -83,6 +83,8 @@ def self.add_int32(first, second)
expect(memory_pointer.get_int32(0)).to eq(input.bytesize)
expect(memory_pointer.get_int32(Cobhan::SIZEOF_INT32)).to eq(0)
expect(memory_pointer.get_bytes(Cobhan::BUFFER_HEADER_SIZE, input.bytesize)).to eq(input)
ensure
memory_pointer&.free
end
end

Expand All @@ -92,6 +94,8 @@ def self.add_int32(first, second)
output = CobhanApp.cbuffer_to_string(memory_pointer)
expect(output).to eq(input)
expect(output.encoding).to eq(Encoding::UTF_8)
ensure
memory_pointer&.free
end

it 'returns a string from C buffer pointing to a temp file' do
Expand All @@ -112,6 +116,8 @@ def self.add_int32(first, second)
output = CobhanApp.cbuffer_to_string(out_buffer)
expect(output).to eq('A' * 2048)
expect(output.encoding).to eq(Encoding::UTF_8)
ensure
[in_buffer, out_buffer].compact.each(&:free)
end
end

Expand All @@ -131,6 +137,8 @@ def self.add_int32(first, second)

expect(CobhanApp.temp_to_string(buffer_ptr, length)).to eq('content')
expect(File.exist?(file.path)).to eq(false)
ensure
buffer_ptr&.free
end
end

Expand All @@ -140,6 +148,8 @@ def self.add_int32(first, second)
expect(memory_pointer.get_int32(0)).to eq(10)
expect(memory_pointer.get_int32(Cobhan::SIZEOF_INT32)).to eq(0)
expect(memory_pointer.size).to eq(10 + Cobhan::BUFFER_HEADER_SIZE)
ensure
memory_pointer&.free
end
end

Expand All @@ -149,6 +159,8 @@ def self.add_int32(first, second)
memory_pointer = CobhanApp.int_to_buffer(number)
expect(memory_pointer.get_int64(0)).to eq(number)
expect(memory_pointer.size).to eq(Cobhan::SIZEOF_INT32 * 2)
ensure
memory_pointer&.free
end
end

Expand All @@ -157,6 +169,8 @@ def self.add_int32(first, second)
number = (2**63) - 1
memory_pointer = CobhanApp.int_to_buffer(number)
expect(CobhanApp.buffer_to_int(memory_pointer)).to eq(number)
ensure
memory_pointer&.free
end
end
end
6 changes: 6 additions & 0 deletions spec/support/cobhan_module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ def to_upper(input)
raise 'Failed to convert toUpper' if result.negative?

FFI.cbuffer_to_string(out_buffer)
ensure
[in_buffer, out_buffer].compact.each(&:free)
end

def filter_json(json_input, disallowed_value)
Expand All @@ -50,6 +52,8 @@ def filter_json(json_input, disallowed_value)
raise 'Failed to filter json' if result.negative?

FFI.cbuffer_to_string(json_output_buffer)
ensure
[json_input_buffer, disallowed_value_buffer, json_output_buffer].compact.each(&:free)
end

def base64_encode(input)
Expand All @@ -60,6 +64,8 @@ def base64_encode(input)
raise 'Failed to base64 encode' if result.negative?

FFI.cbuffer_to_string(output_buffer)
ensure
[input_buffer, output_buffer].compact.each(&:free)
end

def sleep_test(seconds)
Expand Down
Loading