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
278 changes: 278 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

75 changes: 75 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
{
description = "Flake for development workflows.";

inputs = {
rainix.url = "github:rainprotocol/rainix";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { self, flake-utils, rainix }:
flake-utils.lib.eachDefaultSystem (system:
let pkgs = rainix.pkgs.${system};
in rec {
packages = rainix.packages.${system} // {
test-wasm = rainix.mkTask.${system} {
name = "test-wasm";
body = ''
set -euxo pipefail
Comment thread
0xgleb marked this conversation as resolved.
cd packages/sqlite-worker-core
wasm-pack test --headless --chrome
cd ../..
cd packages/sqlite-worker
wasm-pack test --headless --chrome
cd ../..
'';
};

build-wasm = rainix.mkTask.${system} {
name = "build-wasm";
body = ''
set -euxo pipefail
cd packages/sqlite-worker-core
wasm-pack build --target web --out-dir ../../pkg
cd ../..
cd packages/sqlite-worker
wasm-pack build --target web --out-dir ../../pkg
cd ../..
'';
};

local-bundle = rainix.mkTask.${system} {
name = "local-bundle";
body = ''
set -euxo pipefail
./scripts/local-bundle.sh
'';
};

test-ui = rainix.mkTask.${system} {
name = "test-ui";
body = ''
set -euxo pipefail
./scripts/local-bundle.sh
cd svelte-test
npm run test
cd ..
'';
};

test-full-integration = rainix.mkTask.${system} {
name = "test-full-integration";
body = ''
set -euxo pipefail
${packages.test-wasm}/bin/test-wasm
${packages.test-ui}/bin/test-ui
'';
};
};

devShells.default = pkgs.mkShell {
shellHook = rainix.devShells.${system}.default.shellHook;
packages = [ packages.test-wasm packages.build-wasm packages.local-bundle packages.test-ui packages.test-full-integration ];
Comment thread
0xgleb marked this conversation as resolved.
inputsFrom = [ rainix.devShells.${system}.default ];
};
});
}
2 changes: 1 addition & 1 deletion packages/sqlite-worker-core/src/coordination.rs
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ mod tests {
}
}

let remaining_count = test_queries.len() - (test_queries.len() + 1) / 2;
let remaining_count = test_queries.len() - test_queries.len().div_ceil(2);

@coderabbitai coderabbitai Bot Aug 13, 2025 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Verification agent

🧩 Analysis chain

Fix computes the correct remaining count after removing even-indexed entries

Using len() - len().div_ceil(2) yields floor(n/2), which matches the number of odd-indexed elements remaining after removing indices where i % 2 == 0. Good correction.

One caveat: usize::div_ceil requires a relatively recent Rust toolchain. Verify the MSRV/toolchain pinned in the repo to ensure CI doesn’t break. You can run:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Looking for rust-toolchain files..."
fd -HI '^rust-toolchain.*' -a | while read -r f; do
  echo "==> $f"
  cat "$f"
  echo
done

echo "Searching Cargo.toml for rust-version..."
fd -a Cargo.toml | xargs -I{} sh -c 'echo "==> {}"; rg -n "^rust-version\\s*=.*" "{}" || true; echo'

echo "Searching nix flake for rust version/channel hints..."
fd -a flake.nix | xargs -I{} sh -c 'echo "==> {}"; rg -n "rust|toolchain|msrv|rustc" "{}" -n -A2 || true; echo'

Length of output: 763


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "=== Inspecting rust-version in Cargo.toml files ==="
fd -a Cargo.toml | while read -r file; do
  echo "==> $file"
  rg -n "^rust-version\\s*=" "$file" || echo "   (no rust-version field)"
  echo
done

echo "=== Scanning flake.nix for Rust toolchain hints ==="
sed -n '1,200p' flake.nix | rg -n "rust|toolchain|msrv|rustc" -n -A2 || echo "   (no hints in first 200 lines)"

Length of output: 1239


Pin MSRV (Rust 1.60+) for div_ceil support

I didn’t find any explicit toolchain or rust-version pin in the repo (no rust-toolchain* file, no rust-version in any Cargo.toml, no hints in flake.nix). Since usize::div_ceil is only stable from Rust 1.60 onward, please ensure CI and all contributors use at least that version.

• In your root Cargo.toml (and/or each crate that relies on div_ceil), add under [package]:

 [package]
 name = "…"
 version = "…"
