From 71396186edb4935e2149d85bc33836779964f106 Mon Sep 17 00:00:00 2001 From: Anton Yemelyanov Date: Tue, 9 Jan 2024 05:40:22 +0200 Subject: [PATCH] wip - lints + CI --- .github/workflows/ci.yaml | 93 ++++++++++++++++++++++++++++++++++++--- Cargo.toml | 14 +++--- core/src/core.rs | 27 +++++++----- core/src/imports.rs | 2 +- core/src/modules/mod.rs | 2 +- 5 files changed, 113 insertions(+), 25 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 96fa1bd..0da938e 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -251,14 +251,65 @@ jobs: # build wasm-pack build --target web --out-name kaspa-ng --out-dir ../../dist-chrome ./extensions/chrome + # build-release: + # name: Ubuntu Release + # runs-on: ubuntu-latest + # steps: + + # - name: Install desktop dependencies + # run: | + # sudo apt install -y libglib2.0-dev libatk1.0-dev libgtk-3-dev + + # - name: Checkout sources + # uses: actions/checkout@v3 + + # - name: Install Protoc + # uses: arduino/setup-protoc@v1 + # with: + # repo-token: ${{ secrets.GITHUB_TOKEN }} + + # - name: Install stable toolchain + # uses: dtolnay/rust-toolchain@stable + + # - name: Cache + # uses: actions/cache@v3 + # with: + # path: | + # ~/.cargo/bin/ + # ~/.cargo/registry/index/ + # ~/.cargo/registry/cache/ + # ~/.cargo/git/db/ + # target/ + # key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} + + # - name: Install zig + # if: runner.os == 'Linux' + # uses: goto-bus-stop/setup-zig@v2 # needed for cargo-zigbuild + + # - name: Build on Linux + # if: runner.os == 'Linux' + # # We're using musl to make the binaries statically linked and portable + # run: | + # cargo install cargo-zigbuild + # cargo --verbose zigbuild --release --target x86_64-unknown-linux-gnu.2.27 # Use an older glibc version build-release: - name: Ubuntu Release - runs-on: ubuntu-latest + runs-on: ${{ matrix.os }} + strategy: + fail-fast: false + matrix: + # Build gnu-linux on ubuntu-18.04 and musl on ubuntu latest + # os: [ ubuntu-18.04, ubuntu-latest, windows-latest, macos-latest ] + # os: [ ubuntu-latest, windows-latest, macos-latest ] + os: [ windows-latest, macos-latest ] + name: Building, ${{ matrix.os }} steps: + - name: Fix CRLF on Windows + if: runner.os == 'Windows' + run: git config --global core.autocrlf false - name: Install desktop dependencies run: | - sudo apt install -y libglib2.0-dev libatk1.0-dev libgtk-3-dev + sudo apt install -y libglib2.0-dev libatk1.0-dev libgtk-3-dev librust-atk-dev - name: Checkout sources uses: actions/checkout@v3 @@ -282,7 +333,7 @@ jobs: target/ key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - - name: Install zig + - name: Install zig on linux if: runner.os == 'Linux' uses: goto-bus-stop/setup-zig@v2 # needed for cargo-zigbuild @@ -291,4 +342,36 @@ jobs: # We're using musl to make the binaries statically linked and portable run: | cargo install cargo-zigbuild - cargo --verbose zigbuild --release --target x86_64-unknown-linux-gnu.2.27 # Use an older glibc version + cargo --verbose zigbuild --bin kaspa-ng --release --target x86_64-unknown-linux-gnu.2.27 # Use an older glibc version + mkdir kaspa-ng-${{ github.event.release.tag_name }}-linux-gnu-amd64 || true + cp target/x86_64-unknown-linux-gnu/release/kaspa-ng kaspa-ng-${{ github.event.release.tag_name }}-linux-gnu-amd64/ + archive="kaspa-ng-${{ github.event.release.tag_name }}-linux-gnu-amd64/kaspa-ng-${{ github.event.release.tag_name }}-linux-gnu-amd64.zip" + asset_name="kaspa-ng-${{ github.event.release.tag_name }}-linux-gnu-amd64.zip" + zip -r "${archive}" ./kaspa-ng-${{ github.event.release.tag_name }}-linux-gnu-amd64/* + echo "archive=${archive}" >> $GITHUB_ENV + echo "asset_name=${asset_name}" >> $GITHUB_ENV + + - name: Build on Windows + if: runner.os == 'Windows' + shell: bash + run: | + cargo build --bin kaspa-ng --release + mkdir kaspa-ng-${{ github.event.release.tag_name }}-windows-x64 || true + cp target/release/kaspa-ng.exe kaspa-ng-${{ github.event.release.tag_name }}-windows-x64/ + archive="kaspa-ng-${{ github.event.release.tag_name }}-windows-x64/kaspa-ng-${{ github.event.release.tag_name }}-windows-x64.zip" + asset_name="kaspa-ng-${{ github.event.release.tag_name }}-windows-x64.zip" + powershell "Compress-Archive kaspa-ng-${{ github.event.release.tag_name }}-windows-x64/* \"${archive}\"" + echo "archive=${archive}" >> $GITHUB_ENV + echo "asset_name=${asset_name}" >> $GITHUB_ENV + + - name: Build on MacOS + if: runner.os == 'macOS' + run: | + cargo build --bin kaspa-ng --release + mkdir kaspa-ng-${{ github.event.release.tag_name }}-macos-arm64 || true + cp target/release/kaspa-ng kaspa-ng-${{ github.event.release.tag_name }}-macos-arm64/ + archive="kaspa-ng-${{ github.event.release.tag_name }}-macos-arm64/kaspa-ng-${{ github.event.release.tag_name }}-macos-arm64.zip" + asset_name="kaspa-ng-${{ github.event.release.tag_name }}-macos-arm64.zip" + zip -r "${archive}" ./kaspa-ng-${{ github.event.release.tag_name }}-macos-arm64/* + echo "archive=${archive}" >> $GITHUB_ENV + echo "asset_name=${asset_name}" >> $GITHUB_ENV diff --git a/Cargo.toml b/Cargo.toml index a72aa98..b49b61d 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -26,11 +26,11 @@ kaspa-ng-macros = { version = "0.1.0", path = "macros/" } # |___ |__] |__| | # ___________________ -egui = "0.24.0" -epaint = "0.24.0" -egui_plot = "0.24.0" -egui_extras = { version = "0.24.0", features = ["svg","image"] } -eframe = { version = "0.24.0", default-features = false, features = [ +egui = "=0.24.0" +epaint = "=0.24.0" +egui_plot = "=0.24.0" +egui_extras = { version = "=0.24.0", features = ["svg","image"] } +eframe = { version = "=0.24.0", default-features = false, features = [ "accesskit", # Make egui comptaible with screen readers. NOTE: adds a lot of dependencies. "default_fonts", # Embed the default egui fonts. "glow", # Use the glow rendering backend. Alternative: "wgpu". @@ -169,4 +169,6 @@ xxhash-rust = { version = "0.8.7", features = ["xxh3"] } zeroize = { version = "1", default-features = false, features = ["alloc"] } [profile.release] -opt-level = 2 # fast and small wasm +opt-level = 2 +# opt-level = 3 +# lto = true diff --git a/core/src/core.rs b/core/src/core.rs index ee5c263..9c9ba39 100644 --- a/core/src/core.rs +++ b/core/src/core.rs @@ -9,10 +9,10 @@ use kaspa_metrics_core::MetricsSnapshot; use kaspa_wallet_core::api::TransactionsDataGetResponse; use kaspa_wallet_core::events::Events as CoreWallet; use kaspa_wallet_core::storage::{Binding, Hint, PrvKeyDataInfo}; -use workflow_wasm::callback::CallbackMap; use std::borrow::Cow; #[allow(unused_imports)] use workflow_i18n::*; +use workflow_wasm::callback::CallbackMap; pub enum Exception { UtxoIndexNotEnabled { url: Option }, @@ -53,7 +53,7 @@ pub struct Core { pub servers: Arc>, pub debug: bool, pub window_frame: bool, - callback_map : CallbackMap, + callback_map: CallbackMap, } impl Core { @@ -198,7 +198,8 @@ impl Core { this.update_servers(); this.wallet_update_list(); - #[cfg(target_arch = "wasm32")] { + #[cfg(target_arch = "wasm32")] + { this.register_visibility_handler(); } @@ -598,7 +599,7 @@ impl Core { _frame: &mut eframe::Frame, ) -> Result<()> { match event { - Events::VisibilityChange(_state) => { } + Events::VisibilityChange(_state) => {} Events::ServerList { server_list } => { self.servers = server_list; } @@ -1095,8 +1096,8 @@ impl Core { } pub fn register_visibility_handler(&self) { - use workflow_wasm::callback::*; use workflow_dom::utils::document; + use workflow_wasm::callback::*; let block_dag_background_state = self.get::().background_state(); @@ -1105,15 +1106,18 @@ impl Core { let visibility_state = document().visibility_state(); match visibility_state { VisibilityState::Visible => { - crate::runtime::runtime().block_dag_monitor_service().enable(None); - - }, + crate::runtime::runtime() + .block_dag_monitor_service() + .enable(None); + } VisibilityState::Hidden => { if !block_dag_background_state.load(Ordering::SeqCst) { - crate::runtime::runtime().block_dag_monitor_service().disable(None); + crate::runtime::runtime() + .block_dag_monitor_service() + .disable(None); } - }, - _ => { } + } + _ => {} }; sender .try_send(Events::VisibilityChange(visibility_state)) @@ -1124,5 +1128,4 @@ impl Core { document().set_onvisibilitychange(Some(callback.as_ref())); self.callback_map.retain(callback).unwrap(); } - } diff --git a/core/src/imports.rs b/core/src/imports.rs index 9c84aa3..6e6a7bc 100644 --- a/core/src/imports.rs +++ b/core/src/imports.rs @@ -34,6 +34,7 @@ pub use std::sync::OnceLock; pub use std::sync::{Arc, Mutex, MutexGuard, RwLock}; pub use std::time::Duration; +pub use web_sys::VisibilityState; pub use workflow_core::abortable::Abortable; pub use workflow_core::channel::{oneshot, Channel, Receiver, Sender}; pub use workflow_core::enums::Describe; @@ -43,7 +44,6 @@ pub use workflow_core::time::{unixtime_as_millis_f64, Instant}; pub use workflow_http as http; pub use workflow_i18n::*; pub use workflow_log::*; -pub use web_sys::VisibilityState; pub use ahash::{AHashMap, AHashSet}; pub use pad::{Alignment, PadStr}; diff --git a/core/src/modules/mod.rs b/core/src/modules/mod.rs index 5e18855..ad1e2ad 100644 --- a/core/src/modules/mod.rs +++ b/core/src/modules/mod.rs @@ -194,7 +194,7 @@ impl std::fmt::Debug for Module { } } -impl Eq for Module { } +impl Eq for Module {} impl PartialEq for Module { fn eq(&self, other: &Self) -> bool {