Skip to content

Commit 2d464b9

Browse files
committed
Source gem support
1 parent 163f409 commit 2d464b9

File tree

4 files changed

+67
-15
lines changed

4 files changed

+67
-15
lines changed

.github/workflows/build-gems.yml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
- "releases/*"
88

99
jobs:
10-
build-gems:
10+
build-platform-gems:
1111
runs-on: ubuntu-latest
1212
strategy:
1313
fail-fast: false
@@ -31,23 +31,49 @@ jobs:
3131
working-directory: ./temporalio
3232
cache-version: v1-${{ matrix.rubyPlatform }}
3333

34-
- name: Cross compile gems
34+
- name: Cross compile gem
3535
uses: oxidize-rb/actions/cross-gem@v1
3636
id: cross-gem
3737
with:
3838
platform: ${{ matrix.rubyPlatform }}
3939
ruby-versions: "3.1,3.2,3.3"
4040
working-directory: ./temporalio
4141

42-
- name: Upload gems
42+
- name: Upload gem
4343
uses: actions/upload-artifact@v4
4444
with:
4545
name: ${{ matrix.rubyPlatform }}-gem
4646
path: ${{ steps.cross-gem.outputs.gem-path }}
4747

48+
build-source-gem:
49+
runs-on: ubuntu-latest
50+
steps:
51+
- name: Checkout repository
52+
uses: actions/checkout@v4
53+
with:
54+
submodules: recursive
55+
56+
- name: Setup Ruby and Rust
57+
uses: oxidize-rb/actions/setup-ruby-and-rust@v1
58+
with:
59+
ruby-version: "3.3"
60+
bundler-cache: true
61+
cargo-cache: true
62+
cache-version: v1-source
63+
64+
- name: Build
65+
working-directory: ./temporalio
66+
run: bundle exec rake build
67+
68+
- name: Upload gem
69+
uses: actions/upload-artifact@v4
70+
with:
71+
name: source-gem
72+
path: temporalio/pkg/*.gem
73+
4874
smoke-test-gems:
4975
needs:
50-
- build-gems
76+
- build-platform-gems
5177
strategy:
5278
fail-fast: false
5379
matrix:

README.md

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ Notably missing from this SDK:
5454
- [Platform Support](#platform-support)
5555
- [Development](#development)
5656
- [Build](#build)
57+
- [Build Platform-specific Gem](#build-platform-specific-gem)
5758
- [Testing](#testing)
5859
- [Code Formatting and Type Checking](#code-formatting-and-type-checking)
5960
- [Proto Generation](#proto-generation)
@@ -76,12 +77,14 @@ Or via `gem install` like:
7677
gem install temporalio
7778
```
7879

80+
**NOTE**: Only macOS ARM/x64 and Linux ARM/x64 are supported, and the platform-specific gem chosen is based on when the
81+
gem/bundle install is performed. A source gem is published but cannot be used directly and will fail to build if tried.
82+
MinGW-based Windows and Linux MUSL do not have gems. See the [Platform Support](#platform-support) section for more
83+
information.
84+
7985
**NOTE**: Due to [an issue](https://github.com/temporalio/sdk-ruby/issues/162), fibers (and `async` gem) are only
8086
supported on Ruby versions 3.3 and newer.
8187

82-
**NOTE**: MinGW-based Windows, Linux MUSL, and pure source based gems are not currently published. See the
83-
[Platform Support](#platform-support) section for more information.
84-
8588
### Implementing an Activity
8689

8790
Implementing workflows is not yet supported in the Ruby SDK, but implementing activities is.
@@ -465,9 +468,9 @@ This means Linux and macOS for ARM and x64 have published gems. Currently, a gem
465468
Due to [an issue](https://github.com/temporalio/sdk-ruby/issues/172) with Windows and multi-threaded Rust, MinGW-based
466469
Windows (i.e. `x64-mingw-ucrt`) is not supported. But WSL is supported using the normal Linux gem.
467470

468-
At this time a pure source gem is not published, which means that when trying to install the gem on an unsupported
469-
platform, you may get an error that it is not available. Building from source requires many files across submodules and
470-
requires Rust to be installed. See the [Build](#build) section for how to build a gem from the repository.
471+
At this time a pure source gem is published for documentation reasons, but it cannot be built and will fail if tried.
472+
Building from source requires many files across submodules and requires Rust to be installed. See the [Build](#build)
473+
section for how to build a the repository.
471474

472475
The SDK works on Ruby 3.1+, but due to [an issue](https://github.com/temporalio/sdk-ruby/issues/162), fibers (and
473476
`async` gem) are only supported on Ruby versions 3.3 and newer.
@@ -491,13 +494,32 @@ To build shared library for development use:
491494

492495
bundle exec rake compile
493496

494-
Note, this is not `compile:dev` because debug-mode in Rust has
497+
**NOTE**: This will make the current directory usable for the current Ruby version by putting the shared library
498+
`lib/temporalio/internal/bridge/temporalio_bridge.<ext>` in the proper place. But this development shared library may
499+
not work for other Ruby versions or other OS/arch combinations. For that, see "Build Platform-specific Gem" below.
500+
501+
**NOTE**: This is not `compile:dev` because debug-mode in Rust has
495502
[an issue](https://github.com/rust-lang/rust/issues/34283) that causes runtime stack size problems.
496503

497-
To lint, build, and test release:
504+
To lint, build, and test:
498505

499506
bundle exec rake
500507

508+
#### Build Platform-specific Gem
509+
510+
The standard `bundle exec rake build` will produce a gem in the `pkg` directory, but that gem will not be usable because
511+
the shared library is not present (neither the Rust code nor the compiled form). To create a platform-specific gem that
512+
can be used, `rb-sys-dock` must be run. See the
513+
[Cross-Compilation documentation](https://oxidize-rb.github.io/rb-sys/tutorial/publishing/cross-compilation.html) in the
514+
`rb-sys` repository. For example, running:
515+
516+
bundle exec rb-sys-dock --platform x86_64-linux --ruby-versions 3.2,3.3 --build
517+
518+
Will create a `pkg/temporalio-<version>-x86_64-linux.gem` file that can be used in x64 Linux environments on both Ruby
519+
3.2 and Ruby 3.3 because it contains the shared libraries. For this specific example, the shared libraries are inside
520+
the gem at `lib/temporalio/internal/bridge/3.2/temporalio_bridge.<ext>` and
521+
`lib/temporalio/internal/bridge/3.3/temporalio_bridge.<ext>`.
522+
501523
### Testing
502524

503525
This project uses `minitest`. To test:

temporalio/Rakefile

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ task build: :compile
1010

1111
GEMSPEC = Gem::Specification.load('temporalio.gemspec')
1212

13-
RbSys::ExtensionTask.new('temporalio_bridge', GEMSPEC) do |ext|
14-
ext.lib_dir = 'lib/temporalio/internal/bridge'
13+
begin
14+
RbSys::ExtensionTask.new('temporalio_bridge', GEMSPEC) do |ext|
15+
ext.lib_dir = 'lib/temporalio/internal/bridge'
16+
end
17+
rescue RbSys::CargoMetadataError
18+
raise 'Source gem cannot be installed directly, must be a supported platform'
1519
end
1620

1721
require 'rake/testtask'

temporalio/temporalio.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Gem::Specification.new do |spec|
1616
spec.metadata['homepage_uri'] = spec.homepage
1717
spec.metadata['source_code_uri'] = 'https://github.com/temporalio/sdk-ruby'
1818

19-
spec.files = Dir['lib/**/*.rb', 'LICENSE', 'README.md', 'Cargo.*', 'temporalio.gemspec']
19+
spec.files = Dir['lib/**/*.rb', 'LICENSE', 'README.md', 'Cargo.*', 'temporalio.gemspec', 'Gemfile', 'Rakefile']
2020

2121
spec.bindir = 'exe'
2222
spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }

0 commit comments

Comments
 (0)