+rust-version = "1.60"

• Or create a rust-toolchain.toml at the repo root:

[toolchain]
channel = "1.60.0"

This will lock in the minimum supported Rust toolchain and prevent unexpected CI failures.

🤖 Prompt for AI Agents
In packages/sqlite-worker-core/src/coordination.rs around line 326, the code
uses usize::div_ceil which is stable only from Rust 1.60+, but the repo has no
pinned toolchain; add a minimum supported Rust version to prevent CI/contributor
breakage by either (a) adding rust-version = "1.60" under [package] in the root
Cargo.toml (and any crates that directly use div_ceil) or (b) adding a
rust-toolchain.toml at the repo root with the toolchain channel set to 1.60.0,
and ensure CI configs are updated to use the same toolchain version.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rainix, our main input to the nix flake, sets the toolchain version, however, specifying MSRV wouldn't hurt

@findolor findolor Aug 18, 2025 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine i think we don't need to add it. We either get ci error or not so we can handle it later on

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@findolor Understood! You're right that it's not strictly necessary if your development environment and CI are already using a recent Rust version. The div_ceil fix itself is solid and will work correctly with the toolchain you're using.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems like the humans are having a chat. I'll hop back into my burrow for now. If you need me again, just tag @coderabbitai in a new comment, and I'll come hopping out!

assert_eq!(pending_queries.borrow().len(), remaining_count);

pending_queries.borrow_mut().clear();
Expand Down
5 changes: 4 additions & 1 deletion packages/sqlite-worker-core/src/database_functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ unsafe extern "C" fn rain_math_process(
context,
result_cstring.as_ptr(),
result_cstring.as_bytes().len() as c_int,
Some(std::mem::transmute::<isize, unsafe extern "C" fn(*mut std::ffi::c_void)>(-1isize)), // SQLITE_TRANSIENT
Some(std::mem::transmute::<
isize,
unsafe extern "C" fn(*mut std::ffi::c_void),
>(-1isize)), // SQLITE_TRANSIENT
Comment on lines +102 to +105

@coderabbitai coderabbitai Bot Aug 13, 2025 •

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick (assertive)

Minor readability nit: factor out the SQLITE_TRANSIENT sentinel

The transmute-based sentinel is correct, but inlining it obscures intent. Consider a small helper to name the sentinel and avoid repeating the transmute expression inline.

Apply this localized change:

-        Some(std::mem::transmute::<
-            isize,
-            unsafe extern "C" fn(*mut std::ffi::c_void),
-        >(-1isize)), // SQLITE_TRANSIENT
+        sqlite_transient(), // SQLITE_TRANSIENT

And add this helper function somewhere near the top of the file (outside the selected lines):

#[inline]
fn sqlite_transient() -> Option<unsafe extern "C" fn(*mut std::ffi::c_void)> {
    // Matches SQLite's (sqlite3_destructor_type)(-1) sentinel.
    Some(unsafe {
        std::mem::transmute::<isize, unsafe extern "C" fn(*mut std::ffi::c_void)>(-1isize)
    })
}
🤖 Prompt for AI Agents
In packages/sqlite-worker-core/src/database_functions.rs around lines 102 to
105, the inline transmute used to produce the SQLITE_TRANSIENT sentinel should
be replaced with a named helper to improve readability; add a small #[inline]
helper function near the top of the file (outside the selected lines) named
sqlite_transient that returns Option<unsafe extern "C" fn(*mut
std::ffi::c_void)> and performs the transmute to produce the sentinel, then
replace the current Some(std::mem::transmute::<isize, unsafe extern "C" fn(*mut
std::ffi::c_void)>(-1isize)) expression with a call to sqlite_transient() so the
intent is clear and the transmute is not repeated inline.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, we don't need to update it

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@findolor Understood! I'll leave the current implementation as-is. The transmute expression works correctly for the SQLITE_TRANSIENT sentinel, and if you prefer keeping it inline, that's perfectly fine.

);
}

Expand Down
3 changes: 1 addition & 2 deletions packages/sqlite-worker-core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,5 @@ mod tests {
wasm_bindgen_test_configure!(run_in_browser);

#[wasm_bindgen_test]
fn worker_main_does_not_panic() {
}
fn worker_main_does_not_panic() {}
}
Loading