fix(qr): Crystal use C FFI instead of qr-code shard

Crystal shards pre-cached during build aren't available for
single-file execution. Use @[Link("qrencode")] FFI instead.
This commit is contained in:
russell@unturf.com 2026-01-28 07:59:57 -05:00
parent edfe6dc865
commit bd91337584

View file

@ -1,5 +1,19 @@
require "qr-code"
@[Link("qrencode")]
lib LibQRencode
struct QRcode
version : LibC::Int
width : LibC::Int
data : UInt8*
end
qr = QRCode.new("unsandbox-qr-ok")
rows = qr.modules.size
puts "QR:unsandbox-qr-ok:ROWS:#{rows}"
fun QRcode_encodeString(s : LibC::Char*, version : LibC::Int, level : LibC::Int, hint : LibC::Int, casesensitive : LibC::Int) : QRcode*
fun QRcode_free(qr : QRcode*)
end
qr = LibQRencode.QRcode_encodeString("unsandbox-qr-ok", 0, 1, 2, 1)
if qr.null?
puts "QR encode failed"
exit 1
end
puts "QR:unsandbox-qr-ok:ROWS:#{qr.value.width}"
LibQRencode.QRcode_free(qr)