From bd913375841571f658a759bdfa647c881f90efc6 Mon Sep 17 00:00:00 2001 From: "russell@unturf.com" Date: Wed, 28 Jan 2026 07:59:57 -0500 Subject: [PATCH] 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. --- test/qr.cr | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/test/qr.cr b/test/qr.cr index 2c7a094..6efc11a 100644 --- a/test/qr.cr +++ b/test/qr.cr @@ -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)