justfile 20 KB

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