Module: ZplRenderer::Binary
- Defined in:
- lib/zpl_renderer/binary.rb
Overview
Locates the bundled zpl-renderer native binary for the current platform.
Constant Summary collapse
- BINARY_NAME =
"zpl-renderer"
Class Method Summary collapse
- .candidates ⇒ Object
- .missing_message ⇒ Object
- .path ⇒ Object
- .platform_triple ⇒ Object
- .windows? ⇒ Boolean
Class Method Details
.candidates ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/zpl_renderer/binary.rb', line 31 def candidates root = File.("../..", __dir__) name = windows? ? "#{BINARY_NAME}.exe" : BINARY_NAME triple = platform_triple [ ENV["ZPL_RENDERER_BINARY"], File.join(root, "vendor", "bin", triple, name), File.join(root, "vendor", "bin", name), File.join(root, "renderer", "target", "release", name), File.join(root, "renderer", "target", "debug", name) ].compact end |
.missing_message ⇒ Object
49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/zpl_renderer/binary.rb', line 49 def <<~MSG Could not find the zpl-renderer binary for #{platform_triple}. Tried: #{candidates.map { |c| " - #{c}" }.join("\n")} Build it with: cd renderer && cargo build --release Or set ZPL_RENDERER_BINARY to an absolute path. MSG end |
.path ⇒ Object
12 13 14 15 |
# File 'lib/zpl_renderer/binary.rb', line 12 def path candidates.find { |candidate| File.file?(candidate) && File.executable?(candidate) } || raise(BinaryMissingError, ) end |
.platform_triple ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/zpl_renderer/binary.rb', line 17 def platform_triple case RUBY_PLATFORM when /x86_64-linux-musl/ then "x86_64-unknown-linux-musl" when /aarch64-linux-musl|arm64-linux-musl/ then "aarch64-unknown-linux-musl" when /x86_64-linux/ then "x86_64-unknown-linux-gnu" when /aarch64-linux|arm64-linux/ then "aarch64-unknown-linux-gnu" when /x86_64-darwin/ then "x86_64-apple-darwin" when /arm64-darwin|aarch64-darwin/ then "aarch64-apple-darwin" when /x64-mingw|x86_64-mingw|x64-mswin|x86_64-mswin/ then "x86_64-pc-windows-msvc" else RUBY_PLATFORM end end |
.windows? ⇒ Boolean
45 46 47 |
# File 'lib/zpl_renderer/binary.rb', line 45 def windows? !!(RUBY_PLATFORM =~ /mswin|mingw|cygwin/) end |