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

Turn the no_std feature into default-enabled std #74

Merged
merged 1 commit into from Jul 8, 2023

Conversation

kupiakos
Copy link
Contributor

@kupiakos kupiakos commented Jun 10, 2023

This gets #68 over the finish line to being a functional #![no_std] library.

This also:

  • fixes the no_std not being enabled due to a swapped cfg_attr.
  • tests this builds with a #![no_std] binary.
  • A lot of the cfg's have been removed due to being unneeded.
  • adds a new dependency
  • updates the version to 2.0
  • adds a ci command to to use cargo-no-std to check no-std

Some notes on changes from #68:

Everything in core is a subset of things in std. core is available in std environments, so if you're building a no_std-compatible library, it's best to import things that don't require std from core.

core2 is also meant to be used as a no_std polyfill with its std feature. That is, you can reference core2::io, and if the std feature is enabled, it actually references std::io.

Cargo.toml Outdated Show resolved Hide resolved

[dev-dependencies]
libflate = { path = "../", version = "1" }
libflate = { path = "../", version = "1", default-features = false }
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
libflate = { path = "../", version = "1", default-features = false }
libflate = { path = "../", version = "2", default-features = false }

Or, just remove the version completely. Since we're using a path dependency here, the version isn't necessary.

Copy link
Contributor Author

@kupiakos kupiakos Jun 12, 2023

Choose a reason for hiding this comment

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

IIUC it's necessary for crates.io and docs.rs to have version declarations in order to build docs and run crater tests correctly

Copy link
Contributor

Choose a reason for hiding this comment

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

That's usually correct, but with path dependencies you don't need to specify version. You can specify the version, but if you do, it has to match the Cargo.toml version (meaning you would need to make the above edit).

Copy link
Contributor Author

@kupiakos kupiakos Jun 13, 2023

Choose a reason for hiding this comment

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

I will be keeping both version and path specifiers.

with path dependencies you don't need to specify version

The issue is with building tests using crates.io sources, since cargo publish packages the source of just that crate as a tarball, instead of having access to the full git repository. So, if a dependency is specified with just a path specifier, I doubt docs.rs or crates.io-side unit tests will be able to run correctly. Cargo calls out the distinction that crates.io has here in its documentation:

The git or path dependency will be used locally (in which case the version is checked against the local copy), and when published to a registry like crates.io, it will use the registry version.

For an example in the wild, see serde, which in its dev-dependencies imports serde_derive using both path and version specifiers.

Copy link
Contributor

Choose a reason for hiding this comment

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

For an example in the wild, see serde, which in its dev-dependencies imports serde_derive using both path and version specifiers.

Right on, then the suggested edit should work. Necessary with the major version bump.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done. I went with the same style as writing 2.0 instead of 2 if that makes a difference to you.

src/deflate/mod.rs Outdated Show resolved Hide resolved
src/bit.rs Outdated Show resolved Hide resolved
src/gzip.rs Show resolved Hide resolved
src/util.rs Show resolved Hide resolved
src/zlib.rs Show resolved Hide resolved
@rmsyn
Copy link
Contributor

rmsyn commented Jun 10, 2023

Some minor edits for imports to fix std/no_std test builds.

There is also a needed change in a file you didn't edit, src/lz77.rs:

    use crate::deflate::symbol::Symbol;
+   #[cfg(not(feature = "std"))]
+   use alloc::{vec, vec::Vec};

Otherwise, LGTM. Thanks for adding the example binary, and test runner!

.github/workflows/ci.yml Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
src/deflate/encode.rs Outdated Show resolved Hide resolved
src/deflate/encode.rs Outdated Show resolved Hide resolved
src/deflate/encode.rs Outdated Show resolved Hide resolved
src/finish.rs Outdated Show resolved Hide resolved
src/finish.rs Outdated Show resolved Hide resolved
src/gzip.rs Outdated Show resolved Hide resolved
@rmsyn
Copy link
Contributor

rmsyn commented Jun 13, 2023

@kupiakos Please run both std and no_std test builds, and make sure they complete successfully.

# std tests
cargo test --all

# no_std tests
cargo test --all --no-default-features

They complete successfully with the suggested edits in this PR.

src/deflate/decode.rs Outdated Show resolved Hide resolved
src/gzip.rs Outdated Show resolved Hide resolved
kupiakos added a commit to kupiakos/libflate that referenced this pull request Jun 13, 2023
kupiakos added a commit to kupiakos/libflate that referenced this pull request Jun 13, 2023
@kupiakos
Copy link
Contributor Author

@rmsyn PTAL at the changes. Again, my apologies on missing the #![no_std] tests. In my defense, most of the embedded unit tests I work with don't have a std feature, they're default #![no_std] and so I forget cargo test --no-default-features is even an option 😄

@sile Can you check that the Github workflow works as intended? Not sure if @rmsyn can.

.github/workflows/ci.yml Outdated Show resolved Hide resolved
@rmsyn
Copy link
Contributor

rmsyn commented Jun 14, 2023

PTAL at the changes.

LGTM, all the tests pass under std and no_std builds. Not sure about the CI runners, but they look like they should work now.

edit: one kind of hacky way to see if test runners work is to open a PR against your fork of the repository. It should run the CI. Not a local way to run CI, but could be useful.

@sile
Copy link
Owner

sile commented Jun 18, 2023

@kupiakos Some CI checks have failed (in case you haven't noticed yet).

@kupiakos
Copy link
Contributor Author

kupiakos commented Jul 8, 2023

Sorry for taking so long to get to this. It was a mistyped flag many things. I'm figuring out testing the CI on my PR as suggested, though feel free to approve your workflow when you see this.

This also:
- fixes the `no_std` not being enabled due to a swapped `cfg_attr`.
- tests this builds with a `#![no_std]` binary.
- A lot of the cfg's have been removed due to being unneeded.
- adds a new dependency
- updates the version to 2.0
- adds a ci command to to use cargo-no-std to check no-std

Some notes on changes from sile#68:

Everything in `core` is a subset of things in `std`.
`core` is available in `std` environments, so if you're building
a `no_std`-compatible library, it's best to import things that
don't _require_ `std` from `core.

core2 is also meant to be used as a `no_std` polyfill with its
`std` feature. That is, you can reference `core2::io`, and if the
`std` feature is enabled, it actually references `std::io`.
@kupiakos
Copy link
Contributor Author

kupiakos commented Jul 8, 2023

@sile I've confirmed CI works on my end, and have squashed all the fixup commits for a cleaner history.

Copy link
Owner

@sile sile left a comment

Choose a reason for hiding this comment

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

LGTM, thank you!

@sile sile merged commit cc5fb68 into sile:master Jul 8, 2023
19 checks passed
@sile
Copy link
Owner

sile commented Jul 8, 2023

Thank you too, @rmsyn, for your review!

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

3 participants