paritytech / primitives

Other
33 stars 23 forks source link

ethereum-types `make it work in no_std` #42

Closed niklasad1 closed 6 years ago

niklasad1 commented 6 years ago

This PR depends on #41

Tested by

// main.rs
#![feature(lang_items, start, panic_implementation)]
#![no_std]

extern crate libc;
extern crate ethereum_types;

use ethereum_types::{Address, Public, Secret, Signature};

#[start]
fn start(_argc: isize, _argv: *const *const u8) -> isize {
    0
}

#[lang = "eh_personality"]
#[no_mangle]
pub extern "C" fn rust_eh_personality() {}

#[panic_implementation]
fn panic(_info: &core::panic::PanicInfo) -> ! {
    unsafe {
        libc::abort();
    }
}
// Cargo.toml
[dependencies]
libc = { version = "0.2.42", default-features = false }
ethereum-types = { git = "https://github.com/niklasad1/primitives", default-features = false, branch = "ethereum-types/no-std" }

Output

no_std git:(master) ✗ cargo build
   Compiling semver-parser v0.7.0
   Compiling crunchy v0.1.6
   Compiling libc v0.2.42
   Compiling byteorder v1.2.3
   Compiling tiny-keccak v1.4.2
   Compiling semver v0.9.0
   Compiling fixed-hash v0.2.1 (https://github.com/niklasad1/primitives?branch=ethereum-types/no-std#a10d900f)
   Compiling ethbloom v0.5.0 (https://github.com/niklasad1/primitives?branch=ethereum-types/no-std#a10d900f)
   Compiling rustc_version v0.2.2
   Compiling uint v0.2.1 (https://github.com/niklasad1/primitives?branch=ethereum-types/no-std#a10d900f)
   Compiling ethereum-types v0.3.2 (https://github.com/niklasad1/primitives?branch=ethereum-types/no-std#a10d900f)
   Compiling no_std v0.1.0 (file:///home/niklasad1/Projects/RustExamples/no_std)
warning: unused imports: `Address`, `Public`, `Secret`, `Signature`
 --> src/main.rs:7:22
  |
7 | use ethereum_types::{Address, Public, Secret, Signature};
  |                      ^^^^^^^  ^^^^^^  ^^^^^^  ^^^^^^^^^
  |
  = note: #[warn(unused_imports)] on by default

    Finished dev [unoptimized + debuginfo] target(s) in 1m 09s
moriaab commented 6 years ago

Thank you so much! It works!

niklasad1 commented 6 years ago

@tomusdrw Ok to merge?

tomusdrw commented 6 years ago

@niklasad1 would prefer to add a compilation check for no_std on travis. But will log it as a separate issue.

tomusdrw commented 6 years ago

OH, sorry just noticed #43 and #44. Merging this.