Skip to content

Commit

Permalink
fix: add musl gems for Ruby (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
sighphyre authored Nov 4, 2024
1 parent 0e7f9ff commit dd5f287
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 47 deletions.
79 changes: 60 additions & 19 deletions .github/workflows/publish-ruby.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,18 @@ jobs:
platform: x86_64-linux
- binary: libyggdrasilffi_arm64.so
platform: arm-linux
- binary: libyggdrasilffi_aarch64.so
platform: aarch64-linux
- binary: libyggdrasilffi_x86_64.dll
- binary: libyggdrasilffi_x86_64-musl.so
platform: x86_64-linux-musl
- binary: libyggdrasilffi_arm64-musl.so
platform: aarch64-linux-musl
- binary: yggdrasilffi_x86_64.dll
platform: x64-mingw32
- binary: yggdrasilffi_arm64.dll
platform: arm64-mingw32
- binary: libyggdrasilffi_x86_64.dylib
platform: x86_64-darwin
- binary: libyggdrasilffi_arm64.dylib
platform: arm64-darwin
- binary: libyggdrasilffi_arm64.dll
platform: arm64-mingw32

steps:
- uses: actions/checkout@v4
Expand All @@ -40,7 +42,7 @@ jobs:
- name: Download Binary
run: |
BINARY_URL="https://github.com/${{ github.repository }}/releases/download/${CORE_VERSION}/${{ matrix.binary }}"
BINARY_URL="https://github.com/${{ github.repository }}/releases/download/unleash-yggdrasil-v${CORE_VERSION}/${{ matrix.binary }}"
TARGET_DIR="ruby-engine/lib"
mkdir -p "$TARGET_DIR"
Expand All @@ -57,15 +59,27 @@ jobs:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Build and Publish Linux Gem
- name: Build Gem
run: |
cd ruby-engine
gem build yggdrasil-engine.gemspec
gem push *.gem
working-directory: ${{ github.workspace }}
env:
GEM_HOST_API_KEY: ${{ secrets.GEMS_PUBLISH_KEY }}

- name: Build Gem
run: |
cd ruby-engine
gem build yggdrasil-engine.gemspec
export GEM_FILE=$(ls yggdrasil-engine-*.gem)
echo "gem_file_name=$GEM_FILE" >> $GITHUB_ENV
- name: Upload Gem
uses: actions/upload-artifact@v4
with:
name: ${{ env.gem_file_name }}
path: ruby-engine/${{ env.gem_file_name }}

build_jruby_gems:
runs-on: ubuntu-latest
strategy:
Expand Down Expand Up @@ -102,25 +116,23 @@ jobs:
echo "CORE_VERSION=$CORE_VERSION" >> $GITHUB_ENV
- name: Set up Binary List
env:
CORE_VERSION: ${{ github.event.inputs.release_version }}
run: |
# List of binaries we want to download
binaries=(
"libyggdrasilffi_aarch64.so"
"libyggdrasilffi_arm64.dll"
"libyggdrasilffi_arm64.dylib"
"libyggdrasilffi_x86_64.so"
"libyggdrasilffi_arm64.so"
"libyggdrasilffi_x86_64.dll"
"libyggdrasilffi_x86_64-musl.so"
"libyggdrasilffi_arm64-musl.so"
"yggdrasilffi_x86_64.dll"
"yggdrasilffi_arm64.dll"
"libyggdrasilffi_x86_64.dylib"
"libyggdrasilffi_x86_64.so"
"libyggdrasilffi_arm64.dylib"
)
echo "binaries=${binaries[@]}" >> $GITHUB_ENV
- name: Download All Binaries
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CORE_VERSION: ${{ env.CORE_VERSION }}
run: |
TARGET_DIR="ruby-engine/lib"
mkdir -p "$TARGET_DIR"
Expand All @@ -130,7 +142,7 @@ jobs:
echo "Downloading $binary..."
curl -L -o "$TARGET_DIR/$binary" \
-H "Authorization: token $GITHUB_TOKEN" \
"https://github.com/${{ github.repository }}/releases/download/${CORE_VERSION}/$binary"
"https://github.com/${{ github.repository }}/releases/download/unleash-yggdrasil-v${CORE_VERSION}/$binary"
if [ -f "$TARGET_DIR/$binary" ]; then
echo "$binary downloaded successfully."
Expand All @@ -140,11 +152,40 @@ jobs:
fi
done
- name: Build and Publish Gem for JRuby
- name: Build JRuby Gem
run: |
cd ruby-engine
gem build yggdrasil-engine.gemspec
gem push *.gem
export GEM_FILE=$(ls yggdrasil-engine-*.gem)
echo "gem_file_name=$GEM_FILE" >> $GITHUB_ENV
working-directory: ${{ github.workspace }}
env:
GEM_HOST_API_KEY: ${{ secrets.GEMS_PUBLISH_KEY }}

- name: Upload JRuby Gem
uses: actions/upload-artifact@v4
with:
name: ${{ env.gem_file_name }}
path: ruby-engine/${{ env.gem_file_name }}


publish_gems:
runs-on: ubuntu-latest
needs: [build_single_binary_gems, build_jruby_gems]
steps:
- uses: actions/download-artifact@v4
name: Download artifacts
with:
pattern: yggdrasil-engine-*
path: gems

- name: Publish Gems
run: |
cd gems
find . -name "*.gem" -type f | while read -r gem_file; do
echo "Pushing $gem_file..."
gem push "$gem_file"
done
env:
GEM_HOST_API_KEY: ${{ secrets.GEMS_PUBLISH_KEY }}

19 changes: 0 additions & 19 deletions ruby-engine/Gemfile.lock

This file was deleted.

21 changes: 13 additions & 8 deletions ruby-engine/lib/yggdrasil_engine.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,34 @@ def platform_specific_lib
os = RbConfig::CONFIG['host_os']
cpu = RbConfig::CONFIG['host_cpu']

extension = case os
extension, prefix = case os
when /darwin|mac os/
'dylib'
['dylib', 'lib']
when /linux/
'so'
['so', 'lib']
when /mswin|msys|mingw|cygwin|bccwin|wince|emc/
'dll'
['dll', '']
else
raise "unsupported platform #{os}"
end

arch_suffix = case cpu
when /x86_64/
'x86_64'
when /arm/
when /arm|aarch64/
'arm64'
when /aarch64/
'aarch64'
else
raise "unsupported architecture #{cpu}"
end

"libyggdrasilffi_#{arch_suffix}.#{extension}"
lib_type_suffix = if os =~ /linux/
musl = system("ldd /bin/sh | grep -q musl")
musl ? "-musl" : ""
else
""
end

"#{prefix}yggdrasilffi_#{arch_suffix}#{lib_type_suffix}.#{extension}"
end

def to_variant(raw_variant)
Expand Down
2 changes: 1 addition & 1 deletion ruby-engine/yggdrasil-engine.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Gem::Specification.new do |s|
target_platform = -> { ENV['YGG_BUILD_PLATFORM'] || Gem::Platform::CURRENT }

s.name = 'yggdrasil-engine'
s.version = '0.0.7'
s.version = '0.0.8'
s.date = '2023-06-28'
s.summary = 'Unleash engine for evaluating feature toggles'
s.description = '...'
Expand Down

0 comments on commit dd5f287

Please sign in to comment.