Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add no_std feature #13

Merged
merged 3 commits into from
Jul 18, 2017
Merged

add no_std feature #13

merged 3 commits into from
Jul 18, 2017

Conversation

vitiral
Copy link
Contributor

@vitiral vitiral commented May 28, 2017

this adds support for no_std applications/libraries (like microcontrollers) by using conditional features

On nightly with no_std:

#  rustup run nightly cargo test --features no_std                                                                                                                                           <<<
    Finished dev [unoptimized + debuginfo] target(s) in 0.0 secs
     Running target/debug/deps/crc-c3e90d0dfab413be

running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured

     Running target/debug/deps/crc-9d7b680262789a74

running 10 tests
test crc32::checksum_castagnoli ... ok
test crc32::checksum_ieee ... ok
test crc32::digest_castagnoli ... ok
test crc32::checksum_koopman ... ok
test crc32::digest_ieee ... ok
test crc64::checksum_ecma ... ok
test crc32::digest_koopman ... ok
test crc64::digest_iso ... ok
test crc64::checksum_iso ... ok
test crc64::digest_ecma ... ok

test result: ok. 10 passed; 0 failed; 0 ignored; 0 measured

     Running target/debug/deps/hash-bb44b103cb920ad0

running 2 tests
test hasher::checksum_hashcrc32 ... ok
test hasher::checksum_hashcrc64 ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured

   Doc-tests crc

running 2 tests
test src/lib.rs -  (line 6) ... ok
test src/lib.rs -  (line 27) ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured

on stable with std:

# rustup run stable cargo test                                                                                                                                                                 
   Compiling crc v1.4.0 (file:///home/garrett/projects/ruststuff/crc-rs)                                                                                                                                          
    Finished dev [unoptimized + debuginfo] target(s) in 1.64 secs                                                                                                                                                 
     Running target/debug/deps/crc-57a43f894e443797                                                                                                                                                               
                                                                                                                                                                                                                  
running 0 tests

test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured

     Running target/debug/deps/crc-79b2fcd023832a0c                                                                                                                                                               
                                                                                                                                                                                                                  
running 10 tests
test crc32::checksum_castagnoli ... ok                                                                                                                                                                            
test crc32::checksum_ieee ... ok                                                                                                                                                                                  
test crc32::checksum_koopman ... ok                                                                                                                                                                               
test crc32::digest_castagnoli ... ok                                                                                                                                                                              
test crc32::digest_ieee ... ok                                                                                                                                                                                    
test crc64::checksum_iso ... ok                                                                                                                                                                                   
test crc64::checksum_ecma ... ok                                                                                                                                                                                  
test crc64::digest_ecma ... ok                                                                                                                                                                                    
test crc32::digest_koopman ... ok                                                                                                                                                                                 
test crc64::digest_iso ... ok                                                                                                                                                                                     
                                                                                                                                                                                                                  
test result: ok. 10 passed; 0 failed; 0 ignored; 0 measured

     Running target/debug/deps/hash-da1e5eadb26ad3bb                                                                                                                                                              
                                                                                                                                                                                                                  
running 2 tests
test hasher::checksum_hashcrc32 ... ok
test hasher::checksum_hashcrc64 ... ok

test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured

   Doc-tests crc                                                                                                                                                                                                  
                                                                                                                                                                                                                  
running 2 tests
test src/lib.rs -  (line 27) ... ok                                                                                                                                                                               
test src/lib.rs -  (line 6) ... ok                                                                                                                                                                                
                                                                                                                                                                                                                  
test result: ok. 2 passed; 0 failed; 0 ignored; 0 measured
#

@whitequark
Copy link
Contributor

As a developer who deploys to embedded devices: I would not use a library that employs lazy_static. Not only there is no reason whatsoever to calculate CRC tables at runtime when you can simply include them in the source code--it's not like they ever change--or at least do it at compile-time, but on a real-time system this would easily cause a missed deadline by whichever code path calls the corresponding CRC function first.

@vitiral
Copy link
Contributor Author

vitiral commented May 29, 2017

Huh, I wasn't thinking about that. Two questions :

  • why is it not a table already? Can I open a PR for that?
  • it seems to me like rust should be able to have a build_static crate that can do const evaluations like this at build time (using build.rs). Do you have thoughts on that?

@whitequark
Copy link
Contributor

it seems to me like rust should be able to have a build_static crate that can do const evaluations like this at build time (using build.rs). Do you have thoughts on that?

I feel like this is unnecessary complexity and a simple accessory binary included in the source code for posterity and verification but never normally built is more than enough.

@vitiral
Copy link
Contributor Author

vitiral commented May 29, 2017 via email

@vitiral
Copy link
Contributor Author

vitiral commented May 31, 2017

just finished using build_const in the build.rs. I would say it is pretty simple -- but then again I am the developer of build_const.

If you would like I could put it in a script instead so the constant files could be generated whenever was convienient (build_const has helpers to make this transition seamless)

@vitiral
Copy link
Contributor Author

vitiral commented Jun 5, 2017

Fixes #11

Can this be merged? There is literally no benefit to lazy_static for this crate anymore.

@oyvindln
Copy link

oyvindln commented Jul 1, 2017

Looks like the crate author hasn't been active on github or twitter for a few months now. Maybe creating a new crate with the improvements in the open PRs could be considered.

@vitiral
Copy link
Contributor Author

vitiral commented Jul 1, 2017

@mrhooray if you could give me rights on cargo I would gladly take over this repo! I totally understand that sometimes life gets hard 😄

@oyvindln
Copy link

@vitiral Would you be interested in making a fork of this crate and put it on crates.io to use until the author shows up? I can help out with it if needed.

@mrhooray
Copy link
Owner

@vitiral @oyvindln sorry for the late response and thanks @vitiral for integrating with his module to have build time constants

Not very familiar with build process, would this be a breaking change or it'd be fully compatible with v1?


extern crate build_const;

pub fn make_table_crc32(poly: u32) -> [u32; 256] {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does it make sense to move these two make table fns to a util file/module so that we don't have to repeat them in crc32.rs and crc64.rs

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We could move them into an internal "crate" which both build.rs and the individual modules depend on. I can do that if you would like.

I also didn't like copy/pasting them.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moving make_table out of crc32/crc64 is a breaking change since they're public
i'll see weather we could reference them in build.rs after merging.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was thinking we could have an internal crate which build.rs used and some of the functions were re-exported in crc32 and crc64 -- making it non-breaking.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point. let me try that

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#16 was created to address this

@vitiral
Copy link
Contributor Author

vitiral commented Jul 17, 2017

@mrhooray it is not a breaking change, it just removes a dependency (and adds one) and allows for use in no_std libraries.

@mrhooray mrhooray merged commit 1ae49cb into mrhooray:master Jul 18, 2017
@mrhooray mrhooray mentioned this pull request Aug 8, 2017
mrhooray pushed a commit that referenced this pull request Nov 19, 2017
mrhooray added a commit that referenced this pull request Nov 19, 2017
mrhooray added a commit that referenced this pull request Nov 20, 2017
mrhooray added a commit that referenced this pull request Nov 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants