Skip to content

Commit

Permalink
Provide precompiled gem for x86_64-linux-gnu
Browse files Browse the repository at this point in the history
  • Loading branch information
andyundso committed Jan 7, 2025
1 parent 9136dee commit 9597c41
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 51 deletions.
48 changes: 8 additions & 40 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ jobs:
platform:
- "x64-mingw32"
- "x64-mingw-ucrt"
name: cross-compile-windows
- "x86_64-linux-gnu"
name: cross-compile
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4
Expand Down Expand Up @@ -330,33 +331,6 @@ jobs:
ruby -e "require 'tiny_tds'; puts TinyTds::Gem.root_path"
exit $LASTEXITCODE
compile-native-ports:
runs-on: ubuntu-22.04
name: cross-compile-linux
steps:
- uses: actions/checkout@v4

- uses: ruby/setup-ruby@v1
with:
ruby-version: 3.4
bundler-cache: true

- name: Write used versions into file
run: bundle exec rake ports:version_file

- name: Cache ports
uses: actions/cache@v4
with:
path: ports
key: native-v3-${{ hashFiles('**/.ports_versions') }}
restore-keys: |
native-v3-${{ hashFiles('* */.ports_versions') }}
native-v3-
- name: Build required libraries
run: |
bundle exec rake ports
test-linux:
needs:
- compile-native-ports
Expand Down Expand Up @@ -385,20 +359,14 @@ jobs:
ruby-version: ${{ matrix.ruby-version }}
bundler-cache: true

- name: Write used versions into file
run: |
bundle exec rake ports:version_file
- name: Cache ports
uses: actions/cache@v4
- name: Download precompiled gem
uses: actions/download-artifact@v4
with:
path: ports
key: native-v3-${{ hashFiles('**/.ports_versions') }}
fail-on-cache-miss: true
name: x86_64-linux-gnu

- name: Build gem
run: |
bundle exec rake build
- name: Install native gem and restore cross-compiled code from it
shell: pwsh
run: "& ./test/bin/restore-from-native-gem.ps1"

- name: Setup MSSQL
uses: rails-sqlserver/setup-mssql@v1
Expand Down
5 changes: 3 additions & 2 deletions Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ SPEC = Gem::Specification.load(File.expand_path('../tiny_tds.gemspec', __FILE__)

CrossLibrary = Struct.new :platform, :openssl_config, :toolchain
CrossLibraries = [
['x64-mingw-ucrt', 'mingw64', 'x86_64-w64-mingw32'],
['x64-mingw32', 'mingw64', 'x86_64-w64-mingw32'],
['x64-mingw-ucrt', 'mingw64'],
['x64-mingw32', 'mingw64'],
['x86_64-linux-gnu', 'linux-x86_64'],
].map do |platform, openssl_config, toolchain|
CrossLibrary.new platform, openssl_config, toolchain
end
Expand Down
18 changes: 9 additions & 9 deletions ext/tiny_tds/extconf.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
require 'mini_portile2'

openssl_platform = with_config("openssl-platform")
toolchain = with_config("toolchain")

class BuildRecipe < MiniPortile
def initialize(name, version, files)
Expand All @@ -29,11 +28,11 @@ def initialize(name, version, files)

# this will yield all ports into the same directory, making our path configuration for the linker easier
def port_path
"#{@target}/#{host}"
"#{@target}/#{RUBY_PLATFORM}"
end

def tmp_path
"tmp/#{host}/ports/#{@name}/#{@version}"
"tmp/#{RUBY_PLATFORM}/ports/#{@name}/#{@version}"
end

def cook_and_activate
Expand Down Expand Up @@ -70,14 +69,11 @@ def install
end

recipe.openssl_platform = openssl_platform
recipe.host = toolchain
recipe.cook_and_activate
end

libiconv_recipe = BuildRecipe.new("libiconv", ICONV_VERSION, [ICONV_SOURCE_URI]).tap do |recipe|
recipe.configure_options << "CFLAGS=-fPIC" if RUBY_PLATFORM =~ /linux/
recipe.host = toolchain

recipe.cook_and_activate
end

Expand All @@ -88,17 +84,16 @@ def install
# removing one or the other leads to build failures in any case of FreeTDS
recipe.configure_options << "CFLAGS=-fPIC" if RUBY_PLATFORM =~ /linux/
recipe.configure_options << "LDFLAGS=-L#{openssl_recipe.path}/lib"
recipe.configure_options << "LIBS=-liconv -lssl -lcrypto #{"-lwsock32 -lgdi32 -lws2_32 -lcrypt32" if RUBY_PLATFORM =~ /mingw|mswin/}"
recipe.configure_options << "LIBS=-liconv -lssl -lcrypto #{"-lwsock32 -lgdi32 -lws2_32 -lcrypt32" if RUBY_PLATFORM =~ /mingw|mswin/} #{"-ldl -lpthread" if RUBY_PLATFORM =~ /linux/}"
recipe.configure_options << "CPPFLAGS=-I#{openssl_recipe.path}/include"

recipe.configure_options << "OPENSSL_CFLAGS=-L#{openssl_recipe.path}/lib"
recipe.configure_options << "OPENSSL_LIBS=-lssl -lcrypto #{"-lwsock32 -lgdi32 -lws2_32 -lcrypt32" if RUBY_PLATFORM =~ /mingw|mswin/}"
recipe.configure_options << "OPENSSL_LIBS=-lssl -lcrypto #{"-lwsock32 -lgdi32 -lws2_32 -lcrypt32" if RUBY_PLATFORM =~ /mingw|mswin/} #{"-ldl -lpthread" if RUBY_PLATFORM =~ /linux/}"

recipe.configure_options << "--with-openssl=#{openssl_recipe.path}"
recipe.configure_options << "--with-libiconv-prefix=#{libiconv_recipe.path}"
recipe.configure_options << "--disable-odbc"

recipe.host = toolchain
recipe.cook_and_activate
end

Expand All @@ -121,6 +116,11 @@ def install
find_library("wsock32", nil)
end

if RUBY_PLATFORM =~ /linux/
find_library("dl", nil)
find_library("pthread", nil)
end

find_library("crypto", nil)
find_library("ssl", nil)
find_library("iconv", "libiconv_open")
Expand Down
11 changes: 11 additions & 0 deletions test/bin/restore-from-native-gem.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
$rubyArchitecture = (ruby -e "puts RbConfig::CONFIG['arch']").Trim()
$gemVersion = (Get-Content VERSION).Trim()
$gemToUnpack = "./tiny_tds-$gemVersion-$rubyArchitecture.gem"

Write-Host "Looking to unpack $gemToUnpack"
gem unpack --target ./tmp "$gemToUnpack"

# Restore precompiled code
$source = (Resolve-Path ".\tmp\tiny_tds-$gemVersion-$rubyArchitecture\lib\tiny_tds").Path
$destination = (Resolve-Path ".\lib\tiny_tds").Path
Get-ChildItem $source -Recurse -Exclude "*.rb" | Copy-Item -Destination {Join-Path $destination $_.FullName.Substring($source.length)}

0 comments on commit 9597c41

Please sign in to comment.