From 6d07bcde93579d8f001ca09ae9637ed928aeb631 Mon Sep 17 00:00:00 2001 From: slinkydeveloper Date: Wed, 7 Jul 2021 11:13:39 +0200 Subject: [PATCH] WIP Signed-off-by: Francesco Guardiani --- .github/workflows/rust_tests.yml | 48 +++++++++++++-------- Cargo.toml | 13 +++--- example-projects/no-std-example/Cargo.toml | 15 +++++++ example-projects/no-std-example/src/main.rs | 25 +++++++++++ src/lib.rs | 3 ++ 5 files changed, 79 insertions(+), 25 deletions(-) create mode 100644 example-projects/no-std-example/Cargo.toml create mode 100644 example-projects/no-std-example/src/main.rs diff --git a/.github/workflows/rust_tests.yml b/.github/workflows/rust_tests.yml index acd01481..3b50e227 100644 --- a/.github/workflows/rust_tests.yml +++ b/.github/workflows/rust_tests.yml @@ -53,36 +53,20 @@ jobs: # If glibc, compile and test all - uses: actions-rs/cargo@v1 - name: "Build" + name: "Build glibc" if: matrix.target == 'x86_64-unknown-linux-gnu' with: command: build toolchain: ${{ matrix.toolchain }} args: --target ${{ matrix.target }} --all-features - uses: actions-rs/cargo@v1 - name: "Test" + name: "Test glibc" if: matrix.target == 'x86_64-unknown-linux-gnu' with: command: test toolchain: ${{ matrix.toolchain }} args: --target ${{ matrix.target }} --all-features - # If glibc, compile and test only the core module with no_std - - uses: actions-rs/cargo@v1 - name: "Build" - if: matrix.target == 'x86_64-unknown-linux-gnu' - with: - command: build - toolchain: ${{ matrix.toolchain }} - args: --target ${{ matrix.target }} --package cloudevents-sdk --workspace --no-default-features - - uses: actions-rs/cargo@v1 - name: "Test" - if: matrix.target == 'x86_64-unknown-linux-gnu' - with: - command: test - toolchain: ${{ matrix.toolchain }} - args: --target ${{ matrix.target }} --package cloudevents-sdk --workspace --no-default-features - # If musl, compile and test all - uses: actions-rs/cargo@v1 name: "Build" @@ -145,3 +129,31 @@ jobs: command: build toolchain: ${{ matrix.toolchain }} args: --target ${{ matrix.target }} --manifest-path ./example-projects/warp-example/Cargo.toml + + check_no_std: + name: Check no_std + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: actions-rs/toolchain@v1 + with: + toolchain: stable + override: true + # Caching stuff + - uses: actions/cache@v2 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + key: ${{ runner.os }}-cargo-no-std-deps-${{ hashFiles('**/Cargo.toml') }} + - uses: actions/cache@v2 + with: + path: | + target/ + key: ${{ runner.os }}-cargo-no-std-build-${{ hashFiles('**/Cargo.toml') }} + - name: Download cargo-nono + run: curl -LSfs https://japaric.github.io/trust/install.sh | sh -s -- --git hobofan/cargo-nono + - name: Run check + run: ./cargo-nono check diff --git a/Cargo.toml b/Cargo.toml index f1305718..abf3e80e 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,6 +17,11 @@ categories = ["web-programming", "encoding", "data-structures", "no_std"] name = "cloudevents" [features] +# Without default features, the package acts as no_std +default = ["std"] + +std = ["snafu/std", "url"] + actix = ["actix-web", "async-trait", "lazy_static", "bytes", "futures"] reqwest = ["reqwest-lib", "async-trait", "lazy_static", "bytes"] rdkafka = ["rdkafka-lib", "lazy_static", "bytes", "futures"] @@ -28,16 +33,10 @@ serde_json = "^1.0" chrono = { version = "^0.4", features = ["serde"] } delegate-attr = "^0.2" base64 = "^0.12" -snafu = { version = "^0.6", default-features = false} +snafu = { version = "^0.6", default-features = false } bitflags = "^1.2" url = { version = "^2.1", features = ["serde"], optional = true } -[features] -# Without default features, the package acts as no_std -default = ["std"] - -std = ["snafu/std", "url"] - # runtime optional deps actix-web = { version = "^3", default-features = false, optional = true } reqwest-lib = { version = "^0.11", default-features = false, features = ["rustls-tls"], optional = true, package = "reqwest" } diff --git a/example-projects/no-std-example/Cargo.toml b/example-projects/no-std-example/Cargo.toml new file mode 100644 index 00000000..35bae0d7 --- /dev/null +++ b/example-projects/no-std-example/Cargo.toml @@ -0,0 +1,15 @@ +[package] +name = "no-std-example" +version = "0.1.0" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +cloudevents-sdk = { path = "../..", default-features = false } + +[profile.dev] +panic = "abort" + +[profile.release] +panic = "abort" \ No newline at end of file diff --git a/example-projects/no-std-example/src/main.rs b/example-projects/no-std-example/src/main.rs new file mode 100644 index 00000000..f1946219 --- /dev/null +++ b/example-projects/no-std-example/src/main.rs @@ -0,0 +1,25 @@ +#![no_std] +#![no_main] + +use core::panic::PanicInfo; + +use cloudevents; +use cloudevents::EventBuilder; + +#[panic_handler] +fn panic(_info: &PanicInfo) -> ! { + loop {} +} + +#[no_mangle] +pub extern "C" fn _start() -> ! { + loop { + #[allow(dead_code)] + let event = cloudevents::EventBuilderV10::new() + .id("my_id") + .source("my_source") + .subject("some_subject") + .build() + .unwrap(); + } +} diff --git a/src/lib.rs b/src/lib.rs index 9f1eb3f8..cfaf10f2 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -53,6 +53,7 @@ //! [Responders]: https://actix.rs/docs/handlers/ #![deny(broken_intra_doc_links)] + #![cfg_attr(not(any(feature = "std", test)), no_std)] #[cfg(feature = "alloc")] @@ -62,7 +63,9 @@ extern crate std as alloc; #[cfg(any(feature = "std", test))] extern crate std as core; +#[cfg(feature = "std")] pub mod binding; + pub mod event; pub mod message;