From bfb30a1311702d324849b1e3943930dd1cc0691c Mon Sep 17 00:00:00 2001
From: Mqxx <62719703+Mqxx@users.noreply.github.com>
Date: Wed, 17 Dec 2025 15:58:07 +0100
Subject: [PATCH 01/17] feat: reafctor function
---
.gitignore | 1 +
jsr/scripts/convert_binary_to_json.ts | 15 +++++++++++++++
2 files changed, 16 insertions(+)
create mode 100644 jsr/scripts/convert_binary_to_json.ts
diff --git a/.gitignore b/.gitignore
index 63c68c9..05ff4e0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -26,6 +26,7 @@ compile_commands.json
# Generated files
generated/
src/version_config.cpp
+*.so
# OS
.DS_Store
diff --git a/jsr/scripts/convert_binary_to_json.ts b/jsr/scripts/convert_binary_to_json.ts
new file mode 100644
index 0000000..22a2e69
--- /dev/null
+++ b/jsr/scripts/convert_binary_to_json.ts
@@ -0,0 +1,15 @@
+const dataArray = Deno.readFileSync('./libcpp_bindings_linux.so')
+
+function base64FromBytes(bytes: Uint8Array): string {
+ // Chunk to avoid call stack limits in String.fromCharCode(...bigArray)
+ const chunkSize = 0x8000;
+ let binary = "";
+ for (let i = 0; i < bytes.length; i += chunkSize) {
+ const chunk = bytes.subarray(i, i + chunkSize);
+ binary += String.fromCharCode(...chunk);
+ }
+ return btoa(binary);
+}
+
+Deno.writeTextFileSync('./libcpp_bindings_linux.json', base64FromBytes(dataArray))
+
From 1dad2395b1885af5733cf5919060b476ea76f7c7 Mon Sep 17 00:00:00 2001
From: Mqxx <62719703+Mqxx@users.noreply.github.com>
Date: Thu, 18 Dec 2025 09:14:34 +0100
Subject: [PATCH 02/17] ci: Refactor JSR binary embedding and update workflow
Replaces the old embed_so.ts and convert_binary_to_json.ts scripts with a new embed_binary.ts script for embedding binaries as JSON. Updates the GitHub Actions workflow to use the new script, adds dry-run publishing, and cleans up related files. Also updates jsr.json.in export path for consistency.
---
.github/workflows/publish-jsr.yml | 27 ++++++++------
jsr/bin/x84_64.json | 7 ----
jsr/jsr.json.in | 2 +-
jsr/scripts/convert_binary_to_json.ts | 15 --------
jsr/scripts/embed_binary.ts | 26 ++++++++++++++
jsr/scripts/embed_so.ts | 51 ---------------------------
6 files changed, 43 insertions(+), 85 deletions(-)
delete mode 100644 jsr/bin/x84_64.json
delete mode 100644 jsr/scripts/convert_binary_to_json.ts
create mode 100644 jsr/scripts/embed_binary.ts
delete mode 100644 jsr/scripts/embed_so.ts
diff --git a/.github/workflows/publish-jsr.yml b/.github/workflows/publish-jsr.yml
index 63df8cc..1f4834b 100644
--- a/.github/workflows/publish-jsr.yml
+++ b/.github/workflows/publish-jsr.yml
@@ -3,7 +3,11 @@ name: Publish to JSR (@serial/cpp-bindings-linux)
on:
workflow_dispatch:
inputs: {}
+
push:
+ branches:
+ - '*'
+
tags:
- "v*"
@@ -48,19 +52,20 @@ jobs:
run: |
cmake --build build --config Release
- - name: Embed .so as JSON/base64 for JSR
+ - name: Embed binary as JSON/base64 for JSR
run: |
- deno run --allow-read --allow-write jsr/scripts/embed_so.ts \
- build/libcpp_bindings_linux.so \
- jsr/bin/x84_64.json \
- linux-x86_64
-
- - name: Publish package to JSR
+ deno run --allow-read --allow-write jsr/scripts/embed_binary.ts \
+ --binaryPath="build/libcpp_bindings_linux.so" \
+ --target="linux-x86_64"
+
+ - name: Publish package to JSR (real)
+ if: github.ref_name == 'main' || startsWith(github.ref, 'refs/tags/')
working-directory: jsr
run: |
- # CMake + embed_so.ts generate files (jsr/jsr.json + binaries/*.json),
- # which makes the worktree dirty. Publishing is still deterministic because
- # the workflow builds + generates in a single run.
deno publish --allow-dirty
-
+ - name: Publish package to JSR (dry-run)
+ if: github.ref_name != 'main' && !startsWith(github.ref, 'refs/tags/')
+ working-directory: jsr
+ run: |
+ deno publish --allow-dirty --dry-run
diff --git a/jsr/bin/x84_64.json b/jsr/bin/x84_64.json
deleted file mode 100644
index 4184085..0000000
--- a/jsr/bin/x84_64.json
+++ /dev/null
@@ -1,7 +0,0 @@
-{
- "target": "linux-x86_64",
- "filename": "libcpp_bindings_linux.so",
- "encoding": "base64",
- "sha256": "",
- "data": ""
-}
diff --git a/jsr/jsr.json.in b/jsr/jsr.json.in
index 3e8c0b5..b98afff 100644
--- a/jsr/jsr.json.in
+++ b/jsr/jsr.json.in
@@ -4,7 +4,7 @@
"license": "LGPL-3.0-only",
"description": "Linux shared-library bindings for Serial-IO/cpp-core (distributed via JSON/base64 because JSR has limited binary support).",
"exports": {
- "./x84_64": "./bin/x84_64.json"
+ "./bin/x84_64": "./bin/x84_64.json"
},
"publish": {
"include": [
diff --git a/jsr/scripts/convert_binary_to_json.ts b/jsr/scripts/convert_binary_to_json.ts
deleted file mode 100644
index 22a2e69..0000000
--- a/jsr/scripts/convert_binary_to_json.ts
+++ /dev/null
@@ -1,15 +0,0 @@
-const dataArray = Deno.readFileSync('./libcpp_bindings_linux.so')
-
-function base64FromBytes(bytes: Uint8Array): string {
- // Chunk to avoid call stack limits in String.fromCharCode(...bigArray)
- const chunkSize = 0x8000;
- let binary = "";
- for (let i = 0; i < bytes.length; i += chunkSize) {
- const chunk = bytes.subarray(i, i + chunkSize);
- binary += String.fromCharCode(...chunk);
- }
- return btoa(binary);
-}
-
-Deno.writeTextFileSync('./libcpp_bindings_linux.json', base64FromBytes(dataArray))
-
diff --git a/jsr/scripts/embed_binary.ts b/jsr/scripts/embed_binary.ts
new file mode 100644
index 0000000..93d33d1
--- /dev/null
+++ b/jsr/scripts/embed_binary.ts
@@ -0,0 +1,26 @@
+import { parseArgs } from "jsr:@std/cli@1.0.24";
+
+
+const args = parseArgs<{
+ binaryPath : string,
+ target : string
+}>(Deno.args);
+
+const jsrBinPath = './jsr/bin';
+
+Deno.mkdirSync(jsrBinPath, {recursive: true});
+
+Deno.copyFileSync(args.binaryPath, `${jsrBinPath}/x84_64.so`);
+
+const dataArray = Deno.readFileSync(args.binaryPath);
+
+Deno.writeTextFileSync(
+ `${jsrBinPath}/x84_64.json`,
+ JSON.stringify({
+ target: args.target,
+ filename: args.binaryPath,
+ encoding: 'base64',
+ data: dataArray.toBase64()
+ })
+);
+
diff --git a/jsr/scripts/embed_so.ts b/jsr/scripts/embed_so.ts
deleted file mode 100644
index 81cdafe..0000000
--- a/jsr/scripts/embed_so.ts
+++ /dev/null
@@ -1,51 +0,0 @@
-// Usage:
-// deno run --allow-read --allow-write jsr/scripts/embed_so.ts \
-// ./build/libcpp_bindings_linux.so ./jsr/bin/x84_64.json linux-x86_64
-//
-// This converts the shared library into a JSON file containing base64 data for publishing to JSR.
-
-function bytesToHex(bytes: Uint8Array): string {
- return Array.from(bytes, (b) => b.toString(16).padStart(2, "0")).join("");
-}
-
-function base64FromBytes(bytes: Uint8Array): string {
- // Chunk to avoid call stack limits in String.fromCharCode(...bigArray)
- const chunkSize = 0x8000;
- let binary = "";
- for (let i = 0; i < bytes.length; i += chunkSize) {
- const chunk = bytes.subarray(i, i + chunkSize);
- binary += String.fromCharCode(...chunk);
- }
- return btoa(binary);
-}
-
-if (import.meta.main) {
- const [inPath, outPath, target = "linux-x86_64"] = Deno.args;
- if (!inPath || !outPath) {
- console.error(
- "Expected: