malachite 0.2.1 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5052dfabfaf3ab568017e5dca181503e42aa32ef
4
- data.tar.gz: 3e54fe1a9525ff6568127cfe0d94ee86daf31851
3
+ metadata.gz: 0ba4057a948f808a684ea7dd503ccaabe46bbba5
4
+ data.tar.gz: 8d2b9b35cd4104cd735e0c92db2c7098b98b30f4
5
5
  SHA512:
6
- metadata.gz: a43b53c157f009ef74ae837dd005be597c8c292eaa1c4d7fbb95d1748fb157f4a259fd01b93be2e27806ad81d07939dab3e6fc73401aee403248339840d3c72e
7
- data.tar.gz: 5034fd9f28ad91b68d74fe1e9438644c111d03bcf14591814b4ab7859874f6a7f8978491210b04290249cd763ff4c2789e83bbf68356755646684db8742e3734
6
+ metadata.gz: ec0603aa1eac3c6d5428c2b321ef4cb6a5a97f7aa91e36d356872f37419afec30e6a2f806e89ce8eac3e362ac9da93d61a021c93dfdfd7804bb859d9dd787631
7
+ data.tar.gz: d923d46e0ab54ff1c0d687a24a7019c715cf08b93d5fe5f7df08621f095f616308393e8a3e9d1525390f93bfc49532e95faea3b0822483b813e769c6aab03f89
data/.gitignore CHANGED
@@ -1,6 +1,5 @@
1
1
  Gemfile.lock
2
2
  .rvmrc
3
- .ruby-version
4
3
  tags
5
4
  *.swp
6
5
  *.gem
@@ -0,0 +1 @@
1
+ 2.3.3
data/README.md CHANGED
@@ -1,10 +1,16 @@
1
1
  ### Malachite
2
2
 
