justfile 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  1. alias b := build
  2. alias c := check
  3. alias t := test
  4. default:
  5. @just --list
  6. # Create a new SQL migration file
  7. new-migration target name:
  8. #!/usr/bin/env bash
  9. set -euo pipefail
  10. if [ "{{target}}" != "mint" ] && [ "{{target}}" != "wallet" ]; then
  11. echo "Error: target must be either 'mint' or 'wallet'"
  12. exit 1
  13. fi
  14. timestamp=$(date +%Y%m%d%H%M%S)
  15. migration_path="./crates/cdk-sql-common/src/{{target}}/migrations/${timestamp}_{{name}}.sql"
  16. # Create the file
  17. mkdir -p "$(dirname "$migration_path")"
  18. touch "$migration_path"
  19. echo "Created new migration: $migration_path"
  20. final-check: typos format clippy test
  21. # run `cargo build` on everything
  22. build *ARGS="--workspace --all-targets":
  23. #!/usr/bin/env bash
  24. set -euo pipefail
  25. if [ ! -f Cargo.toml ]; then
  26. cd {{invocation_directory()}}
  27. fi
  28. cargo build {{ARGS}}
  29. # run `cargo check` on everything
  30. check *ARGS="--workspace --all-targets":
  31. #!/usr/bin/env bash
  32. set -euo pipefail
  33. if [ ! -f Cargo.toml ]; then
  34. cd {{invocation_directory()}}
  35. fi
  36. cargo check {{ARGS}}
  37. # run code formatters
  38. format:
  39. #!/usr/bin/env bash
  40. set -euo pipefail
  41. if [ ! -f Cargo.toml ]; then
  42. cd {{invocation_directory()}}
  43. fi
  44. cargo fmt --all
  45. nixpkgs-fmt $(echo **.nix)
  46. # run doc tests
  47. test:
  48. #!/usr/bin/env bash
  49. set -euo pipefail
  50. if [ ! -f Cargo.toml ]; then
  51. cd {{invocation_directory()}}
  52. fi
  53. cargo test --lib --workspace --exclude cdk-postgres
  54. # Run pure integration tests
  55. cargo test -p cdk-integration-tests --test mint
  56. # run doc tests
  57. test-pure db="memory":
  58. #!/usr/bin/env bash
  59. set -euo pipefail
  60. if [ ! -f Cargo.toml ]; then
  61. cd {{invocation_directory()}}
  62. fi
  63. # Run pure integration tests (cargo test will only build what's needed for the test)
  64. CDK_TEST_DB_TYPE={{db}} cargo test -p cdk-integration-tests --test integration_tests_pure -- --test-threads 1
  65. # Run swap flow tests (detailed testing of swap operation)
  66. CDK_TEST_DB_TYPE={{db}} cargo test -p cdk-integration-tests --test test_swap_flow -- --test-threads 1
  67. # Run wallet saga tests
  68. CDK_TEST_DB_TYPE={{db}} cargo test -p cdk-integration-tests --test wallet_saga -- --test-threads 1
  69. test-all db="memory":
  70. #!/usr/bin/env bash
  71. set -euo pipefail
  72. just test {{db}}
  73. bash ./misc/itests.sh "{{db}}"
  74. bash ./misc/fake_itests.sh "{{db}}" external_signatory
  75. bash ./misc/fake_itests.sh "{{db}}"
  76. # Mutation Testing Commands
  77. # Run mutation tests on a specific crate
  78. # Usage: just mutants <crate-name>
  79. # Example: just mutants cashu
  80. mutants CRATE:
  81. #!/usr/bin/env bash
  82. set -euo pipefail
  83. echo "Running mutation tests on crate: {{CRATE}}"
  84. cargo mutants --package {{CRATE}} -vV
  85. # Run mutation tests on the cashu crate
  86. mutants-cashu:
  87. #!/usr/bin/env bash
  88. set -euo pipefail
  89. echo "Running mutation tests on cashu crate..."
  90. cargo mutants --package cashu -vV
  91. # Run mutation tests on the cdk crate
  92. mutants-cdk:
  93. #!/usr/bin/env bash
  94. set -euo pipefail
  95. echo "Running mutation tests on cdk crate..."
  96. cargo mutants --package cdk -vV
  97. # Run mutation tests on entire workspace (WARNING: very slow)
  98. mutants-all:
  99. #!/usr/bin/env bash
  100. set -euo pipefail
  101. echo "Running mutation tests on entire workspace..."
  102. echo "WARNING: This may take a very long time!"
  103. cargo mutants -vV
  104. # Quick mutation test for current work (alias for mutants-diff)
  105. mutants-quick:
  106. #!/usr/bin/env bash
  107. set -euo pipefail
  108. echo "Running mutations on changed files since HEAD..."
  109. cargo mutants --in-diff HEAD -vV
  110. # Fuzzing Commands
  111. # Run fuzzing on a specific target
  112. # Usage: just fuzz <target> [duration] [jobs]
  113. # Example: just fuzz fuzz_token
  114. # Example: just fuzz fuzz_token 60
  115. # Example: just fuzz fuzz_token 60 4 (run for 60s on 4 cores)
  116. fuzz TARGET DURATION="0" JOBS="1":
  117. #!/usr/bin/env bash
  118. set -euo pipefail
  119. echo "Running fuzzer on target: {{TARGET}} (jobs: {{JOBS}})"
  120. cd fuzz
  121. # Create corpus directory if it doesn't exist
  122. mkdir -p "corpus/{{TARGET}}"
  123. # Use seeds directory if it exists
  124. SEEDS_DIR=""
  125. if [ -d "seeds/{{TARGET}}" ]; then
  126. SEEDS_DIR="seeds/{{TARGET}}"
  127. fi
  128. FORK_FLAG=""
  129. if [ "{{JOBS}}" != "1" ]; then
  130. FORK_FLAG="-fork={{JOBS}}"
  131. fi
  132. if [ "{{DURATION}}" = "0" ]; then
  133. cargo fuzz run {{TARGET}} corpus/{{TARGET}} $SEEDS_DIR -- $FORK_FLAG
  134. else
  135. cargo fuzz run {{TARGET}} corpus/{{TARGET}} $SEEDS_DIR -- -max_total_time={{DURATION}} $FORK_FLAG
  136. fi
  137. # List available fuzz targets
  138. fuzz-list:
  139. #!/usr/bin/env bash
  140. set -euo pipefail
  141. echo "Available fuzz targets:"
  142. cd fuzz
  143. cargo fuzz list
  144. # Run all fuzz targets for a short duration (useful for CI)
  145. # Usage: just fuzz-ci [duration] [jobs]
  146. # Example: just fuzz-ci 30 4 (run each target for 30s on 4 cores)
  147. fuzz-ci DURATION="30" JOBS="1":
  148. #!/usr/bin/env bash
  149. set -euo pipefail
  150. echo "Running all fuzz targets for {{DURATION}} seconds each (jobs: {{JOBS}})..."
  151. cd fuzz
  152. FORK_FLAG=""
  153. if [ "{{JOBS}}" != "1" ]; then
  154. FORK_FLAG="-fork={{JOBS}}"
  155. fi
  156. for target in $(cargo fuzz list); do
  157. echo "Fuzzing $target..."
  158. mkdir -p "corpus/$target"
  159. SEEDS_DIR=""
  160. if [ -d "seeds/$target" ]; then
  161. SEEDS_DIR="seeds/$target"
  162. fi
  163. cargo fuzz run "$target" "corpus/$target" $SEEDS_DIR -- -max_total_time={{DURATION}} $FORK_FLAG
  164. done
  165. echo "All fuzz targets completed!"
  166. # Run mutation tests only on changed code since HEAD
  167. mutants-diff:
  168. #!/usr/bin/env bash
  169. set -euo pipefail
  170. echo "Running mutation tests on changed code..."
  171. cargo mutants --in-diff HEAD -vV
  172. # Run mutation tests and save output to log file
  173. # Usage: just mutants-log <crate-name> <log-suffix>
  174. # Example: just mutants-log cashu baseline
  175. mutants-log CRATE SUFFIX:
  176. #!/usr/bin/env bash
  177. set -euo pipefail
  178. if [ ! -f Cargo.toml ]; then
  179. cd {{invocation_directory()}}
  180. fi
  181. LOG_FILE="mutants-{{CRATE}}-{{SUFFIX}}.log"
  182. echo "Running mutation tests on {{CRATE}}, saving to $LOG_FILE..."
  183. cargo mutants --package {{CRATE}} -vV 2>&1 | tee "$LOG_FILE"
  184. echo "Results saved to $LOG_FILE"
  185. # Mutation test with baseline comparison
  186. # Usage: just mutants-check <crate-name>
  187. # Example: just mutants-check cashu
  188. mutants-check CRATE:
  189. #!/usr/bin/env bash
  190. set -euo pipefail
  191. BASELINE="mutants-{{CRATE}}-baseline.log"
  192. if [ ! -f "$BASELINE" ]; then
  193. echo "ERROR: No baseline found at $BASELINE"
  194. echo "Run: just mutants-log {{CRATE}} baseline"
  195. exit 1
  196. fi
  197. cargo mutants --package {{CRATE}} -vV | tee mutants-{{CRATE}}-current.log
  198. # Compare results
  199. echo "=== Baseline vs Current ==="
  200. diff <(grep "^CAUGHT\|^MISSED" "$BASELINE" | wc -l) \
  201. <(grep "^CAUGHT\|^MISSED" mutants-{{CRATE}}-current.log | wc -l) || true
  202. test-nutshell:
  203. #!/usr/bin/env bash
  204. set -euo pipefail
  205. # Function to cleanup docker containers
  206. cleanup() {
  207. echo "Cleaning up docker containers..."
  208. docker stop nutshell 2>/dev/null || true
  209. docker rm nutshell 2>/dev/null || true
  210. unset CDK_ITESTS_DIR
  211. }
  212. # Trap to ensure cleanup happens on exit (success or failure)
  213. trap cleanup EXIT
  214. # Clean up any leftover containers from previous runs
  215. docker stop nutshell 2>/dev/null || true
  216. docker rm nutshell 2>/dev/null || true
  217. docker run -d --network=host --name nutshell -e MINT_LIGHTNING_BACKEND=FakeWallet -e MINT_LISTEN_HOST=0.0.0.0 -e MINT_LISTEN_PORT=3338 -e MINT_PRIVATE_KEY=TEST_PRIVATE_KEY -e MINT_INPUT_FEE_PPK=100 cashubtc/nutshell:latest poetry run mint
  218. export CDK_ITESTS_DIR=$(mktemp -d)
  219. # Wait for the Nutshell service to be ready
  220. echo "Waiting for Nutshell to start..."
  221. max_attempts=30
  222. attempt=0
  223. while ! curl -s http://127.0.0.1:3338/v1/info > /dev/null; do
  224. attempt=$((attempt+1))
  225. if [ $attempt -ge $max_attempts ]; then
  226. echo "Nutshell failed to start after $max_attempts attempts"
  227. echo "=== Docker container status ==="
  228. docker ps -a --filter name=nutshell
  229. echo "=== Docker logs ==="
  230. docker logs nutshell 2>&1 || true
  231. exit 1
  232. fi
  233. echo "Waiting for Nutshell to start (attempt $attempt/$max_attempts)..."
  234. # Show container status every 10 attempts
  235. if [ $((attempt % 10)) -eq 0 ]; then
  236. echo "=== Container status check ==="
  237. docker ps -a --filter name=nutshell
  238. fi
  239. sleep 1
  240. done
  241. echo "Nutshell is ready!"
  242. # Set environment variables and run tests
  243. export CDK_TEST_MINT_URL=http://127.0.0.1:3338
  244. export LN_BACKEND=FAKEWALLET
  245. # Track test results
  246. test_exit_code=0
  247. # Run first test and capture exit code
  248. echo "Running happy_path_mint_wallet test..."
  249. if ! cargo test -p cdk-integration-tests --test happy_path_mint_wallet; then
  250. echo "ERROR: happy_path_mint_wallet test failed"
  251. test_exit_code=1
  252. fi
  253. # Run second test and capture exit code
  254. echo "Running test_fees test..."
  255. if ! cargo test -p cdk-integration-tests --test test_fees; then
  256. echo "ERROR: test_fees test failed"
  257. test_exit_code=1
  258. fi
  259. unset CDK_TEST_MINT_URL
  260. unset LN_BACKEND
  261. # Exit with error code if any test failed
  262. if [ $test_exit_code -ne 0 ]; then
  263. echo "One or more tests failed"
  264. exit $test_exit_code
  265. fi
  266. echo "All tests passed successfully"
  267. # run `cargo clippy` on everything
  268. clippy *ARGS="--workspace --all-targets":
  269. cargo clippy {{ARGS}} -- -D warnings
  270. # run `cargo clippy --fix` on everything
  271. clippy-fix *ARGS="--workspace --all-targets":
  272. cargo clippy {{ARGS}} --fix
  273. typos:
  274. typos
  275. # fix all typos
  276. [no-exit-message]
  277. typos-fix:
  278. just typos -w
  279. # run all linting checks (format check, typos, nix format)
  280. lint:
  281. #!/usr/bin/env bash
  282. set -euo pipefail
  283. if [ ! -f Cargo.toml ]; then
  284. cd {{invocation_directory()}}
  285. fi
  286. echo "Checking Rust formatting..."
  287. cargo fmt --all -- --check
  288. echo "Checking Nix formatting..."
  289. nixpkgs-fmt --check $(echo **.nix)
  290. echo "Checking for typos..."
  291. typos
  292. echo "All checks passed!"
  293. # Goose AI Recipe Commands
  294. # Update changelog from staged changes using Goose AI
  295. goose-git-msg:
  296. #!/usr/bin/env bash
  297. set -euo pipefail
  298. goose run --recipe ./misc/recipes/git-commit-message.yaml --interactive
  299. # Create git message from staged changes using Goose AI
  300. goose-changelog-staged:
  301. #!/usr/bin/env bash
  302. set -euo pipefail
  303. goose run --recipe ./misc/recipes/changelog-update.yaml --interactive
  304. # Update changelog from recent commits using Goose AI
  305. # Usage: just goose-changelog-commits [number_of_commits]
  306. goose-changelog-commits *COMMITS="5":
  307. #!/usr/bin/env bash
  308. set -euo pipefail
  309. COMMITS={{COMMITS}} goose run --recipe ./misc/recipes/changelog-from-commits.yaml --interactive
  310. itest db:
  311. #!/usr/bin/env bash
  312. set -euo pipefail
  313. bash ./misc/itests.sh "{{db}}"
  314. fake-mint-itest db:
  315. #!/usr/bin/env bash
  316. set -euo pipefail
  317. bash ./misc/fake_itests.sh "{{db}}"
  318. bash ./misc/fake_itests.sh "{{db}}" external_signatory
  319. itest-payment-processor ln:
  320. #!/usr/bin/env bash
  321. set -euo pipefail
  322. bash ./misc/mintd_payment_processor.sh "{{ln}}"
  323. fake-auth-mint-itest db openid_discovery:
  324. #!/usr/bin/env bash
  325. set -euo pipefail
  326. bash ./misc/fake_auth_itests.sh "{{db}}" "{{openid_discovery}}"
  327. nutshell-wallet-itest:
  328. #!/usr/bin/env bash
  329. set -euo pipefail
  330. bash ./misc/nutshell_wallet_itest.sh
  331. # Start interactive regtest environment (Bitcoin + 4 LN nodes + 2 CDK mints)
  332. regtest db="sqlite":
  333. #!/usr/bin/env bash
  334. set -euo pipefail
  335. bash ./misc/interactive_regtest_mprocs.sh {{db}}
  336. # Lightning Network Commands (require regtest environment to be running)
  337. # Get CLN node 1 info
  338. ln-cln1 *ARGS:
  339. #!/usr/bin/env bash
  340. set -euo pipefail
  341. bash ./misc/regtest_helper.sh ln-cln1 {{ARGS}}
  342. # Get CLN node 2 info
  343. ln-cln2 *ARGS:
  344. #!/usr/bin/env bash
  345. set -euo pipefail
  346. bash ./misc/regtest_helper.sh ln-cln2 {{ARGS}}
  347. # Get LND node 1 info
  348. ln-lnd1 *ARGS:
  349. #!/usr/bin/env bash
  350. set -euo pipefail
  351. bash ./misc/regtest_helper.sh ln-lnd1 {{ARGS}}
  352. # Get LND node 2 info
  353. ln-lnd2 *ARGS:
  354. #!/usr/bin/env bash
  355. set -euo pipefail
  356. bash ./misc/regtest_helper.sh ln-lnd2 {{ARGS}}
  357. # Bitcoin regtest commands
  358. btc *ARGS:
  359. #!/usr/bin/env bash
  360. set -euo pipefail
  361. bash ./misc/regtest_helper.sh btc {{ARGS}}
  362. # Mine blocks in regtest
  363. btc-mine blocks="10":
  364. #!/usr/bin/env bash
  365. set -euo pipefail
  366. bash ./misc/regtest_helper.sh btc-mine {{blocks}}
  367. # Show mint information
  368. mint-info:
  369. #!/usr/bin/env bash
  370. set -euo pipefail
  371. bash ./misc/regtest_helper.sh mint-info
  372. # Run integration tests against regtest environment
  373. mint-test:
  374. #!/usr/bin/env bash
  375. set -euo pipefail
  376. bash ./misc/regtest_helper.sh mint-test
  377. # Restart mints after recompiling (useful for development)
  378. restart-mints:
  379. #!/usr/bin/env bash
  380. set -euo pipefail
  381. bash ./misc/regtest_helper.sh restart-mints
  382. # Show regtest environment status
  383. regtest-status:
  384. #!/usr/bin/env bash
  385. set -euo pipefail
  386. bash ./misc/regtest_helper.sh show-status
  387. # Show regtest environment logs
  388. regtest-logs:
  389. #!/usr/bin/env bash
  390. set -euo pipefail
  391. bash ./misc/regtest_helper.sh show-logs
  392. run-examples:
  393. cargo r --example p2pk
  394. cargo r --example mint-token
  395. cargo r --example melt-token
  396. cargo r --example proof_selection
  397. cargo r --example wallet
  398. check-wasm *ARGS="--target wasm32-unknown-unknown":
  399. #!/usr/bin/env bash
  400. set -euo pipefail
  401. if [ ! -f Cargo.toml ]; then
  402. cd {{invocation_directory()}}
  403. fi
  404. buildargs=(
  405. "-p cdk"
  406. "-p cdk --no-default-features"
  407. "-p cdk --no-default-features --features wallet"
  408. "-p cdk --no-default-features --features mint"
  409. )
  410. for arg in "${buildargs[@]}"; do
  411. echo "Checking '$arg'"
  412. cargo check $arg {{ARGS}}
  413. echo
  414. done
  415. release m="":
  416. #!/usr/bin/env bash
  417. set -euo pipefail
  418. args=(
  419. "-p cashu"
  420. "-p cdk-prometheus"
  421. "-p cdk-common"
  422. "-p cdk-sql-common"
  423. "-p cdk-sqlite"
  424. "-p cdk-postgres"
  425. "-p cdk-redb"
  426. "-p cdk-signatory"
  427. "-p cdk-fake-wallet"
  428. "-p cdk"
  429. "-p cdk-ffi"
  430. "-p cdk-axum"
  431. "-p cdk-mint-rpc"
  432. "-p cdk-cln"
  433. "-p cdk-lnd"
  434. "-p cdk-lnbits"
  435. "-p cdk-ldk-node"
  436. "-p cdk-payment-processor"
  437. "-p cdk-cli"
  438. "-p cdk-mintd"
  439. )
  440. for arg in "${args[@]}";
  441. do
  442. echo "Publishing '$arg'"
  443. cargo publish $arg {{m}}
  444. echo
  445. done
  446. # Extract version from the cdk-ffi crate
  447. VERSION=$(cargo metadata --format-version 1 --no-deps | jq -r '.packages[] | select(.name == "cdk-ffi") | .version')
  448. # Trigger Swift package release after Rust crates are published
  449. echo "📦 Triggering Swift package release for version $VERSION..."
  450. just ffi-release-swift $VERSION
  451. check-docs:
  452. #!/usr/bin/env bash
  453. set -euo pipefail
  454. args=(
  455. "-p cashu"
  456. "-p cdk-common"
  457. "-p cdk-sql-common"
  458. "-p cdk"
  459. "-p cdk-redb"
  460. "-p cdk-sqlite"
  461. "-p cdk-postgres"
  462. "-p cdk-axum"
  463. "-p cdk-cln"
  464. "-p cdk-lnd"
  465. "-p cdk-lnbits"
  466. "-p cdk-ldk-node"
  467. "-p cdk-fake-wallet"
  468. "-p cdk-mint-rpc"
  469. "-p cdk-npubcash"
  470. "-p cdk-prometheus"
  471. "-p cdk-payment-processor"
  472. "-p cdk-signatory"
  473. "-p cdk-cli"
  474. "-p cdk-mintd"
  475. "-p cdk-ffi"
  476. )
  477. for arg in "${args[@]}"; do
  478. echo "Checking '$arg' docs"
  479. cargo doc $arg --all-features
  480. echo
  481. done
  482. # Build docs for all crates and error on warnings
  483. docs-strict:
  484. #!/usr/bin/env bash
  485. set -euo pipefail
  486. args=(
  487. "-p cashu"
  488. "-p cdk-common"
  489. "-p cdk-sql-common"
  490. "-p cdk"
  491. "-p cdk-redb"
  492. "-p cdk-sqlite"
  493. "-p cdk-postgres"
  494. "-p cdk-axum"
  495. "-p cdk-cln"
  496. "-p cdk-lnd"
  497. "-p cdk-lnbits"
  498. "-p cdk-ldk-node"
  499. "-p cdk-fake-wallet"
  500. "-p cdk-mint-rpc"
  501. "-p cdk-npubcash"
  502. "-p cdk-prometheus"
  503. "-p cdk-payment-processor"
  504. "-p cdk-signatory"
  505. "-p cdk-cli"
  506. "-p cdk-mintd"
  507. "-p cdk-ffi"
  508. )
  509. for arg in "${args[@]}"; do
  510. echo "Building docs for $arg with strict warnings"
  511. RUSTDOCFLAGS="-D warnings" cargo doc $arg --all-features --no-deps
  512. echo
  513. done
  514. # =============================================================================
  515. # FFI Commands - CDK Foreign Function Interface bindings
  516. # =============================================================================
  517. # Helper function to get library extension based on platform
  518. _ffi-lib-ext:
  519. #!/usr/bin/env bash
  520. if [[ "$OSTYPE" == "darwin"* ]]; then
  521. echo "dylib"
  522. else
  523. echo "so"
  524. fi
  525. # Build the FFI library
  526. ffi-build *ARGS="--release":
  527. cargo build {{ARGS}} --package cdk-ffi --features postgres
  528. # Generate bindings for a specific language
  529. ffi-generate LANGUAGE *ARGS="--release": ffi-build
  530. #!/usr/bin/env bash
  531. set -euo pipefail
  532. LANG="{{LANGUAGE}}"
  533. # Validate language
  534. case "$LANG" in
  535. python|swift|kotlin)
  536. ;;
  537. *)
  538. echo "❌ Unsupported language: $LANG"
  539. echo "Supported languages: python, swift, kotlin"
  540. exit 1
  541. ;;
  542. esac
  543. # Set emoji and build type
  544. case "$LANG" in
  545. python) EMOJI="🐍" ;;
  546. swift) EMOJI="🍎" ;;
  547. kotlin) EMOJI="🎯" ;;
  548. esac
  549. # Determine build type and library path
  550. if [[ "{{ARGS}}" == *"--release"* ]] || [[ "{{ARGS}}" == "" ]]; then
  551. BUILD_TYPE="release"
  552. else
  553. BUILD_TYPE="debug"
  554. cargo build --package cdk-ffi --features postgres
  555. fi
  556. LIB_EXT=$(just _ffi-lib-ext)
  557. echo "$EMOJI Generating $LANG bindings..."
  558. mkdir -p target/bindings/$LANG
  559. cargo run --bin uniffi-bindgen generate \
  560. --library target/$BUILD_TYPE/libcdk_ffi.$LIB_EXT \
  561. --language $LANG \
  562. --out-dir target/bindings/$LANG
  563. echo "✅ $LANG bindings generated in target/bindings/$LANG/"
  564. # Generate Python bindings (shorthand)
  565. ffi-generate-python *ARGS="--release":
  566. just ffi-generate python {{ARGS}}
  567. # Generate Swift bindings (shorthand)
  568. ffi-generate-swift *ARGS="--release":
  569. just ffi-generate swift {{ARGS}}
  570. # Generate Kotlin bindings (shorthand)
  571. ffi-generate-kotlin *ARGS="--release":
  572. just ffi-generate kotlin {{ARGS}}
  573. # Generate bindings for all supported languages
  574. ffi-generate-all *ARGS="--release": ffi-build
  575. @echo "🔧 Generating UniFFI bindings for all languages..."
  576. just ffi-generate python {{ARGS}}
  577. just ffi-generate swift {{ARGS}}
  578. just ffi-generate kotlin {{ARGS}}
  579. @echo "✅ All bindings generated successfully!"
  580. # Run Python FFI tests
  581. ffi-test: ffi-generate-python
  582. #!/usr/bin/env bash
  583. set -euo pipefail
  584. echo "🧪 Running Python FFI tests..."
  585. python3 crates/cdk-ffi/tests/test_transactions.py
  586. python3 crates/cdk-ffi/tests/test_kvstore.py
  587. echo "✅ Tests completed!"
  588. # Build debug version and generate Python bindings quickly (for development)
  589. ffi-dev-python:
  590. #!/usr/bin/env bash
  591. set -euo pipefail
  592. # Generate Python bindings first
  593. just ffi-generate python --debug
  594. # Copy library to Python bindings directory
  595. LIB_EXT=$(just _ffi-lib-ext)
  596. echo "📦 Copying library to Python bindings directory..."
  597. cp target/debug/libcdk_ffi.$LIB_EXT target/bindings/python/
  598. # Launch Python REPL with CDK FFI loaded
  599. cd target/bindings/python
  600. echo "🐍 Launching Python REPL with CDK FFI library loaded..."
  601. echo "💡 The 'cdk_ffi' module is pre-imported and ready to use!"
  602. python3 -i -c "from cdk_ffi import *; print('✅ CDK FFI library loaded successfully!');"
  603. # Test language bindings with a simple import
  604. ffi-test-bindings LANGUAGE: (ffi-generate LANGUAGE "--debug")
  605. #!/usr/bin/env bash
  606. set -euo pipefail
  607. LANG="{{LANGUAGE}}"
  608. LIB_EXT=$(just _ffi-lib-ext)
  609. echo "📦 Copying library to $LANG bindings directory..."
  610. cp target/debug/libcdk_ffi.$LIB_EXT target/bindings/$LANG/
  611. cd target/bindings/$LANG
  612. echo "🧪 Testing $LANG bindings..."
  613. case "$LANG" in
  614. python)
  615. python3 -c "import cdk_ffi; print('✅ Python bindings work!')"
  616. ;;
  617. *)
  618. echo "✅ $LANG bindings generated (manual testing required)"
  619. ;;
  620. esac
  621. # Test Python bindings (shorthand)
  622. ffi-test-python:
  623. just ffi-test-bindings python
  624. # Trigger Swift Package release workflow
  625. ffi-release-swift VERSION:
  626. #!/usr/bin/env bash
  627. set -euo pipefail
  628. echo "🚀 Triggering Publish Swift Package workflow..."
  629. echo " Version: {{VERSION}}"
  630. echo " CDK Ref: v{{VERSION}}"
  631. # Trigger the workflow using GitHub CLI
  632. gh workflow run "Publish Swift Package" \
  633. --repo cashubtc/cdk-swift \
  634. --field version="{{VERSION}}" \
  635. --field cdk_repo="cashubtc/cdk" \
  636. --field cdk_ref="v{{VERSION}}"
  637. echo "✅ Workflow triggered successfully!"