From 58b6b8cc8d282f59da0ac2084475ab40206bd73d Mon Sep 17 00:00:00 2001 From: Romain Ruetschi <106849+romac@users.noreply.github.com> Date: Thu, 27 Jul 2023 18:50:19 +0200 Subject: [PATCH 1/2] Add `no_std` compatibility test --- .github/workflows/rust.yml | 7 ++++++- Cargo.toml | 4 ++++ pbjson-no-std/Cargo.toml | 17 +++++++++++++++++ pbjson-no-std/src/main.rs | 20 ++++++++++++++++++++ pbjson-types/Cargo.toml | 4 ++-- 5 files changed, 49 insertions(+), 3 deletions(-) create mode 100644 pbjson-no-std/Cargo.toml create mode 100644 pbjson-no-std/src/main.rs diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 4a360bb..c4557b1 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -80,8 +80,13 @@ jobs: with: command: nextest args: run --all-features --no-fail-fast --no-capture - - name: Run tests (no-std) + - name: Run tests (no_std) uses: actions-rs/cargo@v1 with: command: nextest args: run --no-default-features --no-fail-fast --no-capture + - name: Check no_std compatibility + uses: actions-rs/cargo@v1 + with: + command: rustc + args: --manifest-path pbjson-no-std/Cargo.toml -- -C link-arg=-nostartfiles diff --git a/Cargo.toml b/Cargo.toml index b13ec79..7bfb4c0 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -5,3 +5,7 @@ members = [ "pbjson-test", "pbjson-types", ] + +exclude = [ + "pbjson-no-std" +] diff --git a/pbjson-no-std/Cargo.toml b/pbjson-no-std/Cargo.toml new file mode 100644 index 0000000..d179dc2 --- /dev/null +++ b/pbjson-no-std/Cargo.toml @@ -0,0 +1,17 @@ +[package] +name = "pbjson-no-std" +version = "0.1.0" +edition = "2021" +publish = false +description = "A library for testing no_std compatibility of pbjson" + +[profile.dev] +panic = "abort" + +[profile.release] +panic = "abort" + +[dependencies] +informalsystems-pbjson = { path = "../pbjson", default-features = false } +informalsystems-pbjson-types = { path = "../pbjson-types", default-features = false } + diff --git a/pbjson-no-std/src/main.rs b/pbjson-no-std/src/main.rs new file mode 100644 index 0000000..44d69c8 --- /dev/null +++ b/pbjson-no-std/src/main.rs @@ -0,0 +1,20 @@ +#![no_std] +#![no_main] + +use core::panic::PanicInfo; + +/// This function is called on panic. +#[panic_handler] +fn panic(_info: &PanicInfo) -> ! { + loop {} +} + +#[no_mangle] +pub extern "C" fn _start() -> ! { + loop {} +} + +#[allow(unused_imports)] +use pbjson; +#[allow(unused_imports)] +use pbjson_types; diff --git a/pbjson-types/Cargo.toml b/pbjson-types/Cargo.toml index f649340..d9cf55b 100644 --- a/pbjson-types/Cargo.toml +++ b/pbjson-types/Cargo.toml @@ -15,12 +15,12 @@ name = "pbjson_types" [features] default = ["std"] -std = ["chrono/std", "informalsystems-pbjson/std", "prost/std", "serde/std"] +std = ["chrono/std", "informalsystems-pbjson/std", "prost/std", "serde/std", "bytes/std"] [dependencies] # In alphabetical order informalsystems-pbjson = { path = "../pbjson", version = "0.6.0" , default-features = false } -bytes = "1.0" +bytes = { version = "1.0", default-features = false } chrono = { version = "0.4", default-features = false, features = ["alloc"] } prost = { version = "0.11", default-features = false } serde = { version = "1.0", features = ["derive"], default-features = false } From e54f504cb04e429bdb3cf14f0a659965235fd077 Mon Sep 17 00:00:00 2001 From: Farhad Shabani Date: Thu, 27 Jul 2023 13:08:58 -0700 Subject: [PATCH 2/2] fix: enable prost-derive feature for prost --- .gitignore | 1 + pbjson-no-std/src/{main.rs => lib.rs} | 1 - pbjson-test/Cargo.toml | 2 +- pbjson-types/Cargo.toml | 6 +++--- 4 files changed, 5 insertions(+), 5 deletions(-) rename pbjson-no-std/src/{main.rs => lib.rs} (96%) diff --git a/.gitignore b/.gitignore index 088ba6b..ac3f8b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Generated by Cargo # will have compiled files and executables /target/ +/pbjson-no-std/target/ # Remove Cargo.lock from gitignore if creating an executable, leave it for libraries # More information here https://doc.rust-lang.org/cargo/guide/cargo-toml-vs-cargo-lock.html diff --git a/pbjson-no-std/src/main.rs b/pbjson-no-std/src/lib.rs similarity index 96% rename from pbjson-no-std/src/main.rs rename to pbjson-no-std/src/lib.rs index 44d69c8..e1bda95 100644 --- a/pbjson-no-std/src/main.rs +++ b/pbjson-no-std/src/lib.rs @@ -1,5 +1,4 @@ #![no_std] -#![no_main] use core::panic::PanicInfo; diff --git a/pbjson-test/Cargo.toml b/pbjson-test/Cargo.toml index 06eb6e5..f8cd58b 100644 --- a/pbjson-test/Cargo.toml +++ b/pbjson-test/Cargo.toml @@ -11,7 +11,7 @@ publish = false name = "pbjson_test" [dependencies] -prost = { version = "0.11", default-features = false} +prost = { version = "0.11", default-features = false, features = ["prost-derive"] } informalsystems-pbjson = { path = "../pbjson" , default-features = false} informalsystems-pbjson-types = { path = "../pbjson-types" , default-features = false} serde = { version = "1.0", default-features = false, features = ["derive", "alloc"] } diff --git a/pbjson-types/Cargo.toml b/pbjson-types/Cargo.toml index d9cf55b..1089d80 100644 --- a/pbjson-types/Cargo.toml +++ b/pbjson-types/Cargo.toml @@ -15,18 +15,18 @@ name = "pbjson_types" [features] default = ["std"] -std = ["chrono/std", "informalsystems-pbjson/std", "prost/std", "serde/std", "bytes/std"] +std = ["bytes/std", "chrono/std", "informalsystems-pbjson/std", "prost/std", "serde/std", "serde_json/std"] [dependencies] # In alphabetical order informalsystems-pbjson = { path = "../pbjson", version = "0.6.0" , default-features = false } bytes = { version = "1.0", default-features = false } chrono = { version = "0.4", default-features = false, features = ["alloc"] } -prost = { version = "0.11", default-features = false } +prost = { version = "0.11", default-features = false, features = ["prost-derive"] } serde = { version = "1.0", features = ["derive"], default-features = false } [dev-dependencies] -serde_json = "1.0" +serde_json = { version = "1.0", default-features = false, features = ["alloc"] } [build-dependencies] informalsystems-pbjson-build = { path = "../pbjson-build", version = "0.6.0" }