Skip to content

Commit 603d779

Browse files
authored
Merge pull request #8 from fetlife/switch-to-rb-sys
Switch to rb-sys to compile native extension
2 parents a811f26 + 9593a6b commit 603d779

16 files changed

Lines changed: 244 additions & 143 deletions

File tree

.github/workflows/ci.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ "main" ]
6+
pull_request:
7+
branches: [ "main" ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
rust:
14+
name: Rust
15+
runs-on: ubuntu-latest
16+
steps:
17+
- uses: actions/[email protected]
18+
- uses: actions-rust-lang/setup-rust-toolchain@v1
19+
- name: Run tests
20+
run: cargo test --verbose
21+
22+
ruby_extension:
23+
name: Ruby ${{ matrix.ruby }} on ${{ matrix.os }}
24+
runs-on: ${{ matrix.os }}
25+
strategy:
26+
fail-fast: false
27+
matrix:
28+
os: [ubuntu-latest, macos-latest]
29+
ruby: ["3.0", "3.4"]
30+
steps:
31+
- uses: actions/[email protected]
32+
- uses: ruby/setup-ruby@v1
33+
with:
34+
ruby-version: ${{ matrix.ruby }}
35+
bundler-cache: true
36+
- uses: actions-rust-lang/setup-rust-toolchain@v1
37+
- name: Run Ruby extension smoke tests
38+
run: bundle exec rake test
39+
40+
windows_cross_build:
41+
name: Cross-build Windows native gem
42+
runs-on: ubuntu-latest
43+
steps:
44+
- uses: actions/[email protected]
45+
- uses: ruby/setup-ruby@v1
46+
with:
47+
ruby-version: "3.4"
48+
bundler-cache: true
49+
- name: Cross-build x64-mingw-ucrt gem
50+
run: bundle exec rb-sys-dock --platform x64-mingw-ucrt --build

.github/workflows/release.yml

Lines changed: 38 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -3,106 +3,78 @@ on:
33
push:
44
tags:
55
- "[0-9]*.[0-9]*.[0-9]*"
6+
- "v[0-9]*.[0-9]*.[0-9]*"
67

78
jobs:
8-
build_gem:
9+
build_source_gem:
910
name: Build source gem
1011
runs-on: ubuntu-latest
1112
steps:
12-
- uses: actions/checkout@v4
13-
- uses: ruby/setup-ruby-pkgs@v1
13+
- uses: actions/checkout@v6.0.2
14+
- uses: ruby/setup-ruby@v1
1415
with:
1516
ruby-version: 3.4
16-
- run: sudo apt-get update
17-
- run: gem update --system
18-
- run: rake gem
17+
bundler-cache: true
18+
- run: bundle exec rake build
1919
- name: Upload source gem
20-
uses: actions/upload-artifact@v4
20+
uses: actions/upload-artifact@v7.0.0
2121
with:
22-
name: distributing_iterator.gem
22+
name: source-gem
2323
path: pkg/*.gem
2424
retention-days: 1
2525

26-
compile_native_gems:
27-
name: Compile native gem
28-
needs: build_gem
26+
build_native_gems:
27+
name: Build native gem (${{ matrix.platform }})
28+
runs-on: ubuntu-latest
2929
strategy:
30+
fail-fast: false
3031
matrix:
31-
include:
32-
- os: ubuntu-24.04
33-
platform: x86_64-linux
34-
ruby: "3.4"
35-
- os: ubuntu-24.04-arm
36-
platform: aarch64-linux
37-
ruby: "3.4"
38-
- os: macos-latest
39-
platform: arm64-darwin
40-
ruby: "3.4"
41-
runs-on: ${{ matrix.os }}
32+
platform:
33+
- x86_64-linux
34+
- aarch64-linux
35+
- x86_64-darwin
36+
- arm64-darwin
37+
- x64-mingw-ucrt
4238
steps:
43-
- uses: actions/checkout@v4
44-
45-
- uses: ruby/setup-ruby-pkgs@v1
39+
- uses: actions/[email protected]
40+
- uses: ruby/setup-ruby@v1
4641
with:
47-
ruby-version: ${{ matrix.ruby }}
48-
49-
- name: Install gem-compiler
50-
run: gem install gem-compiler
51-
52-
- name: Download source gem
53-
uses: actions/download-artifact@v4
54-
with:
55-
name: distributing_iterator.gem
56-
path: pkg/
57-
58-
- name: Compile gem
59-
run: |
60-
SOURCE_GEM=$(ls pkg/*.gem | grep -v -- '-x86_64-linux\|aarch64-linux\|arm64-darwin')
61-
gem compile $SOURCE_GEM --prune
62-
63-
- name: Upload compiled gem
64-
uses: actions/upload-artifact@v4
42+
ruby-version: 3.4
43+
bundler-cache: true
44+
- name: Build native gems
45+
run: bundle exec rb-sys-dock --platform ${{ matrix.platform }} --build
46+
- name: Upload native gems
47+
uses: actions/[email protected]
6548
with:
66-
name: distributing_iterator-${{ matrix.platform }}.gem
67-
path: ./*.gem
49+
name: native-gem-${{ matrix.platform }}
50+
path: pkg/*-${{ matrix.platform }}.gem
6851
retention-days: 1
6952

7053
release:
7154
name: Create GitHub Release
72-
needs: compile_native_gems
55+
needs:
56+
- build_source_gem
57+
- build_native_gems
7358
runs-on: ubuntu-latest
59+
permissions:
60+
contents: write
7461
steps:
75-
- uses: actions/checkout@v4
76-
7762
- name: Extract version
7863
id: extract_version
7964
run: |
8065
VERSION=${GITHUB_REF#refs/tags/}
66+
VERSION=${VERSION#v}
8167
echo "GEM_VERSION=$VERSION" >> $GITHUB_ENV
8268
8369
- name: Download all artifacts
84-
uses: actions/download-artifact@v4
70+
uses: actions/download-artifact@v8.0.1
8571
with:
8672
path: artifacts
8773

88-
- name: Rename gem files with version
89-
run: |
90-
mkdir -p release_gems
91-
for gem in artifacts/distributing_iterator-*.gem/*.gem; do
92-
# Extract platform from the original filename
93-
platform=$(basename $gem | sed -E 's/distributing_iterator-([^-]+-[^-]+)\.gem/\1/')
94-
95-
96-
target_filename="distributing_iterator-${GEM_VERSION}-${platform}.gem"
97-
target_path="release_gems/$target_filename"
98-
mv "$gem" "$target_path"
99-
done
100-
# Move source gem to release_gems directory
101-
mv artifacts/distributing_iterator.gem/*.gem release_gems/distributing_iterator-${GEM_VERSION}.gem
102-
10374
- name: Create release
10475
uses: softprops/action-gh-release@v2
10576
with:
106-
tag_name: ${{ env.GEM_VERSION }}
107-
files: release_gems/*.gem
77+
tag_name: ${{ github.ref_name }}
78+
name: distributing_iterator ${{ env.GEM_VERSION }}
79+
files: artifacts/**/*.gem
10880
generate_release_notes: true

.github/workflows/rust.yml

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

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,13 @@
22
# will have compiled files and executables
33
debug/
44
target/
5+
tmp/
6+
ext/distributing_iterator/Makefile
7+
ext/distributing_iterator/mkmf.log
8+
ext/distributing_iterator/.sitearchdir.time
9+
lib/distributing_iterator/distributing_iterator.bundle
10+
lib/distributing_iterator/distributing_iterator.so
11+
lib/distributing_iterator/distributing_iterator.dll
512

613
# Remove Cargo.lock from gitignore if creating an executable, leave it for libraries
714
# More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html
@@ -14,3 +21,5 @@ target/
1421
*.pdb
1522

1623
pkg/
24+
.DS_Store
25+
Gemfile.lock

Cargo.lock

Lines changed: 11 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
[package]
22
name = "distributing-iterator"
3-
version = "0.2.0"
3+
version = "0.2.1"
44
edition = "2024"
55
publish = false
66
authors = ["Fetlife <[email protected]>", "Andrii Dmytrenko <[email protected]>"]
77

88
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
99

1010
[dependencies]
11-
magnus = { version="0.7.1", optional = true }
11+
magnus = { version="0.8.2", optional = true }
1212
csv = { version = "^1.3", optional = true }
1313
fnv = "1.0.7"
1414
indexmap = "2.8.0"
@@ -22,7 +22,7 @@ name = "distributing_iterator"
2222
crate-type = ["cdylib", "lib"]
2323

2424
[features]
25-
default = ["ruby_ext"]
25+
default = ["csv"]
2626
ruby_ext = ["dep:magnus", "csv"]
2727
csv = ["dep:csv"]
2828

README.md

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ id,name
6969
3,xyzzy
7070
CSV
7171

72-
output = DistributingIterator.distribute(csv, 'id', 3)
72+
output = DistributingIterator.distribute_csv(csv, 'id', 3)
7373

7474
puts output
7575
# id,name
@@ -93,21 +93,49 @@ puts output
9393

9494
# Releasing a New Version
9595

96+
To work on the gem locally:
97+
98+
```bash
99+
bundle install
100+
bundle exec rake compile
101+
bundle exec rake test
102+
```
103+
104+
To build a source gem:
105+
106+
```bash
107+
bundle exec rake build
108+
```
109+
110+
To build a native gem for the current platform:
111+
112+
```bash
113+
bundle exec rake native gem
114+
```
115+
116+
To build a cross-compiled native gem for a specific platform:
117+
118+
```bash
119+
bundle exec rb-sys-dock --platform x86_64-linux --build
120+
```
121+
96122
To release a new version of the gem:
97123

98124
1. Update the version number in `Cargo.toml` and `lib/distributing_iterator/version.rb`
99-
2. Create and push a new git tag with the version number (e.g., `v1.0.0`):
125+
2. Create and push a new git tag with the version number (e.g., `0.2.1` or `v0.2.1`):
100126
```bash
101-
git tag 1.0.0
102-
git push origin 1.0.0
127+
git tag 0.2.1
128+
git push origin 0.2.1
103129
```
104130

105131
The release workflow will automatically:
106132
- Build the source gem
107133
- Compile native gems for multiple platforms:
108134
- x86_64 Linux
109135
- aarch64 Linux
136+
- x86_64 macOS
110137
- arm64 macOS
138+
- x64 Windows (UCRT)
111139
- Create a GitHub release with all compiled gems
112140
- Generate release notes based on the commits since the last release
113141

0 commit comments

Comments
 (0)