Skip to content

Commit

Permalink
Use vendored taglib for swig
Browse files Browse the repository at this point in the history
This is working towards deterministic `rake swig` (see
#136).
  • Loading branch information
jacobvosmaer committed Apr 6, 2024
1 parent 33066c1 commit 5d092fb
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 33 deletions.
51 changes: 22 additions & 29 deletions tasks/ext.rake
Original file line number Diff line number Diff line change
@@ -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',
Expand All @@ -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'
Expand Down Expand Up @@ -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}"

Expand All @@ -114,4 +107,4 @@ file "#{tmp}/#{taglib}.tar.gz" => [tmp] do |t|
end
end

directory tmp
directory Taglib.tmp
11 changes: 7 additions & 4 deletions tasks/swig.rake
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen-string-literal: true

require_relative 'taglib'

# Tasks for generating SWIG wrappers in ext

# Execute SWIG for the specified extension.
Expand All @@ -13,22 +15,23 @@ 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'])
abort 'When defined, the TAGLIB_DIR environment variable must point to a valid directory.'
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',
Expand Down
37 changes: 37 additions & 0 deletions tasks/taglib.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 5d092fb

Please sign in to comment.