From 7134ab68d43d00f6df8b846039c19d25873c7f95 Mon Sep 17 00:00:00 2001 From: zjp Date: Fri, 3 Jan 2025 20:47:43 +0800 Subject: [PATCH 1/5] chore: move clippy new_without_default lint to Cargo.toml; ref https://github.com/kern-crates/.github/pull/28 --- .github/workflows/ci.yml | 2 +- Cargo.toml | 3 +++ 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 531ddd1..6bab917 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: - name: Check code format run: cargo fmt --all -- --check - name: Clippy - run: cargo clippy --target ${{ matrix.targets }} --all-features -- -A clippy::new_without_default + run: cargo clippy --target ${{ matrix.targets }} --all-features - name: Build run: cargo build --target ${{ matrix.targets }} --all-features - name: Unit test diff --git a/Cargo.toml b/Cargo.toml index 2471d01..f7f7d53 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -16,3 +16,6 @@ cfg-if = "1.0" [target.'cfg(target_arch = "x86_64")'.dependencies] x86_64 = "0.15" + +[lints.clippy] +new_without_default = "allow" From 8d85a32a588e1a3c87dafc534a5af448c4a7eba8 Mon Sep 17 00:00:00 2001 From: zjp Date: Fri, 3 Jan 2025 20:51:07 +0800 Subject: [PATCH 2/5] feat: keep Cargo.lock; ref https://github.com/kern-crates/.github/pull/27 --- .gitignore | 1 - Cargo.lock | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+), 1 deletion(-) create mode 100644 Cargo.lock diff --git a/.gitignore b/.gitignore index ff78c42..23bb4fa 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,3 @@ /target /.vscode .DS_Store -Cargo.lock diff --git a/Cargo.lock b/Cargo.lock new file mode 100644 index 0000000..f6493cb --- /dev/null +++ b/Cargo.lock @@ -0,0 +1,53 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 4 + +[[package]] +name = "bit_field" +version = "0.10.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "dc827186963e592360843fb5ba4b973e145841266c1357f7180c43526f2e5b61" + +[[package]] +name = "bitflags" +version = "2.6.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" + +[[package]] +name = "cfg-if" +version = "1.0.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" + +[[package]] +name = "rustversion" +version = "1.0.19" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4" + +[[package]] +name = "volatile" +version = "0.4.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "442887c63f2c839b346c192d047a7c87e73d0689c9157b00b53dcc27dd5ea793" + +[[package]] +name = "x86_64" +version = "0.15.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0f042214de98141e9c8706e8192b73f56494087cc55ebec28ce10f26c5c364ae" +dependencies = [ + "bit_field", + "bitflags", + "rustversion", + "volatile", +] + +[[package]] +name = "x86_rtc" +version = "0.1.1" +dependencies = [ + "cfg-if", + "x86_64", +] From eea3fb7af1493dc95f1aeaef916b1763a67227f7 Mon Sep 17 00:00:00 2001 From: zjp Date: Fri, 3 Jan 2025 22:17:44 +0800 Subject: [PATCH 3/5] fix: static_mut_refs lint from rustc Braces are needed to hinder clippy lint and compact in single line. Fefer to what I posted on URLO for an example: https://users.rust-lang.org/t/static-mut-refs-lint-is-amusing/123439 --------------------------------------------------------------------------- Raw static_mut_refs lint outputs: warning: creating a mutable reference to mutable static is discouraged --> src/lib.rs:208:17 | 208 | COMMAND_PORT.write(CMOS_DISABLE_NMI | register); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ mutable reference to mutable static | = note: for more information, see = note: mutable references to mutable statics are dangerous; it's undefined behavior if any other pointer to the static is used or if any other reference is created for the static while the mutable reference lives = note: `#[warn(static_mut_refs)]` on by default warning: creating a mutable reference to mutable static is discouraged --> src/lib.rs:209:17 | 209 | DATA_PORT.read() | ^^^^^^^^^^^^^^^^ mutable reference to mutable static | = note: for more information, see = note: mutable references to mutable statics are dangerous; it's undefined behavior if any other pointer to the static is used or if any other reference is created for the static while the mutable reference lives warning: creating a mutable reference to mutable static is discouraged --> src/lib.rs:215:17 | 215 | COMMAND_PORT.write(CMOS_DISABLE_NMI | register); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ mutable reference to mutable static | = note: for more information, see = note: mutable references to mutable statics are dangerous; it's undefined behavior if any other pointer to the static is used or if any other reference is created for the static while the mutable reference lives warning: creating a mutable reference to mutable static is discouraged --> src/lib.rs:216:17 | 216 | DATA_PORT.write(value) | ^^^^^^^^^^^^^^^^^^^^^^ mutable reference to mutable static | = note: for more information, see = note: mutable references to mutable statics are dangerous; it's undefined behavior if any other pointer to the static is used or if any other reference is created for the static while the mutable reference lives --- src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 45fff40..975fc01 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -205,15 +205,15 @@ cfg_if::cfg_if! { fn read_cmos_register(register: u8) -> u8 { unsafe { - COMMAND_PORT.write(CMOS_DISABLE_NMI | register); - DATA_PORT.read() + (*{ &raw mut COMMAND_PORT }).write(CMOS_DISABLE_NMI | register); + (*{ &raw mut DATA_PORT }).read() } } fn write_cmos_register(register: u8, value: u8) { unsafe { - COMMAND_PORT.write(CMOS_DISABLE_NMI | register); - DATA_PORT.write(value) + (*{ &raw mut COMMAND_PORT }).write(CMOS_DISABLE_NMI | register); + (*{ &raw mut DATA_PORT }).write(value) } } From 6d8d878e0f0f9fc2b57813075a66a1b99045d3ee Mon Sep 17 00:00:00 2001 From: zjp Date: Sun, 5 Jan 2025 20:46:31 +0800 Subject: [PATCH 4/5] fix(ci): exclude riscv64gc-unknown-none-elf and aarch64-unknown-none-softfloat This crate targets x86. --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 6bab917..c3b81e4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -9,7 +9,7 @@ jobs: fail-fast: false matrix: rust-toolchain: [nightly] - targets: [x86_64-unknown-linux-gnu, x86_64-unknown-none, riscv64gc-unknown-none-elf, aarch64-unknown-none-softfloat] + targets: [x86_64-unknown-linux-gnu, x86_64-unknown-none] steps: - uses: actions/checkout@v4 - uses: dtolnay/rust-toolchain@nightly From bc0fa1fda55de6ad4a1fc8d6fbfa09b7cf8d0ac1 Mon Sep 17 00:00:00 2001 From: zjp Date: Sun, 5 Jan 2025 20:47:39 +0800 Subject: [PATCH 5/5] ci: cargo clippy -- -D warnings (deny warnings) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c3b81e4..ec5f9ad 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,7 +22,7 @@ jobs: - name: Check code format run: cargo fmt --all -- --check - name: Clippy - run: cargo clippy --target ${{ matrix.targets }} --all-features + run: cargo clippy --target ${{ matrix.targets }} --all-features -- -D warnings - name: Build run: cargo build --target ${{ matrix.targets }} --all-features - name: Unit test