From 5d092fbe003177eef7f18d4c2c2720b4018b2ad6 Mon Sep 17 00:00:00 2001 From: Jacob Vosmaer Date: Sat, 6 Apr 2024 19:37:37 +0200 Subject: [PATCH] Use vendored taglib for swig This is working towards deterministic `rake swig` (see https://github.com/robinst/taglib-ruby/issues/136). --- tasks/ext.rake | 51 +++++++++++++++++++++---------------------------- tasks/swig.rake | 11 +++++++---- tasks/taglib.rb | 37 +++++++++++++++++++++++++++++++++++ 3 files changed, 66 insertions(+), 33 deletions(-) create mode 100644 tasks/taglib.rb diff --git a/tasks/ext.rake b/tasks/ext.rake index b86eaef..c56fff2 100644 --- a/tasks/ext.rake +++ b/tasks/ext.rake @@ -1,22 +1,15 @@ # frozen-string-literal: true +require_relative 'taglib' + # Extension tasks and cross-compiling host = 'i686-w64-mingw32' -$plat = ENV['PLATFORM'] || 'i386-mingw32' - -taglib_version = ENV['TAGLIB_VERSION'] || '1.9.1' -taglib = "taglib-#{taglib_version}" - -tmp = "#{Dir.pwd}/tmp" -tmp_arch = "#{tmp}/#{$plat}" toolchain_file = "#{Dir.pwd}/ext/win.cmake" -install_dir = "#{tmp_arch}/#{taglib}" -install_dll = "#{install_dir}/bin/libtag.dll" -install_so = "#{install_dir}/lib/libtag.so" -$cross_config_options = ["--with-opt-dir=#{install_dir}"] +install_dll = "#{Taglib.install_dir}/bin/libtag.dll" +$cross_config_options = ["--with-opt-dir=#{Taglib.install_dir}"] -taglib_url = "https://github.com/taglib/taglib/archive/v#{taglib_version}.tar.gz" +taglib_url = "https://github.com/taglib/taglib/archive/v#{Taglib.version}.tar.gz" taglib_options = ['-DCMAKE_BUILD_TYPE=Release', '-DBUILD_EXAMPLES=OFF', '-DBUILD_TESTS=OFF', @@ -27,7 +20,7 @@ taglib_options = ['-DCMAKE_BUILD_TYPE=Release', def configure_cross_compile(ext) ext.cross_compile = true - ext.cross_platform = $plat + ext.cross_platform = Taglib.plat ext.cross_config_options.concat($cross_config_options) ext.cross_compiling do |gem| gem.files << 'lib/libtag.dll' @@ -75,37 +68,37 @@ task :cross do ENV['CXX'] = "#{host}-g++" end -file "#{tmp_arch}/stage/lib/libtag.dll" => [install_dll] do |f| +file "#{Taglib.tmp_arch}/stage/lib/libtag.dll" => [install_dll] do |f| install install_dll, f end -file install_dll => ["#{tmp}/#{taglib}"] do - chdir "#{tmp}/#{taglib}" do - sh %(cmake -DCMAKE_INSTALL_PREFIX=#{install_dir} -DCMAKE_TOOLCHAIN_FILE=#{toolchain_file} #{taglib_options}) +file install_dll => ["#{Taglib.tmp}/#{Taglib.dir}"] do + chdir "#{Taglib.tmp}/#{taglib}" do + sh %(cmake -DCMAKE_INSTALL_PREFIX=#{Taglib.install_dir} -DCMAKE_TOOLCHAIN_FILE=#{toolchain_file} #{taglib_options}) sh 'make VERBOSE=1' sh 'make install' end end -task vendor: [install_so] +task vendor: [Taglib.library] -file install_so => ["#{tmp_arch}/#{taglib}", "#{tmp_arch}/#{taglib}-build", "#{tmp}/#{taglib}"] do - chdir "#{tmp_arch}/#{taglib}-build" do - sh %(cmake -DCMAKE_INSTALL_PREFIX=#{install_dir} #{taglib_options} #{tmp}/#{taglib}) - sh 'make install VERBOSE=1' +file Taglib.library => ["#{Taglib.tmp_arch}/#{Taglib.dir}", "#{Taglib.tmp_arch}/#{Taglib.dir}-build", "#{Taglib.tmp}/#{Taglib.dir}"] do + chdir "#{Taglib.tmp_arch}/#{Taglib.dir}-build" do + sh %(cmake -DCMAKE_INSTALL_PREFIX=#{Taglib.install_dir} #{taglib_options} #{Taglib.source}) + sh 'make install -j 4 VERBOSE=1' end end -directory "#{tmp_arch}/#{taglib}" -directory "#{tmp_arch}/#{taglib}-build" +directory "#{Taglib.tmp_arch}/#{Taglib.dir}" +directory "#{Taglib.tmp_arch}/#{Taglib.dir}-build" -file "#{tmp}/#{taglib}" => ["#{tmp}/#{taglib}.tar.gz"] do - chdir tmp do - sh "tar xzf #{taglib}.tar.gz" +file Taglib.source => ["#{Taglib.tmp}/#{Taglib.dir}.tar.gz"] do + chdir Taglib.tmp do + sh "tar xzf #{Taglib.dir}.tar.gz" end end -file "#{tmp}/#{taglib}.tar.gz" => [tmp] do |t| +file "#{Taglib.tmp}/#{Taglib.dir}.tar.gz" => [Taglib.tmp] do |t| require 'open-uri' puts "Downloading #{taglib_url}" @@ -114,4 +107,4 @@ file "#{tmp}/#{taglib}.tar.gz" => [tmp] do |t| end end -directory tmp +directory Taglib.tmp diff --git a/tasks/swig.rake b/tasks/swig.rake index 50d5cf4..68589f2 100644 --- a/tasks/swig.rake +++ b/tasks/swig.rake @@ -1,5 +1,7 @@ # frozen-string-literal: true +require_relative 'taglib' + # Tasks for generating SWIG wrappers in ext # Execute SWIG for the specified extension. @@ -13,7 +15,7 @@ def run_swig(mod) swig = `which swig2.0`.chomp if swig.empty? # Standard search location for headers - include_args = %w[-I/usr/local/include -I/usr/include] + include_args = "-I#{Taglib.install_dir}/include" if ENV.key?('TAGLIB_DIR') unless File.directory?(ENV['TAGLIB_DIR']) @@ -21,14 +23,15 @@ def run_swig(mod) end # Push it in front to get it searched first. - include_args.unshift("-I#{ENV['TAGLIB_DIR']}/include") + include_args = "-I#{ENV['TAGLIB_DIR']}/include" end - sh "cd ext/#{mod} && #{swig} -c++ -ruby -autorename -initname #{mod} #{include_args.join(' ')} #{mod}.i" + sh "cd ext/#{mod} && #{swig} -c++ -ruby -autorename -initname #{mod} #{include_args} #{mod}.i" end task swig: - ['ext/taglib_base/taglib_base_wrap.cxx', + [Taglib.library, + 'ext/taglib_base/taglib_base_wrap.cxx', 'ext/taglib_mpeg/taglib_mpeg_wrap.cxx', 'ext/taglib_id3v1/taglib_id3v1_wrap.cxx', 'ext/taglib_id3v2/taglib_id3v2_wrap.cxx', diff --git a/tasks/taglib.rb b/tasks/taglib.rb new file mode 100644 index 0000000..397b558 --- /dev/null +++ b/tasks/taglib.rb @@ -0,0 +1,37 @@ +# frozen-string-literal: true + +class Taglib + class << self + def plat + ENV['PLATFORM'] || 'i386-mingw32' + end + + def version + ENV['TAGLIB_VERSION'] || '1.9.1' + end + + def dir + "taglib-#{version}" + end + + def tmp + "#{__dir__}/../tmp" + end + + def source + "#{tmp}/#{dir}" + end + + def tmp_arch + "#{tmp}/#{plat}" + end + + def install_dir + "#{tmp_arch}/#{dir}" + end + + def library + "#{install_dir}/lib/libtag.#{RbConfig::CONFIG['SOEXT']}" + end + end +end