Skip to content

Commit

Permalink
Bring no-std-check into the main workspace
Browse files Browse the repository at this point in the history
  • Loading branch information
mzabaluev committed Feb 23, 2024
1 parent 03974f5 commit 8d9fc6b
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 58 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ members = [
"pbt-gen",
"proto",
"rpc",
"testgen"
"testgen",
"tools/no-std-check"
]

exclude = [
"proto-compiler",
"tools/no-std-check"
]

[profile.release.package.cometbft-light-client-js]
Expand Down
1 change: 0 additions & 1 deletion tools/no-std-check/.gitignore

This file was deleted.

4 changes: 4 additions & 0 deletions tools/no-std-check/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,7 @@ substrate-std = [
"sp-runtime/std",
"sp-std/std",
]

[[example]]
name = "no_std"
crate-type = ["lib"]
10 changes: 5 additions & 5 deletions tools/no-std-check/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,29 +5,29 @@ setup:
rustup target add wasm32-unknown-unknown --toolchain $(NIGHTLY_VERSION)

build-substrate:
cargo build \
cargo build --examples \
--no-default-features \
--features use-substrate,substrate-std

check-panic-conflict:
cargo build \
cargo build --examples \
--no-default-features \
--features panic-handler

check-cargo-build-std:
rustup run $(NIGHTLY_VERSION) -- \
cargo build -Z build-std=core,alloc \
cargo build --examples -Z build-std=core,alloc \
--no-default-features \
--target x86_64-unknown-linux-gnu

check-wasm:
rustup run $(NIGHTLY_VERSION) -- \
cargo build \
cargo build --examples \
--target wasm32-unknown-unknown

check-substrate:
rustup run $(NIGHTLY_VERSION) -- \
cargo build \
cargo build --examples \
--no-default-features \
--features use-substrate \
--target wasm32-unknown-unknown
49 changes: 49 additions & 0 deletions tools/no-std-check/examples/no_std.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#![no_std]
#![allow(unused_imports)]

extern crate alloc;

// Import the crates that we want to check if they are fully no-std compliance

use cometbft;
use cometbft_light_client_verifier;
use cometbft_proto;

#[cfg(feature = "sp-core")]
use sp_core;

#[cfg(feature = "sp-io")]
use sp_io;

#[cfg(feature = "sp-runtime")]
use sp_runtime;

#[cfg(feature = "sp-std")]
use sp_std;

use core::panic::PanicInfo;

/*
This function definition checks for the compliance of no-std in
dependencies by causing a compile error if this crate is
linked with `std`. When that happens, you should see error messages
such as follows:
```
error[E0152]: found duplicate lang item `panic_impl`
--> no-std-check/src/lib.rs
|
12 | fn panic(_info: &PanicInfo) -> ! {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the lang item is first defined in crate `std` (which `offending-crate` depends on)
```
*/
#[cfg(feature = "panic-handler")]
#[panic_handler]
#[no_mangle]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
55 changes: 5 additions & 50 deletions tools/no-std-check/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,50 +1,5 @@
// ensure_no_std/src/main.rs
#![no_std]
#![allow(unused_imports)]

extern crate alloc;

// Import the crates that we want to check if they are fully no-std compliance

use cometbft;
use cometbft_light_client_verifier;
use cometbft_proto;

#[cfg(feature = "sp-core")]
use sp_core;

#[cfg(feature = "sp-io")]
use sp_io;

#[cfg(feature = "sp-runtime")]
use sp_runtime;

#[cfg(feature = "sp-std")]
use sp_std;

use core::panic::PanicInfo;

/*
This function definition checks for the compliance of no-std in
dependencies by causing a compile error if this crate is
linked with `std`. When that happens, you should see error messages
such as follows:
```
error[E0152]: found duplicate lang item `panic_impl`
--> no-std-check/src/lib.rs
|
12 | fn panic(_info: &PanicInfo) -> ! {
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
= note: the lang item is first defined in crate `std` (which `offending-crate` depends on)
```
*/
#[cfg(feature = "panic-handler")]
#[panic_handler]
#[no_mangle]
fn panic(_info: &PanicInfo) -> ! {
loop {}
}
// This is a dummy library source.
//
// The check against linkage with std is performed in an example target.
// This allows us to include this crate in the main workspace and have
// `cargo test` build the example without the test harness, which requires std.

0 comments on commit 8d9fc6b

Please sign in to comment.