Skip to content

Commit e963846

Browse files
authored
[CI] Package and test gem install during CI build (#63)
* Use thermite gem for invoking cargo compiler * Add extension-specific Rakefile * Switch to using the main Rakefile for the build * Fix Rubocop * Include Cargo.toml in .gem * Include Bridge src files in .gem * fixup! Include Bridge src files in .gem * Include all sdk-core in .gem * Use separate Rakefile for native extension build * Use gem build/install instead of rake install in CI
1 parent 058f385 commit e963846

File tree

8 files changed

+42
-10
lines changed

8 files changed

+42
-10
lines changed

.github/workflows/ci.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,7 @@ jobs:
6363
- run: bundle exec rake bridge:release
6464
- run: bundle exec rake test_server:build
6565
- run: bundle exec rspec
66+
- name: Package and install the gem
67+
run: |
68+
gem build temporal.gemspec
69+
gem install $(echo temporal-ruby-*.gem)

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ _yardoc/
1010
/spec/reports/
1111
/tmp/
1212

13+
# Thermite artefacts
14+
mkmf.log
15+
lib/bridge.so
16+
1317
# rspec failure tracking
1418
.rspec_status
1519

.rubocop.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ Metrics/AbcSize:
5555

5656
Metrics/BlockLength:
5757
Exclude:
58+
- temporal.gemspec
5859
- spec/**/*_spec.rb
5960

6061
Metrics/ClassLength:

Rakefile

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,19 @@
11
require 'bundler/gem_tasks'
22
require 'rbs_protobuf'
33
require 'fileutils'
4+
require 'thermite/tasks'
45

56
API_PROTO_ROOT = 'bridge/sdk-core/protos/api_upstream'.freeze
67
CORE_PROTO_ROOT = 'bridge/sdk-core/protos/local'.freeze
78
PROTOBUF_PATH = 'lib/gen'.freeze
89
RBS_SIG_PATH = 'sig/protos'.freeze
910
GRPC_PATH = 'spec/support/grpc'.freeze
1011

12+
Thermite::Tasks.new(
13+
cargo_project_path: File.expand_path('bridge', __dir__),
14+
ruby_project_path: __dir__,
15+
)
16+
1117
namespace :bridge do
1218
desc 'Run a linter on SDK Core Bridge'
1319
task :lint do
@@ -16,21 +22,18 @@ namespace :bridge do
1622

1723
desc 'Build SDK Core Bridge'
1824
task :build do
19-
sh 'cd bridge && cargo build'
25+
ENV['CARGO_PROFILE'] = 'debug'
26+
Rake::Task['thermite:build'].invoke
2027
end
2128

2229
desc 'Release SDK Core Bridge'
23-
task :release do
24-
sh 'cd bridge && cargo build --release'
25-
end
30+
task release: ['thermite:build']
2631

2732
# Mac OS with rbenv users keep leaving behind build artifacts from
2833
# when they tried to build against a statically linked Ruby and then
2934
# try against a dynamically linked one causing errors in the build result
3035
desc 'Clean up previous build artefacts'
31-
task :clean do
32-
sh 'cd bridge && cargo clean'
33-
end
36+
task clean: ['thermite:clean']
3437
end
3538

3639
namespace :test_server do

bridge/Cargo.toml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ name = "bridge"
33
version = "0.0.1"
44
authors = ["Anthony D <anthony@temporal.io>"]
55
edition = "2021"
6+
repository = "https://github.com/temporalio/sdk-ruby"
67

78
[dependencies]
89
lazy_static = "1.4.0"
@@ -20,3 +21,6 @@ url = "2.2"
2021
[lib]
2122
name = "bridge"
2223
crate-type = ["dylib"]
24+
25+
[package.metadata.thermite]
26+
github_releases = true

ext/Rakefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
require 'thermite/tasks'
2+
3+
Thermite::Tasks.new(
4+
cargo_project_path: File.expand_path('../bridge', __dir__),
5+
ruby_project_path: File.expand_path('..', __dir__),
6+
)
7+
8+
task default: 'thermite:build'

lib/temporal/bridge.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
require 'rutie'
22

3-
BRIDGE_DIR = File.expand_path('../../bridge/src', File.dirname(__FILE__))
3+
BRIDGE_DIR = File.expand_path('..', __dir__)
44

55
module Temporal
66
module Bridge
77
# TODO: Expand this into more specific error types
88
class Error < StandardError; end
99

10-
Rutie.new(:bridge, release: ENV['DEBUG'] ? :debug : :release).init('init_bridge', BRIDGE_DIR)
10+
Rutie
11+
.new(:bridge, lib_path: '', lib_suffix: 'so', lib_prefix: '')
12+
.init('init_bridge', BRIDGE_DIR)
1113
end
1214
end

temporal.gemspec

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,18 @@ Gem::Specification.new do |spec|
1212
spec.email = ['anthony@temporal.io']
1313

1414
spec.require_paths = ['lib']
15-
spec.files = Dir['{lib}/**/*.*'] + %w[temporal.gemspec Gemfile LICENSE README.md]
15+
spec.extensions = ['ext/Rakefile']
16+
17+
spec.files =
18+
Dir['lib/**/*.*'] +
19+
Dir['bridge/**/*.*'].reject { |x| x.include?('/target/') } +
20+
%w[ext/Rakefile temporal.gemspec Gemfile LICENSE README.md]
1621

1722
spec.required_ruby_version = '>= 2.7.0'
1823

1924
spec.add_dependency 'google-protobuf', '~> 3.21.1' # Protobuf
2025
spec.add_dependency 'rutie', '~> 0.0.4' # Rust bindings
26+
spec.add_dependency 'thermite', '~> 0.13.0' # For compiling Rust ext
2127

2228
spec.add_development_dependency 'grpc' # Ruby GRPC for the mock server
2329
spec.add_development_dependency 'grpc-tools' # GRPC generator for the mock server

0 commit comments

Comments
 (0)