diff --git a/Justfile b/Justfile index d65b7bfc..abeacb92 100644 --- a/Justfile +++ b/Justfile @@ -1,16 +1,29 @@ # export RUST_BACKTRACE := "short" -macro_backtrace := 'RUSTC_BOOTSTRAP=1 RUSTFLAGS="-Zmacro-backtrace"' +export RUSTC_BOOTSTRAP := "1" +export RUSTFLAGS := "-Z macro-backtrace" +export SQLX_OFFLINE := "true" + +flags_for_js := "RUSTFLAGS='-Z macro-backtrace --cfg getrandom_backend=\"wasm_js\"'" all *ARGS: fmt (test ARGS) clippy udeps doc run-example-basic-server *ARGS: createdb basic-crdb || true - sqlx migrate run --source crdb-postgres/migrations --database-url "postgres:///basic-crdb" - CARGO_TARGET_DIR="target/host" {{macro_backtrace}} watchexec -r -e rs,toml -E RUST_LOG="trace,tokio_tungstenite=debug,tungstenite=debug" --workdir examples/basic cargo run -p basic-server -- {{ARGS}} + sqlx migrate run \ + --source crdb-postgres/migrations \ + --database-url "postgres:///basic-crdb" + CARGO_TARGET_DIR="target/host" \ + watchexec -r -e rs,toml \ + -E RUST_LOG="trace,tokio_tungstenite=debug,tungstenite=debug" \ + --workdir examples/basic \ + cargo run -p basic-server -- {{ARGS}} serve-example-basic-client-js *ARGS: - CARGO_TARGET_DIR="../target/wasm" {{macro_backtrace}} watchexec -r -e rs,toml,html --workdir examples/basic/client-js trunk serve + CARGO_TARGET_DIR="../target/wasm" \ + watchexec -r -e rs,toml,html \ + --workdir examples/basic/client-js \ + trunk serve fmt: cargo fmt @@ -21,48 +34,62 @@ test *ARGS: (test-crate ARGS) (test-example-basic ARGS) test-standalone *ARGS: (test-crate-native "--exclude" "crdb-postgres" ARGS) (test-example-basic ARGS) clippy: - CARGO_TARGET_DIR="target/clippy" SQLX_OFFLINE="true" cargo clippy --all-features -- -D warnings + CARGO_TARGET_DIR="target/clippy" \ + cargo clippy --all-features -- -D warnings udeps: - RUSTC_BOOTSTRAP=1 \ CARGO_TARGET_DIR="target/udeps" \ - SQLX_OFFLINE="true" \ - cargo udeps --workspace --all-features - RUSTC_BOOTSTRAP=1 \ + cargo udeps --workspace --all-features CARGO_TARGET_DIR="target/udeps" \ - SQLX_OFFLINE="true" \ - RUSTFLAGS='--cfg getrandom_backend="wasm_js"' \ - cargo udeps --workspace \ - --exclude crdb-postgres --exclude crdb-server --exclude crdb-sqlite \ - --target wasm32-unknown-unknown + {{flags_for_js}} \ + cargo udeps --workspace \ + --exclude crdb-postgres \ + --exclude crdb-server \ + --exclude crdb-sqlite \ + --target wasm32-unknown-unknown udeps-full: - RUSTC_BOOTSTRAP=1 \ CARGO_TARGET_DIR="target/udeps" \ - SQLX_OFFLINE="true" \ - cargo hack udeps --each-feature - RUSTC_BOOTSTRAP=1 \ + cargo hack udeps --each-feature + + CARGO_TARGET_DIR="target/udeps" \ + cargo hack udeps --tests --each-feature + CARGO_TARGET_DIR="target/udeps" \ - SQLX_OFFLINE="true" \ - cargo hack udeps --tests --each-feature - RUSTC_BOOTSTRAP=1 \ + {{flags_for_js}} \ + cargo hack udeps --each-feature \ + --workspace \ + --exclude crdb-postgres \ + --exclude crdb-server \ + --exclude crdb-sqlite \ + --exclude-features server,sqlx-postgres,sqlx-sqlite,_tests \ + --target wasm32-unknown-unknown + CARGO_TARGET_DIR="target/udeps" \ - SQLX_OFFLINE="true" \ - RUSTFLAGS='--cfg getrandom_backend="wasm_js"' \ - cargo udeps --workspace \ - --exclude crdb-postgres --exclude crdb-server --exclude crdb-sqlite \ - --target wasm32-unknown-unknown + {{flags_for_js}} \ + cargo hack udeps --tests --each-feature \ + --workspace \ + --exclude crdb-postgres \ + --exclude crdb-server \ + --exclude crdb-sqlite \ + --exclude-features server,sqlx-postgres,sqlx-sqlite \ + --target wasm32-unknown-unknown doc: - CARGO_TARGET_DIR="target/doc" SQLX_OFFLINE="true" cargo doc --all-features --workspace + CARGO_TARGET_DIR="target/doc" \ + cargo doc --all-features --workspace make-test-db: dropdb crdb-test || true createdb crdb-test - sqlx migrate run --source crdb-postgres/migrations --database-url "postgres:///crdb-test" + sqlx migrate run \ + --source crdb-postgres/migrations \ + --database-url "postgres:///crdb-test" rebuild-offline-queries: make-test-db - cargo sqlx prepare --database-url "postgres:///crdb-test" -- --all-features --tests + cargo sqlx prepare \ + --database-url "postgres:///crdb-test" -- \ + --all-features --tests list-todo-types: rg 'TODO\(' | grep -v Justfile | sed 's/^.*TODO(//;s/).*$//' | sort | uniq -c || true @@ -76,10 +103,10 @@ clean: test-crate *ARGS: (test-crate-native ARGS) (test-crate-wasm32 ARGS) test-crate-native *ARGS: - SQLX_OFFLINE="true" cargo nextest run --workspace --all-features {{ARGS}} + cargo nextest run --workspace --all-features {{ARGS}} test-crate-wasm32 *ARGS: - RUSTFLAGS='--cfg getrandom_backend="wasm_js"' \ + {{flags_for_js}} \ cargo test -p crdb-indexed-db \ --features _tests \ --target wasm32-unknown-unknown \ @@ -90,14 +117,19 @@ test-example-basic *ARGS: build-example-basic-client (test-example-basic-host AR build-example-basic-client: cd examples/basic && \ CARGO_TARGET_DIR="target/wasm" \ - RUSTFLAGS='--cfg getrandom_backend="wasm_js"' \ - {{macro_backtrace}} \ + {{flags_for_js}} \ cargo build \ -p basic-client-js \ --target wasm32-unknown-unknown test-example-basic-host *ARGS: - cd examples/basic && CARGO_TARGET_DIR="target/host" {{macro_backtrace}} cargo nextest run -p basic-api -p basic-server -p basic-client-native --no-tests=pass {{ARGS}} + cd examples/basic && \ + CARGO_TARGET_DIR="target/host" \ + cargo nextest run \ + --workspace \ + --exclude basic-client-js \ + --no-tests=pass \ + {{ARGS}} fuzz-pg-simple ARGS='': cargo bolero test \ @@ -110,7 +142,7 @@ fuzz-idb-simple ARGS='': # TODO(blocked): remove path override, when https://github.com/rustwasm/wasm-bindgen/pull/3800 lands? PATH="../wasm-bindgen/target/debug:$PATH" \ WASM_BINDGEN_TEST_TIMEOUT=86400 \ - RUSTFLAGS='--cfg getrandom_backend="wasm_js"' \ + {{flags_for_js}} \ cargo test \ -p crdb-indexed-db \ --target wasm32-unknown-unknown \ @@ -131,7 +163,7 @@ fuzz-idb-perms ARGS='': # TODO(blocked): remove path override, when https://github.com/rustwasm/wasm-bindgen/pull/3800 lands? PATH="../wasm-bindgen/target/debug:$PATH" \ WASM_BINDGEN_TEST_TIMEOUT=86400 \ - RUSTFLAGS='--cfg getrandom_backend="wasm_js"' \ + {{flags_for_js}} \ cargo test \ -p crdb-indexed-db \ --target wasm32-unknown-unknown \ @@ -166,7 +198,7 @@ fuzz-idb-full ARGS='': # TODO(blocked): remove path override, when https://github.com/rustwasm/wasm-bindgen/pull/3800 lands? PATH="../wasm-bindgen/target/debug:$PATH" \ WASM_BINDGEN_TEST_TIMEOUT=86400 \ - RUSTFLAGS='--cfg getrandom_backend="wasm_js"' \ + {{flags_for_js}} \ cargo test \ -p crdb-indexed-db \ --target wasm32-unknown-unknown \ diff --git a/crdb-client/Cargo.toml b/crdb-client/Cargo.toml index 17a0e767..a31f9924 100644 --- a/crdb-client/Cargo.toml +++ b/crdb-client/Cargo.toml @@ -11,6 +11,7 @@ anyhow.workspace = true async-stream.workspace = true educe.workspace = true futures.workspace = true +getrandom.workspace = true serde_json.workspace = true tokio.workspace = true tokio-util.workspace = true diff --git a/crdb-core/Cargo.toml b/crdb-core/Cargo.toml index 7c07c346..411d5b9c 100644 --- a/crdb-core/Cargo.toml +++ b/crdb-core/Cargo.toml @@ -6,7 +6,7 @@ edition = "2021" [features] arbitrary = ["dep:arbitrary", "arbitrary-json", "rust_decimal/rust-fuzz"] indexed-db = ["dep:indexed-db", "serde-wasm-bindgen", "web-sys"] -server = ["axum", "getrandom", "rand", "sqlx-postgres"] +server = ["axum", "rand", "sqlx-postgres"] sqlx-postgres = ["sqlx", "sqlx/postgres", "sqlx/uuid", "uuid"] sqlx-sqlite = ["sqlx", "sqlx/sqlite", "sqlx/uuid", "uuid"] uuid = ["dep:uuid"] @@ -16,6 +16,7 @@ anyhow.workspace = true bitflags.workspace = true deepsize.workspace = true educe.workspace = true +getrandom.workspace = true icu_casemap.workspace = true icu_normalizer.workspace = true icu_properties.workspace = true @@ -35,7 +36,6 @@ writeable.workspace = true arbitrary = { workspace = true, optional = true } arbitrary-json = { workspace = true, optional = true } axum = { workspace = true, optional = true } -getrandom = { workspace = true, optional = true } indexed-db = { workspace = true, optional = true } rand = { workspace = true, optional = true } serde-wasm-bindgen = { workspace = true, optional = true } diff --git a/crdb-helpers/Cargo.toml b/crdb-helpers/Cargo.toml index 417e7b66..6d2fd7b5 100644 --- a/crdb-helpers/Cargo.toml +++ b/crdb-helpers/Cargo.toml @@ -4,18 +4,12 @@ version = "0.1.0" edition = "2021" [features] -js = [ - "crdb-core/indexed-db", - "getrandom-0-2/js", - "serde-wasm-bindgen", - "wasm-bindgen", -] +js = ["crdb-core/indexed-db", "serde-wasm-bindgen", "wasm-bindgen"] [dependencies] crdb-core.workspace = true anyhow.workspace = true -getrandom-0-2.workspace = true serde_json.workspace = true serde-wasm-bindgen = { workspace = true, optional = true } diff --git a/crdb-indexed-db/Cargo.toml b/crdb-indexed-db/Cargo.toml index ee812822..10592ccd 100644 --- a/crdb-indexed-db/Cargo.toml +++ b/crdb-indexed-db/Cargo.toml @@ -10,6 +10,7 @@ _tests = [ "console_error_panic_hook", "crdb-test-utils", "getrandom", + "getrandom-0-2/js", "rand", "rand-0-8", "tracing-wasm", @@ -39,6 +40,7 @@ arbitrary = { workspace = true, optional = true } bolero = { workspace = true, optional = true } console_error_panic_hook = { workspace = true, optional = true } getrandom = { workspace = true, optional = true } +getrandom-0-2 = { workspace = true, optional = true } rand = { workspace = true, optional = true } rand-0-8 = { workspace = true, optional = true } tracing-wasm = { workspace = true, optional = true } diff --git a/crdb-postgres/Cargo.toml b/crdb-postgres/Cargo.toml index 0f500aa5..12f907e4 100644 --- a/crdb-postgres/Cargo.toml +++ b/crdb-postgres/Cargo.toml @@ -13,6 +13,7 @@ crdb-helpers.workspace = true anyhow.workspace = true futures.workspace = true +getrandom.workspace = true lockable.workspace = true reord.workspace = true serde_json.workspace = true diff --git a/crdb-server/Cargo.toml b/crdb-server/Cargo.toml index 83404be4..8e694606 100644 --- a/crdb-server/Cargo.toml +++ b/crdb-server/Cargo.toml @@ -14,6 +14,7 @@ bytes.workspace = true chrono.workspace = true cron.workspace = true futures.workspace = true +getrandom.workspace = true serde.workspace = true serde_json.workspace = true sqlx.workspace = true diff --git a/crdb-sqlite/Cargo.toml b/crdb-sqlite/Cargo.toml index d0bd8d2e..494aedf3 100644 --- a/crdb-sqlite/Cargo.toml +++ b/crdb-sqlite/Cargo.toml @@ -7,6 +7,7 @@ edition = "2021" crdb-core = { workspace = true, features = ["sqlx-sqlite"] } anyhow.workspace = true +getrandom.workspace = true serde_json.workspace = true sqlx = { workspace = true, features = ["sqlite", "uuid"] } ulid.workspace = true diff --git a/crdb-test-utils/Cargo.toml b/crdb-test-utils/Cargo.toml index dbd3c7fc..c103291c 100644 --- a/crdb-test-utils/Cargo.toml +++ b/crdb-test-utils/Cargo.toml @@ -12,6 +12,7 @@ arbitrary.workspace = true deepsize.workspace = true educe.workspace = true futures.workspace = true +getrandom.workspace = true paste.workspace = true rust_decimal.workspace = true serde.workspace = true diff --git a/crdb/Cargo.toml b/crdb/Cargo.toml index 961da7c0..e387a32a 100644 --- a/crdb/Cargo.toml +++ b/crdb/Cargo.toml @@ -20,6 +20,3 @@ crdb-macros.workspace = true crdb-client = { workspace = true, optional = true } crdb-indexed-db = { workspace = true, optional = true } crdb-server = { workspace = true, optional = true } - -[dev-dependencies] -getrandom-0-2 = { workspace = true, features = ["js"] } diff --git a/examples/basic/client-js/Cargo.toml b/examples/basic/client-js/Cargo.toml index 75f28686..2e0a1ef0 100644 --- a/examples/basic/client-js/Cargo.toml +++ b/examples/basic/client-js/Cargo.toml @@ -9,6 +9,7 @@ chrono = "0.4.34" console_error_panic_hook = "0.1.7" crdb = { path = "../../../crdb", features = ["client", "indexed-db"] } futures = "0.3.30" +getrandom = { version = "0.3.1", features = ["wasm_js"] } gloo-net = "0.5.0" serde_json = "1.0" tracing = "0.1.40"