saxonc-runtime 12.9.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7f85d6b83c31c30c9230826dbbe287c2521bba229ba8ed5b4a5a0f09918d3e9c
4
+ data.tar.gz: 92c85165b22aaeb1a8e5be147c3b0dd68fc7bf85d704385fc76ba1ccce87db01
5
+ SHA512:
6
+ metadata.gz: c263ff997c3864c6099ec7a109f9b1b2e0c8734497baeedb524ee1ed6676ffafe62d1a1cec97d019679ee030a8f8275e4cf6a5c6da648a675b00f79dc7b2ffbf
7
+ data.tar.gz: f39ea587cef3dfc23205eba23716fd79d7a06316cbfc8b29433ef07b04f5a0163fc139d51ce69541748d0de636180d2710e207958e4cb1c0fdd44eedf4ccb5a7
data/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # saxonc-runtime
2
+
3
+ A small helper gem that downloads and exposes SaxonC binaries for the `saxonc` gem (or any consumer that needs `SAXONC_HOME`). It detects your platform, fetches the right archive, and keeps it in a cache.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ gem install saxonc-runtime
9
+ # or
10
+ bundle add saxonc-runtime
11
+ ```
12
+
13
+ By default it installs the Home Edition (HE). Pick another edition with:
14
+
15
+ ```bash
16
+ SAXONC_EDITION=pe gem install saxonc-runtime
17
+ # or ee
18
+ ```
19
+
20
+ Force a fresh download (ignore cache):
21
+
22
+ ```bash
23
+ SAXONC_LIBS_FORCE=1 gem install saxonc-runtime
24
+ ```
25
+
26
+ ## Using with `saxonc`
27
+
28
+ When `saxonc` builds its native extension it will, by default, ask this gem for `SAXONC_HOME`. You don't need to do anything extra.
29
+
30
+ If you already have a SaxonC install, skip the download and point `saxonc` (and this helper) at it:
31
+
32
+ ```bash
33
+ export SAXONC_HOME=/Users/janot/Code/ruby-saxonc/SaxonCHE-macos-arm64-12-9-0/SaxonCHE
34
+ gem install saxonc
35
+ ```
36
+
37
+ Or use mkmf flags when compiling `saxonc` from source:
38
+
39
+ ```bash
40
+ gem install saxonc -- --with-saxonche-dir=/path/to/SaxonCHE
41
+ # or supply include/lib separately
42
+ gem install saxonc -- \
43
+ --with-saxonche-include=/path/to/SaxonCHE/include \
44
+ --with-saxonche-lib=/path/to/SaxonCHE/lib
45
+ ```
46
+
47
+ Precedence when locating SaxonC: `--with-saxonche-*` flags > `SAXONC_HOME` > cached runtime from this gem.
48
+
49
+ ## Development
50
+
51
+ ```bash
52
+ bundle install
53
+ bundle exec rake spec
54
+ ```
55
+
56
+ To release, bump `lib/saxon/runtime/version.rb`, tag `vX.Y.Z`, and push; the GitHub Actions release workflow will build, attach the gem to the GitHub Release, and publish to RubyGems.
data/Rakefile ADDED
@@ -0,0 +1,12 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "rubocop/rake_task"
9
+
10
+ RuboCop::RakeTask.new
11
+
12
+ task default: %i[spec rubocop]
@@ -0,0 +1,130 @@
1
+ module Saxon::Runtime
2
+ class Edition
3
+ attr_reader :version, :platform
4
+
5
+ VERSION_REGEX = /\A(\d+)\.(\d+)\.(\d+)\z/
6
+ def initialize(version = Saxon::Runtime::SAXON_VERSION)
7
+ unless version.match?(VERSION_REGEX)
8
+ raise ArgumentError, "Invalid version format: #{version}. Expected format: 'X.Y.Z'"
9
+ end
10
+ @version = version
11
+
12
+ unless platform
13
+ raise "Unsupported platform: #{os or "unknown"}-#{arch or "unknown"}"
14
+ end
15
+ @platform = platform
16
+ end
17
+
18
+ def path
19
+ File.expand_path File.join(Saxon::Runtime.base_dir, version, edition, platform)
20
+ end
21
+
22
+ def installed?
23
+ File.exist?(path)
24
+ end
25
+
26
+ def available_platforms
27
+ [
28
+ 'linux-x86_64',
29
+ 'linux-aarch64',
30
+ 'macos-x86_64',
31
+ 'macos-arm64',
32
+ 'windows-x86_64'
33
+ ]
34
+ end
35
+
36
+ def platform
37
+ platform = "#{os}-#{arch}"
38
+ available_platforms.include?(platform) ? platform : nil
39
+ end
40
+
41
+ def download_url
42
+ "https://downloads.saxonica.com/SaxonC/#{edition}/#{version_major}/SaxonCHE-#{platform}-#{version_major}-#{version_minor}-#{version_patch}.zip"
43
+ end
44
+
45
+ def install!
46
+ STDERR.puts "SaxonC does not appear to be installed in #{path}, installing!"
47
+ FileUtils.mkdir_p Saxon::Runtime.base_dir
48
+
49
+ Tempfile.create("saxonc.zip") do |zip_file|
50
+
51
+ begin
52
+ zip_file.open "wb" do |file|
53
+ STDERR.puts "Downloading SaxonC from #{download_url}..."
54
+ file.write URI.open(download_url).read
55
+ end
56
+ rescue OpenURI::HTTPError => e
57
+ raise "Failed to download SaxonC from #{download_url}, perhaps the version or platform is not supported: #{e.message}"
58
+ rescue StandardError => e
59
+ raise "An error occurred while downloading SaxonC: #{e.message}"
60
+ end
61
+
62
+ STDERR.puts "Extracting SaxonC..."
63
+ Zip::File.open(zip_file.path) do |zip_file|
64
+ zip_file.each do |entry|
65
+ entry.extract(File.join(temp_dir, entry.name))
66
+ end
67
+ end
68
+
69
+ extracted_dir = Dir['saxonc*'].find { |path| File.directory?(path) }
70
+
71
+ if FileUtils.mv extracted_dir, path
72
+ STDOUT.puts "\nSuccessfully installed SaxonC to #{path}!\n"
73
+ end
74
+
75
+ if FileUtils.rm_rf temp_dir
76
+ STDOUT.puts "Removed temporarily downloaded files."
77
+ end
78
+ end
79
+
80
+ raise "Failed to install SaxonC. Sorry :(" unless File.exist?(path)
81
+ end
82
+
83
+ def ensure_installed!
84
+ install! unless installed?
85
+ end
86
+
87
+ private
88
+
89
+ def version_major
90
+ version.split('.')[0]
91
+ end
92
+
93
+ def version_minor
94
+ version.split('.')[1]
95
+ end
96
+
97
+ def version_patch
98
+ version.split('.')[2]
99
+ end
100
+
101
+ def os
102
+ case RbConfig::CONFIG['host_os']
103
+ when /linux/
104
+ 'linux'
105
+ when /darwin/
106
+ 'macos'
107
+ when /mswin|mingw|cygwin/
108
+ 'windows'
109
+ else
110
+ nil
111
+ end
112
+ end
113
+
114
+ def arch
115
+ RbConfig::CONFIG['host_cpu']
116
+ end
117
+
118
+ def edition
119
+ self.class.name.split('::').last
120
+ end
121
+
122
+ def temp_path
123
+ ENV['TMPDIR'] || ENV['TEMP'] || '/tmp'
124
+ end
125
+ end
126
+
127
+ HE = Class.new(Edition)
128
+ PE = Class.new(Edition)
129
+ EE = Class.new(Edition)
130
+ end
@@ -0,0 +1,8 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Saxon
4
+ module Runtime
5
+ SAXON_VERSION = "12.9.0"
6
+ VERSION = SAXON_VERSION + ".0"
7
+ end
8
+ end
@@ -0,0 +1,45 @@
1
+ # frozen_string_literal: true
2
+ require_relative "runtime/version"
3
+ require "fileutils"
4
+
5
+ module Saxon
6
+ module Runtime
7
+ class Error < StandardError; end
8
+ class UnknownEdition < Error; end;
9
+ class UnsupportedPlatform < Error; end;
10
+
11
+ class << self
12
+ def edition
13
+ @edition || Saxon::Runtime::HE.new
14
+ end
15
+
16
+ def edition=(edition)
17
+ @edition = edition
18
+ end
19
+
20
+ def base_dir
21
+ @base_dir ||= File.join(File.expand_path('~'), '.saxonc')
22
+ end
23
+
24
+ def base_dir=(dir)
25
+ @base_dir = dir
26
+ end
27
+
28
+ def path
29
+ edition.path
30
+ end
31
+
32
+ # Removes the local saxon copies
33
+ def implode!
34
+ FileUtils.rm_rf File.join(File.expand_path('~'), '.saxonc')
35
+ end
36
+
37
+ # Clears cached state. Primarily useful for testing.
38
+ def reset!
39
+ @base_dir = @path = @edition = @version = nil
40
+ end
41
+ end
42
+ end
43
+ end
44
+
45
+ require 'saxon/runtime/edition'
metadata ADDED
@@ -0,0 +1,50 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: saxonc-runtime
3
+ version: !ruby/object:Gem::Version
4
+ version: 12.9.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jakob Kofoed Janot
8
+ bindir: exe
9
+ cert_chain: []
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
+ dependencies: []
12
+ description: A small helper gem that downloads and exposes SaxonC binaries for the
13
+ `saxonc` gem (or any consumer that needs `SAXONC_HOME`). It detects your platform,
14
+ fetches the right archive, and keeps it in a cache.
15
+ email:
16
+ - jakob@janot.dk
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - README.md
22
+ - Rakefile
23
+ - lib/saxon/runtime.rb
24
+ - lib/saxon/runtime/edition.rb
25
+ - lib/saxon/runtime/version.rb
26
+ homepage: https://github.com/jakobjanot/ruby-saxonc-runtime
27
+ licenses: []
28
+ metadata:
29
+ allowed_push_host: https://rubygems.org
30
+ homepage_uri: https://github.com/jakobjanot/ruby-saxonc-runtime
31
+ source_code_uri: https://github.com/jakobjanot/ruby-saxonc-runtime
32
+ rdoc_options: []
33
+ require_paths:
34
+ - lib
35
+ required_ruby_version: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: 3.2.0
40
+ required_rubygems_version: !ruby/object:Gem::Requirement
41
+ requirements:
42
+ - - ">="
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ requirements: []
46
+ rubygems_version: 4.0.0
47
+ specification_version: 4
48
+ summary: A small helper gem that downloads and exposes SaxonC binaries for the `saxonc`
49
+ gem.
50
+ test_files: []