rpdfium-binary 0.1.7811
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 +7 -0
- data/CHANGELOG.md +35 -0
- data/LICENSE +20 -0
- data/README.md +103 -0
- data/lib/rpdfium/binary/downloader.rb +151 -0
- data/lib/rpdfium/binary/version.rb +11 -0
- data/lib/rpdfium/binary.rb +166 -0
- metadata +83 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: e21b3576ee324095a4f98678b374647f2074da0bc976747bfeb442c001cf028b
|
|
4
|
+
data.tar.gz: 6cdd6154d6b1b4360a3a56c0b0b05ad6c31a7d39f7e54d7b62780f796acd045e
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 5ab1bbcddd4ad0ac972c820781d2ce06819c715edd058dfcf7aa962b2922018f182b7bc286e29229317d72ed3e8f0ae0f1a3308b4c024bd0b551d9577edd9fdb
|
|
7
|
+
data.tar.gz: 95f67f1b977ed1beab09b47034b31c8d8d903422b4912d225c69b9ec136eaf1c5d89495127936685334e8a77f5af8d6f825a9da7c956dbd15e6c22792982b99e
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
## [0.1.7811] - prima release
|
|
4
|
+
|
|
5
|
+
Prima release di `rpdfium-binary`. Distribuisce PDFium build chromium/7811
|
|
6
|
+
da [bblanchon/pdfium-binaries](https://github.com/bblanchon/pdfium-binaries).
|
|
7
|
+
|
|
8
|
+
### Aggiunto
|
|
9
|
+
|
|
10
|
+
- Gemma generica `rpdfium-binary` (platform=ruby) con fallback download
|
|
11
|
+
via `Net::HTTP` stdlib alla prima `library_path`.
|
|
12
|
+
- Gemme platform-specific con binario impacchettato in `vendor/lib/`:
|
|
13
|
+
- `x86_64-linux`, `aarch64-linux`
|
|
14
|
+
- `x86_64-linux-musl`, `aarch64-linux-musl`
|
|
15
|
+
- `arm64-darwin`, `x86_64-darwin`
|
|
16
|
+
- `x64-mingw-ucrt`, `x86-mingw32`, `aarch64-mingw-ucrt`
|
|
17
|
+
- Modulo `Rpdfium::Binary` con:
|
|
18
|
+
- detection piattaforma (OS + CPU + libc musl/glibc)
|
|
19
|
+
- locator (`library_path`, `bundled?`)
|
|
20
|
+
- downloader con redirect HTTP, verifica SHA256, estrazione tarball
|
|
21
|
+
- Rake tasks:
|
|
22
|
+
- `fetch:<platform>` / `fetch:all` — scarica i tarball upstream
|
|
23
|
+
- `package:ruby` — builda la gemma generica
|
|
24
|
+
- `package:<platform>` / `package:all` — builda le gemme platform-specific
|
|
25
|
+
- `sums` — stampa SHA256 dei .gem
|
|
26
|
+
- Cache directory XDG-compliant (`~/.local/share/rpdfium/binaries/...`)
|
|
27
|
+
con override via `RPDFIUM_BINARY_CACHE` e `XDG_DATA_HOME`.
|
|
28
|
+
- Test minitest per detection, locator, downloader (URL building,
|
|
29
|
+
SHA256, estrazione, path traversal).
|
|
30
|
+
|
|
31
|
+
### Sicurezza
|
|
32
|
+
|
|
33
|
+
- Path traversal: `extract!` ignora entry tar che contengono `..`.
|
|
34
|
+
- SHA256 obbligatorio quando passato; `ChecksumError` su mismatch.
|
|
35
|
+
- Solo HTTPS verso `github.com` in `Downloader.asset_url`.
|
data/LICENSE
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
6
|
+
you may not use this file except in compliance with the License.
|
|
7
|
+
You may obtain a copy of the License at
|
|
8
|
+
|
|
9
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
10
|
+
|
|
11
|
+
Unless required by applicable law or agreed to in writing, software
|
|
12
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
13
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
14
|
+
|
|
15
|
+
Copyright 2026 The rpdfium contributors
|
|
16
|
+
|
|
17
|
+
Bundled PDFium binaries are redistributed under their upstream licenses
|
|
18
|
+
(Apache-2.0 / BSD-3-Clause). See LICENSES.* files alongside the binary.
|
|
19
|
+
|
|
20
|
+
Full license text: https://www.apache.org/licenses/LICENSE-2.0.txt
|
data/README.md
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
# rpdfium-binary
|
|
2
|
+
|
|
3
|
+
Companion gem for [`rpdfium`](https://github.com/retsef/rpdfium) that
|
|
4
|
+
ships precompiled [PDFium](https://pdfium.googlesource.com/pdfium/)
|
|
5
|
+
binaries for major platforms.
|
|
6
|
+
|
|
7
|
+
Mirrors [pypdfium2](https://github.com/pypdfium2-team/pypdfium2)'s wheel
|
|
8
|
+
approach: the platform-specific gem includes its native library
|
|
9
|
+
directly, the generic Ruby-platform gem falls back to a runtime
|
|
10
|
+
download from
|
|
11
|
+
[bblanchon/pdfium-binaries](https://github.com/bblanchon/pdfium-binaries).
|
|
12
|
+
|
|
13
|
+
## Installation
|
|
14
|
+
|
|
15
|
+
```bash
|
|
16
|
+
gem install rpdfium-binary
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
RubyGems will pick the right gem for your platform automatically. If
|
|
20
|
+
none of the precompiled gems matches (e.g. FreeBSD, exotic libc), the
|
|
21
|
+
generic Ruby-platform gem is installed instead, and the binary is
|
|
22
|
+
downloaded on first use into the user data directory.
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
require "rpdfium" # or just rpdfium-binary
|
|
26
|
+
puts Rpdfium::Binary.library_path
|
|
27
|
+
# => "/.../rpdfium-binary-0.1.7811-x86_64-linux/vendor/lib/libpdfium.so"
|
|
28
|
+
puts Rpdfium::Binary.bundled?
|
|
29
|
+
# => true (false on the runtime-download path)
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## Supported platforms
|
|
33
|
+
|
|
34
|
+
| Ruby platform tag | bblanchon asset |
|
|
35
|
+
|-------------------------|----------------------------------|
|
|
36
|
+
| `x86_64-linux` | `pdfium-linux-x64.tgz` |
|
|
37
|
+
| `aarch64-linux` | `pdfium-linux-arm64.tgz` |
|
|
38
|
+
| `x86_64-linux-musl` | `pdfium-linux-musl-x64.tgz` |
|
|
39
|
+
| `aarch64-linux-musl` | `pdfium-linux-musl-arm64.tgz` |
|
|
40
|
+
| `arm64-darwin` | `pdfium-mac-arm64.tgz` |
|
|
41
|
+
| `x86_64-darwin` | `pdfium-mac-x64.tgz` |
|
|
42
|
+
| `x64-mingw-ucrt` | `pdfium-win-x64.tgz` |
|
|
43
|
+
| `x86-mingw32` | `pdfium-win-x86.tgz` |
|
|
44
|
+
| `aarch64-mingw-ucrt` | `pdfium-win-arm64.tgz` |
|
|
45
|
+
|
|
46
|
+
For unsupported platforms, set `PDFIUM_LIBRARY_PATH` to the path of
|
|
47
|
+
your own `libpdfium.{so,dylib,dll}`.
|
|
48
|
+
|
|
49
|
+
## Configuration
|
|
50
|
+
|
|
51
|
+
| Env var | Effect |
|
|
52
|
+
|---|---|
|
|
53
|
+
| `PDFIUM_LIBRARY_PATH` | Hard override; rpdfium loads exactly this file. |
|
|
54
|
+
| `RPDFIUM_BINARY_PDFIUM_BUILD` | Override the PDFium build number to fetch (default: bundled gem version). |
|
|
55
|
+
| `RPDFIUM_BINARY_CACHE` | Override the cache directory for runtime-downloaded binaries. |
|
|
56
|
+
| `XDG_DATA_HOME` | Standard XDG override for the cache root. |
|
|
57
|
+
|
|
58
|
+
## How it works
|
|
59
|
+
|
|
60
|
+
The gemspec checks `ENV["RPDFIUM_BINARY_PLATFORM"]` at build time. The
|
|
61
|
+
provided Rake tasks build:
|
|
62
|
+
|
|
63
|
+
- the **generic gem** (`platform=ruby`) without bundled binary, with the
|
|
64
|
+
runtime-download fallback;
|
|
65
|
+
- one **platform-specific gem** per supported target, each with its own
|
|
66
|
+
`vendor/lib/libpdfium.<ext>` packaged inside.
|
|
67
|
+
|
|
68
|
+
```bash
|
|
69
|
+
rake fetch:all # downloads all tarballs into vendor/
|
|
70
|
+
rake package:all # builds *.gem files for each platform
|
|
71
|
+
rake sums # prints SHA256 sums for release notes
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
A maintainer's release flow looks like:
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
PDFIUM_BUILD=7811 rake fetch:all
|
|
78
|
+
rake package:all
|
|
79
|
+
rake sums # paste into the GitHub release page
|
|
80
|
+
gem push rpdfium-binary-0.1.7811-x86_64-linux.gem
|
|
81
|
+
gem push rpdfium-binary-0.1.7811-arm64-darwin.gem
|
|
82
|
+
# ... etc, plus the generic ruby gem
|
|
83
|
+
gem push rpdfium-binary-0.1.7811.gem
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Memory & threading notes
|
|
87
|
+
|
|
88
|
+
- The shared library is loaded **once per process** by `rpdfium`. The
|
|
89
|
+
binary file itself is just data on disk; loading it is the responsibility
|
|
90
|
+
of the FFI binding.
|
|
91
|
+
- `Rpdfium::Binary.library_path` is memoized; calling it many times is
|
|
92
|
+
free.
|
|
93
|
+
- Runtime downloads use `Net::HTTP` from the standard library — no
|
|
94
|
+
external runtime dependencies. SHA256 verification is supported when
|
|
95
|
+
the gem ships with a checksum DB (release-time embedded).
|
|
96
|
+
|
|
97
|
+
## License
|
|
98
|
+
|
|
99
|
+
This gem's Ruby code is Apache-2.0. PDFium itself is dual-licensed
|
|
100
|
+
Apache-2.0 / BSD-3-Clause. Bundled binaries from
|
|
101
|
+
[bblanchon/pdfium-binaries](https://github.com/bblanchon/pdfium-binaries)
|
|
102
|
+
are redistributed under their respective upstream licenses, included in
|
|
103
|
+
the gem under `vendor/`.
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "net/http"
|
|
4
|
+
require "uri"
|
|
5
|
+
require "digest"
|
|
6
|
+
require "zlib"
|
|
7
|
+
require "rubygems/package"
|
|
8
|
+
require "tmpdir"
|
|
9
|
+
require "fileutils"
|
|
10
|
+
|
|
11
|
+
module Rpdfium
|
|
12
|
+
module Binary
|
|
13
|
+
# Scarica e installa un asset di pdfium-binaries.
|
|
14
|
+
# Usa solo stdlib (net/http, openssl, zlib, rubygems/package).
|
|
15
|
+
# Supporta redirect HTTP, verifica SHA256 opzionale, atomicità via tmp dir.
|
|
16
|
+
module Downloader
|
|
17
|
+
module_function
|
|
18
|
+
|
|
19
|
+
RELEASE_BASE = "https://github.com/bblanchon/pdfium-binaries/releases"
|
|
20
|
+
|
|
21
|
+
# Costruisce l'URL dell'asset per una data piattaforma e build.
|
|
22
|
+
# Se build == "latest" usa l'URL "latest/download/...", altrimenti
|
|
23
|
+
# quello specifico "/download/chromium/<N>/...".
|
|
24
|
+
def asset_url(platform_key, pdfium_build)
|
|
25
|
+
asset = "pdfium-#{platform_key}.tgz"
|
|
26
|
+
if pdfium_build == "latest"
|
|
27
|
+
"#{RELEASE_BASE}/latest/download/#{asset}"
|
|
28
|
+
else
|
|
29
|
+
"#{RELEASE_BASE}/download/chromium/#{pdfium_build}/#{asset}"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Mappa di SHA256 attesi. La gemma platform-specific include i
|
|
34
|
+
# propri SHA come parte del package_data (file YAML caricato a
|
|
35
|
+
# build time). La gemma generica può usare valori inseriti via
|
|
36
|
+
# ENV o lasciare nil (download senza verifica, sconsigliato).
|
|
37
|
+
def expected_sha256(platform_key, pdfium_build)
|
|
38
|
+
return nil unless defined?(SHA256_DB)
|
|
39
|
+
|
|
40
|
+
SHA256_DB.dig(pdfium_build, platform_key)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# SCARICA l'asset, verifica il checksum, ESTRAE solo i file utili
|
|
44
|
+
# (libpdfium*, LICENSE) in dest_dir/lib/ e dest_dir/.
|
|
45
|
+
def fetch!(url:, dest_dir:, library_name:, sha256: nil)
|
|
46
|
+
FileUtils.mkdir_p(dest_dir)
|
|
47
|
+
Dir.mktmpdir("rpdfium-binary-") do |tmp|
|
|
48
|
+
tarball = File.join(tmp, "pdfium.tgz")
|
|
49
|
+
download(url, tarball)
|
|
50
|
+
verify_sha256!(tarball, sha256) if sha256
|
|
51
|
+
extract!(tarball, tmp)
|
|
52
|
+
install_into!(tmp, dest_dir, library_name)
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# ---- HTTP download con redirect ----
|
|
57
|
+
|
|
58
|
+
def download(url, dest, redirect_limit: 10)
|
|
59
|
+
raise DownloadError, "too many redirects" if redirect_limit <= 0
|
|
60
|
+
|
|
61
|
+
uri = URI.parse(url)
|
|
62
|
+
Net::HTTP.start(uri.host, uri.port,
|
|
63
|
+
use_ssl: uri.scheme == "https",
|
|
64
|
+
read_timeout: 120, open_timeout: 30) do |http|
|
|
65
|
+
req = Net::HTTP::Get.new(uri.request_uri)
|
|
66
|
+
req["User-Agent"] = "rpdfium-binary/#{Rpdfium::Binary::VERSION}"
|
|
67
|
+
http.request(req) do |res|
|
|
68
|
+
case res
|
|
69
|
+
when Net::HTTPSuccess
|
|
70
|
+
File.open(dest, "wb") { |f| res.read_body { |c| f.write(c) } }
|
|
71
|
+
when Net::HTTPRedirection
|
|
72
|
+
download(res["location"], dest, redirect_limit: redirect_limit - 1)
|
|
73
|
+
else
|
|
74
|
+
raise DownloadError, "HTTP #{res.code} from #{url}"
|
|
75
|
+
end
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
rescue SocketError, Errno::ECONNREFUSED, Net::OpenTimeout => e
|
|
79
|
+
raise DownloadError, "Cannot reach #{uri.host}: #{e.message}"
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# ---- Verifica integrità ----
|
|
83
|
+
|
|
84
|
+
def verify_sha256!(path, expected)
|
|
85
|
+
actual = Digest::SHA256.file(path).hexdigest
|
|
86
|
+
return if actual.casecmp(expected).zero?
|
|
87
|
+
|
|
88
|
+
raise ChecksumError, "SHA256 mismatch for #{path}\n" \
|
|
89
|
+
" expected: #{expected}\n" \
|
|
90
|
+
" actual: #{actual}"
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# ---- Estrazione tarball gzip ----
|
|
94
|
+
# I tarball bblanchon hanno layout:
|
|
95
|
+
# include/ -> headers (non ci servono)
|
|
96
|
+
# lib/libpdfium.so | bin/pdfium.dll
|
|
97
|
+
# args.gn, build.txt, ...
|
|
98
|
+
# LICENSE, LICENSES.chromium.html -> includili sempre
|
|
99
|
+
def extract!(tgz_path, dest)
|
|
100
|
+
File.open(tgz_path, "rb") do |io|
|
|
101
|
+
gz = Zlib::GzipReader.new(io)
|
|
102
|
+
Gem::Package::TarReader.new(gz).each do |entry|
|
|
103
|
+
next unless entry.file?
|
|
104
|
+
|
|
105
|
+
name = entry.full_name
|
|
106
|
+
# Bypass percorsi sospetti
|
|
107
|
+
next if name.include?("..")
|
|
108
|
+
|
|
109
|
+
# Salviamo solo:
|
|
110
|
+
# - il binario nativo (in lib/ o bin/)
|
|
111
|
+
# - file di licenza
|
|
112
|
+
keep = name.match?(%r{(?:^|/)lib/lib(?:pdfium)\.[^/]+$}) ||
|
|
113
|
+
name.match?(%r{(?:^|/)bin/pdfium\.dll$}) ||
|
|
114
|
+
name.match?(/LICENSE/i)
|
|
115
|
+
next unless keep
|
|
116
|
+
|
|
117
|
+
target = File.join(dest, name)
|
|
118
|
+
FileUtils.mkdir_p(File.dirname(target))
|
|
119
|
+
File.open(target, "wb") { |f| f.write(entry.read) }
|
|
120
|
+
# Conserva permessi eseguibili
|
|
121
|
+
File.chmod(entry.header.mode & 0o7777, target) rescue nil
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|
|
125
|
+
|
|
126
|
+
# Sposta i file utili nella destinazione finale.
|
|
127
|
+
# dest_dir/<library_filename> ← libpdfium.{so,dylib} | pdfium.dll
|
|
128
|
+
# dest_dir/LICENSE.pdfium ← LICENSE
|
|
129
|
+
# dest_dir/LICENSES_third_party* ← se presenti
|
|
130
|
+
def install_into!(staging, dest_dir, library_name)
|
|
131
|
+
# Cerca il binario in staging (può essere dentro lib/ o bin/)
|
|
132
|
+
candidates = Dir[File.join(staging, "**", library_name)]
|
|
133
|
+
if candidates.empty?
|
|
134
|
+
# Su macOS il file in lib/ può avere nome diverso (es. con
|
|
135
|
+
# versionamento), prova un fallback più permissivo.
|
|
136
|
+
candidates = Dir[File.join(staging, "**", "libpdfium*")] +
|
|
137
|
+
Dir[File.join(staging, "**", "pdfium.dll")]
|
|
138
|
+
end
|
|
139
|
+
raise DownloadError, "no PDFium binary found in tarball" if candidates.empty?
|
|
140
|
+
|
|
141
|
+
chosen = candidates.first
|
|
142
|
+
FileUtils.cp(chosen, File.join(dest_dir, library_name))
|
|
143
|
+
|
|
144
|
+
# Salviamo anche le licenze
|
|
145
|
+
# Dir[File.join(staging, "**", "*LICENSE*")].each do |lic|
|
|
146
|
+
# FileUtils.cp(lic, File.join(dest_dir, File.basename(lic)))
|
|
147
|
+
# end
|
|
148
|
+
end
|
|
149
|
+
end
|
|
150
|
+
end
|
|
151
|
+
end
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Rpdfium
|
|
4
|
+
module Binary
|
|
5
|
+
# Schema: <gem_major>.<gem_minor>.<pdfium_build>
|
|
6
|
+
# Es. 0.1.7811 = prima minor di rpdfium-binary, basata su pdfium chromium/7811.
|
|
7
|
+
# Il PDFium build number è leggibile dal nome della release upstream
|
|
8
|
+
# (https://github.com/bblanchon/pdfium-binaries/releases).
|
|
9
|
+
VERSION = "0.1.7811"
|
|
10
|
+
end
|
|
11
|
+
end
|
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "binary/version"
|
|
4
|
+
require_relative "binary/downloader"
|
|
5
|
+
|
|
6
|
+
module Rpdfium
|
|
7
|
+
# Companion gem distributing prebuilt PDFium binaries.
|
|
8
|
+
#
|
|
9
|
+
# In una gemma "platform-specific" (es. rpdfium-binary-0.1.7811-x86_64-linux),
|
|
10
|
+
# il binario è già impacchettato in `vendor/lib/` ed è disponibile alla
|
|
11
|
+
# prima require senza I/O di rete.
|
|
12
|
+
#
|
|
13
|
+
# La gemma "ruby" generica (platform=ruby) NON include il binario: alla
|
|
14
|
+
# prima `library_path` lo scarica da pdfium-binaries di bblanchon, lo
|
|
15
|
+
# verifica via SHA256 (se forniti) e lo cache nella user data dir
|
|
16
|
+
# (`~/.local/share/rpdfium/binaries/<version>/<platform>/`).
|
|
17
|
+
#
|
|
18
|
+
# Il path viene poi esposto a rpdfium via `Rpdfium::Binary.library_path`,
|
|
19
|
+
# che `rpdfium/raw.rb` interroga prima di tentare il caricamento di sistema.
|
|
20
|
+
module Binary
|
|
21
|
+
class Error < StandardError; end
|
|
22
|
+
class UnsupportedPlatform < Error; end
|
|
23
|
+
class DownloadError < Error; end
|
|
24
|
+
class ChecksumError < Error; end
|
|
25
|
+
|
|
26
|
+
# Versione di PDFium impacchettato. Estratta dal file VERSION o dalla
|
|
27
|
+
# build info se presente, fallback al numero in VERSION costante.
|
|
28
|
+
PDFIUM_BUILD = ENV.fetch("RPDFIUM_BINARY_PDFIUM_BUILD",
|
|
29
|
+
Rpdfium::Binary::VERSION.split(".").last)
|
|
30
|
+
|
|
31
|
+
# ---- Detection piattaforma host ----
|
|
32
|
+
|
|
33
|
+
# Restituisce il "platform key" usato internamente, es. "linux-x64",
|
|
34
|
+
# "mac-arm64", "win-x64". Stesso schema dei file di bblanchon.
|
|
35
|
+
def self.platform_key
|
|
36
|
+
@platform_key ||= detect_platform_key
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def self.detect_platform_key
|
|
40
|
+
cpu = host_cpu
|
|
41
|
+
case host_os
|
|
42
|
+
when :linux
|
|
43
|
+
musl = libc_is_musl? ? "musl-" : ""
|
|
44
|
+
"linux-#{musl}#{cpu}"
|
|
45
|
+
when :darwin then "mac-#{cpu}"
|
|
46
|
+
when :windows then "win-#{cpu}"
|
|
47
|
+
else
|
|
48
|
+
raise UnsupportedPlatform,
|
|
49
|
+
"Unsupported OS: #{RbConfig::CONFIG['host_os']}"
|
|
50
|
+
end
|
|
51
|
+
end
|
|
52
|
+
|
|
53
|
+
def self.host_os
|
|
54
|
+
case RbConfig::CONFIG["host_os"]
|
|
55
|
+
when /linux/ then :linux
|
|
56
|
+
when /darwin/ then :darwin
|
|
57
|
+
when /mingw|mswin|cygwin/ then :windows
|
|
58
|
+
else :unknown
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
|
|
62
|
+
def self.host_cpu
|
|
63
|
+
cpu = RbConfig::CONFIG["host_cpu"]
|
|
64
|
+
case cpu
|
|
65
|
+
when /x86_64|amd64/ then "x64"
|
|
66
|
+
when /aarch64|arm64/ then "arm64"
|
|
67
|
+
when /i[3-6]86/ then "x86"
|
|
68
|
+
when /^arm/ then "arm"
|
|
69
|
+
else
|
|
70
|
+
raise UnsupportedPlatform, "Unsupported CPU: #{cpu}"
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# Detection musl libc su Linux. Su glibc questa system call fallisce
|
|
75
|
+
# silenziosamente, su Alpine restituisce un path che contiene 'musl'.
|
|
76
|
+
# Fallback: ldd --version (alpine ldd non supporta --version e va
|
|
77
|
+
# in stderr con "musl libc").
|
|
78
|
+
def self.libc_is_musl?
|
|
79
|
+
return false unless host_os == :linux
|
|
80
|
+
|
|
81
|
+
# Strategia 1: Look at ldd output
|
|
82
|
+
out = `ldd --version 2>&1`
|
|
83
|
+
return true if out.include?("musl")
|
|
84
|
+
|
|
85
|
+
# Strategia 2: ispeziona /usr/bin/ldd se è uno script
|
|
86
|
+
ldd_path = `command -v ldd 2>/dev/null`.strip
|
|
87
|
+
if !ldd_path.empty? && File.readable?(ldd_path)
|
|
88
|
+
head = File.read(ldd_path, 1024) rescue ""
|
|
89
|
+
return true if head.include?("musl")
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
false
|
|
93
|
+
rescue StandardError
|
|
94
|
+
false
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Nome file libreria nativa per la piattaforma corrente.
|
|
98
|
+
def self.library_filename
|
|
99
|
+
case host_os
|
|
100
|
+
when :darwin then "libpdfium.dylib"
|
|
101
|
+
when :windows then "pdfium.dll"
|
|
102
|
+
else "libpdfium.so"
|
|
103
|
+
end
|
|
104
|
+
end
|
|
105
|
+
|
|
106
|
+
# ---- Locator ----
|
|
107
|
+
|
|
108
|
+
# Restituisce il path assoluto al .so/.dylib/.dll di PDFium.
|
|
109
|
+
# In una gemma platform-specific lo trova subito; altrimenti scarica.
|
|
110
|
+
def self.library_path
|
|
111
|
+
return @library_path if defined?(@library_path) && @library_path
|
|
112
|
+
|
|
113
|
+
@library_path = locate_bundled || download_and_cache
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Restituisce true se il binario è già pre-impacchettato (gemma
|
|
117
|
+
# platform-specific). In quel caso non c'è I/O di rete a runtime.
|
|
118
|
+
def self.bundled?
|
|
119
|
+
!locate_bundled.nil?
|
|
120
|
+
end
|
|
121
|
+
|
|
122
|
+
# Reset (utile per test)
|
|
123
|
+
def self.reset!
|
|
124
|
+
remove_instance_variable(:@library_path) if defined?(@library_path)
|
|
125
|
+
remove_instance_variable(:@platform_key) if defined?(@platform_key)
|
|
126
|
+
end
|
|
127
|
+
|
|
128
|
+
# ---- Cerca binario impacchettato nella gemma ----
|
|
129
|
+
|
|
130
|
+
def self.locate_bundled
|
|
131
|
+
candidates = [
|
|
132
|
+
File.expand_path("../../vendor/lib/#{library_filename}", __dir__),
|
|
133
|
+
File.expand_path("../../vendor/#{platform_key}/lib/#{library_filename}", __dir__)
|
|
134
|
+
]
|
|
135
|
+
candidates.find { |p| File.file?(p) }
|
|
136
|
+
rescue UnsupportedPlatform
|
|
137
|
+
nil
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
# ---- Download fallback ----
|
|
141
|
+
|
|
142
|
+
def self.cache_dir
|
|
143
|
+
base = ENV["RPDFIUM_BINARY_CACHE"] ||
|
|
144
|
+
ENV["XDG_DATA_HOME"] ||
|
|
145
|
+
File.expand_path("~/.local/share")
|
|
146
|
+
File.join(base, "rpdfium", "binaries", PDFIUM_BUILD, platform_key)
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
def self.download_and_cache
|
|
150
|
+
target_dir = cache_dir
|
|
151
|
+
target = File.join(target_dir, library_filename)
|
|
152
|
+
return target if File.file?(target)
|
|
153
|
+
|
|
154
|
+
require_relative "binary/downloader"
|
|
155
|
+
Downloader.fetch!(
|
|
156
|
+
url: Downloader.asset_url(platform_key, PDFIUM_BUILD),
|
|
157
|
+
dest_dir: target_dir,
|
|
158
|
+
library_name: library_filename,
|
|
159
|
+
sha256: Downloader.expected_sha256(platform_key, PDFIUM_BUILD)
|
|
160
|
+
)
|
|
161
|
+
raise DownloadError, "binary not found at #{target}" unless File.file?(target)
|
|
162
|
+
|
|
163
|
+
target
|
|
164
|
+
end
|
|
165
|
+
end
|
|
166
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: rpdfium-binary
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.1.7811
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Roberto Scinocca
|
|
8
|
+
bindir: bin
|
|
9
|
+
cert_chain: []
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
|
+
dependencies:
|
|
12
|
+
- !ruby/object:Gem::Dependency
|
|
13
|
+
name: rake
|
|
14
|
+
requirement: !ruby/object:Gem::Requirement
|
|
15
|
+
requirements:
|
|
16
|
+
- - "~>"
|
|
17
|
+
- !ruby/object:Gem::Version
|
|
18
|
+
version: '13.0'
|
|
19
|
+
type: :development
|
|
20
|
+
prerelease: false
|
|
21
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
22
|
+
requirements:
|
|
23
|
+
- - "~>"
|
|
24
|
+
- !ruby/object:Gem::Version
|
|
25
|
+
version: '13.0'
|
|
26
|
+
- !ruby/object:Gem::Dependency
|
|
27
|
+
name: minitest
|
|
28
|
+
requirement: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - "~>"
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '5.20'
|
|
33
|
+
type: :development
|
|
34
|
+
prerelease: false
|
|
35
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
36
|
+
requirements:
|
|
37
|
+
- - "~>"
|
|
38
|
+
- !ruby/object:Gem::Version
|
|
39
|
+
version: '5.20'
|
|
40
|
+
description: |
|
|
41
|
+
Companion gem for `rpdfium` that ships precompiled PDFium shared libraries
|
|
42
|
+
(Apache-2.0/BSD-3-Clause) from bblanchon/pdfium-binaries. Mirrors the
|
|
43
|
+
pypdfium2 wheels approach: each platform-specific gem includes its native
|
|
44
|
+
library directly, while the generic Ruby-platform gem falls back to a
|
|
45
|
+
runtime download.
|
|
46
|
+
email:
|
|
47
|
+
- roberto.scinocca@hey.com
|
|
48
|
+
executables: []
|
|
49
|
+
extensions: []
|
|
50
|
+
extra_rdoc_files: []
|
|
51
|
+
files:
|
|
52
|
+
- CHANGELOG.md
|
|
53
|
+
- LICENSE
|
|
54
|
+
- README.md
|
|
55
|
+
- lib/rpdfium/binary.rb
|
|
56
|
+
- lib/rpdfium/binary/downloader.rb
|
|
57
|
+
- lib/rpdfium/binary/version.rb
|
|
58
|
+
homepage: https://github.com/retsef/rpdfium
|
|
59
|
+
licenses:
|
|
60
|
+
- Apache-2.0
|
|
61
|
+
metadata:
|
|
62
|
+
source_code_uri: https://github.com/retsef/rpdfium
|
|
63
|
+
changelog_uri: https://github.com/retsef/rpdfium/blob/main/rpdfium-binary/CHANGELOG.md
|
|
64
|
+
rubygems_mfa_required: 'true'
|
|
65
|
+
pdfium_build: '7811'
|
|
66
|
+
rdoc_options: []
|
|
67
|
+
require_paths:
|
|
68
|
+
- lib
|
|
69
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
|
+
requirements:
|
|
71
|
+
- - ">="
|
|
72
|
+
- !ruby/object:Gem::Version
|
|
73
|
+
version: 3.0.0
|
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
75
|
+
requirements:
|
|
76
|
+
- - ">="
|
|
77
|
+
- !ruby/object:Gem::Version
|
|
78
|
+
version: '0'
|
|
79
|
+
requirements: []
|
|
80
|
+
rubygems_version: 4.0.6
|
|
81
|
+
specification_version: 4
|
|
82
|
+
summary: Prebuilt PDFium binaries for the rpdfium gem
|
|
83
|
+
test_files: []
|