Skip to content

Commit 3daf180

Browse files
okapi location fixes, ruby gem binary include, unnecessary dependencies removed (#375)
1 parent db0df86 commit 3daf180

22 files changed

Lines changed: 227 additions & 227 deletions

.github/workflows/build-ruby.yml

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,20 +52,14 @@ jobs:
5252
- name: Build and run tests
5353
run: |
5454
gem install bundler
55-
gem install rspec
5655
gem install rubocop
5756
bundle install
5857
python ../devops/build_sdks.py --language=ruby
5958
bundle exec rake
60-
rake test
6159
shell: pwsh
6260
working-directory: ruby
6361
env:
6462
API_GITHUB_TOKEN: ${{ secrets.API_GITHUB_TOKEN }}
65-
RUBY_DLL_PATH: "${{ github.workspace }}/libs" # Required for Ruby on Windows
66-
DYLD_FALLBACK_LIBRARY_PATH: "${{ github.workspace }}/libs"
67-
DYLD_LIBRARY_PATH: "${{ github.workspace }}/libs"
68-
LD_LIBRARY_PATH: "${{ github.workspace }}/libs"
6963
- name: Run linters
7064
uses: wearerequired/[email protected]
7165
with:

devops/build_sdks.py

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,21 @@ def copy_okapi_libs(copy_to: str, windows_path='windows'):
6161
pass
6262

6363

64+
def deep_copy_okapi_libs(copy_to: str):
65+
copy_from = abspath(join(dirname(__file__), '..','libs'))
66+
logging.info(f"Copying okapi libs from: {copy_from}\nto: {copy_to}")
67+
shutil.rmtree(copy_to, ignore_errors=True)
68+
shutil.copytree(copy_from, copy_to)
69+
70+
71+
def copy_okapi_file(copy_from: str, copy_to: str):
72+
try:
73+
clean_dir(copy_to)
74+
shutil.copy2(copy_from, copy_to)
75+
except FileNotFoundError:
76+
pass
77+
78+
6479
def clean_dir(language_dir: str) -> None:
6580
logging.info(f"Cleaning directory={language_dir}")
6681
try:
@@ -123,8 +138,10 @@ def build_ruby(args) -> None:
123138
ruby_dir = get_language_dir('ruby')
124139
update_line(join(ruby_dir, 'lib', 'version.rb'),
125140
{' VERSION =': f" VERSION = '{get_package_versions(args)}'"})
126-
copy_okapi_libs(abspath(join(ruby_dir, '..', 'libs')))
127-
copy_okapi_libs(ruby_dir) # Ruby FFI loads from current directory first, this enables macos
141+
# TODO - Support Ruby on ARM
142+
copy_okapi_file(abspath(join(dirname(__file__), '..','libs','windows','okapi.dll')),abspath(join(ruby_dir,'libs','windows')))
143+
copy_okapi_file(abspath(join(dirname(__file__), '..','libs','macos','libokapi.dylib')), abspath(join(ruby_dir,'libs','macos')))
144+
copy_okapi_file(abspath(join(dirname(__file__), '..','libs','linux','libokapi.so')), abspath(join(ruby_dir,'libs','linux')))
128145

129146

130147
def build_golang(args) -> None:

java/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,4 @@ test {
5959
jar {
6060
archiveBaseName.set(getArchivesBaseName())
6161
archiveVersion.set(jarVersion)
62-
}
62+
}

python/setup.cfg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,4 @@ exclude =
3939
per-file-ignores =
4040
# Ignore line too long because it's a base16 constant string
4141
tests/test_hash.py: E501
42-
tests/test_keys.py: E501
42+
tests/test_keys.py: E501

ruby/lib/did_comm.rb

Lines changed: 0 additions & 24 deletions
This file was deleted.

ruby/lib/did_key.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

ruby/lib/hashing.rb

Lines changed: 0 additions & 24 deletions
This file was deleted.

ruby/lib/ld_proofs.rb

Lines changed: 0 additions & 14 deletions
This file was deleted.

ruby/lib/oberon.rb

Lines changed: 0 additions & 34 deletions
This file was deleted.

ruby/lib/okapi.rb

Lines changed: 15 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,14 @@
11
# frozen_string_literal: true
22

3-
require_relative 'ld_proofs'
43
require 'ffi'
54
require 'os'
6-
require 'okapi/keys/v1/keys_pb'
7-
require 'okapi/examples/v1/examples_pb'
8-
require 'okapi/proofs/v1/proofs_pb'
9-
require 'okapi/transport/v1/transport_pb'
10-
require 'okapi/security/v1/security_pb'
11-
12-
Examples_V1 = Okapi::Examples::V1
13-
Hashing_V1 = Okapi::Hashing::V1
14-
Keys_V1 = Okapi::Keys::V1
15-
Proofs_V1 = Okapi::Proofs::V1
16-
Security_V1 = Okapi::Security::V1
17-
Transport_V1 = Okapi::Transport::V1
185

196
# Okapi wrapper module
207
module Okapi
218
extend FFI::Library
229
@library_path = nil
2310
@library_linked = false
11+
2412
def self.library_path
2513
@library_path
2614
end
@@ -31,7 +19,7 @@ def self.library_path=(path)
3119

3220
def self.library_directory
3321
return 'windows' if OS.windows?
34-
return 'linux' if OS.linux?
22+
return 'linux' if OS.linux? # TODO: Support linux on ARM
3523
return 'macos' if OS.mac?
3624

3725
raise NotImplementedError
@@ -46,13 +34,11 @@ def self.library_name
4634
end
4735

4836
class ByteBuffer < FFI::Struct
49-
layout :len, :int64,
50-
:data, :pointer
37+
layout :len, :int64, :data, :pointer
5138
end
5239

5340
class ExternError < FFI::Struct
54-
layout :code, :int32,
55-
:message, :string
41+
layout :code, :int32, :message, :string
5642
end
5743

5844
# rubocop:disable Metrics/MethodLength
@@ -61,16 +47,17 @@ def self.load_native_library
6147
return if @library_linked
6248

6349
@library_linked = true
64-
65-
full_path = library_name
66-
full_path = File.expand_path(File.join(library_path, library_name)) unless library_path.nil?
67-
begin
68-
ffi_lib full_path
50+
# Get the environment variable RUBY_DLL_PATH on all platforms as a failsafe,
51+
# MacOS system integrity protection, I'm looking at you.
52+
possible_library_paths = [File.expand_path(File.join(__dir__, '..', 'libs', library_directory, library_name)),
53+
library_name,
54+
File.expand_path(File.join(library_path || '', library_name))]
55+
possible_library_paths.each do |lib_path|
56+
puts("Attempting to load binary: #{lib_path}")
57+
ffi_lib lib_path
58+
break
6959
rescue LoadError
70-
# Get the environment variable RUBY_DLL_PATH on all platforms as a failsafe,
71-
# MacOS system integrity protection, I'm looking at you.
72-
full_path = File.expand_path(File.join(ENV['RUBY_DLL_PATH'], library_name))
73-
ffi_lib full_path
60+
# Ignored
7461
end
7562

7663
attach_function :didkey_generate, [ByteBuffer.by_value, ByteBuffer.by_ref, ExternError.by_ref], :int
@@ -118,6 +105,7 @@ def self.ffi_call(function, request, response_klass)
118105
byte_buffer_free(response_buffer)
119106
response
120107
end
108+
121109
# rubocop:enable Metrics/MethodLength
122110
# rubocop:enable Metrics/AbcSize
123111

0 commit comments

Comments
 (0)