From 9597c4130edfe040c72aec915c4b3a0dd3042a10 Mon Sep 17 00:00:00 2001 From: Andy Pfister Date: Tue, 7 Jan 2025 16:23:33 +0100 Subject: [PATCH] Provide precompiled gem for `x86_64-linux-gnu` --- .github/workflows/ci.yml | 48 +++++----------------------- Rakefile | 5 +-- ext/tiny_tds/extconf.rb | 18 +++++------ test/bin/restore-from-native-gem.ps1 | 11 +++++++ 4 files changed, 31 insertions(+), 51 deletions(-) create mode 100644 test/bin/restore-from-native-gem.ps1 diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b351250c..d7cd16b7 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -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 @@ -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 @@ -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 diff --git a/Rakefile b/Rakefile index 1b85493f..a950e589 100644 --- a/Rakefile +++ b/Rakefile @@ -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 diff --git a/ext/tiny_tds/extconf.rb b/ext/tiny_tds/extconf.rb index 9355d4d9..d75e141b 100644 --- a/ext/tiny_tds/extconf.rb +++ b/ext/tiny_tds/extconf.rb @@ -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) @@ -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 @@ -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 @@ -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 @@ -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") diff --git a/test/bin/restore-from-native-gem.ps1 b/test/bin/restore-from-native-gem.ps1 new file mode 100644 index 00000000..ad59dfd2 --- /dev/null +++ b/test/bin/restore-from-native-gem.ps1 @@ -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)}