From 1b1af0cdd0cf221e2706430f05242757a9574604 Mon Sep 17 00:00:00 2001 From: Yuki Kishimoto Date: Mon, 23 Dec 2024 13:11:05 +0100 Subject: [PATCH] Replace `build.rs` with `generate.rs` Add `generate.sh` script --- contrib/scripts/generate.sh | 10 +++++++ contrib/scripts/precommit.sh | 1 + justfile | 3 --- rust/Cargo.lock | 48 +++++++++++++++------------------- rust/Cargo.toml | 13 ++++++--- rust/{build.rs => generate.rs} | 2 -- 6 files changed, 42 insertions(+), 35 deletions(-) create mode 100755 contrib/scripts/generate.sh rename rust/{build.rs => generate.rs} (90%) diff --git a/contrib/scripts/generate.sh b/contrib/scripts/generate.sh new file mode 100755 index 0000000..d45f4f3 --- /dev/null +++ b/contrib/scripts/generate.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +set -euo pipefail + +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" +RUST_DIR="${SCRIPT_DIR}/../../rust" + +cd "${RUST_DIR}" + +cargo run --bin generate --features codegen diff --git a/contrib/scripts/precommit.sh b/contrib/scripts/precommit.sh index f04d8a3..f7da722 100755 --- a/contrib/scripts/precommit.sh +++ b/contrib/scripts/precommit.sh @@ -4,6 +4,7 @@ set -exuo pipefail DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +"${DIR}/generate.sh" # Generate dart output "${DIR}/check-fmt.sh" # Format the code "${DIR}/check-crate.sh" # Check crate "${DIR}/check-flutter.sh" # Check flutter diff --git a/justfile b/justfile index f9ff5d6..9d96016 100755 --- a/justfile +++ b/justfile @@ -4,9 +4,6 @@ set windows-shell := ["powershell.exe", "-NoLogo", "-Command"] default: @just --list -build: - cd rust && cargo build - precommit: @bash contrib/scripts/precommit.sh diff --git a/rust/Cargo.lock b/rust/Cargo.lock index cd82f5b..ac24b70 100644 --- a/rust/Cargo.lock +++ b/rust/Cargo.lock @@ -763,9 +763,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.22" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69371e34337c4c984bbe322360c2547210bf632eb2814bbe78a6e87a2935bd2b" +checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" dependencies = [ "clap_builder", "clap_derive", @@ -773,9 +773,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.22" +version = "4.5.23" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "6e24c1b4099818523236a8ca881d2b45db98dadfb4625cf6608c12069fcbbde1" +checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" dependencies = [ "anstream", "anstyle", @@ -797,9 +797,9 @@ dependencies = [ [[package]] name = "clap_lex" -version = "0.7.3" +version = "0.7.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "afb84c814227b90d6895e01398aee0d8033c00e7466aca416fb6a8e0eb19d8a7" +checksum = "f46ad14479a25103f283c0f10005961cf086d8dc42205bb44c46ac563475dca6" [[package]] name = "coarsetime" @@ -840,15 +840,15 @@ dependencies = [ [[package]] name = "console" -version = "0.15.8" +version = "0.15.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "0e1f83fc076bd6dd27517eacdf25fef6c4dfe5f1d7448bafaaf3a26f13b5e4eb" +checksum = "ea3c6ecd8059b57859df5c69830340ed3c41d30e3da0c1cbed90a96ac853041b" dependencies = [ "encode_unicode", - "lazy_static", "libc", - "unicode-width 0.1.14", - "windows-sys 0.52.0", + "once_cell", + "unicode-width", + "windows-sys 0.59.0", ] [[package]] @@ -905,9 +905,9 @@ dependencies = [ [[package]] name = "crossbeam-channel" -version = "0.5.13" +version = "0.5.14" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "33480d6946193aa8033910124896ca395333cae7e2d1113d1fef6c3272217df2" +checksum = "06ba6d68e24814cb8de6bb986db8222d3a027d15872cabc0d18817bc3c0e4471" dependencies = [ "crossbeam-utils", ] @@ -1380,9 +1380,9 @@ dependencies = [ [[package]] name = "encode_unicode" -version = "0.3.6" +version = "1.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a357d28ed41a50f9c765dbfe56cbc04a64e53e5fc58ba79fbc34c10ef3df831f" +checksum = "34aa73646ffb006b8f5147f3dc182bd4bcb190227ce861fc4a4844bf8e3cb2c0" [[package]] name = "enum-iterator" @@ -1480,9 +1480,9 @@ checksum = "7360491ce676a36bf9bb3c56c1aa791658183a54d2744120f27285738d90465a" [[package]] name = "fastrand" -version = "2.2.0" +version = "2.3.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "486f806e73c5707928240ddc295403b1b93c96a02038563881c4a2fd84b81ac4" +checksum = "37909eebbb50d72f9059c3b6d82c0463f2ff062c9e95845c43a6c9c0355411be" [[package]] name = "fern" @@ -2309,7 +2309,7 @@ dependencies = [ "console", "number_prefix", "portable-atomic", - "unicode-width 0.2.0", + "unicode-width", "web-time", ] @@ -3576,15 +3576,15 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.41" +version = "0.38.42" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d7f649912bc1495e167a6edee79151c84b1bad49748cb4f1f1167f459f6224f6" +checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" dependencies = [ "bitflags 2.6.0", "errno", "libc", "linux-raw-sys", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -5399,12 +5399,6 @@ dependencies = [ "tinyvec", ] -[[package]] -name = "unicode-width" -version = "0.1.14" -source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7dd6e30e90baa6f72411720665d41d89b9a3d039dc45b8faea1ddd07f617f6af" - [[package]] name = "unicode-width" version = "0.2.0" diff --git a/rust/Cargo.toml b/rust/Cargo.toml index 3dd9c9f..0169397 100644 --- a/rust/Cargo.toml +++ b/rust/Cargo.toml @@ -7,14 +7,21 @@ publish = false [lib] crate-type = ["cdylib", "staticlib"] +[[bin]] +name = "generate" +path = "generate.rs" +required-features = ["codegen"] + +[features] +default = [] +codegen = ["dep:flutter_rust_bridge_codegen"] + [dependencies] anyhow = "1.0" flutter_rust_bridge = "=2.0.0" +flutter_rust_bridge_codegen = { version = "=2.0.0", optional = true } nostr-sdk = { git = "https://github.com/rust-nostr/nostr", rev = "3b988fb13e0ea39c13dad116bd63333ea5d2bc36", default-features = false, features = ["all-nips", "tor"] } -[build-dependencies] -flutter_rust_bridge_codegen = "=2.0.0" - [profile.release] opt-level = 'z' # Optimize for size. lto = true # Enable Link Time Optimization diff --git a/rust/build.rs b/rust/generate.rs similarity index 90% rename from rust/build.rs rename to rust/generate.rs index f0b421d..8a71241 100644 --- a/rust/build.rs +++ b/rust/generate.rs @@ -6,8 +6,6 @@ use lib_flutter_rust_bridge_codegen::codegen; use lib_flutter_rust_bridge_codegen::codegen::Config; fn main() { - println!("cargo:rerun-if-changed=src/api"); - // Execute code generator with auto-detected config codegen::generate( Config::from_config_file("../flutter_rust_bridge.yaml")