3
- A RubyGem which enables calling Go code from Rails. Probably not production ready.
3
+ Call Go functions directly from Rails.
4
+
5
+ ### Requirements
6
+
7
+ Requires Ruby >= 2.0.0, Go 1.5 <-> 1.11.
8
+
9
+ Xcode 8.3 is broken, do not use until [this is fixed](https://github.com/golang/go/issues/19734)
4
10
 
5
11
  ### Installation
6
12
 
7
- Install [Go 1.5 or later](https://golang.org/doc/install) on relevant machines.
13
+ Install [Go](https://golang.org/doc/install). You must have a proper GOPATH.
8
14
 
9
15
  Add this to your Gemfile:
10
16
 
@@ -12,8 +18,6 @@ Add this to your Gemfile:
12
18
  gem 'malachite'
13
19
  ```
14
20
 
15
- Make a subdirectory of "app" called "go".
16
-
17
21
  ### Write Some Go Functions
18
22
 
19
23
  Everything in ```app/go``` will get compiled into one library, so to get it to work with
@@ -56,7 +60,7 @@ Check out the wiki on [Testing](https://github.com/zhubert/malachite/wiki/Testin
56
60
 
57
61
  ### How Does it Work?
58
62
 
59
- One part code generation, another part pure evil.
63
+ Code generation.
60
64
 
61
65
  * The first time the function is called, Malachite will build a shared library from all the Go code in your ```app/go``` folder
62
66
  * It then uses Ruby's Fiddle to call the shared library
@@ -64,7 +68,7 @@ One part code generation, another part pure evil.
64
68
 
65
69
  Because of the JSON step, you'll only see real performance gains on computationally difficult tasks. Ruby's JSON conversion is a large tax.
66
70
 
67
- Note: You can also request precompilation. In an initializer:
71
+ Note: You can also request precompilation. This is helpful for production environments. In an initializer:
68
72
 
69
73
  ```ruby
70
74
  Malachite.precompile
@@ -73,3 +77,7 @@ Malachite.precompile
73
77
  ### Ruby 2.2.4+
74
78
 
75
79
  It's strongly recommended to use the [newest release of Ruby](https://www.ruby-lang.org/en/news/2015/12/16/unsafe-tainted-string-usage-in-fiddle-and-dl-cve-2015-7551/) as there was a security issue with older versions of Fiddle.
80
+
81
+ ### Production Readiness
82
+
83
+ Likely more gotchas with architecture variations and Cgo. Submit a PR if you find something.
@@ -2,10 +2,11 @@ module Malachite
2
2
  class Compiler
3
3
  def initialize
4
4
  @compiled_file = path_to_compiled_file
5
+ @compiled_header = path_to_compiled_header
5
6
  end
6
7
 
7
8
  def compile
8
- return @compiled_file if File.exist?(@compiled_file)
9
+ return @compiled_file if File.exist?(@compiled_file) && File.exist?(@compiled_header)
9
10
  compile!
10
11
  end
11
12
 
@@ -13,12 +14,23 @@ module Malachite
13
14
 
14
15
  def compile!
15
16
  modify_source_files_in_tmp
17
+
16
18
  if modified_go_files == []
17
- fail Malachite::BuildError, 'Nothing to build, there are no Go files in tmp'
19
+ raise Malachite::BuildError, 'Nothing to build, there are no Go files in tmp'
18
20
  end
19
- unless system('go', 'build', '-buildmode=c-shared', '-o', @compiled_file, *modified_go_files)
20
- fail Malachite::BuildError, 'Unable to Build Shared Library, is Go 1.5+ installed?'
21
+
22
+ unless system({ 'CGO_ENABLED' => '1' }, 'go', 'build', '-buildmode=c-shared', '-o', @compiled_file, *modified_go_files)
23
+ raise Malachite::BuildError, 'Unable to Build Shared Library, is Go 1.5+ installed?'
21
24
  end
25
+
26
+ unless File.exist?(@compiled_header)
27
+ raise Malachite::BuildError, 'Unable to Build Header File'
28
+ end
29
+
30
+ unless File.exist?(@compiled_file)
31
+ raise Malachite::BuildError, 'Unable to Build Shared Object'
32
+ end
33
+
22
34
  path_to_compiled_file
23
35
  end
24
36
 
@@ -47,5 +59,9 @@ module Malachite
47
59
  def path_to_compiled_file
48
60
  Rails.root.join('tmp', 'malachite.so').to_s
49
61
  end
62
+
63
+ def path_to_compiled_header
64
+ Rails.root.join('tmp', 'malachite.h').to_s
65
+ end
50
66
  end
51
67
  end
@@ -2,6 +2,6 @@ namespace :malachite do
2
2
  desc 'runs all Go tests in app/go'
3
3
  task :test do
4
4
  test_files = Dir["#{Rails.root.join('app', 'go')}/**/*.go"]
5
- system('go', 'test', *test_files)
5
+ system({ 'CGO_ENABLED' => '1' }, 'go', 'test', *test_files)
6
6
  end
7
7
  end
@@ -1,3 +1,3 @@
1
1
  module Malachite
2
- VERSION = '0.2.1'
2
+ VERSION = '1.1.0'
3
3
  end
@@ -15,9 +15,8 @@ Gem::Specification.new do |spec|
15
15
  spec.version = Malachite::VERSION
16
16
 
17
17
  spec.required_ruby_version = '>= 2.0.0'
18
- spec.add_dependency 'json', '~> 1.0'
18
+ spec.add_dependency 'activesupport'
19
19
  spec.add_development_dependency 'bundler', '~> 1.9'
20
20
  spec.add_development_dependency 'rake', '~> 10.0'
21
21
  spec.add_development_dependency 'minitest', '~> 5'
22
- spec.add_development_dependency 'activesupport', '~> 4'
23
22
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class ClientTest < MiniTest::Unit::TestCase
3
+ class ClientTest < MiniTest::Test
4
4
  def setup
5
5
  @client = Malachite::Client.new('upcase', ['foo'])
6
6
  end
@@ -1,6 +1,6 @@
1
1
  require 'test_helper'
2
2
 
3
- class FileCompilerTest < MiniTest::Unit::TestCase
3
+ class FileCompilerTest < MiniTest::Test
4
4
  def setup
5
5
  @source = Malachite::FileCompiler.new(Rails.root.join('app', 'go', 'upcase.go')).compile
6
6
  end
@@ -0,0 +1,11 @@
1
+ require 'test_helper'
2
+
3
+ # Not really a performance test, but designed to generate more work
4
+ class PerformanceTest < MiniTest::Test
5
+ def test_confirm_compilation_matches_fixture
6
+ 1000.times do
7
+ @client = Malachite::Client.new('upcase', ['foo'])
8
+ assert_equal @client.call, ['FOO']
9
+ end
10
+ end
11
+ end
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: malachite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zack Hubert
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-01-12 00:00:00.000000000 Z
11
+ date: 2019-10-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: json
14
+ name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '1.0'
19
+ version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: '1.0'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -66,20 +66,6 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '5'
69
- - !ruby/object:Gem::Dependency
70
- name: activesupport
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: '4'
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: '4'
83
69
  description: A RubyGem which enables calling Go code from Rails.
84
70
  email:
85
71
  - zhubert@gmail.com
@@ -88,6 +74,7 @@ extensions: []
88
74
  extra_rdoc_files: []
89
75
  files:
90
76
  - ".gitignore"
77
+ - ".ruby-version"
91
78
  - Gemfile
92
79
  - README.md
93
80
  - Rakefile
@@ -110,6 +97,7 @@ files:
110
97
  - test/dummy/app/go/upcase.go
111
98
  - test/file_compiler_test.rb
112
99
  - test/fixtures/valid_upcase.go
100
+ - test/performance_test.rb
113
101
  - test/rails_stub.rb
114
102
  - test/test_helper.rb
115
103
  homepage: http://www.zhubert.com
@@ -132,7 +120,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
132
120
  version: '0'
133
121
  requirements: []
134
122
  rubyforge_project:
135
- rubygems_version: 2.4.5.1
123
+ rubygems_version: 2.5.2
136
124
  signing_key:
137
125
  specification_version: 4
138
126
  summary: A RubyGem which enables calling Go code from Rails