Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 18 additions & 11 deletions .github/workflows/publish-jsr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ name: Publish to JSR (@serial/cpp-bindings-linux)
on:
workflow_dispatch:
inputs: {}

push:
branches:
- '*'

tags:
- "v*"

Expand Down Expand Up @@ -36,7 +40,7 @@ jobs:
- name: Setup Deno
uses: denoland/setup-deno@v2
with:
deno-version: "2.6.0"
deno-version: "2.x"

- name: Configure CMake (Release)
env:
Expand All @@ -48,19 +52,22 @@ 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 \
./jsr/scripts/embed_binary.sh \
./build/libcpp_bindings_linux.so \
./jsr/package/bin \
linux-x86_64
cp LICENSE ./jsr/package/LICENSE

- name: Publish package to JSR
working-directory: jsr
- name: Publish package to JSR (real)
if: github.ref_type == 'tag'
working-directory: jsr/package
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_type != 'tag'
working-directory: jsr/package
run: |
deno publish --allow-dirty --dry-run
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ compile_commands.json
# Generated files
generated/
src/version_config.cpp
*.so

# OS
.DS_Store
Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ project(
# Generate JSR package metadata from the same git-derived version as the library.
# We generate into the build directory to avoid touching tracked files during normal local builds.
configure_file(
"${CMAKE_SOURCE_DIR}/jsr/jsr.json.in"
"${CMAKE_SOURCE_DIR}/jsr/jsr.json"
"${CMAKE_SOURCE_DIR}/jsr/package/jsr.json.in"
"${CMAKE_SOURCE_DIR}/jsr/package/jsr.json"
@ONLY
)

Expand Down
7 changes: 0 additions & 7 deletions jsr/bin/x84_64.json

This file was deleted.

File renamed without changes.
7 changes: 1 addition & 6 deletions jsr/README.md → jsr/package/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ blob**.
Import the JSON and write the `.so` to disk (consumer project example):

```ts
import blob from "@serial/cpp-bindings-linux/x84_64" with { type: "json" };
import blob from "@serial/cpp-bindings-linux/bin/x84_64" with { type: "json" };

const bytes = new TextEncoder().encode(atob(blob.data));

Expand All @@ -17,8 +17,3 @@ Deno.writeFileSync(tempFilePath, bytes, { mode: 0o755 });

// Now you can open the binary using for example `Deno.dlopen`
```

## License

This package is licensed under **LGPL-3.0-only** (see the repository root
`LICENSE`).
5 changes: 3 additions & 2 deletions jsr/jsr.json.in → jsr/package/jsr.json.in
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
{
"name": "@serial/cpp-bindings-linux",
"version": "@PROJECT_VERSION@",
"license": "LGPL-3.0-only",
"license": "LICENSE",
"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/x86_64": "./bin/x86_64.json"
},
"publish": {
"include": [
"README.md",
"LICENSE",
"jsr.json",
"bin/**"
]
Expand Down
35 changes: 35 additions & 0 deletions jsr/scripts/embed_binary.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/bin/sh
set -eu

if [ "$#" -ne 3 ]; then
echo "Usage: $0 <binaryPath> <jsrBinPath> <target>" >&2
exit 1
fi

BINARY_PATH=$1
JSR_BIN_PATH=$2
TARGET=$3

if [ ! -f "$BINARY_PATH" ]; then
echo "Error: Binary path is not a file: $BINARY_PATH" >&2
exit 1
fi

FILENAME=$(basename "$BINARY_PATH")

mkdir -p "$JSR_BIN_PATH"

cp "$BINARY_PATH" "$JSR_BIN_PATH/x86_64.so"

BASE64_DATA=$(base64 "$BINARY_PATH" | tr -d '\n')

jq -n \
--arg target "$TARGET" \
--arg filename "$FILENAME" \
--arg data "$BASE64_DATA" \
'{
target: $target,
filename: $filename,
encoding: "base64",
data: $data
}' > "$JSR_BIN_PATH/x86_64.json"
51 changes: 0 additions & 51 deletions jsr/scripts/embed_so.ts

This file was deleted.

Loading