diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 5fc11c6..3e876c9 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,11 @@ -on: [push] +on: + pull_request: + types: [opened, reopened] + branches: + - main + push: + branches: + - main name: Test @@ -7,46 +14,34 @@ jobs: name: Test runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Install latest nightly - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - override: true - components: rustfmt, clippy + - uses: actions/checkout@v3 + - name: Install toolchain + run: rustup show - - name: Run cargo fmt - uses: actions-rs/cargo@v1 - with: - command: fmt - args: -- --check + - name: Run cargo fmt + run: cargo fmt -- --check - - name: Run cargo clippy - uses: actions-rs/cargo@v1 - with: - command: clippy - args: -- -D warnings + - name: Run cargo clippy + uses: actions-rs/cargo@v1 + run: cargo clippy -- -D warnings - - name: Run cargo test - uses: actions-rs/cargo@v1 - with: - command: test + - name: Run cargo clippy alloc + uses: actions-rs/cargo@v1 + run: > + cargo clippy --no-default-features --features alloc -- -D warnings #magic___^_^___line + - name: Run cargo test + run: cargo test + + - name: Run cargo test alloc + run: cargo test --no-default-features --features alloc no-std-build: name: Test no_std support runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Install latest nightly - uses: actions-rs/toolchain@v1 - with: - toolchain: nightly - override: true - components: rustfmt, clippy - target: thumbv6m-none-eabi - - - name: Build stark-felt - uses: actions-rs/cargo@v1 - with: - command: build - args: --package stark-felt --target thumbv6m-none-eabi --no-default-features + - uses: actions/checkout@v3 + - name: Check wasm compatibility + run: |- + cd ensure_no_std + rustup show + cargo build -r diff --git a/Cargo.toml b/Cargo.toml index 89aaadc..5eb1aa9 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,11 +1,19 @@ [workspace] members = [ - "crates/stark-felt", + "crates/stark-felt", "crates/starknet-types-core", "crates/starknet-types-rpc", ] +exclude = ["ensure_no_std"] + [workspace.package] -authors = ["Shahar Papini <@spapinistarkware>", "Abdelhamid Bakhta <@abdelhamidbakhta>", "Dan Brownstein <@dan-starkware>", "Federico Carrone <@unbalancedparentheses>", "Jonathan Lei <@xJonathanLEI>"] +authors = [ + "Shahar Papini <@spapinistarkware>", + "Abdelhamid Bakhta <@abdelhamidbakhta>", + "Dan Brownstein <@dan-starkware>", + "Federico Carrone <@unbalancedparentheses>", + "Jonathan Lei <@xJonathanLEI>", +] edition = "2021" -repository = "https://github.com/starknet-io/types-rs" \ No newline at end of file +repository = "https://github.com/starknet-io/types-rs" diff --git a/crates/stark-felt/src/lib.rs b/crates/stark-felt/src/lib.rs index ef5ed95..e8db9f5 100644 --- a/crates/stark-felt/src/lib.rs +++ b/crates/stark-felt/src/lib.rs @@ -15,8 +15,6 @@ pub type BitArrayStore = [u32; 8]; extern crate alloc; #[cfg(not(feature = "std"))] use alloc::string::ToString; -#[cfg(not(feature = "std"))] -use alloc::vec::Vec; use lambdaworks_math::{ field::{ diff --git a/ensure_no_std/.cargo/config.toml b/ensure_no_std/.cargo/config.toml new file mode 100644 index 0000000..f4e8c00 --- /dev/null +++ b/ensure_no_std/.cargo/config.toml @@ -0,0 +1,2 @@ +[build] +target = "wasm32-unknown-unknown" diff --git a/ensure_no_std/Cargo.toml b/ensure_no_std/Cargo.toml new file mode 100644 index 0000000..d8d5e0e --- /dev/null +++ b/ensure_no_std/Cargo.toml @@ -0,0 +1,19 @@ +[package] +name = "ensure_no_std" +version = "0.1.0" +edition = "2021" + +[dependencies] +stark-felt = { path = "../crates/stark-felt", default-features = false, features = [ + "alloc", +] } +starknet-types-core = { path = "../crates/starknet-types-core", default-features = false } +starknet-types-rpc = { path = "../crates/starknet-types-rpc", default-features = false } +wee_alloc = "0.4.5" + + +[profile.dev] +panic = "abort" + +[profile.release] +panic = "abort" diff --git a/ensure_no_std/rust-toolchain.toml b/ensure_no_std/rust-toolchain.toml new file mode 100644 index 0000000..2a2a217 --- /dev/null +++ b/ensure_no_std/rust-toolchain.toml @@ -0,0 +1,5 @@ +[toolchain] +channel = "nightly-2023-02-26" +components = ["rustfmt", "clippy"] +targets = ["wasm32-unknown-unknown"] +profile = "minimal" diff --git a/ensure_no_std/src/main.rs b/ensure_no_std/src/main.rs new file mode 100644 index 0000000..edbb888 --- /dev/null +++ b/ensure_no_std/src/main.rs @@ -0,0 +1,21 @@ +#![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 {} +} + +#[global_allocator] +static ALLOC: wee_alloc::WeeAlloc = wee_alloc::WeeAlloc::INIT; + +#[allow(unused_imports)] +use stark_felt; diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 0000000..80b43cd --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "nightly-2023-02-26" +components = ["rustfmt", "clippy"] +profile = "minimal"