From 857f64badb0f7ec789b98ccd9a39cc595a2bcf19 Mon Sep 17 00:00:00 2001 From: Al Liu Date: Sat, 25 May 2024 10:58:59 +0800 Subject: [PATCH] update --- .github/workflows/ci.yml | 41 +++++---------------------- .github/workflows/loc.yml | 58 +++++++++++++++++++++++++++++++++++++++ Cargo.toml | 4 ++- README-zh_CN.md | 13 +++++---- README.md | 9 +++--- ci/miri.sh | 6 ++-- ci/sanitizer.sh | 12 ++++---- src/lib.rs | 10 +++++++ 8 files changed, 100 insertions(+), 53 deletions(-) create mode 100644 .github/workflows/loc.yml diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c6ba154..42cb38b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -104,13 +104,13 @@ jobs: run: | cargo install cross cross build --target ${{ matrix.target }} - if: matrix.target != 'wasm32-unknown-unknown' - # # WASM support - # - name: cargo build --target ${{ matrix.target }} - # run: | - # rustup target add ${{ matrix.target }} - # cargo build --features js --target ${{ matrix.target }} - # if: matrix.target == 'wasm32-unknown-unknown' + if: matrix.target != 'wasm32-unknown-unknown' && matrix.target != 'wasm32-wasi' + # WASM support + - name: cargo build --target ${{ matrix.target }} + run: | + rustup target add ${{ matrix.target }} + cargo build --target ${{ matrix.target }} + if: matrix.target == 'wasm32-unknown-unknown' || matrix.target == 'wasm32-wasi' # - name: cargo build --target ${{ matrix.target }} # run: | # rustup target add ${{ matrix.target }} @@ -304,31 +304,6 @@ jobs: # run: valgrind --error-exitcode=1 --leak-check=full --show-leak-kinds=all ./target/debug/foo # working-directory: integration - docs: - name: docs - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v3 - - name: Cache cargo build and registry - uses: actions/cache@v3 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ubuntu-latest-docs-${{ hashFiles('**/Cargo.lock') }} - restore-keys: | - ubuntu-latest-docs- - - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ env.nightly }} - override: true - - name: "doc --lib --all-features" - run: cargo doc --lib --no-deps --all-features - env: - RUSTFLAGS: --cfg docsrs - RUSTDOCFLAGS: --cfg docsrs -Dwarnings - coverage: name: coverage runs-on: ubuntu-latest @@ -339,9 +314,7 @@ jobs: - cross - test - sanitizer - - miri - loom - - docs steps: - uses: actions/checkout@v3 - name: Install latest nightly diff --git a/.github/workflows/loc.yml b/.github/workflows/loc.yml new file mode 100644 index 0000000..9011e7f --- /dev/null +++ b/.github/workflows/loc.yml @@ -0,0 +1,58 @@ +name: loc + +on: + push: + branches: + - main + paths-ignore: + - 'README.md' + - 'COPYRIGHT' + - 'LICENSE*' + - '**.md' + - '**.txt' + - 'art' + pull_request: + paths-ignore: + - 'README.md' + - 'COPYRIGHT' + - 'LICENSE*' + - '**.md' + - '**.txt' + - 'art' + workflow_dispatch: + +jobs: + loc: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Install Rust + run: | + rustup update stable && rustup default stable + rustup component add clippy + rustup component add rustfmt + + - name: Install tokeit + run: | + cargo install tokeit --force + + - name: Count total lines of code + run: | + tokeit + - name: Upload total loc to GitHub Gist + uses: actions/github-script@v6 + with: + github-token: ${{ secrets.GIST_PAT }} + script: | + const fs = require('fs'); + const output = fs.readFileSync('tokeit.json', 'utf8'); + const gistId = '327b2a8aef9003246e45c6e47fe63937'; + await github.rest.gists.update({ + gist_id: gistId, + files: { + "template-rs": { + content: output + } + } + }); diff --git a/Cargo.toml b/Cargo.toml index 583f5a6..34be434 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,9 @@ name = "foo" harness = false [features] -default = [] +default = ["std"] +alloc = [] +std = [] [dependencies] diff --git a/README-zh_CN.md b/README-zh_CN.md index 21d7466..7a07f4d 100644 --- a/README-zh_CN.md +++ b/README-zh_CN.md @@ -5,28 +5,29 @@ 开源Rust代码库GitHub模版 -[github][Github-url] -[Build][CI-url] +[github][Github-url] +LoC +[Build][CI-url] [codecov][codecov-url] [docs.rs][doc-url] [crates.io][crates-url] -[rustc][rustc-url] - -[license-apache][license-apache-url] -[license-mit][license-mit-url] +[crates.io][crates-url] +license [English][en-url] | 简体中文 ## Installation + ```toml [dependencies] template_rs = "0.1" ``` ## Features + - [x] 更快的创建GitHub开源Rust代码库 #### License diff --git a/README.md b/README.md index 218fb4f..1af27e2 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,13 @@ A template for creating Rust open-source GitHub repo. [github][Github-url] +LoC [Build][CI-url] [codecov][codecov-url] [docs.rs][doc-url] -[crates.io][crates-url] -[crates.io][crates-url] - +[crates.io][crates-url] +[crates.io][crates-url] license English | [简体中文][zh-cn-url] @@ -20,6 +20,7 @@ English | [简体中文][zh-cn-url] ## Installation + ```toml [dependencies] template_rs = "0.1" @@ -30,7 +31,7 @@ template_rs = "0.1" #### License -`Template-rs` is under the terms of both the MIT license and the +`template-rs` is under the terms of both the MIT license and the Apache License (Version 2.0). See [LICENSE-APACHE](LICENSE-APACHE), [LICENSE-MIT](LICENSE-MIT) for details. diff --git a/ci/miri.sh b/ci/miri.sh index 7ea1a2c..35ec5f4 100755 --- a/ci/miri.sh +++ b/ci/miri.sh @@ -7,5 +7,7 @@ cargo miri setup export MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-disable-isolation -Zmiri-symbolic-alignment-check" -cargo hack miri test --each-feature - +cargo miri test --tests --target x86_64-unknown-linux-gnu +cargo miri test --tests --target aarch64-unknown-linux-gnu +cargo miri test --tests --target i686-unknown-linux-gnu +cargo miri test --tests --target powerpc64-unknown-linux-gnu diff --git a/ci/sanitizer.sh b/ci/sanitizer.sh index a21beb3..c8b9eee 100755 --- a/ci/sanitizer.sh +++ b/ci/sanitizer.sh @@ -4,14 +4,14 @@ set -ex export ASAN_OPTIONS="detect_odr_violation=0 detect_leaks=0" -# Run address sanitizer with cargo-hack +# Run address sanitizer RUSTFLAGS="-Z sanitizer=address" \ -cargo hack test --lib --each-feature +cargo test --tests --target x86_64-unknown-linux-gnu -# Run leak sanitizer with cargo-hack +# Run leak sanitizer RUSTFLAGS="-Z sanitizer=leak" \ -cargo hack test --lib --each-feature +cargo test --tests --target x86_64-unknown-linux-gnu -# Run thread sanitizer with cargo-hack +# Run thread sanitizer RUSTFLAGS="-Z sanitizer=thread" \ -cargo hack -Zbuild-std test --lib --each-feature +cargo -Zbuild-std test --tests --target x86_64-unknown-linux-gnu diff --git a/src/lib.rs b/src/lib.rs index dbdf2a0..d110fcc 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -1,8 +1,18 @@ //! A template for creating Rust open-source repo on GitHub +#![cfg_attr(not(any(feature = "std", test)), no_std)] #![cfg_attr(docsrs, feature(doc_cfg))] #![cfg_attr(docsrs, allow(unused_attributes))] #![deny(missing_docs)] +#[cfg(all(not(feature = "std"), feature = "alloc"))] +extern crate alloc as std; + +#[cfg(all(feature = "std", not(feature = "alloc")))] +extern crate std; + +#[cfg(all(feature = "std", feature = "alloc"))] +extern crate std; + /// template pub fn it_works() -> usize { 4