From 65e5d49214a5f63736c464f7e86a8104839aef20 Mon Sep 17 00:00:00 2001 From: Andy Pfister Date: Mon, 6 Jan 2025 22:04:30 +0100 Subject: [PATCH] wip: restructure the entire thing --- ext/tiny_tds/extconf.rb | 167 +++++++++++++++++++++++----------------- tasks/native_gem.rake | 3 +- tasks/ports.rake | 90 ---------------------- tasks/ports/freetds.rb | 32 -------- tasks/ports/libiconv.rb | 26 ------- tasks/ports/openssl.rb | 62 --------------- tasks/ports/recipe.rb | 64 --------------- 7 files changed, 98 insertions(+), 346 deletions(-) delete mode 100644 tasks/ports/freetds.rb delete mode 100644 tasks/ports/libiconv.rb delete mode 100644 tasks/ports/openssl.rb delete mode 100644 tasks/ports/recipe.rb diff --git a/ext/tiny_tds/extconf.rb b/ext/tiny_tds/extconf.rb index d0691792..e85461fb 100644 --- a/ext/tiny_tds/extconf.rb +++ b/ext/tiny_tds/extconf.rb @@ -1,91 +1,118 @@ -ENV['RC_ARCHS'] = '' if RUBY_PLATFORM =~ /darwin/ - -# :stopdoc: - +require 'pp' require 'mkmf' -require 'rbconfig' -require_relative './extconsts' - -# Shamelessly copied from nokogiri -# - -def do_help - print < ['ports:cross'] do +task 'gem:native' do require 'rake_compiler_dock' # make sure to install our bundle @@ -18,6 +18,5 @@ task 'gem:for_platform', [:gem_platform] do |_task, args| args.with_defaults(gem_platform: RbConfig::CONFIG["arch"]) sh "bundle install" - Rake::Task["ports:compile"].invoke(GEM_PLATFORM_HOSTS[args.gem_platform][:host], args.gem_platform) sh "RUBY_CC_VERSION=#{GEM_PLATFORM_HOSTS[args.gem_platform][:ruby_versions]} rake native:#{args.gem_platform} gem" end diff --git a/tasks/ports.rake b/tasks/ports.rake index 1ab6bf96..f60d0867 100644 --- a/tasks/ports.rake +++ b/tasks/ports.rake @@ -1,91 +1,4 @@ -# encoding: UTF-8 -require 'mini_portile2' -require 'fileutils' -require_relative 'ports/libiconv' -require_relative 'ports/openssl' -require_relative 'ports/freetds' -require_relative '../ext/tiny_tds/extconsts' - namespace :ports do - libraries_to_compile = { - openssl: Ports::Openssl.new(OPENSSL_VERSION), - libiconv: Ports::Libiconv.new(ICONV_VERSION), - freetds: Ports::Freetds.new(FREETDS_VERSION) - } - - directory "ports" - CLEAN.include "ports/*mingw*" - CLEAN.include "ports/*.installed" - - task :openssl, [:host, :gem_platform] do |_task, args| - args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"]) - - libraries_to_compile[:openssl].files = [OPENSSL_SOURCE_URI] - libraries_to_compile[:openssl].host = args.host - libraries_to_compile[:openssl].gem_platform = args.gem_platform - - libraries_to_compile[:openssl].cook - libraries_to_compile[:openssl].activate - end - - task :libiconv, [:host, :gem_platform] do |_task, args| - args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"]) - - libraries_to_compile[:libiconv].files = [ICONV_SOURCE_URI] - libraries_to_compile[:libiconv].host = args.host - libraries_to_compile[:libiconv].gem_platform = args.gem_platform - libraries_to_compile[:libiconv].cook - libraries_to_compile[:libiconv].activate - end - - task :freetds, [:host, :gem_platform] do |_task, args| - args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"]) - - libraries_to_compile[:freetds].files = [FREETDS_SOURCE_URI] - libraries_to_compile[:freetds].host = args.host - libraries_to_compile[:freetds].gem_platform = args.gem_platform - - if libraries_to_compile[:openssl] - # freetds doesn't have an option that will provide an rpath - # so we do it manually - ENV['OPENSSL_CFLAGS'] = "-Wl,-rpath -Wl,#{libraries_to_compile[:openssl].path}/lib64" - # Add the pkgconfig file with MSYS2'ish path, to prefer our ports build - # over MSYS2 system OpenSSL. - ENV['PKG_CONFIG_PATH'] = "#{libraries_to_compile[:openssl].path.gsub(/^(\w):/i) { "/" + $1.downcase }}/lib64/pkgconfig:#{ENV['PKG_CONFIG_PATH']}" - libraries_to_compile[:freetds].configure_options << "--with-openssl=#{libraries_to_compile[:openssl].path}" - end - - if libraries_to_compile[:libiconv] - libraries_to_compile[:freetds].configure_options << "--with-libiconv-prefix=#{libraries_to_compile[:libiconv].path}" - end - - libraries_to_compile[:freetds].cook - libraries_to_compile[:freetds].activate - end - - task :compile, [:host, :gem_platform] do |_task, args| - args.with_defaults(host: RbConfig::CONFIG['host'], gem_platform: RbConfig::CONFIG["arch"]) - - puts "Compiling ports for #{args.host} (Ruby platform #{args.gem_platform}) ..." - - libraries_to_compile.keys.each do |lib| - Rake::Task["ports:#{lib}"].invoke(args.host, args.gem_platform) - end - end - - desc 'Build the ports windows binaries via rake-compiler-dock' - task 'cross' do - require 'rake_compiler_dock' - - # build the ports for all our cross compile hosts - GEM_PLATFORM_HOSTS.each do |gem_platform, meta| - # make sure to install our bundle - build = ['bundle'] - build << "RUBY_CC_VERSION=#{meta[:ruby_versions]} rake ports:compile[#{meta[:host]},#{gem_platform}] MAKE='make -j`nproc`'" - RakeCompilerDock.sh build.join(' && '), platform: gem_platform - end - end - desc "Notes the actual versions for the compiled ports into a file" task "version_file", [:gem_platform] do |_task, args| args.with_defaults(gem_platform: RbConfig::CONFIG["arch"]) @@ -103,6 +16,3 @@ namespace :ports do end end end - -desc 'Build ports and activate libraries for the current architecture.' -task :ports => ['ports:compile'] diff --git a/tasks/ports/freetds.rb b/tasks/ports/freetds.rb deleted file mode 100644 index d0f4166c..00000000 --- a/tasks/ports/freetds.rb +++ /dev/null @@ -1,32 +0,0 @@ -require_relative './recipe' - -module Ports - class Freetds < Recipe - def initialize(version) - super('freetds', version) - - set_patches - end - - private - - def configure_defaults - opts = super - - opts << '--with-pic' - opts << '--disable-odbc' - opts << '--with-tdsver=7.3' - - if windows? - opts << '--sysconfdir=C:/Sites' - opts << '--enable-sspi' - end - - opts - end - - def set_patches - self.patch_files.concat get_patches(name, version) - end - end -end diff --git a/tasks/ports/libiconv.rb b/tasks/ports/libiconv.rb deleted file mode 100644 index 52e0f184..00000000 --- a/tasks/ports/libiconv.rb +++ /dev/null @@ -1,26 +0,0 @@ -require_relative './recipe' - -module Ports - class Libiconv < Recipe - def initialize(version) - super('libiconv', version) - - set_patches - end - - private - - def configure_defaults - [ - "--host=#{@host}", - '--disable-static', - '--enable-shared', - 'CFLAGS=-fPIC -O2' - ] - end - - def set_patches - self.patch_files.concat get_patches(name, version) - end - end -end diff --git a/tasks/ports/openssl.rb b/tasks/ports/openssl.rb deleted file mode 100644 index 17da4e0a..00000000 --- a/tasks/ports/openssl.rb +++ /dev/null @@ -1,62 +0,0 @@ -require_relative './recipe' - -module Ports - class Openssl < Recipe - def initialize(version) - super('openssl', version) - - set_patches - end - - def configure - return if configured? - - md5_file = File.join(tmp_path, 'configure.md5') - digest = Digest::MD5.hexdigest(computed_options.to_s) - File.open(md5_file, "w") { |f| f.write digest } - - # Windows doesn't recognize the shebang so always explicitly use sh - execute('configure', "sh -c \"./Configure #{computed_options.join(' ')}\"") - end - - def install - unless installed? - execute('install', %Q(#{make_cmd} install_sw install_ssldirs)) - end - end - - private - - def configure_defaults - opts = [ - 'shared', - target_arch, - "--openssldir=#{path}", - ] - - if cross_build? - opts << "--cross-compile-prefix=#{host}-" - end - - opts - end - - def target_arch - if windows? - arch = '' - arch = '64' if host=~ /x86_64/ - - "mingw#{arch}" - else - arch = 'x32' - arch = 'x86_64' if host=~ /x86_64/ - - "linux-#{arch}" - end - end - - def set_patches - self.patch_files.concat get_patches(name, version) - end - end -end diff --git a/tasks/ports/recipe.rb b/tasks/ports/recipe.rb deleted file mode 100644 index b3d4dd04..00000000 --- a/tasks/ports/recipe.rb +++ /dev/null @@ -1,64 +0,0 @@ -# encoding: UTF-8 -require 'mini_portile2' -require 'fileutils' -require 'rbconfig' - -module Ports - class Recipe < MiniPortile - attr_writer :gem_platform - - def cook - checkpoint = "ports/checkpoints/#{name}-#{version}-#{gem_platform}.installed" - - unless File.exist? checkpoint - super - FileUtils.mkdir_p("ports/checkpoints") - FileUtils.touch checkpoint - end - end - - private - - attr_reader :gem_platform - - def port_path - "#{@target}/#{gem_platform}/#{@name}/#{@version}" - end - - def tmp_path - "tmp/#{gem_platform}/ports/#{@name}/#{@version}" - end - - def configure_defaults - [ - "--host=#{@host}", - '--disable-static', - '--enable-shared' - ] - end - - def windows? - host =~ /mswin|mingw32/ - end - - def system_host - RbConfig::CONFIG['host'] - end - - def cross_build? - host != system_host - end - - def get_patches(libname, version) - patches = [] - - patch_path = File.expand_path( - File.join('..','..','..','patches',libname,version), - __FILE__ - ) - - patches.concat(Dir[File.join(patch_path, '*.patch')].sort) - patches.concat(Dir[File.join(patch_path, '*.diff')].sort) - end - end -end